comparison libswscale/utils.c @ 30923:0be6ed163321

libswscale: Relicense almost all x86 assembler optimizations as LGPL. This is of course done with permissions from the authors. The only GPL component left are MMX optimizations for YUV to RGB conversion.
author diego
date Sat, 27 Mar 2010 11:31:02 +0000
parents f91ad62a2281
children 100a50819c58
comparison
equal deleted inserted replaced
30922:7e3b047c51e7 30923:0be6ed163321
1 /* 1 /*
2 * Copyright (C) 2001-2003 Michael Niedermayer <michaelni@gmx.at> 2 * Copyright (C) 2001-2003 Michael Niedermayer <michaelni@gmx.at>
3 * 3 *
4 * This file is part of FFmpeg. 4 * This file is part of FFmpeg.
5 * 5 *
6 * FFmpeg is free software; you can redistribute it and/or modify 6 * FFmpeg is free software; you can redistribute it and/or
7 * it under the terms of the GNU General Public License as published by 7 * modify it under the terms of the GNU Lesser General Public
8 * the Free Software Foundation; either version 2 of the License, or 8 * License as published by the Free Software Foundation; either
9 * (at your option) any later version. 9 * version 2.1 of the License, or (at your option) any later version.
10 * 10 *
11 * FFmpeg is distributed in the hope that it will be useful, 11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * GNU General Public License for more details. 14 * Lesser General Public License for more details.
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU Lesser General Public
17 * along with FFmpeg; if not, write to the Free Software 17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 *
20 * the C code (not assembly, mmx, ...) of this file can be used
21 * under the LGPL license too
22 */ 19 */
23 20
24 #define _SVID_SOURCE //needed for MAP_ANONYMOUS 21 #define _SVID_SOURCE //needed for MAP_ANONYMOUS
25 #include <inttypes.h> 22 #include <inttypes.h>
26 #include <string.h> 23 #include <string.h>
506 av_free(filter); 503 av_free(filter);
507 av_free(filter2); 504 av_free(filter2);
508 return ret; 505 return ret;
509 } 506 }
510 507
511 #if ARCH_X86 && (HAVE_MMX2 || CONFIG_RUNTIME_CPUDETECT) && CONFIG_GPL 508 #if ARCH_X86 && (HAVE_MMX2 || CONFIG_RUNTIME_CPUDETECT)
512 static int initMMX2HScaler(int dstW, int xInc, uint8_t *filterCode, int16_t *filter, int32_t *filterPos, int numSplits) 509 static int initMMX2HScaler(int dstW, int xInc, uint8_t *filterCode, int16_t *filter, int32_t *filterPos, int numSplits)
513 { 510 {
514 uint8_t *fragmentA; 511 uint8_t *fragmentA;
515 x86_reg imm8OfPShufW1A; 512 x86_reg imm8OfPShufW1A;
516 x86_reg imm8OfPShufW2A; 513 x86_reg imm8OfPShufW2A;
664 if (filterCode) 661 if (filterCode)
665 filterPos[((i/2)+1)&(~1)]= xpos>>16; // needed to jump to the next part 662 filterPos[((i/2)+1)&(~1)]= xpos>>16; // needed to jump to the next part
666 663
667 return fragmentPos + 1; 664 return fragmentPos + 1;
668 } 665 }
669 #endif /* ARCH_X86 && (HAVE_MMX2 || CONFIG_RUNTIME_CPUDETECT) && CONFIG_GPL */ 666 #endif /* ARCH_X86 && (HAVE_MMX2 || CONFIG_RUNTIME_CPUDETECT) */
670 667
671 static void getSubSampleFactors(int *h, int *v, enum PixelFormat format) 668 static void getSubSampleFactors(int *h, int *v, enum PixelFormat format)
672 { 669 {
673 *h = av_pix_fmt_descriptors[format].log2_chroma_w; 670 *h = av_pix_fmt_descriptors[format].log2_chroma_w;
674 *v = av_pix_fmt_descriptors[format].log2_chroma_h; 671 *v = av_pix_fmt_descriptors[format].log2_chroma_h;
949 } 946 }
950 } 947 }
951 948
952 /* precalculate horizontal scaler filter coefficients */ 949 /* precalculate horizontal scaler filter coefficients */
953 { 950 {
954 #if ARCH_X86 && (HAVE_MMX2 || CONFIG_RUNTIME_CPUDETECT) && CONFIG_GPL 951 #if ARCH_X86 && (HAVE_MMX2 || CONFIG_RUNTIME_CPUDETECT)
955 // can't downscale !!! 952 // can't downscale !!!
956 if (c->canMMX2BeUsed && (flags & SWS_FAST_BILINEAR)) { 953 if (c->canMMX2BeUsed && (flags & SWS_FAST_BILINEAR)) {
957 c->lumMmx2FilterCodeSize = initMMX2HScaler( dstW, c->lumXInc, NULL, NULL, NULL, 8); 954 c->lumMmx2FilterCodeSize = initMMX2HScaler( dstW, c->lumXInc, NULL, NULL, NULL, 8);
958 c->chrMmx2FilterCodeSize = initMMX2HScaler(c->chrDstW, c->chrXInc, NULL, NULL, NULL, 4); 955 c->chrMmx2FilterCodeSize = initMMX2HScaler(c->chrDstW, c->chrXInc, NULL, NULL, NULL, 4);
959 956
981 #ifdef MAP_ANONYMOUS 978 #ifdef MAP_ANONYMOUS
982 mprotect(c->lumMmx2FilterCode, c->lumMmx2FilterCodeSize, PROT_EXEC | PROT_READ); 979 mprotect(c->lumMmx2FilterCode, c->lumMmx2FilterCodeSize, PROT_EXEC | PROT_READ);
983 mprotect(c->chrMmx2FilterCode, c->chrMmx2FilterCodeSize, PROT_EXEC | PROT_READ); 980 mprotect(c->chrMmx2FilterCode, c->chrMmx2FilterCodeSize, PROT_EXEC | PROT_READ);
984 #endif 981 #endif
985 } else 982 } else
986 #endif /* ARCH_X86 && (HAVE_MMX2 || CONFIG_RUNTIME_CPUDETECT) && CONFIG_GPL */ 983 #endif /* ARCH_X86 && (HAVE_MMX2 || CONFIG_RUNTIME_CPUDETECT) */
987 { 984 {
988 const int filterAlign= 985 const int filterAlign=
989 (flags & SWS_CPU_CAPS_MMX) ? 4 : 986 (flags & SWS_CPU_CAPS_MMX) ? 4 :
990 (flags & SWS_CPU_CAPS_ALTIVEC) ? 8 : 987 (flags & SWS_CPU_CAPS_ALTIVEC) ? 8 :
991 1; 988 1;
1538 av_freep(&c->vLumFilterPos); 1535 av_freep(&c->vLumFilterPos);
1539 av_freep(&c->vChrFilterPos); 1536 av_freep(&c->vChrFilterPos);
1540 av_freep(&c->hLumFilterPos); 1537 av_freep(&c->hLumFilterPos);
1541 av_freep(&c->hChrFilterPos); 1538 av_freep(&c->hChrFilterPos);
1542 1539
1543 #if ARCH_X86 && CONFIG_GPL 1540 #if ARCH_X86
1544 #ifdef MAP_ANONYMOUS 1541 #ifdef MAP_ANONYMOUS
1545 if (c->lumMmx2FilterCode) munmap(c->lumMmx2FilterCode, c->lumMmx2FilterCodeSize); 1542 if (c->lumMmx2FilterCode) munmap(c->lumMmx2FilterCode, c->lumMmx2FilterCodeSize);
1546 if (c->chrMmx2FilterCode) munmap(c->chrMmx2FilterCode, c->chrMmx2FilterCodeSize); 1543 if (c->chrMmx2FilterCode) munmap(c->chrMmx2FilterCode, c->chrMmx2FilterCodeSize);
1547 #elif HAVE_VIRTUALALLOC 1544 #elif HAVE_VIRTUALALLOC
1548 if (c->lumMmx2FilterCode) VirtualFree(c->lumMmx2FilterCode, 0, MEM_RELEASE); 1545 if (c->lumMmx2FilterCode) VirtualFree(c->lumMmx2FilterCode, 0, MEM_RELEASE);
1551 av_free(c->lumMmx2FilterCode); 1548 av_free(c->lumMmx2FilterCode);
1552 av_free(c->chrMmx2FilterCode); 1549 av_free(c->chrMmx2FilterCode);
1553 #endif 1550 #endif
1554 c->lumMmx2FilterCode=NULL; 1551 c->lumMmx2FilterCode=NULL;
1555 c->chrMmx2FilterCode=NULL; 1552 c->chrMmx2FilterCode=NULL;
1556 #endif /* ARCH_X86 && CONFIG_GPL */ 1553 #endif /* ARCH_X86 */
1557 1554
1558 av_freep(&c->yuvTable); 1555 av_freep(&c->yuvTable);
1559 1556
1560 av_free(c); 1557 av_free(c);
1561 } 1558 }