~ubuntu-branches/ubuntu/precise/ffmpeg-debian/precise

« back to all changes in this revision

Viewing changes to libpostproc/postprocess.c

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2009-01-20 09:20:53 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20090120092053-izz63p40hc98qfgp
Tags: 3:0.svn20090119-1ubuntu1
* merge from debian. LP: #318501
* new version fixes CVE-2008-3230, LP: #253767

Show diffs side-by-side

added added

removed removed

Lines of Context:
79
79
#include <stdio.h>
80
80
#include <stdlib.h>
81
81
#include <string.h>
82
 
#ifdef HAVE_MALLOC_H
83
 
#include <malloc.h>
84
 
#endif
85
82
//#undef HAVE_MMX2
86
83
//#define HAVE_3DNOW
87
84
//#undef HAVE_MMX
95
92
    return LIBPOSTPROC_VERSION_INT;
96
93
}
97
94
 
98
 
#ifdef HAVE_ALTIVEC_H
 
95
#if HAVE_ALTIVEC_H
99
96
#include <altivec.h>
100
97
#endif
101
98
 
105
102
#define TEMP_STRIDE 8
106
103
//#define NUM_BLOCKS_AT_ONCE 16 //not used yet
107
104
 
108
 
#if defined(ARCH_X86)
 
105
#if ARCH_X86
109
106
DECLARE_ASM_CONST(8, uint64_t, w05)= 0x0005000500050005LL;
110
107
DECLARE_ASM_CONST(8, uint64_t, w04)= 0x0004000400040004LL;
111
108
DECLARE_ASM_CONST(8, uint64_t, w20)= 0x0020002000200020LL;
153
150
};
154
151
 
155
152
 
156
 
#if defined(ARCH_X86)
 
