1 /*****************************************************************************
2 * Copyright (C) 2013 x265 project
4 * Authors: Steve Borho <steve@borho.org>
5 * Min Chen <chenm003@163.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
21 * This program is also available under a commercial proprietary license.
22 * For more information, contact us at license @ x265.com.
23 *****************************************************************************/
39 SAO_NUM_BO_CLASSES
= 32
56 enum { SAO_MAX_DEPTH
= 4 };
57 enum { SAO_BO_BITS
= 5 };
58 enum { MAX_NUM_SAO_CLASS
= 33 };
59 enum { SAO_BIT_INC
= X265_MAX(X265_DEPTH
- 10, 0) };
60 enum { OFFSET_THRESH
= 1 << X265_MIN(X265_DEPTH
- 5, 5) };
61 enum { NUM_EDGETYPE
= 5 };
62 enum { NUM_PLANE
= 3 };
63 enum { NUM_MERGE_MODE
= 3 };
65 static const uint32_t s_eoTable
[NUM_EDGETYPE
];
67 typedef int32_t (PerClass
[MAX_NUM_SAO_TYPE
][MAX_NUM_SAO_CLASS
]);
68 typedef int32_t (PerPlane
[NUM_PLANE
][MAX_NUM_SAO_TYPE
][MAX_NUM_SAO_CLASS
]);
70 /* allocated per part */
73 PerClass
* m_offsetOrg
;
75 /* allocated per CTU */
76 PerPlane
* m_countPreDblk
;
77 PerPlane
* m_offsetOrgPreDblk
;
79 double m_depthSaoRate
[2][4];
81 int8_t m_offsetEo
[NUM_EDGETYPE
];
89 pixel
* m_clipTableBase
;
106 Entropy m_entropyCoder
;
107 SAOContexts m_rdContexts
;
114 double m_chromaLambda
;
115 /* TODO: No doubles for distortion */
119 bool create(x265_param
* param
);
122 void allocSaoParam(SAOParam
* saoParam
) const;
124 void startSlice(Frame
* pic
, Entropy
& initState
, int qp
);
126 void resetSaoUnit(SaoCtuParam
* saoUnit
);
128 // CTU-based SAO process without slice granularity
129 void processSaoCu(int addr
, int typeIdx
, int plane
);
130 void processSaoUnitRow(SaoCtuParam
* ctuParam
, int idxY
, int plane
);
132 void copySaoUnit(SaoCtuParam
* saoUnitDst
, const SaoCtuParam
* saoUnitSrc
);
134 void calcSaoStatsCu(int addr
, int plane
);
135 void calcSaoStatsCu_BeforeDblk(Frame
* pic
, int idxX
, int idxY
);
137 void saoComponentParamDist(SAOParam
* saoParam
, int addr
, int addrUp
, int addrLeft
, SaoCtuParam mergeSaoParam
[2], double* mergeDist
);
138 void sao2ChromaParamDist(SAOParam
* saoParam
, int addr
, int addrUp
, int addrLeft
, SaoCtuParam mergeSaoParam
[][2], double* mergeDist
);
140 inline int estIterOffset(int typeIdx
, int classIdx
, double lambda
, int offset
, int32_t count
, int32_t offsetOrg
,
141 int32_t* currentDistortionTableBo
, double* currentRdCostTableBo
);
142 inline int64_t estSaoTypeDist(int plane
, int typeIdx
, double lambda
, int32_t* currentDistortionTableBo
, double* currentRdCostTableBo
);
144 void rdoSaoUnitRowInit(SAOParam
* saoParam
);
145 void rdoSaoUnitRowEnd(const SAOParam
* saoParam
, int numctus
);
146 void rdoSaoUnitRow(SAOParam
* saoParam
, int idxY
);
151 #endif // ifndef X265_SAO_H