TomsMoCompAll.inc 6.77 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
/*
 * GStreamer
 * Copyright (c) 2002 Tom Barry  All rights reserved.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

/*
 * Relicensed for GStreamer from GPL to LGPL with permit from Tom Barry.
 * See: http://bugzilla.gnome.org/show_bug.cgi?id=163578
 */


#ifndef TopFirst
#define TopFirst IsOdd
#endif

#ifdef SEFUNC
#undef SEFUNC
#endif

35 36
#if defined(IS_MMXEXT)
#define SEFUNC(x) Search_Effort_MMXEXT_##x(int src_pitch, int dst_pitch, int rowsize, const unsigned char *pWeaveSrc, const unsigned char *pWeaveSrcP, unsigned char *pWeaveDest, int IsOdd, const unsigned char *pCopySrc, const unsigned char *pCopySrcP, int FldHeight)
37
#elif defined(IS_3DNOW)
38
#define SEFUNC(x) Search_Effort_3DNOW_##x(int src_pitch, int dst_pitch, int rowsize, const unsigned char *pWeaveSrc, const unsigned char *pWeaveSrcP, unsigned char *pWeaveDest, int IsOdd, const unsigned char *pCopySrc, const unsigned char *pCopySrcP, int FldHeight)
39
#elif defined(IS_MMX)
40
#define SEFUNC(x) Search_Effort_MMX_##x(int src_pitch, int dst_pitch, int rowsize, const unsigned char *pWeaveSrc, const unsigned char *pWeaveSrcP, unsigned char *pWeaveDest, int IsOdd, const unsigned char *pCopySrc, const unsigned char *pCopySrcP, int FldHeight)
41 42
#else
#define SEFUNC(x) Search_Effort_C_##x(int src_pitch, int dst_pitch, int rowsize, const unsigned char *pWeaveSrc, const unsigned char *pWeaveSrcP, unsigned char *pWeaveDest, int IsOdd, const unsigned char *pCopySrc, const unsigned char *pCopySrcP, int FldHeight)
43 44 45 46 47 48 49 50 51 52
#endif

#include "TomsMoCompAll2.inc"

#define USE_STRANGE_BOB

#include "TomsMoCompAll2.inc"

#undef USE_STRANGE_BOB

53
#undef SEFUNC
54 55
#if defined(IS_MMXEXT)
#define SEFUNC(x) Search_Effort_MMXEXT_##x(src_pitch, dst_pitch, rowsize, pWeaveSrc, pWeaveSrcP, pWeaveDest, IsOdd, pCopySrc, pCopySrcP, FldHeight)
56 57
#elif defined(IS_3DNOW)
#define SEFUNC(x) Search_Effort_3DNOW_##x(src_pitch, dst_pitch, rowsize, pWeaveSrc, pWeaveSrcP, pWeaveDest, IsOdd, pCopySrc, pCopySrcP, FldHeight)
58
#elif defined(IS_MMX)
59
#define SEFUNC(x) Search_Effort_MMX_##x(src_pitch, dst_pitch, rowsize, pWeaveSrc, pWeaveSrcP, pWeaveDest, IsOdd, pCopySrc, pCopySrcP, FldHeight)
60 61
#else
#define SEFUNC(x) Search_Effort_C_##x(src_pitch, dst_pitch, rowsize, pWeaveSrc, pWeaveSrcP, pWeaveDest, IsOdd, pCopySrc, pCopySrcP, FldHeight)
62
#endif
63

