104 #undef PROFILE_THE_BEAST 107 typedef unsigned char ubyte;
108 typedef signed char sbyte;
146 static const vector
unsigned char 147 perm_rgb_0 = { 0x00, 0x01, 0x10, 0x02, 0x03, 0x11, 0x04, 0x05,
148 0x12, 0x06, 0x07, 0x13, 0x08, 0x09, 0x14, 0x0a },
149 perm_rgb_1 = { 0x0b, 0x15, 0x0c, 0x0d, 0x16, 0x0e, 0x0f, 0x17,
150 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f },
151 perm_rgb_2 = { 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
152 0x00, 0x01, 0x18, 0x02, 0x03, 0x19, 0x04, 0x05 },
153 perm_rgb_3 = { 0x1a, 0x06, 0x07, 0x1b, 0x08, 0x09, 0x1c, 0x0a,
154 0x0b, 0x1d, 0x0c, 0x0d, 0x1e, 0x0e, 0x0f, 0x1f };
156 #define vec_merge3(x2, x1, x0, y0, y1, y2) \ 158 __typeof__(x0) o0, o2, o3; \ 159 o0 = vec_mergeh(x0, x1); \ 160 y0 = vec_perm(o0, x2, perm_rgb_0); \ 161 o2 = vec_perm(o0, x2, perm_rgb_1); \ 162 o3 = vec_mergel(x0, x1); \ 163 y1 = vec_perm(o3, o2, perm_rgb_2); \ 164 y2 = vec_perm(o3, o2, perm_rgb_3); \ 167 #define vec_mstbgr24(x0, x1, x2, ptr) \ 169 __typeof__(x0) _0, _1, _2; \ 170 vec_merge3(x0, x1, x2, _0, _1, _2); \ 171 vec_st(_0, 0, ptr++); \ 172 vec_st(_1, 0, ptr++); \ 173 vec_st(_2, 0, ptr++); \ 176 #define vec_mstrgb24(x0, x1, x2, ptr) \ 178 __typeof__(x0) _0, _1, _2; \ 179 vec_merge3(x2, x1, x0, _0, _1, _2); \ 180 vec_st(_0, 0, ptr++); \ 181 vec_st(_1, 0, ptr++); \ 182 vec_st(_2, 0, ptr++); \ 189 #define vec_mstrgb32(T, x0, x1, x2, x3, ptr) \ 192 _0 = vec_mergeh(x0, x1); \ 193 _1 = vec_mergeh(x2, x3); \ 194 _2 = (T) vec_mergeh((vector unsigned short) _0, \ 195 (vector unsigned short) _1); \ 196 _3 = (T) vec_mergel((vector unsigned short) _0, \ 197 (vector unsigned short) _1); \ 198 vec_st(_2, 0 * 16, (T *) ptr); \ 199 vec_st(_3, 1 * 16, (T *) ptr); \ 200 _0 = vec_mergel(x0, x1); \ 201 _1 = vec_mergel(x2, x3); \ 202 _2 = (T) vec_mergeh((vector unsigned short) _0, \ 203 (vector unsigned short) _1); \ 204 _3 = (T) vec_mergel((vector unsigned short) _0, \ 205 (vector unsigned short) _1); \ 206 vec_st(_2, 2 * 16, (T *) ptr); \ 207 vec_st(_3, 3 * 16, (T *) ptr); \ 225 (vector signed short) \ 226 vec_perm(x, (__typeof__(x)) { 0 }, \ 227 ((vector unsigned char) { \ 228 0x10, 0x00, 0x10, 0x01, 0x10, 0x02, 0x10, 0x03, \ 229 0x10, 0x04, 0x10, 0x05, 0x10, 0x06, 0x10, 0x07 })) 232 (vector signed short) \ 233 vec_perm(x, (__typeof__(x)) { 0 }, \ 234 ((vector unsigned char) { \ 235 0x10, 0x08, 0x10, 0x09, 0x10, 0x0A, 0x10, 0x0B, \ 236 0x10, 0x0C, 0x10, 0x0D, 0x10, 0x0E, 0x10, 0x0F })) 238 #define vec_clip_s16(x) \ 239 vec_max(vec_min(x, ((vector signed short) { \ 240 235, 235, 235, 235, 235, 235, 235, 235 })), \ 241 ((vector signed short) { 16, 16, 16, 16, 16, 16, 16, 16 })) 243 #define vec_packclp(x, y) \ 244 (vector unsigned char) \ 245 vec_packs((vector unsigned short) \ 246 vec_max(x, ((vector signed short) { 0 })), \ 247 (vector unsigned short) \ 248 vec_max(y, ((vector signed short) { 0 }))) 250 static inline void cvtyuvtoRGB(
SwsContext *c, vector
signed short Y,
251 vector
signed short U, vector
signed short V,
252 vector
signed short *
R, vector
signed short *
G,
253 vector
signed short *
B)
255 vector
signed short vx, ux, uvx;
257 Y = vec_mradds(Y, c->CY, c->OY);
258 U = vec_sub(U, (vector
signed short)
259 vec_splat((vector
signed short) { 128 }, 0));
260 V = vec_sub(V, (vector
signed short)
261 vec_splat((vector
signed short) { 128 }, 0));
264 ux = vec_sl(U, c->CSHIFT);
265 *B = vec_mradds(ux, c->CBU, Y);
268 vx = vec_sl(V, c->CSHIFT);
269 *R = vec_mradds(vx, c->CRV, Y);
272 uvx = vec_mradds(U, c->CGU, Y);
273 *G = vec_mradds(V, c->CGV, uvx);
282 #define DEFCSP420_CVT(name, out_pixels) \ 283 static int altivec_ ## name(SwsContext *c, const unsigned char **in, \ 284 int *instrides, int srcSliceY, int srcSliceH, \ 285 unsigned char **oplanes, int *outstrides) \ 290 int instrides_scl[3]; \ 291 vector unsigned char y0, y1; \ 293 vector signed char u, v; \ 295 vector signed short Y0, Y1, Y2, Y3; \ 296 vector signed short U, V; \ 297 vector signed short vx, ux, uvx; \ 298 vector signed short vx0, ux0, uvx0; \ 299 vector signed short vx1, ux1, uvx1; \ 300 vector signed short R0, G0, B0; \ 301 vector signed short R1, G1, B1; \ 302 vector unsigned char R, G, B; \ 304 const vector unsigned char *y1ivP, *y2ivP, *uivP, *vivP; \ 305 vector unsigned char align_perm; \ 307 vector signed short lCY = c->CY; \ 308 vector signed short lOY = c->OY; \ 309 vector signed short lCRV = c->CRV; \ 310 vector signed short lCBU = c->CBU; \ 311 vector signed short lCGU = c->CGU; \ 312 vector signed short lCGV = c->CGV; \ 313 vector unsigned short lCSHIFT = c->CSHIFT; \ 315 const ubyte *y1i = in[0]; \ 316 const ubyte *y2i = in[0] + instrides[0]; \ 317 const ubyte *ui = in[1]; \ 318 const ubyte *vi = in[2]; \ 320 vector unsigned char *oute = \ 321 (vector unsigned char *) \ 322 (oplanes[0] + srcSliceY * outstrides[0]); \ 323 vector unsigned char *outo = \ 324 (vector unsigned char *) \ 325 (oplanes[0] + srcSliceY * outstrides[0] + outstrides[0]); \ 328 instrides_scl[0] = instrides[0] * 2 - w; \ 330 instrides_scl[1] = instrides[1] - w / 2; \ 332 instrides_scl[2] = instrides[2] - w / 2; \ 334 for (i = 0; i < h / 2; i++) { \ 335 vec_dstst(outo, (0x02000002 | (((w * 3 + 32) / 32) << 16)), 0); \ 336 vec_dstst(oute, (0x02000002 | (((w * 3 + 32) / 32) << 16)), 1); \ 338 for (j = 0; j < w / 16; j++) { \ 339 y1ivP = (const vector unsigned char *) y1i; \ 340 y2ivP = (const vector unsigned char *) y2i; \ 341 uivP = (const vector unsigned char *) ui; \ 342 vivP = (const vector unsigned char *) vi; \ 344 align_perm = vec_lvsl(0, y1i); \ 345 y0 = (vector unsigned char) \ 346 vec_perm(y1ivP[0], y1ivP[1], align_perm); \ 348 align_perm = vec_lvsl(0, y2i); \ 349 y1 = (vector unsigned char) \ 350 vec_perm(y2ivP[0], y2ivP[1], align_perm); \ 352 align_perm = vec_lvsl(0, ui); \ 353 u = (vector signed char) \ 354 vec_perm(uivP[0], uivP[1], align_perm); \ 356 align_perm = vec_lvsl(0, vi); \ 357 v = (vector signed char) \ 358 vec_perm(vivP[0], vivP[1], align_perm); \ 360 u = (vector signed char) \ 362 (vector signed char) \ 363 vec_splat((vector signed char) { 128 }, 0)); \ 364 v = (vector signed char) \ 366 (vector signed char) \ 367 vec_splat((vector signed char) { 128 }, 0)); \ 369 U = vec_unpackh(u); \ 370 V = vec_unpackh(v); \ 377 Y0 = vec_mradds(Y0, lCY, lOY); \ 378 Y1 = vec_mradds(Y1, lCY, lOY); \ 379 Y2 = vec_mradds(Y2, lCY, lOY); \ 380 Y3 = vec_mradds(Y3, lCY, lOY); \ 383 ux = vec_sl(U, lCSHIFT); \ 384 ux = vec_mradds(ux, lCBU, (vector signed short) { 0 }); \ 385 ux0 = vec_mergeh(ux, ux); \ 386 ux1 = vec_mergel(ux, ux); \ 389 vx = vec_sl(V, lCSHIFT); \ 390 vx = vec_mradds(vx, lCRV, (vector signed short) { 0 }); \ 391 vx0 = vec_mergeh(vx, vx); \ 392 vx1 = vec_mergel(vx, vx); \ 395 uvx = vec_mradds(U, lCGU, (vector signed short) { 0 }); \ 396 uvx = vec_mradds(V, lCGV, uvx); \ 397 uvx0 = vec_mergeh(uvx, uvx); \ 398 uvx1 = vec_mergel(uvx, uvx); \ 400 R0 = vec_add(Y0, vx0); \ 401 G0 = vec_add(Y0, uvx0); \ 402 B0 = vec_add(Y0, ux0); \ 403 R1 = vec_add(Y1, vx1); \ 404 G1 = vec_add(Y1, uvx1); \ 405 B1 = vec_add(Y1, ux1); \ 407 R = vec_packclp(R0, R1); \ 408 G = vec_packclp(G0, G1); \ 409 B = vec_packclp(B0, B1); \ 411 out_pixels(R, G, B, oute); \ 413 R0 = vec_add(Y2, vx0); \ 414 G0 = vec_add(Y2, uvx0); \ 415 B0 = vec_add(Y2, ux0); \ 416 R1 = vec_add(Y3, vx1); \ 417 G1 = vec_add(Y3, uvx1); \ 418 B1 = vec_add(Y3, ux1); \ 419 R = vec_packclp(R0, R1); \ 420 G = vec_packclp(G0, G1); \ 421 B = vec_packclp(B0, B1); \ 424 out_pixels(R, G, B, outo); \ 432 outo += (outstrides[0]) >> 4; \ 433 oute += (outstrides[0]) >> 4; \ 435 ui += instrides_scl[1]; \ 436 vi += instrides_scl[2]; \ 437 y1i += instrides_scl[0]; \ 438 y2i += instrides_scl[0]; \ 443 #define out_abgr(a, b, c, ptr) \ 444 vec_mstrgb32(__typeof__(a), ((__typeof__(a)) { 255 }), c, b, a, ptr) 445 #define out_bgra(a, b, c, ptr) \ 446 vec_mstrgb32(__typeof__(a), c, b, a, ((__typeof__(a)) { 255 }), ptr) 447 #define out_rgba(a, b, c, ptr) \ 448 vec_mstrgb32(__typeof__(a), a, b, c, ((__typeof__(a)) { 255 }), ptr) 449 #define out_argb(a, b, c, ptr) \ 450 vec_mstrgb32(__typeof__(a), ((__typeof__(a)) { 255 }), a, b, c, ptr) 451 #define out_rgb24(a, b, c, ptr) vec_mstrgb24(a, b, c, ptr) 452 #define out_bgr24(a, b, c, ptr) vec_mstbgr24(a, b, c, ptr) 454 DEFCSP420_CVT(yuv2_abgr, out_abgr)
455 DEFCSP420_CVT(yuv2_bgra, out_bgra)
456 DEFCSP420_CVT(yuv2_rgba, out_rgba)
457 DEFCSP420_CVT(yuv2_argb, out_argb)
458 DEFCSP420_CVT(yuv2_rgb24, out_rgb24)
459 DEFCSP420_CVT(yuv2_bgr24, out_bgr24)
463 static const vector
unsigned char 464 demux_u = { 0x10, 0x00, 0x10, 0x00,
465 0x10, 0x04, 0x10, 0x04,
466 0x10, 0x08, 0x10, 0x08,
467 0x10, 0x0c, 0x10, 0x0c },
468 demux_v = { 0x10, 0x02, 0x10, 0x02,
469 0x10, 0x06, 0x10, 0x06,
470 0x10, 0x0A, 0x10, 0x0A,
471 0x10, 0x0E, 0x10, 0x0E },
472 demux_y = { 0x10, 0x01, 0x10, 0x03,
473 0x10, 0x05, 0x10, 0x07,
474 0x10, 0x09, 0x10, 0x0B,
475 0x10, 0x0D, 0x10, 0x0F };
480 static int altivec_uyvy_rgb32(
SwsContext *c,
const unsigned char **
in,
481 int *instrides,
int srcSliceY,
int srcSliceH,
482 unsigned char **oplanes,
int *outstrides)
487 vector
unsigned char uyvy;
488 vector
signed short Y,
U,
V;
489 vector
signed short R0, G0,
B0,
R1, G1,
B1;
490 vector
unsigned char R,
G,
B;
491 vector
unsigned char *
out;
495 out = (vector
unsigned char *) (oplanes[0] + srcSliceY * outstrides[0]);
497 for (i = 0; i < h; i++)
498 for (j = 0; j < w / 16; j++) {
499 uyvy = vec_ld(0, img);
501 U = (vector
signed short)
502 vec_perm(uyvy, (vector
unsigned char) { 0 }, demux_u);
503 V = (vector
signed short)
504 vec_perm(uyvy, (vector
unsigned char) { 0 }, demux_v);
505 Y = (vector
signed short)
506 vec_perm(uyvy, (vector
unsigned char) { 0 }, demux_y);
508 cvtyuvtoRGB(c, Y, U, V, &R0, &G0, &B0);
510 uyvy = vec_ld(16, img);
512 U = (vector
signed short)
513 vec_perm(uyvy, (vector
unsigned char) { 0 }, demux_u);
514 V = (vector
signed short)
515 vec_perm(uyvy, (vector
unsigned char) { 0 }, demux_v);
516 Y = (vector
signed short)
517 vec_perm(uyvy, (vector
unsigned char) { 0 }, demux_y);
519 cvtyuvtoRGB(c, Y, U, V, &R1, &G1, &B1);
521 R = vec_packclp(R0, R1);
522 G = vec_packclp(G0, G1);
523 B = vec_packclp(B0, B1);
526 out_rgba(R, G, B, out);
554 if ((c->
srcW & 0xf) != 0)
564 if ((c->
srcH & 0x1) != 0)
570 return altivec_yuv2_rgb24;
573 return altivec_yuv2_bgr24;
576 return altivec_yuv2_argb;
579 return altivec_yuv2_abgr;
582 return altivec_yuv2_rgba;
585 return altivec_yuv2_bgra;
586 default:
return NULL;
594 return altivec_uyvy_rgb32;
595 default:
return NULL;
605 const int inv_table[4],
613 vector
signed short vec;
619 buf.tmp[0] = ((0xffffLL) * contrast >> 8) >> 9;
620 buf.tmp[1] = -256 * brightness;
621 buf.tmp[2] = (inv_table[0] >> 3) * (contrast >> 16) * (saturation >> 16);
622 buf.tmp[3] = (inv_table[1] >> 3) * (contrast >> 16) * (saturation >> 16);
623 buf.tmp[4] = -((inv_table[2] >> 1) * (contrast >> 16) * (saturation >> 16));
624 buf.tmp[5] = -((inv_table[3] >> 1) * (contrast >> 16) * (saturation >> 16));
626 c->CSHIFT = (vector
unsigned short) vec_splat_u16(2);
627 c->CY = vec_splat((vector
signed short) buf.vec, 0);
628 c->OY = vec_splat((vector
signed short) buf.vec, 1);
629 c->CRV = vec_splat((vector
signed short) buf.vec, 2);
630 c->CBU = vec_splat((vector
signed short) buf.vec, 3);
631 c->CGU = vec_splat((vector
signed short) buf.vec, 4);
632 c->CGV = vec_splat((vector
signed short) buf.vec, 5);
640 const int16_t *lumFilter,
641 const int16_t **lumSrc,
643 const int16_t *chrFilter,
644 const int16_t **chrUSrc,
645 const int16_t **chrVSrc,
647 const int16_t **alpSrc,
653 vector
signed short X, X0, X1, Y0, U0, V0, Y1, U1, V1,
U,
V;
654 vector
signed short R0, G0,
B0,
R1, G1,
B1;
656 vector
unsigned char R,
G,
B;
657 vector
unsigned char *
out, *nout;
659 vector
signed short RND = vec_splat_s16(1 << 3);
660 vector
unsigned short SCL = vec_splat_u16(4);
663 vector
signed short *YCoeffs, *CCoeffs;
665 YCoeffs = c->vYCoeffsBank + dstY * lumFilterSize;
666 CCoeffs = c->vCCoeffsBank + dstY * chrFilterSize;
668 out = (vector
unsigned char *) dest;
670 for (i = 0; i < dstW; i += 16) {
674 for (j = 0; j < lumFilterSize; j++) {
675 X0 = vec_ld(0, &lumSrc[j][i]);
676 X1 = vec_ld(16, &lumSrc[j][i]);
677 Y0 = vec_mradds(X0, YCoeffs[j], Y0);
678 Y1 = vec_mradds(X1, YCoeffs[j], Y1);
684 for (j = 0; j < chrFilterSize; j++) {
685 X = vec_ld(0, &chrUSrc[j][i / 2]);
686 U = vec_mradds(X, CCoeffs[j], U);
687 X = vec_ld(0, &chrVSrc[j][i / 2]);
688 V = vec_mradds(X, CCoeffs[j], V);
692 Y0 = vec_sra(Y0, SCL);
693 Y1 = vec_sra(Y1, SCL);
697 Y0 = vec_clip_s16(Y0);
698 Y1 = vec_clip_s16(Y1);
711 U0 = vec_mergeh(U, U);
712 V0 = vec_mergeh(V, V);
714 U1 = vec_mergel(U, U);
715 V1 = vec_mergel(V, V);
717 cvtyuvtoRGB(c, Y0, U0, V0, &R0, &G0, &B0);
718 cvtyuvtoRGB(c, Y1, U1, V1, &R1, &G1, &B1);
720 R = vec_packclp(R0, R1);
721 G = vec_packclp(G0, G1);
722 B = vec_packclp(B0, B1);
726 out_abgr(R, G, B, out);
729 out_bgra(R, G, B, out);
732 out_rgba(R, G, B, out);
735 out_argb(R, G, B, out);
738 out_rgb24(R, G, B, out);
741 out_bgr24(R, G, B, out);
747 static int printed_error_message;
748 if (!printed_error_message) {
750 "altivec_yuv2packedX doesn't support %s output\n",
752 printed_error_message = 1;
765 for (j = 0; j < lumFilterSize; j++) {
766 X0 = vec_ld(0, &lumSrc[j][i]);
767 X1 = vec_ld(16, &lumSrc[j][i]);
768 Y0 = vec_mradds(X0, YCoeffs[j], Y0);
769 Y1 = vec_mradds(X1, YCoeffs[j], Y1);
775 for (j = 0; j < chrFilterSize; j++) {
776 X = vec_ld(0, &chrUSrc[j][i / 2]);
777 U = vec_mradds(X, CCoeffs[j], U);
778 X = vec_ld(0, &chrVSrc[j][i / 2]);
779 V = vec_mradds(X, CCoeffs[j], V);
783 Y0 = vec_sra(Y0, SCL);
784 Y1 = vec_sra(Y1, SCL);
788 Y0 = vec_clip_s16(Y0);
789 Y1 = vec_clip_s16(Y1);
802 U0 = vec_mergeh(U, U);
803 V0 = vec_mergeh(V, V);
805 U1 = vec_mergel(U, U);
806 V1 = vec_mergel(V, V);
808 cvtyuvtoRGB(c, Y0, U0, V0, &R0, &G0, &B0);
809 cvtyuvtoRGB(c, Y1, U1, V1, &R1, &G1, &B1);
811 R = vec_packclp(R0, R1);
812 G = vec_packclp(G0, G1);
813 B = vec_packclp(B0, B1);
815 nout = (vector
unsigned char *) scratch;
818 out_abgr(R, G, B, nout);
821 out_bgra(R, G, B, nout);
824 out_rgba(R, G, B, nout);
827 out_argb(R, G, B, nout);
830 out_rgb24(R, G, B, nout);
833 out_bgr24(R, G, B, nout);
838 "altivec_yuv2packedX doesn't support %s output\n",
843 memcpy(&((uint32_t *) dest)[i], scratch, (dstW - i) / 4);
847 #define YUV2PACKEDX_WRAPPER(suffix, pixfmt) \ 848 void ff_yuv2 ## suffix ## _X_altivec(SwsContext *c, \ 849 const int16_t *lumFilter, \ 850 const int16_t **lumSrc, \ 852 const int16_t *chrFilter, \ 853 const int16_t **chrUSrc, \ 854 const int16_t **chrVSrc, \ 856 const int16_t **alpSrc, \ 857 uint8_t *dest, int dstW, int dstY) \ 859 yuv2packedX_altivec(c, lumFilter, lumSrc, lumFilterSize, \ 860 chrFilter, chrUSrc, chrVSrc, \ 861 chrFilterSize, alpSrc, \ 862 dest, dstW, dstY, pixfmt); \ packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1
const char * sws_format_name(enum AVPixelFormat format)
#define AV_CPU_FLAG_ALTIVEC
standard
av_cold void ff_yuv2rgb_init_tables_ppc(SwsContext *c, const int inv_table[4], int brightness, int contrast, int saturation)
#define AV_LOG_WARNING
Something somehow does not look correct.
packed RGB 8:8:8, 24bpp, RGBRGB...
#define DECLARE_ALIGNED(n, t, v)
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method !=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2) { ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc) { av_free(ac);return NULL;} return ac;} in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar) { ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar ? ac->channels :1;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_dlog(ac->avr, "%d samples - audio_convert: %s to %s (dithered)\", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> out
Macro definitions for various function/variable attributes.
int srcH
Height of source luma/alpha planes.
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
external api for the swscale stuff
enum AVPixelFormat dstFormat
Destination pixel format.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method !=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2) { ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc) { av_free(ac);return NULL;} return ac;} in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar) { ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar ? ac->channels :1;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_dlog(ac->avr, "%d samples - audio_convert: %s to %s (dithered)\", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
#define R0(v, w, x, y, z, i)
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
void av_log(void *avcl, int level, const char *fmt,...)
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
as above, but U and V bytes are swapped
packed RGB 8:8:8, 24bpp, BGRBGR...
int(* SwsFunc)(struct SwsContext *context, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dst[], int dstStride[])
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
av_cold SwsFunc ff_yuv2rgb_init_ppc(SwsContext *c)
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
enum AVPixelFormat srcFormat
Source pixel format.
int srcW
Width of source luma/alpha planes.
AVPixelFormat
Pixel format.