<html>
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <div class="moz-cite-prefix">Am 21.07.2016 um 16:05 schrieb Nayan
      Deshmukh:<br>
    </div>
    <blockquote
cite="mid:CAFd4ddysXS1hBG0zGQ9aeJT83c07=5Kdkx6sE+GPyXD0UVSZGg@mail.gmail.com"
      type="cite">
      <div dir="ltr">Hi Christian,
        <div><br>
        </div>
        <div>Yes, that is for pixel center adjustment. </div>
        <div><br>
        </div>
        <div>let me give you an example, for lanczos I need frac(x)
          where x is the original </div>
        <div>coordinate before scaling. To calculate that first I
          subtract half_pixel and then</div>
        <div>multiply by the original surface size, which gives me the
          original coordinate.</div>
        <div><br>
        </div>
        <div>eg. if the coordinate before scaling was 24.5 (total size
          300) after 2x it becomes</div>
        <div>49. When the frag shader is executed we get 49.5/600 as the
          coordinate so what </div>
        <div>I do is 49.5/600 - 0.5/600 = 49/600 and then multiply it
          with 300 to get 24.5 the </div>
        <div>original coordinate.</div>
      </div>
    </blockquote>
    <br>
    Well in your case the coordinates are always between 0.0 and 1.0, so
    scaling doesn't affect the coordinate.<br>
    <br>
    You could take a look at how I did that in the weave shader:<br>
    1. In the vertex shader I use 0..width instead of 0..1 for the range
    (from create_vert_shader() in vl_compositor.c):<br>
    <br>
        * o_vtop.x = vtex.x <br>
        * o_vtop.y = vtex.y * tmp.x + 0.25f <br>
    <br>
    2. Then in the fragment shader I just need to do the following to
    get the original coordinate to sample from:<br>
        * t_tc.y = (round(i_tc.y - 0.5) + 0.5) / height * 2<br>
    <br>
    I use 0.25 and "height * 2" here because the top/bottom fields are
    always halve the height and shifted a bit up/down.<br>
    <br>
    For your case that should just be:<br>
    <br>
    o_vtex.x = i_vpos.x * video_width<br>
    o_vtex.y = i_vpos.y * video_height<br>
    <br>
    In the vertex shader and then:<br>
    <br>
    t_tc.x = (round(i_tc.x - 0.5) + 0.5) / video_width<br>
    t_tc.y = (round(i_tc.x - 0.5) + 0.5) / video_height<br>
    <br>
    In the fragment shader to get the correct coordinate. No need to
    actually mess with the destination sizes here.<br>
    <br>
    Regards,<br>
    Christian.<br>
    <br>
    <blockquote
cite="mid:CAFd4ddysXS1hBG0zGQ9aeJT83c07=5Kdkx6sE+GPyXD0UVSZGg@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <div><br>
        </div>
        <div>Regards,<br>
        </div>
        <div>Nayan.</div>
        <div>
          <div class="gmail_extra">
            <div class="gmail_quote">On Thu, Jul 21, 2016 at 7:20 PM,
              Christian König <span dir="ltr"><<a
                  moz-do-not-send="true"
                  href="mailto:deathsimple@vodafone.de">deathsimple@vodafone.de</a>></span>
              wrote:<br>
              <blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
                <div bgcolor="#FFFFFF">
                  <div><span>
                      <blockquote type="cite">
                        <div><br>
                        </div>
                        <div>This seems to be the reason for the
                          artifacts.</div>
                        <div> </div>
                        <blockquote class="gmail_quote"
                          style="margin:0px 0px 0px
0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
                          <div>
                            <div>
                              <blockquote class="gmail_quote"
                                style="margin:0px 0px 0px
0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
                                +   ureg_SUB(shader,
                                ureg_writemask(t_array[0],
                                TGSI_WRITEMASK_XY),<br>
                                +            i_vtex, half_pixel);<br>
                              </blockquote>
                            </div>
                          </div>
                        </blockquote>
                        <div><br>
                        </div>
                        <div>On debugging I found that after removing
                          this ^^^ instruction the artifacts are gone.</div>
                        <div>Not sure why is this happening but the
                          filter is working fine.</div>
                        <div><br>
                        </div>
                        <div>Any ideas Christian?</div>
                      </blockquote>
                      <br>
                    </span> Could it be that your values run out of the
                    representable numeric range? Otherwise I run out of
                    ideas as well.<br>
                    <br>
                    Additional to that I'm not 100% sure I get what are
                    you trying to do here. Is that for the pixel center
                    adjustment?<br>
                    <br>
                    Regards,<br>
                    Christian.
                    <div>
                      <div><br>
                        <br>
                        Am 20.07.2016 um 14:02 schrieb Nayan Deshmukh:<br>
                      </div>
                    </div>
                  </div>
                  <div>
                    <div>
                      <blockquote type="cite">
                        <div dir="ltr">Hi Christian,
                          <div><br>
                          </div>
                          <div>Thanks for the review.</div>
                          <div><br>
                          </div>
                          <div class="gmail_extra"><br>
                            <div class="gmail_quote">On Tue, Jul 19,
                              2016 at 4:58 PM, Christian König <span
                                dir="ltr"><<a moz-do-not-send="true"
                                  href="mailto:deathsimple@vodafone.de">deathsimple@vodafone.de</a>></span>
                              wrote:<br>
                              <blockquote class="gmail_quote"
                                style="margin:0px 0px 0px
0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><span>Am
                                  18.07.2016 um 21:55 schrieb Nayan
                                  Deshmukh:<br>
                                  <blockquote class="gmail_quote"
                                    style="margin:0px 0px 0px