153
#if ARCH_X86
157
154
static inline void prefetchnta(void *p)
158
155
{
159
156
    __asm__ volatile(   "prefetchnta (%0)\n\t"
557
554
 
558
555
//Note: we have C, MMX, MMX2, 3DNOW version there is no 3DNOW+MMX2 one
559
556
//Plain C versions
560
 
#if !defined (HAVE_MMX) || defined (RUNTIME_CPUDETECT)
 
557
#if !(HAVE_MMX || HAVE_ALTIVEC) || defined (RUNTIME_CPUDETECT)
561
558
#define COMPILE_C
562
559
#endif
563
560
 
564
 
#ifdef HAVE_ALTIVEC
 
561
#if HAVE_ALTIVEC
565
562
#define COMPILE_ALTIVEC
566
563
#endif //HAVE_ALTIVEC
567
564
 
568
 
#if defined(ARCH_X86)
 
565
#if ARCH_X86
569
566
 
570
 
#if (defined (HAVE_MMX) && !defined (HAVE_3DNOW) && !defined (HAVE_MMX2)) || defined (RUNTIME_CPUDETECT)
 
567
#if (HAVE_MMX && !HAVE_3DNOW && !HAVE_MMX2) || defined (RUNTIME_CPUDETECT)
571
568
#define COMPILE_MMX
572
569
#endif
573
570
 
574
 
#if defined (HAVE_MMX2) || defined (RUNTIME_CPUDETECT)
 
571
#if HAVE_MMX2 || defined (RUNTIME_CPUDETECT)
575
572
#define COMPILE_MMX2
576
573
#endif
577
574
 
578
 
#if (defined (HAVE_3DNOW) && !defined (HAVE_MMX2)) || defined (RUNTIME_CPUDETECT)
 
575
#if (HAVE_3DNOW && !HAVE_MMX2) || defined (RUNTIME_CPUDETECT)
579
576
#define COMPILE_3DNOW
580
577
#endif
581
 
#endif /* defined(ARCH_X86) */
 
578
#endif /* ARCH_X86 */
582
579
 
583
580
#undef HAVE_MMX
 
581
#define HAVE_MMX 0
584
582
#undef HAVE_MMX2
 
583
#define HAVE_MMX2 0
585
584
#undef HAVE_3DNOW
 
585
#define HAVE_3DNOW 0
586
586
#undef HAVE_ALTIVEC
 
587
#define HAVE_ALTIVEC 0
587
588
 
588
589
#ifdef COMPILE_C
589
 
#undef HAVE_MMX
590
 
#undef HAVE_MMX2
591
 
#undef HAVE_3DNOW
592
590
#define RENAME(a) a ## _C
593
591
#include "postprocess_template.c"
594
592
#endif
595
593
 
596
594
#ifdef COMPILE_ALTIVEC
597
595
#undef RENAME
598
 
#define HAVE_ALTIVEC
 
596
#undef HAVE_ALTIVEC
 
597
#define HAVE_ALTIVEC 1
599
598
#define RENAME(a) a ## _altivec
600
599
#include "postprocess_altivec_template.c"
601
600
#include "postprocess_template.c"
604
603
//MMX versions
605
604
#ifdef COMPILE_MMX
606
605
#undef RENAME
607
 
#define HAVE_MMX
608
 
#undef HAVE_MMX2
609
 
#undef HAVE_3DNOW
 
606
#undef HAVE_MMX
 
607
#define HAVE_MMX 1
610
608
#define RENAME(a) a ## _MMX
611
609
#include "postprocess_template.c"
612
610
#endif
614
612
//MMX2 versions
615
613
#ifdef COMPILE_MMX2
616
614
#undef RENAME
617
 
#define HAVE_MMX
618
 
#define HAVE_MMX2
619
 
#undef HAVE_3DNOW
 
615
#undef HAVE_MMX
 
616
#undef HAVE_MMX2
 
617
#define HAVE_MMX 1
 
618
#define HAVE_MMX2 1
620
619
#define RENAME(a) a ## _MMX2
621
620
#include "postprocess_template.c"
622
621
#endif
624
623
//3DNOW versions
625
624
#ifdef COMPILE_3DNOW
626
625
#undef RENAME
627
 
#define HAVE_MMX
 
626
#undef HAVE_MMX
628
627
#undef HAVE_MMX2
629
 
#define HAVE_3DNOW
 
628
#undef HAVE_3DNOW
 
629
#define HAVE_MMX 1
 
630
#define HAVE_MMX2 0
 
631
#define HAVE_3DNOW 1
630
632
#define RENAME(a) a ## _3DNow
631
633
#include "postprocess_template.c"
632
634
#endif
634
636
// minor note: the HAVE_xyz is messed up after that line so do not use it.
635
637
 
636
638
static inline void postProcess(const uint8_t src[], int srcStride, uint8_t dst[], int dstStride, int width, int height,
637
 
        const QP_STORE_T QPs[], int QPStride, int isColor, pp_mode_t *vm, pp_context_t *vc)
 
639
        const QP_STORE_T QPs[], int QPStride, int isColor, pp_mode *vm, pp_context *vc)
638
640
{
639
641
    PPContext *c= (PPContext *)vc;
640
642
    PPMode *ppMode= (PPMode *)vm;
644
646
    // difference would not be measurable here but it is much better because
645
647
    // someone might exchange the CPU whithout restarting MPlayer ;)
646
648
#ifdef RUNTIME_CPUDETECT
647
 
#if defined(ARCH_X86)
 
649
#if ARCH_X86
648
650
    // ordered per speed fastest first
649
651
    if(c->cpuCaps & PP_CPU_CAPS_MMX2)
650
652
        postProcess_MMX2(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
655
657
    else
656
658
        postProcess_C(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
657
659
#else
658
 
#ifdef HAVE_ALTIVEC
 
660
#if HAVE_ALTIVEC
659
661
    if(c->cpuCaps & PP_CPU_CAPS_ALTIVEC)
660
662
            postProcess_altivec(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
661
663
    else
663
665
            postProcess_C(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
664
666
#endif
665
667
#else //RUNTIME_CPUDETECT
666
 
#ifdef HAVE_MMX2
 
668
#if   HAVE_MMX2
667
669
            postProcess_MMX2(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
668
 
#elif defined (HAVE_3DNOW)
 
670
#elif HAVE_3DNOW
669
671
            postProcess_3DNow(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
670
 
#elif defined (HAVE_MMX)
 
672
#elif HAVE_MMX
671
673
            postProcess_MMX(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
672
 
#elif defined (HAVE_ALTIVEC)
 
674
#elif HAVE_ALTIVEC
673
675
            postProcess_altivec(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
674
676
#else
675
677
            postProcess_C(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
730
732
"\n"
731
733
;
732
734
 
733
 
pp_mode_t *pp_get_mode_by_name_and_quality(const char *name, int quality)
 
735
pp_mode *pp_get_mode_by_name_and_quality(const char *name, int quality)
734
736
{
735
737
    char temp[GET_MODE_BUFFER_SIZE];
736
738
    char *p= temp;
905
907
    return ppMode;
906
908
}
907
909
 
908
 
void pp_free_mode(pp_mode_t *mode){
 
910
void pp_free_mode(pp_mode *mode){
909
911
    av_free(mode);
910
912
}
911
913
 
947
949
 
948
950
static const AVClass av_codec_context_class = { "Postproc", context_to_name, NULL };
949
951
 
950
 
pp_context_t *pp_get_context(int width, int height, int cpuCaps){
 
952
pp_context *pp_get_context(int width, int height, int cpuCaps){
951
953
    PPContext *c= av_malloc(sizeof(PPContext));
952
954
    int stride= (width+15)&(~15);    //assumed / will realloc if needed
953
955
    int qpStride= (width+15)/16 + 2; //assumed / will realloc if needed
995
997
                     uint8_t * dst[3], const int dstStride[3],
996
998
                     int width, int height,
997
999
                     const QP_STORE_T *QP_store,  int QPStride,
998
 
                     pp_mode_t *vm,  void *vc, int pict_type)
 
1000
                     pp_mode *vm,  void *vc, int pict_type)
999
1001
{
1000
1002
    int mbWidth = (width+15)>>4;
1001
1003
    int mbHeight= (height+15)>>4;