64
void FUNCT_NAME(GstDeinterlaceMethod *d_method, GstDeinterlace* object, GstBuffer *outbuf)
65
{
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
  GstDeinterlaceMethodTomsMoComp *self = GST_DEINTERLACE_METHOD_TOMSMOCOMP (d_method);
  long SearchEffort = self->search_effort;
  int UseStrangeBob = self->strange_bob;
  int IsOdd;
  const unsigned char *pWeaveSrc;
  const unsigned char *pWeaveSrcP;
  unsigned char *pWeaveDest;
  const unsigned char *pCopySrc;
  const unsigned char *pCopySrcP;
  unsigned char *pCopyDest;
  int src_pitch;
  int dst_pitch;
  int rowsize;
  int FldHeight;

81 82
  /* double stride do address just every odd/even scanline */
  src_pitch = object->field_stride;
83 84
  dst_pitch = object->row_stride;
  rowsize   = object->row_stride;
85 86 87 88 89 90 91 92 93 94 95 96
  FldHeight = object->field_height;

  pCopySrc   = GST_BUFFER_DATA(object->field_history[object->history_count-1].buf);
  pCopySrcP  = GST_BUFFER_DATA(object->field_history[object->history_count-3].buf);
  pWeaveSrc  = GST_BUFFER_DATA(object->field_history[object->history_count-2].buf);  
  pWeaveSrcP = GST_BUFFER_DATA(object->field_history[object->history_count-4].buf);

  /* use bottom field and interlace top field */
  if (object->field_history[object->history_count-2].flags == PICTURE_INTERLACED_BOTTOM) {
    IsOdd      = 1;

    // if we have an odd field we copy an even field and weave an odd field
97
    pCopyDest = GST_BUFFER_DATA(outbuf);
98 99 100 101 102 103 104
    pWeaveDest = pCopyDest + dst_pitch;
  }
  /* do it vice verca */
  else {

    IsOdd      = 0;
    // if we have an even field we copy an odd field and weave an even field
105 106
    pCopyDest = GST_BUFFER_DATA(outbuf) + dst_pitch;
    pWeaveDest = GST_BUFFER_DATA(outbuf);
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
  }

  
  // copy 1st and last weave lines 
  Fieldcopy(pWeaveDest, pCopySrc, rowsize,		
	    1, dst_pitch*2, src_pitch);
  Fieldcopy(pWeaveDest+(FldHeight-1)*dst_pitch*2,
	    pCopySrc+(FldHeight-1)*src_pitch, rowsize, 
	    1, dst_pitch*2, src_pitch);
  
#ifdef USE_VERTICAL_FILTER
  // Vertical Filter currently not implemented for DScaler !!
  // copy 1st and last lines the copy field
  Fieldcopy(pCopyDest, pCopySrc, rowsize, 
	    1, dst_pitch*2, src_pitch);
  Fieldcopy(pCopyDest+(FldHeight-1)*dst_pitch*2,
	    pCopySrc+(FldHeight-1)*src_pitch, rowsize, 
	    1, dst_pitch*2, src_pitch);
#else
  
  // copy all of the copy field
  Fieldcopy(pCopyDest, pCopySrc, rowsize, 
	    FldHeight, dst_pitch*2, src_pitch);
#endif	
  // then go fill in the hard part, being variously lazy depending upon
  // SearchEffort

  if(!UseStrangeBob) {
    if (SearchEffort == 0)
      {
	SEFUNC(0);
      }
    else if (SearchEffort <= 1)
      {
	SEFUNC(1);
      }
    /*	else if (SearchEffort <= 2)
	{
	SEFUNC(2);
	}
    */
    else if (SearchEffort <= 3)
      {
	SEFUNC(3);
      }
    else if (SearchEffort <= 5)
      {
	SEFUNC(5);
      }
    else if (SearchEffort <= 9)
      {
	SEFUNC(9);
      }
    else if (SearchEffort <= 11)
      {
	SEFUNC(11);
      }
    else if (SearchEffort <= 13)
      {
	SEFUNC(13);
      }
    else if (SearchEffort <= 15)
      {
	SEFUNC(15);
      }
    else if (SearchEffort <= 19)
      {
	SEFUNC(19);
      }
    else if (SearchEffort <= 21)
      {
	SEFUNC(21);
      }
    else 
      {
	SEFUNC(Max);
      }
  }
  else
    {
      if (SearchEffort == 0)
	{
189
	  SEFUNC(0SB);
190 191 192
	}
      else if (SearchEffort <= 1)
	{
193
	  SEFUNC(1SB);
194 195 196
	}
      /*	else if (SearchEffort <= 2)
		{
197
		SEFUNC(2SB);
198 199 200 201
		}
      */
      else if (SearchEffort <= 3)
	{
202
	  SEFUNC(3SB);
203 204 205
	}
      else if (SearchEffort <= 5)
	{
206
	  SEFUNC(5SB);
207 208 209
	}
      else if (SearchEffort <= 9)
	{
210
	  SEFUNC(9SB);
211 212 213
	}
      else if (SearchEffort <= 11)
	{
214
	  SEFUNC(11SB);
215 216 217
	}
      else if (SearchEffort <= 13)
	{
218
	  SEFUNC(13SB);
219 220 221
	}
      else if (SearchEffort <= 15)
	{
222
	  SEFUNC(15SB);
223 224 225
	}
      else if (SearchEffort <= 19)
	{
226
	  SEFUNC(19SB);
227 228 229
	}
      else if (SearchEffort <= 21)
	{
230
	  SEFUNC(21SB);
231 232 233
	}
      else 
	{
234
	  SEFUNC(MaxSB);
235 236 237
	}
    }

238
#if defined(BUILD_X86_ASM) && !defined(IS_C)
239 240 241
  __asm__ __volatile__("emms");
#endif
}