0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
                                    v2: avoCould it be that your values
                                    run out of the representable numeric
                                    range?iding dividing by zero when
                                    calculating lanczos<br>
                                    <br>
                                    Signed-off-by: Nayan Deshmukh <<a
                                      moz-do-not-send="true"
                                      href="mailto:nayan26deshmukh@gmail.com">nayan26deshmukh@gmail.com</a>><br>
                                  </blockquote>
                                  <br>
                                </span> That looks much better, but
                                there are still quite a bunch of
                                artifacts.<br>
                                <br>
                                Take a look at the attached screenshots.
                                good.jpg was created with hqscalling=0,
                                bad with hqscalling=7.<br>
                                <br>
                                Especially on the left side we have
                                lines from top to bottom where there
                                shouldn't be any.<br>
                                <br>
                                Regards,<br>
                                Christian.
                                <div>
                                  <div><br>
                                    <br>
                                    <blockquote class="gmail_quote"
                                      style="margin:0px 0px 0px
0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
                                      ---<br>
                                       
                                      src/gallium/auxiliary/Makefile.sources 
                                           |   2 +<br>
                                       
                                      src/gallium/auxiliary/vl/vl_lanczos_filter.c
                                      | 447 +++++++++++++++++++++++++++<br>
                                       
                                      src/gallium/auxiliary/vl/vl_lanczos_filter.h
                                      |  63 ++++<br>
                                        3 files changed, 512
                                      insertions(+)<br>
                                        create mode 100644
                                      src/gallium/auxiliary/vl/vl_lanczos_filter.c<br>
                                        create mode 100644
                                      src/gallium/auxiliary/vl/vl_lanczos_filter.h<br>
                                      <br>
                                      diff --git
                                      a/src/gallium/auxiliary/Makefile.sources
b/src/gallium/auxiliary/Makefile.sources<br>
                                      index e0311bf..4eb0f65 100644<br>
                                      ---
                                      a/src/gallium/auxiliary/Makefile.sources<br>
                                      +++
                                      b/src/gallium/auxiliary/Makefile.sources<br>
                                      @@ -330,6 +330,8 @@ VL_SOURCES :=
                                      \<br>
                                              vl/vl_deint_filter.h \<br>
                                              vl/vl_idct.c \<br>
                                              vl/vl_idct.h \<br>
                                      +       vl/vl_lanczos_filter.c \<br>
                                      +       vl/vl_lanczos_filter.h \<br>
                                              vl/vl_matrix_filter.c \<br>
                                              vl/vl_matrix_filter.h \<br>
                                              vl/vl_mc.c \<br>
                                      diff --git
                                      a/src/gallium/auxiliary/vl/vl_lanczos_filter.c
b/src/gallium/auxiliary/vl/vl_lanczos_filter.c<br>
                                      new file mode 100644<br>
                                      index 0000000..7c69555<br>
                                      --- /dev/null<br>
                                      +++
                                      b/src/gallium/auxiliary/vl/vl_lanczos_filter.c<br>
                                      @@ -0,0 +1,447 @@<br>
