Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. /*
  2.  * Copyright © <2010>, Intel Corporation.
  3.  *
  4.  * Permission is hereby granted, free of charge, to any person obtaining a
  5.  * copy of this software and associated documentation files (the
  6.  * "Software"), to deal in the Software without restriction, including
  7.  * without limitation the rights to use, copy, modify, merge, publish,
  8.  * distribute, sub license, and/or sell copies of the Software, and to
  9.  * permit persons to whom the Software is furnished to do so, subject to
  10.  * the following conditions:
  11.  *
  12.  * The above copyright notice and this permission notice (including the
  13.  * next paragraph) shall be included in all copies or substantial portions
  14.  * of the Software.
  15.  *
  16.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  17.  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  18.  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
  19.  * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
  20.  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  21.  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  22.  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23.  *
  24.  * This file was originally licensed under the following license
  25.  *
  26.  *  Licensed under the Apache License, Version 2.0 (the "License");
  27.  *  you may not use this file except in compliance with the License.
  28.  *  You may obtain a copy of the License at
  29.  *
  30.  *      http://www.apache.org/licenses/LICENSE-2.0
  31.  *
  32.  *  Unless required by applicable law or agreed to in writing, software
  33.  *  distributed under the License is distributed on an "AS IS" BASIS,
  34.  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  35.  *  See the License for the specific language governing permissions and
  36.  *  limitations under the License.
  37.  *
  38.  */
  39. #if !defined(__AVC_ILDB_CHROMA_CORE__)  // Make sure this file is only included once
  40. #define __AVC_ILDB_CHROMA_CORE__
  41.  
  42. ////////// AVC ILDB Chroma Core /////////////////////////////////////////////////////////////////////////////////
  43. //
  44. //      This core performs AVC U or V ILDB filtering on one horizontal edge (8 pixels) of a MB.
  45. //      If data is transposed, it can also de-block a vertical edge.
  46. //
  47. //      Bafore calling this subroutine, caller needs to set the following parameters.
  48. //
  49. //      - EdgeCntlMap1                          //      Edge control map A
  50. //      - EdgeCntlMap2                          //      Edge control map B
  51. //      - P_AddrReg                                     //      Src and dest address register for P pixels
  52. //      - Q_AddrReg                                     //      Src and dest address register for Q pixels      
  53. //      - alpha                                         //  alpha corresponding to the edge to be filtered
  54. //      - beta                                          //  beta corresponding to the edge to be filtered
  55. //      - tc0                                           //      tc0  corresponding to the edge to be filtered
  56. //
  57. //      U or V:
  58. //      +----+----+----+----+
  59. //      | P1 | p0 | q0 | q1 |
  60. //      +----+----+----+----+
  61. //
  62. //      p1 = r[P_AddrReg, 0]<16;8,2>
  63. //      p0 = r[P_AddrReg, 16]<16;8,2>
  64. //      q0 = r[Q_AddrReg, 0]<16;8,2>  
  65. //      q1 = r[Q_AddrReg, 16]<16;8,2>
  66. //
  67. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  68.  
  69. // The region is both src and dest
  70. // P0-P3 and Q0-Q3 should be only used if they have not been modified to new values  
  71. #undef  P1
  72. #undef  P0
  73. #undef  Q0
  74. #undef  Q1
  75.  
  76. #define P1              r[P_AddrReg,  0]<16;8,2>:ub
  77. #define P0              r[P_AddrReg, 16]<16;8,2>:ub
  78. #define Q0              r[Q_AddrReg,  0]<16;8,2>:ub
  79. #define Q1              r[Q_AddrReg, 16]<16;8,2>:ub
  80.  
  81. // New region as dest
  82. #undef  NewP0
  83. #undef  NewQ0
  84.  
  85. #define NewP0   r[P_AddrReg, 16]<2>:ub
  86. #define NewQ0   r[Q_AddrReg,  0]<2>:ub
  87.  
  88. // Filter one chroma edge
  89. FILTER_UV:
  90.  
  91. #if defined(_DEBUG)
  92.         mov             (1)             EntrySignatureC:w                       0x1112:w
  93. #endif
  94.         //---------- Derive filterSampleflag in AVC spec, equition (8-469) ----------
  95.         // bS is in MaskA
  96.  
  97.         // Src copy of the p1, p0, q0, q1
  98. //      mov (8) p1(0)<1>                r[P_AddrReg, 0]<16;8,2>:ub
  99. //      mov (8) p0(0)<1>                r[P_AddrReg, 16]<16;8,2>:ub
  100. //      mov (8) q0(0)<1>                r[Q_AddrReg, 0]<16;8,2>:ub
  101. //      mov (8) q1(0)<1>                r[Q_AddrReg, 16]<16;8,2>:ub
  102.  
  103. //      mov (1) f0.0:uw         MaskA:uw
  104.  
  105.         add (8) q0_p0(0)<1>                     Q0              -P0                             // q0-p0
  106.         add (8) TempRow0(0)<1>          P1              -P0                             // p1-p0
  107.         add (8) TempRow1(0)<1>          Q1              -Q0                             // q1-q0
  108.  
  109.         // Build FilterSampleFlag
  110.         // abs(q0-p0) < alpha
  111.         (f0.0) cmp.l.f0.0 (16) null:w           (abs)q0_p0(0)                   alpha:w
  112.         // abs(p1-p0) < Beta
  113.         (f0.0) cmp.l.f0.0 (16) null:w           (abs)TempRow0(0)                beta:w
  114.         // abs(q1-q0) < Beta
  115.         (f0.0) cmp.l.f0.0 (16) null:w           (abs)TempRow1(0)                beta:w
  116.  
  117.         //-----------------------------------------------------------------------------------------
  118.  
  119.         // if
  120.     (f0.0)      if      (8)             UV_ENDIF1
  121.                 // For channels whose edge control map1 = 1 ---> perform de-blocking
  122.  
  123. //              mov (1)         f0.1:w          MaskB:w         {NoMask}                // Now check for which algorithm to apply
  124.  
  125.                 (f0.1)  if      (8)             UV_ELSE2
  126.  
  127.                         // For channels whose edge control map2 = 1 ---> bS = 4 algorithm
  128.                         // p0' = (2*p1 + p0 + q1 + 2) >> 2
  129.                         // q0' = (2*q1 + q0 + p1 + 2) >> 2
  130.  
  131.                         // Optimized version:
  132.                         // A = (p1 + q1 + 2)
  133.                         // p0' = (p0 + p1 + A) >> 2
  134.                         // q0' = (q0 + q1 + A) >> 2
  135.                         //------------------------------------------------------------------------------------
  136.                        
  137.                         // p0' = (2*p1 + p0 + q1 + 2) >> 2
  138.                         add (8) acc0<1>:w               Q1                              2:w
  139.                         mac (8) acc0<1>:w               P1                              2:w
  140.                         add (8) acc0<1>:w               acc0<8;8,1>:w   P0
  141.                         shr.sat (8)     TempRow0B(0)<2>         acc0<8;8,1>:w           2:w
  142.                        
  143.                         // q0' = (2*q1 + q0 + p1 + 2) >> 2
  144.                         add (8) acc0<1>:w               P1                              2:w
  145.                         mac (8) acc0<1>:w               Q1                              2:w
  146.                         add (8) acc0<1>:w               acc0<8;8,1>:w   Q0
  147.                         shr.sat (8)     TempRow1B(0)<2>         acc0<8;8,1>:w           2:w
  148.  
  149.                         mov (8) NewP0           TempRow0B(0)                                    // p0'
  150.                         mov (8) NewQ0           TempRow1B(0)                                    // q0'
  151.                        
  152.                        
  153. UV_ELSE2:
  154.                 else    (8)             UV_ENDIF2
  155.                         // For channels whose edge control map2 = 0 ---> bS < 4 algorithm
  156.                        
  157.                         // Expand tc0   (tc0 has 4 bytes)
  158. //                      mov (8) tc0_exp(0)<1>   tc0<1;2,0>:ub   {NoMask}                                // tc0_exp = tc0, each tc0 is duplicated 2 times for 2 adjcent pixels  
  159.                         mov (8) acc0<1>:w       tc0<1;2,0>:ub   {NoMask}                                // tc0_exp = tc0, each tc0 is duplicated 2 times for 2 adjcent pixels  
  160.                        
  161.                         // tc_exp = tc0_exp + 1
  162. //                      add (8) tc_exp(0)<1>    tc0_exp(0)              1:w
  163.                         add (8) tc_exp(0)<1>    acc0<8;8,1>:w           1:w
  164.  
  165.                         // delta = Clip3(-tc, tc, ((((q0 - p0)<<2) + (p1-q1) + 4) >> 3))
  166.                         // 4 * (q0-p0) + p1 - q1 + 4
  167.                         add (8) acc0<1>:w               P1                      4:w
  168.                         mac (8) acc0<1>:w               q0_p0(0)        4:w    
  169.                         add (8) acc0<1>:w               acc0<8;8,1>:w           -Q1
  170.                         shr (8) TempRow0(0)<1>  acc0<8;8,1>:w           3:w
  171.  
  172.                         // tc clip
  173.                         cmp.g.f0.0      (8) null:w              TempRow0(0)             tc_exp(0)                               // Clip if > tc0
  174.                         cmp.l.f0.1      (8) null:w              TempRow0(0)             -tc_exp(0)                              // Clip if < -tc0
  175.                        
  176.                         (f0.0) mov (8) TempRow0(0)<1>                           tc_exp(0)
  177.                         (f0.1) mov (8) TempRow0(0)<1>                           -tc_exp(0)
  178.                        
  179.                         // p0' = Clip1(p0 + delta) = Clip3(0, 0xFF, p0 + delta)
  180.                         add.sat (8)     TempRow1B(0)<2>         P0                      TempRow0(0)                             // p0+delta
  181.                
  182.                         // q0' = Clip1(q0 - delta) = Clip3(0, 0xFF, q0 - delta)
  183.                         add.sat (8)     TempRow0B(0)<2>         Q0                      -TempRow0(0)                    // q0-delta
  184.  
  185.                         mov (8) NewP0                           TempRow1B(0)                    // p0'
  186.                         mov (8) NewQ0                           TempRow0B(0)                    // q0'
  187.  
  188.                 endif
  189. UV_ENDIF2:
  190. UV_ENDIF1:
  191.         endif
  192.  
  193. RETURN
  194.  
  195. #endif  // !defined(__AVC_ILDB_CHROMA_CORE__)
  196.