+/**************************************************************************<br>
                                      + *<br>
                                      + * Copyright 2016 Nayan Deshmukh.<br>
                                      + * All Rights Reserved.<br>
                                      + *<br>
                                      + * Permission is hereby granted,
                                      free of charge, to any person
                                      obtaining a<br>
                                      + * copy of this software and
                                      associated documentation files
                                      (the<br>
                                      + * "Software"), to deal in the
                                      Software without restriction,
                                      including<br>
                                      + * without limitation the rights
                                      to use, copy, modify, merge,
                                      publish,<br>
                                      + * distribute, sub license,
                                      and/or sell copies of the
                                      Software, and to<br>
                                      + * permit persons to whom the
                                      Software is furnished to do so,
                                      subject to<br>
                                      + * the following conditions:<br>
                                      + *<br>
                                      + * The above copyright notice and
                                      this permission notice (including
                                      the<br>
                                      + * next paragraph) shall be
                                      included in all copies or
                                      substantial portions<br>
                                      + * of the Software.<br>
                                      + *<br>
                                      + * THE SOFTWARE IS PROVIDED "AS
                                      IS", WITHOUT WARRANTY OF ANY KIND,
                                      EXPRESS<br>
                                      + * OR IMPLIED, INCLUDING BUT NOT
                                      LIMITED TO THE WARRANTIES OF<br>
                                      + * MERCHANTABILITY, FITNESS FOR A
                                      PARTICULAR PURPOSE AND
                                      NON-INFRINGEMENT.<br>
                                      + * IN NO EVENT SHALL VMWARE
                                      AND/OR ITS SUPPLIERS BE LIABLE FOR<br>
                                      + * ANY CLAIM, DAMAGES OR OTHER
                                      LIABILITY, WHETHER IN AN ACTION OF
                                      CONTRACT,<br>
                                      + * TORT OR OTHERWISE, ARISING
                                      FROM, OUT OF OR IN CONNECTION WITH
                                      THE<br>
                                      + * SOFTWARE OR THE USE OR OTHER
                                      DEALINGS IN THE SOFTWARE.<br>
                                      + *<br>
                                      +
**************************************************************************/<br>
                                      +<br>
                                      +#include <stdio.h><br>
                                      +<br>
                                      +#include "pipe/p_context.h"<br>
                                      +<br>
                                      +#include "tgsi/tgsi_ureg.h"<br>
                                      +<br>
                                      +#include "util/u_draw.h"<br>
                                      +#include "util/u_memory.h"<br>
                                      +#include "util/u_math.h"<br>
                                      +#include "util/u_rect.h"<br>
                                      +<br>
                                      +#include "vl_types.h"<br>
                                      +#include "vl_vertex_buffers.h"<br>
                                      +#include "vl_lanczos_filter.h"<br>
                                      +<br>
                                      +enum VS_OUTPUT<br>
                                      +{<br>
                                      +   VS_O_VPOS = 0,<br>
                                      +   VS_O_VTEX = 0<br>
                                      +};<br>
                                      +<br>
                                      +static void *<br>
                                      +create_vert_shader(struct
                                      vl_lanczos_filter *filter)<br>
                                      +{<br>
                                      +   struct ureg_program *shader;<br>
                                      +   struct ureg_src i_vpos;<br>
                                      +   struct ureg_dst o_vpos,
                                      o_vtex;<br>
                                      +<br>
                                      +   shader =
                                      ureg_create(PIPE_SHADER_VERTEX);<br>
                                      +   if (!shader)<br>
                                      +      return NULL;<br>
                                      +<br>
                                      +   i_vpos =
                                      ureg_DECL_vs_input(shader, 0);<br>
                                      +   o_vpos =
                                      ureg_DECL_output(shader,
                                      TGSI_SEMANTIC_POSITION,
                                      VS_O_VPOS);<br>
                                      +   o_vtex =
                                      ureg_DECL_output(shader,
                                      TGSI_SEMANTIC_GENERIC, VS_O_VTEX);<br>
                                      +<br>
                                      +   ureg_MOV(shader, o_vpos,
                                      i_vpos);<br>
                                      +   ureg_MOV(shader, o_vtex,
                                      i_vpos);<br>
                                      +<br>
                                      +   ureg_END(shader);<br>
                                      +<br>
                                      +   return
                                      ureg_create_shader_and_destroy(shader,
                                      filter->pipe);<br>
                                      +}<br>
                                      +<br>
                                      +static void<br>
                                      +create_frag_shader_lanczos(struct
                                      ureg_program *shader, struct
                                      ureg_src a,<br>
                                      +                           struct
                                      ureg_src x, struct ureg_dst
                                      o_fragment)<br>
                                      +{<br>
                                      +   struct ureg_dst temp[8];<br>
                                      +   unsigned i;<br>
                                      +<br>
                                      +   for(i = 0; i < 8; ++i)<br>
                                      +       temp[i] =
                                      ureg_DECL_temporary(shader);<br>
                                      +<br>
                                      +   /*<br>
                                      +    * temp[0] = (x == 0) ? 1.0f :
                                      x<br>
                                      +    * temp[7] = (sin(pi * x) *
                                      sin ((pi * x)/a)) / x^2<br>
                                      +    * o_fragment = (x == 0) ?
                                      1.0f : temp[7]<br>
                                      +    */<br>
                                      +   ureg_MOV(shader, temp[0], x);<br>
                                      +   ureg_SEQ(shader, temp[1], x,
                                      ureg_imm1f(shader, 0.0f));<br>
                                      +<br>
                                      +   ureg_LRP(shader, temp[0],
                                      ureg_src(temp[1]),<br>
                                      +            ureg_imm1f(shader,
                                      1.0f), ureg_src(temp[0]));<br>
                                      +<br>
                                      +   ureg_MUL(shader, temp[2], x,<br>
                                      +            ureg_imm1f(shader,
                                      3.141592));<br>
                                      +   ureg_DIV(shader, temp[3],
                                      ureg_src(temp[2]), a);<br>
                                      +<br>
                                      +   ureg_SIN(shader, temp[4],
                                      ureg_src(temp[2]));<br>
                                      +   ureg_SIN(shader, temp[5],
                                      ureg_src(temp[3]));<br>
                                      +<br>
                                      +   ureg_MUL(shader, temp[6],
                                      ureg_src(temp[4]),<br>
                                      +            ureg_src(temp[5]));<br>
                                      +   ureg_MUL(shader, temp[7],
                                      ureg_imm1f(shader,<br>
                                      +            0.101321), a);<br>
                                      +   ureg_MUL(shader, temp[7],
                                      ureg_src(temp[7]),<br>
                                      +            ureg_src(temp[6]));<br>
                                      +   ureg_DIV(shader, temp[7],
                                      ureg_src(temp[7]),<br>
                                      +            ureg_src(temp[0]));<br>
                                      +   ureg_DIV(shader, o_fragment,<br>
                                      +           ureg_src(temp[7]),
                                      ureg_src(temp[0]));<br>
                                      +<br>
                                      +   ureg_LRP(shader, o_fragment,
                                      ureg_src(temp[1]),<br>
                                      +            ureg_imm1f(shader,
                                      1.0f), ureg_src(o_fragment));<br>
                                      +<br>
                                      +   for(i = 0; i < 8; ++i)<br>
                                      +     
                                       ureg_release_temporary(shader,
                                      temp[i]);<br>
                                      +}<br>
                                      +<br>
                                      +static void *<br>
                                      +create_frag_shader(struct
                                      vl_lanczos_filter *filter,
                                      unsigned num_offsets,<br>
                                      +                   struct
                                      vertex2f *offsets, unsigned a,<br>
                                      +                   unsigned
                                      video_width, unsigned
                                      video_height)<br>
                                      +{<br>
                                      +   struct pipe_screen *screen =
                                      filter->pipe->screen;<br>
                                      +   struct ureg_program *shader;<br>
                                      +   struct ureg_src i_vtex, vtex;<br>
                                      +   struct ureg_src sampler;<br>
                                      +   struct ureg_src half_pixel;<br>
                                      +   struct ureg_dst o_fragment;<br>
                                      +   struct ureg_dst *t_array =
                                      MALLOC(sizeof(struct ureg_dst) *
                                      (num_offsets + 2));<br>
                                      +   struct ureg_dst x, t_sum;<br>
                                      +   unsigned i;<br>
                                      +   bool first;<br>
                                      +<br>
                                      +   if
                                      (screen->get_shader_param(<br>
                                      +      screen,
                                      PIPE_SHADER_FRAGMENT,
                                      PIPE_SHADER_CAP_MAX_TEMPS) <
                                      num_offsets + 2) {<br>
                                      +      return NULL;<br>
                                      +   }<br>
                                      +<br>
                                      +   shader =
                                      ureg_create(PIPE_SHADER_FRAGMENT);<br>
                                      +   if (!shader) {<br>
                                      +      return NULL;<br>
                                      +   }<br>
                                      +<br>
                                      +   i_vtex =
                                      ureg_DECL_fs_input(shader,
                                      TGSI_SEMANTIC_GENERIC, VS_O_VTEX,
                                      TGSI_INTERPOLATE_LINEAR);<br>
                                      +   sampler =
                                      ureg_DECL_sampler(shader, 0);<br>
                                      +<br>
                                      +   for (i = 0; i < num_offsets
                                      + 2; ++i)<br>
                                      +      t_array[i] =
                                      ureg_DECL_temporary(shader);<br>
                                      +   x =
                                      ureg_DECL_temporary(shader);<br>
                                      +<br>
                                      +   half_pixel =
                                      ureg_DECL_constant(shader, 0);<br>
                                      +   o_fragment =
                                      ureg_DECL_output(shader,
                                      TGSI_SEMANTIC_COLOR, 0);<br>
                                      +<br>
                                      +   /*<br>
                                      +    * temp = (i_vtex -
                                      (0.5/dst_size)) * i_size)<br>
                                      +    * x = frac(temp)<br>
                                      +    * vtex = floor(i_vtex)/i_size
                                      + half_pixel<br>
                                      +    */<br>
                                    </blockquote>
                                  </div>
                                </div>
                              </blockquote>
                              <div><br>
                              </div>
                              <div>This seems to be the reason for the
                                artifacts.</div>
                              <div> </div>
                              <blockquote class="gmail_quote"
                                style="margin:0px 0px 0px
0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
                                <div>
                                  <div>
                                    <blockquote class="gmail_quote"
                                      style="margin:0px 0px 0px
0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
                                      +   ureg_SUB(shader,
                                      ureg_writemask(t_array[0],
                                      TGSI_WRITEMASK_XY),<br>
                                      +            i_vtex, half_pixel);<br>
                                    </blockquote>
                                  </div>
                                </div>
                              </blockquote>
                              <div><br>
                              </div>
                              <div>On debugging I found that after
                                removing this ^^^ instruction the
                                artifacts are gone.</div>
                              <div>Not sure why is this happening but
                                the filter is working fine.</div>
                              <div><br>
                              </div>
                              <div>Any ideas Christian?</div>
                              <div><br>
                              </div>
                              <div>Regards,</div>
                              <div>Nayan. </div>
                              <blockquote class="gmail_quote"
                                style="margin:0px 0px 0px
0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
                                <div>
                                  <div>
                                    <blockquote class="gmail_quote"
                                      style="margin:0px 0px 0px
0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
                                      +   ureg_MUL(shader,
                                      ureg_writemask(t_array[1],
                                      TGSI_WRITEMASK_XY),<br>
                                      +            ureg_src(t_array[0]),
                                      ureg_imm2f(shader, video_width,
                                      video_height));<br>
                                      +   ureg_FRC(shader,
                                      ureg_writemask(x,
                                      TGSI_WRITEMASK_XY),<br>
                                      +           
                                      ureg_src(t_array[1]));<br>
                                      +<br>
                                      +   ureg_FLR(shader,
                                      ureg_writemask(t_array[1],
                                      TGSI_WRITEMASK_XY),<br>
                                      +           
                                      ureg_src(t_array[1]));<br>
                                      +   ureg_DIV(shader,
                                      ureg_writemask(t_array[1],
                                      TGSI_WRITEMASK_XY),<br>
                                      +            ureg_src(t_array[1]),
                                      ureg_imm2f(shader, video_width,
                                      video_height));<br>
                                      +   ureg_ADD(shader,
                                      ureg_writemask(t_array[1],
                                      TGSI_WRITEMASK_XY),<br>
                                      +            ureg_src(t_array[1]),
                                      half_pixel);<br>
                                      +   /*<br>
                                      +    * t_array[2..*] = vtex +
                                      offset[0..*]<br>
                                      +    * t_array[2..*] =
                                      tex(t_array[0..*], sampler)<br>
                                      +    * o_fragment = sum(t_array[i]
                                      * lanczos(x - offsets[i].x) *
                                      lanczos(y - offsets[i].y))<br>
                                      +    */<br>
                                      +   vtex = ureg_src(t_array[1]);<br>
                                      +   for (i = 0; i <
                                      num_offsets; ++i) {<br>
                                      +        ureg_ADD(shader,
                                      ureg_writemask(t_array[i + 2],
                                      TGSI_WRITEMASK_XY),<br>
                                      +                  vtex,
                                      ureg_imm2f(shader, offsets[i].x,
                                      offsets[i].y));<br>
                                      +        ureg_MOV(shader,
                                      ureg_writemask(t_array[i + 2],
                                      TGSI_WRITEMASK_ZW),<br>
                                      +                 
                                      ureg_imm1f(shader, 0.0f));<br>
                                      +   }<br>
                                      +<br>
                                      +   for (i = 0; i <
                                      num_offsets; ++i) {<br>
                                      +      ureg_TEX(shader, t_array[i
                                      + 2], TGSI_TEXTURE_2D,
                                      ureg_src(t_array[i + 2]),
                                      sampler);<br>
                                      +   }<br>
                                      +<br>
                                      +   for(i = 0, first = true; i
                                      < num_offsets; ++i) {<br>
                                      +      if (first) {<br>
                                      +         t_sum = t_array[i + 2];<br>
                                      +         ureg_SUB(shader,
                                      ureg_writemask(t_array[i],
                                      TGSI_WRITEMASK_XY),<br>
                                      +                  ureg_src(x),
                                      ureg_imm2f(shader, offsets[i].x *
                                      video_width,<br>
                                      +                  offsets[i].y *
                                      video_height));<br>
                                      +       
                                       create_frag_shader_lanczos(shader,
                                      ureg_imm1f(shader, (float)(a)),<br>
                                      +               
                                       ureg_scalar(ureg_src(t_array[i]),
                                      TGSI_SWIZZLE_X), t_array[i + 1]);<br>
                                      +       
                                       create_frag_shader_lanczos(shader,
                                      ureg_imm1f(shader, (float)(a)),<br>
                                      +               
                                       ureg_scalar(ureg_src(t_array[i]),
                                      TGSI_SWIZZLE_Y), t_array[i]);<br>
                                      +         ureg_MUL(shader,
                                      t_array[i + 1], ureg_src(t_array[i
                                      + 1]),<br>
                                      +                 
                                      ureg_src(t_array[i]));<br>
                                      +         ureg_MUL(shader, t_sum,
                                      ureg_src(t_array[i + 2]),<br>
                                      +                 
                                      ureg_src(t_array[i + 1]));<br>
                                      +         first = false;<br>
                                      +      } else {<br>
                                      +         ureg_SUB(shader,
                                      ureg_writemask(t_array[i],
                                      TGSI_WRITEMASK_XY),<br>
                                      +                  ureg_src(x),
                                      ureg_imm2f(shader, offsets[i].x *
                                      video_width,<br>
                                      +                  offsets[i].y *
                                      video_height));<br>
                                      +       
                                       create_frag_shader_lanczos(shader,
                                      ureg_imm1f(shader, (float)(a)),<br>
                                      +               
                                       ureg_scalar(ureg_src(t_array[i]),
                                      TGSI_SWIZZLE_X), t_array[i + 1]);<br>
                                      +       
                                       create_frag_shader_lanczos(shader,
                                      ureg_imm1f(shader, (float)(a)),<br>
                                      +               
                                       ureg_scalar(ureg_src(t_array[i]),
                                      TGSI_SWIZZLE_Y), t_array[i]);<br>
                                      +         ureg_MUL(shader,
                                      t_array[i + 1], ureg_src(t_array[i
                                      + 1]),<br>
                                      +                 
                                      ureg_src(t_array[i]));<br>
                                      +         ureg_MAD(shader, t_sum,
                                      ureg_src(t_array[i + 2]),<br>
                                      +                 
                                      ureg_src(t_array[i + 1]),
                                      ureg_src(t_sum));<br>
                                      +      }<br>
                                      +   }<br>
                                      +<br>
                                      +   if (first)<br>
                                      +      ureg_MOV(shader,
                                      o_fragment, ureg_imm1f(shader,
                                      0.0f));<br>
                                      +   else<br>
                                      +      ureg_MOV(shader,
                                      o_fragment, ureg_src(t_sum));<br>
                                      +<br>
                                      +   ureg_release_temporary(shader,
                                      x);<br>
                                      +   ureg_END(shader);<br>
                                      +<br>
                                      +   FREE(t_array);<br>
                                      +   return
                                      ureg_create_shader_and_destroy(shader,
                                      filter->pipe);<br>
                                      +}<br>
                                      +<br>
                                      +bool<br>
                                      +vl_lanczos_filter_init(struct
                                      vl_lanczos_filter *filter, struct
                                      pipe_context *pipe,<br>
                                      +                       unsigned
                                      size, unsigned width, unsigned
                                      height)<br>
                                      +{<br>
                                      +   struct pipe_rasterizer_state
                                      rs_state;<br>
                                      +   struct pipe_blend_state blend;<br>
                                      +   struct vertex2f *offsets, v,
                                      sizes;<br>
                                      +   struct pipe_sampler_state
                                      sampler;<br>
                                      +   struct pipe_vertex_element ve;<br>
                                      +   unsigned i, num_offsets = (2 *
                                      size) * (2 * size);<br>
                                      +<br>
                                      +   assert(filter &&
                                      pipe);<br>
                                      +   assert(width &&
                                      height);<br>
                                      +   assert(size);<br>
                                      +<br>
                                      +   memset(filter, 0,
                                      sizeof(*filter));<br>
                                      +   filter->pipe = pipe;<br>
                                      +<br>
                                      +   memset(&rs_state, 0,
                                      sizeof(rs_state));<br>
                                      +   rs_state.half_pixel_center =
                                      true;<br>
                                      +   rs_state.bottom_edge_rule =
                                      true;<br>
                                      +   rs_state.depth_clip = 1;<br>
                                      +   filter->rs_state =
                                      pipe->create_rasterizer_state(pipe,
                                      &rs_state);<br>
                                      +   if (!filter->rs_state)<br>
                                      +      goto error_rs_state;<br>
                                      +<br>
                                      +   memset(&blend, 0, sizeof
                                      blend);<br>
                                      +   blend.rt[0].rgb_func =
                                      PIPE_BLEND_ADD;<br>
                                      +   blend.rt[0].rgb_src_factor =
                                      PIPE_BLENDFACTOR_ONE;<br>
                                      +   blend.rt[0].rgb_dst_factor =
                                      PIPE_BLENDFACTOR_ONE;<br>
                                      +   blend.rt[0].alpha_func =
                                      PIPE_BLEND_ADD;<br>
                                      +   blend.rt[0].alpha_src_factor =
                                      PIPE_BLENDFACTOR_ONE;<br>
                                      +   blend.rt[0].alpha_dst_factor =
                                      PIPE_BLENDFACTOR_ONE;<br>
                                      +   blend.logicop_func =
                                      PIPE_LOGICOP_CLEAR;<br>
                                      +   blend.rt[0].colormask =
                                      PIPE_MASK_RGBA;<br>
                                      +   filter->blend =
                                      pipe->create_blend_state(pipe,
                                      &blend);<br>
                                      +   if (!filter->blend)<br>
                                      +      goto error_blend;<br>
                                      +<br>
                                      +   memset(&sampler, 0,
                                      sizeof(sampler));<br>
                                      +   sampler.wrap_s =
                                      PIPE_TEX_WRAP_CLAMP_TO_EDGE;<br>
                                      +   sampler.wrap_t =
                                      PIPE_TEX_WRAP_CLAMP_TO_EDGE;<br>
                                      +   sampler.wrap_r =
                                      PIPE_TEX_WRAP_CLAMP_TO_EDGE;<br>
                                      +   sampler.min_img_filter =
                                      PIPE_TEX_FILTER_NEAREST;<br>
                                      +   sampler.min_mip_filter =
                                      PIPE_TEX_MIPFILTER_NONE;<br>
                                      +   sampler.mag_img_filter =
                                      PIPE_TEX_FILTER_NEAREST;<br>
                                      +   sampler.compare_mode =
                                      PIPE_TEX_COMPARE_NONE;<br>
                                      +   sampler.compare_func =
                                      PIPE_FUNC_ALWAYS;<br>
                                      +   sampler.normalized_coords = 1;<br>
                                      +   filter->sampler =
                                      pipe->create_sampler_state(pipe,
                                      &sampler);<br>
                                      +   if (!filter->sampler)<br>
                                      +      goto error_sampler;<br>
                                      +<br>
                                      +   filter->quad =
                                      vl_vb_upload_quads(pipe);<br>
                                      +   if(!filter->quad.buffer)<br>
                                      +      goto error_quad;<br>
                                      +<br>
                                      +   memset(&ve, 0,
                                      sizeof(ve));<br>
                                      +   ve.src_offset = 0;<br>
                                      +   ve.instance_divisor = 0;<br>
                                      +   ve.vertex_buffer_index = 0;<br>
                                      +   ve.src_format =
                                      PIPE_FORMAT_R32G32_FLOAT;<br>
                                      +   filter->ves =
                                      pipe->create_vertex_elements_state(pipe,
                                      1, &ve);<br>
                                      +   if (!filter->ves)<br>
                                      +      goto error_ves;<br>
                                      +<br>
                                      +   offsets = MALLOC(sizeof(struct
                                      vertex2f) * num_offsets);<br>
                                      +   if (!offsets)<br>
                                      +      goto error_offsets;<br>
                                      +<br>
                                      +   sizes.x = (float)(size);<br>
                                      +   sizes.y = (float)(size);<br>
                                      +<br>
                                      +   for (v.x = -sizes.x + 1.0f, i
                                      = 0; v.x <= sizes.x; v.x +=
                                      1.0f)<br>
                                      +      for (v.y = -sizes.y + 1.0f;
                                      v.y <= sizes.y; v.y += 1.0f)<br>
                                      +         offsets[i++] = v;<br>
                                      +<br>
                                      +   for (i = 0; i <
                                      num_offsets; ++i) {<br>
                                      +      offsets[i].x /= width;<br>
                                      +      offsets[i].y /= height;<br>
                                      +   }<br>
                                      +<br>
                                      +   filter->vs =
                                      create_vert_shader(filter);<br>
                                      +   if (!filter->vs)<br>
                                      +      goto error_vs;<br>
                                      +<br>
                                      +   filter->fs =
                                      create_frag_shader(filter,
                                      num_offsets, offsets, size, width,
                                      height);<br>
                                      +   if (!filter->fs)<br>
                                      +      goto error_fs;<br>
                                      +<br>
                                      +   FREE(offsets);<br>
                                      +   return true;<br>
                                      +<br>
                                      +error_fs:<br>
                                      +   pipe->delete_vs_state(pipe,
                                      filter->vs);<br>
                                      +<br>
                                      +error_vs:<br>
                                      +   FREE(offsets);<br>
                                      +<br>
                                      +error_offsets:<br>
                                      + 
                                       pipe->delete_vertex_elements_state(pipe,
                                      filter->ves);<br>
                                      +<br>
                                      +error_ves:<br>
                                      + 
                                       pipe_resource_reference(&filter->quad.buffer,
                                      NULL);<br>
                                      +<br>
                                      +error_quad:<br>
                                      + 
                                       pipe->delete_sampler_state(pipe,
                                      filter->sampler);<br>
                                      +<br>
                                      +error_sampler:<br>
                                      + 
                                       pipe->delete_blend_state(pipe,
                                      filter->blend);<br>
                                      +<br>
                                      +error_blend:<br>
                                      + 
                                       pipe->delete_rasterizer_state(pipe,
                                      filter->rs_state);<br>
                                      +<br>
                                      +error_rs_state:<br>
                                      +   return false;<br>
                                      +}<br>
                                      +<br>
                                      +void<br>
                                      +vl_lanczos_filter_cleanup(struct
                                      vl_lanczos_filter *filter)<br>
                                      +{<br>
                                      +   assert(filter);<br>
                                      +<br>
                                      + 
                                       filter->pipe->delete_sampler_state(filter->pipe,
                                      filter->sampler);<br>
                                      + 
                                       filter->pipe->delete_blend_state(filter->pipe,
                                      filter->blend);<br>
                                      + 
                                       filter->pipe->delete_rasterizer_state(filter->pipe,
                                      filter->rs_state);<br>
                                      + 
                                       filter->pipe->delete_vertex_elements_state(filter->pipe,
                                      filter->ves);<br>
                                      + 
                                       pipe_resource_reference(&filter->quad.buffer,
                                      NULL);<br>
                                      +<br>
                                      + 
                                       filter->pipe->delete_vs_state(filter->pipe,
                                      filter->vs);<br>
                                      + 
                                       filter->pipe->delete_fs_state(filter->pipe,
                                      filter->fs);<br>
                                      +}<br>
                                      +<br>
                                      +void<br>
                                      +vl_lanczos_filter_render(struct
                                      vl_lanczos_filter *filter,<br>
                                      +                        struct
                                      pipe_sampler_view *src,<br>
                                      +                        struct
                                      pipe_surface *dst,<br>
                                      +                        struct
                                      u_rect *dst_area,<br>
                                      +                        struct
                                      u_rect *dst_clip)<br>
                                      +{<br>
                                      +   struct pipe_viewport_state
                                      viewport;<br>
                                      +   struct pipe_framebuffer_state
                                      fb_state;<br>
                                      +   struct pipe_scissor_state
                                      scissor;<br>
                                      +   union pipe_color_union
                                      clear_color;<br>
                                      +   struct pipe_transfer
                                      *buf_transfer;<br>
                                      +   struct pipe_resource
                                      *surface_size;<br>
                                      +   assert(filter && src
                                      && dst);<br>
                                      +<br>
                                      +   if (dst_clip) {<br>
                                      +      scissor.minx =
                                      dst_clip->x0;<br>
                                      +      scissor.miny =
                                      dst_clip->y0;<br>
                                      +      scissor.maxx =
                                      dst_clip->x1;<br>
                                      +      scissor.maxy =
                                      dst_clip->y1;<br>
                                      +   } else {<br>
                                      +      scissor.minx = 0;<br>
                                      +      scissor.miny = 0;<br>
                                      +      scissor.maxx =
                                      dst->width;<br>
                                      +      scissor.maxy =
                                      dst->height;<br>
                                      +   }<br>
                                      +<br>
                                      +   clear_color.f[0] =
                                      clear_color.f[1] = 0.0f;<br>
                                      +   clear_color.f[2] =
                                      clear_color.f[3] = 0.0f;<br>
                                      +   surface_size =
                                      pipe_buffer_create<br>
                                      +   (<br>
                                      +      filter->pipe->screen,<br>
                                      +      PIPE_BIND_CONSTANT_BUFFER,<br>
                                      +      PIPE_USAGE_DEFAULT,<br>
                                      +      2*sizeof(float)<br>
                                      +   );<br>
                                      +<br>
                                      +<br>
                                      +   memset(&viewport, 0,
                                      sizeof(viewport));<br>
                                      +   if(dst_area){<br>
                                      +      viewport.scale[0] =
                                      dst_area->x1 - dst_area->x0;<br>
                                      +      viewport.scale[1] =
                                      dst_area->y1 - dst_area->y0;<br>
                                      +      viewport.translate[0] =
                                      dst_area->x0;<br>
                                      +      viewport.translate[1] =
                                      dst_area->y0;<br>
                                      +   } else {<br>
                                      +      viewport.scale[0] =
                                      dst->width;<br>
                                      +      viewport.scale[1] =
                                      dst->height;<br>
                                      +   }<br>
                                      +   viewport.scale[2] = 1;<br>
                                      +<br>
                                      +   float *ptr =
                                      pipe_buffer_map(filter->pipe,
                                      surface_size,<br>
                                      +                             
                                       PIPE_TRANSFER_WRITE |
                                      PIPE_TRANSFER_DISCARD_RANGE,<br>
                                      +                             
                                       &buf_transfer);<br>
                                      +<br>
                                      +   ptr[0] =
                                      0.5f/viewport.scale[0];<br>
                                      +   ptr[1] =
                                      0.5f/viewport.scale[1];<br>
                                      +<br>
                                      + 
                                       pipe_buffer_unmap(filter->pipe,
                                      buf_transfer);<br>
                                      +<br>
                                      +   memset(&fb_state, 0,
                                      sizeof(fb_state));<br>
                                      +   fb_state.width =
                                      dst->width;<br>
                                      +   fb_state.height =
                                      dst->height;<br>
                                      +   fb_state.nr_cbufs = 1;<br>
                                      +   fb_state.cbufs[0] = dst;<br>
                                      +<br>
                                      + 
                                       filter->pipe->set_scissor_states(filter->pipe,
                                      0, 1, &scissor);<br>
                                      + 
                                       filter->pipe->clear_render_target(filter->pipe,
                                      dst, &clear_color,<br>
                                      +                                 
                                         0, 0, dst->width,
                                      dst->height);<br>
                                      + 
                                       pipe_set_constant_buffer(filter->pipe,
                                      PIPE_SHADER_FRAGMENT, 0,
                                      surface_size);<br>
                                      + 
                                       filter->pipe->bind_rasterizer_state(filter->pipe,
                                      filter->rs_state);<br>
                                      + 
                                       filter->pipe->bind_blend_state(filter->pipe,
                                      filter->blend);<br>
                                      + 
                                       filter->pipe->bind_sampler_states(filter->pipe,
                                      PIPE_SHADER_FRAGMENT,<br>
                                      +                                 
                                         0, 1, &filter->sampler);<br>
                                      + 
                                       filter->pipe->set_sampler_views(filter->pipe,
                                      PIPE_SHADER_FRAGMENT,<br>
                                      +                                 
                                       0, 1, &src);<br>
                                      + 
                                       filter->pipe->bind_vs_state(filter->pipe,
                                      filter->vs);<br>
                                      + 
                                       filter->pipe->bind_fs_state(filter->pipe,
                                      filter->fs);<br>
                                      + 
                                       filter->pipe->set_framebuffer_state(filter->pipe,
                                      &fb_state);<br>
                                      + 
                                       filter->pipe->set_viewport_states(filter->pipe,
                                      0, 1, &viewport);<br>
                                      + 
                                       filter->pipe->set_vertex_buffers(filter->pipe,
                                      0, 1, &filter->quad);<br>
                                      + 
                                       filter->pipe->bind_vertex_elements_state(filter->pipe,
                                      filter->ves);<br>
                                      +<br>
                                      + 
                                       util_draw_arrays(filter->pipe,
                                      PIPE_PRIM_QUADS, 0, 4);<br>
                                      +}<br>
                                      diff --git
                                      a/src/gallium/auxiliary/vl/vl_lanczos_filter.h
b/src/gallium/auxiliary/vl/vl_lanczos_filter.h<br>
                                      new file mode 100644<br>
                                      index 0000000..cb469aa<br>
                                      --- /dev/null<br>
                                      +++
                                      b/src/gallium/auxiliary/vl/vl_lanczos_filter.h<br>
                                      @@ -0,0 +1,63 @@<br>
+/**************************************************************************<br>
                                      + *<br>
                                      + * Copyright 2016 Nayan Deshmukh.<br>
                                      + * All Rights Reserved.<br>
                                      + *<br>
                                      + * Permission is hereby granted,
                                      free of charge, to any person
                                      obtaining a<br>
                                      + * copy of this software and
                                      associated documentation files
                                      (the<br>
                                      + * "Software"), to deal in the
                                      Software without restriction,
                                      including<br>
                                      + * without limitation the rights
                                      to use, copy, modify, merge,
                                      publish,<br>
                                      + * distribute, sub license,
                                      and/or sell copies of the
                                      Software, and to<br>
                                      + * permit persons to whom the
                                      Software is furnished to do so,
                                      subject to<br>
                                      + * the following conditions:<br>
                                      + *<br>
                                      + * The above copyright notice and
                                      this permission notice (including
                                      the<br>
                                      + * next paragraph) shall be
                                      included in all copies or
                                      substantial portions<br>
                                      + * of the Software.<br>
                                      + *<br>
                                      + * THE SOFTWARE IS PROVIDED "AS
                                      IS", WITHOUT WARRANTY OF ANY KIND,
                                      EXPRESS<br>
                                      + * OR IMPLIED, INCLUDING BUT NOT
                                      LIMITED TO THE WARRANTIES OF<br>
                                      + * MERCHANTABILITY, FITNESS FOR A
                                      PARTICULAR PURPOSE AND
                                      NON-INFRINGEMENT.<br>
                                      + * IN NO EVENT SHALL VMWARE
                                      AND/OR ITS SUPPLIERS BE LIABLE FOR<br>
                                      + * ANY CLAIM, DAMAGES OR OTHER
                                      LIABILITY, WHETHER IN AN ACTION OF
                                      CONTRACT,<br>
                                      + * TORT OR OTHERWISE, ARISING
                                      FROM, OUT OF OR IN CONNECTION WITH
                                      THE<br>
                                      + * SOFTWARE OR THE USE OR OTHER
                                      DEALINGS IN THE SOFTWARE.<br>
                                      + *<br>
                                      +
**************************************************************************/<br>
                                      +<br>
                                      +/* implementation of lanczos
                                      interpolation filter */<br>
                                      +<br>
                                      +#ifndef vl_lanczos_filter_h<br>
                                      +#define vl_lanczos_filter_h<br>
                                      +<br>
                                      +#include "pipe/p_state.h"<br>
                                      +<br>
                                      +struct vl_lanczos_filter<br>
                                      +{<br>
                                      +   struct pipe_context *pipe;<br>
                                      +   struct pipe_vertex_buffer
                                      quad;<br>
                                      +<br>
                                      +   void *rs_state;<br>
                                      +   void *blend;<br>
                                      +   void *sampler;<br>
                                      +   void *ves;<br>
                                      +   void *vs, *fs;<br>
                                      +};<br>
                                      +<br>
                                      +bool<br>
                                      +vl_lanczos_filter_init(struct
                                      vl_lanczos_filter *filter, struct
                                      pipe_context *pipe,<br>
                                      +                       unsigned
                                      size, unsigned width, unsigned
                                      height);<br>
                                      +<br>
                                      +void<br>
                                      +vl_lanczos_filter_cleanup(struct
                                      vl_lanczos_filter *filter);<br>
                                      +<br>
                                      +<br>
                                      +void<br>
                                      +vl_lanczos_filter_render(struct
                                      vl_lanczos_filter *filter,<br>
                                      +                         struct
                                      pipe_sampler_view *src,<br>
                                      +                         struct
                                      pipe_surface *dst,<br>
                                      +                         struct
                                      u_rect *dst_area,<br>
                                      +                         struct
                                      u_rect *dst_clip);<br>
                                      +<br>
                                      +<br>
                                      +#endif /* vl_lanczos_filter_h */<br>
                                    </blockquote>
                                    <br>
                                  </div>
                                </div>
                              </blockquote>
                            </div>
                            <br>
                          </div>
                        </div>
                      </blockquote>
                      <p><br>
                      </p>
                    </div>
                  </div>
                </div>
              </blockquote>
            </div>
            <br>
          </div>
        </div>
      </div>
    </blockquote>
    <p><br>
    </p>
  </body>
</html>