Changeset 852 in 3DVCSoftware
- Timestamp:
- 13 Feb 2014, 22:34:17 (11 years ago)
- Location:
- branches/HTM-10.0-dev0
- Files:
-
- 3 added
- 179 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HTM-10.0-dev0/COPYING
r56 r852 4 4 granted under this license. 5 5 6 Copyright (c) 2010-201 2, ITU/ISO/IEC6 Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 All rights reserved. 8 8 -
branches/HTM-10.0-dev0/HM.xcodeproj/project.pbxproj
r608 r852 1084 1084 HEADER_SEARCH_PATHS = source/Lib; 1085 1085 ONLY_ACTIVE_ARCH = YES; 1086 SDKROOT = macosx;1086 SDKROOT = ""; 1087 1087 }; 1088 1088 name = Debug; … … 1098 1098 GCC_WARN_UNUSED_VARIABLE = YES; 1099 1099 HEADER_SEARCH_PATHS = source/Lib; 1100 SDKROOT = macosx;1100 SDKROOT = ""; 1101 1101 }; 1102 1102 name = Release; -
branches/HTM-10.0-dev0/build/linux/common/makefile.base
r608 r852 14 14 15 15 CPP = g++ 16 CC = gcc 16 17 AR = ar 17 18 LD = $(CPP) … … 63 64 # 64 65 # release cpp 65 RELEASE_CPPFLAGS = -O3 - ffloat-store -Wuninitialized66 RELEASE_CPPFLAGS = -O3 -Wuninitialized 66 67 67 68 … … 208 209 rm -f $(OBJ_DIR)/$*.d.d 209 210 endef 211 define COMPILE_AND_DEPEND_RELEASE_C 212 $(CC) -c -MMD -MF $(OBJ_DIR)/$*.r.d -MT $(OBJ_DIR)/$*.r.o $(CPPFLAGS) $(RELEASE_CPPFLAGS) -o $@ $(CURDIR)/$< 213 @cp $(OBJ_DIR)/$*.r.d $(OBJ_DIR)/$*.r.P; \ 214 sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \ 215 -e '/^$$/ d' -e 's/$$/ :/' < $(OBJ_DIR)/$*.r.d >> $(OBJ_DIR)/$*.r.P; \ 216 rm -f $(OBJ_DIR)/$*.r.d 217 endef 218 define COMPILE_AND_DEPEND_DEBUG_C 219 $(CC) -c -MMD -MF $(OBJ_DIR)/$*.d.d -MT $(OBJ_DIR)/$*.d.o $(CPPFLAGS) $(DEBUG_CPPFLAGS) -o $@ $(CURDIR)/$< 220 @cp $(OBJ_DIR)/$*.d.d $(OBJ_DIR)/$*.d.P; \ 221 sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \ 222 -e '/^$$/ d' -e 's/$$/ :/' < $(OBJ_DIR)/$*.d.d >> $(OBJ_DIR)/$*.d.P; \ 223 rm -f $(OBJ_DIR)/$*.d.d 224 endef 210 225 211 226 # create release objects … … 251 266 # create release objects 252 267 $(OBJ_DIR)/%.r.o: $(SRC_DIR)/%.c 253 $(COMPILE_AND_DEPEND_RELEASE )268 $(COMPILE_AND_DEPEND_RELEASE_C) 254 269 255 270 # create debug objects 256 271 $(OBJ_DIR)/%.d.o: $(SRC_DIR)/%.c 257 $(COMPILE_AND_DEPEND_DEBUG )272 $(COMPILE_AND_DEPEND_DEBUG_C) 258 273 259 274 # create release objects 260 275 $(OBJ_DIR)/%.r.o: $(SRC_DIR1)/%.c 261 $(COMPILE_AND_DEPEND_RELEASE )276 $(COMPILE_AND_DEPEND_RELEASE_C) 262 277 263 278 # create debug objects 264 279 $(OBJ_DIR)/%.d.o: $(SRC_DIR1)/%.c 265 $(COMPILE_AND_DEPEND_DEBUG )280 $(COMPILE_AND_DEPEND_DEBUG_C) 266 281 267 282 # create release objects 268 283 $(OBJ_DIR)/%.r.o: $(SRC_DIR2)/%.c 269 $(COMPILE_AND_DEPEND_RELEASE )284 $(COMPILE_AND_DEPEND_RELEASE_C) 270 285 271 286 # create debug objects 272 287 $(OBJ_DIR)/%.d.o: $(SRC_DIR2)/%.c 273 $(COMPILE_AND_DEPEND_DEBUG )288 $(COMPILE_AND_DEPEND_DEBUG_C) 274 289 275 290 # create release objects 276 291 $(OBJ_DIR)/%.r.o: $(SRC_DIR3)/%.c 277 $(COMPILE_AND_DEPEND_RELEASE )292 $(COMPILE_AND_DEPEND_RELEASE_C) 278 293 279 294 # create debug objects 280 295 $(OBJ_DIR)/%.d.o: $(SRC_DIR3)/%.c 281 $(COMPILE_AND_DEPEND_DEBUG )296 $(COMPILE_AND_DEPEND_DEBUG_C) 282 297 283 298 # create release objects 284 299 $(OBJ_DIR)/%.r.o: $(SRC_DIR4)/%.c 285 $(COMPILE_AND_DEPEND_RELEASE )300 $(COMPILE_AND_DEPEND_RELEASE_C) 286 301 287 302 # create debug objects 288 303 $(OBJ_DIR)/%.d.o: $(SRC_DIR4)/%.c 289 $(COMPILE_AND_DEPEND_DEBUG )304 $(COMPILE_AND_DEPEND_DEBUG_C) 290 305 291 306 -
branches/HTM-10.0-dev0/cfg/3D-HEVC/NonCTC/allintra/baseCfg_2view+depth_AllIntra.cfg
r738 r852 149 149 #============ Lossless ================ 150 150 TransquantBypassEnableFlag: 0 # Value of PPS flag. 151 CUTransquantBypassFlag Value: 0 # Constant lossless-value signaling per CU, if TransquantBypassEnableFlag is 1.151 CUTransquantBypassFlagForce: 0 # Constant lossless-value signaling per CU, if TransquantBypassEnableFlag is 1. 152 152 153 153 #============ Rate Control ====================== -
branches/HTM-10.0-dev0/cfg/3D-HEVC/NonCTC/allintra/baseCfg_2view_AllIntra.cfg
r655 r852 122 122 #============ Lossless ================ 123 123 TransquantBypassEnableFlag: 0 # Value of PPS flag. 124 CUTransquantBypassFlag Value: 0 # Constant lossless-value signaling per CU, if TransquantBypassEnableFlag is 1.124 CUTransquantBypassFlagForce: 0 # Constant lossless-value signaling per CU, if TransquantBypassEnableFlag is 1. 125 125 126 126 #============ Rate Control ====================== -
branches/HTM-10.0-dev0/cfg/3D-HEVC/NonCTC/allintra/baseCfg_3view+depth_AllIntra.cfg
r738 r852 164 164 #============ Lossless ================ 165 165 TransquantBypassEnableFlag: 0 # Value of PPS flag. 166 CUTransquantBypassFlag Value: 0 # Constant lossless-value signaling per CU, if TransquantBypassEnableFlag is 1.166 CUTransquantBypassFlagForce: 0 # Constant lossless-value signaling per CU, if TransquantBypassEnableFlag is 1. 167 167 168 168 #============ Rate Control ====================== -
branches/HTM-10.0-dev0/cfg/3D-HEVC/NonCTC/allintra/baseCfg_3view_AllIntra.cfg
r655 r852 124 124 #============ Lossless ================ 125 125 TransquantBypassEnableFlag: 0 # Value of PPS flag. 126 CUTransquantBypassFlag Value: 0 # Constant lossless-value signaling per CU, if TransquantBypassEnableFlag is 1.126 CUTransquantBypassFlagForce: 0 # Constant lossless-value signaling per CU, if TransquantBypassEnableFlag is 1. 127 127 128 128 #============ Rate Control ====================== -
branches/HTM-10.0-dev0/cfg/3D-HEVC/NonCTC/fco/baseCfg_3view+depth.cfg
r833 r852 213 213 #============ Lossless ================ 214 214 TransquantBypassEnableFlag: 0 # Value of PPS flag. 215 CUTransquantBypassFlag Value: 0 # Constant lossless-value signaling per CU, if TransquantBypassEnableFlag is 1.215 CUTransquantBypassFlagForce: 0 # Constant lossless-value signaling per CU, if TransquantBypassEnableFlag is 1. 216 216 217 217 #============ Rate Control ====================== -
branches/HTM-10.0-dev0/cfg/3D-HEVC/NonCTC/rc/baseCfg_3view+depth_rate_control.cfg
r724 r852 213 213 #============ Lossless ================ 214 214 TransquantBypassEnableFlag: 0 # Value of PPS flag. 215 CUTransquantBypassFlag Value: 0 # Constant lossless-value signaling per CU, if TransquantBypassEnableFlag is 1.215 CUTransquantBypassFlagForce: 0 # Constant lossless-value signaling per CU, if TransquantBypassEnableFlag is 1. 216 216 217 217 #============ Rate Control ====================== -
branches/HTM-10.0-dev0/cfg/3D-HEVC/baseCfg_2view+depth.cfg
r833 r852 183 183 #============ Lossless ================ 184 184 TransquantBypassEnableFlag: 0 # Value of PPS flag. 185 CUTransquantBypassFlag Value: 0 # Constant lossless-value signaling per CU, if TransquantBypassEnableFlag is 1.185 CUTransquantBypassFlagForce: 0 # Constant lossless-value signaling per CU, if TransquantBypassEnableFlag is 1. 186 186 187 187 #============ Rate Control ====================== -
branches/HTM-10.0-dev0/cfg/3D-HEVC/baseCfg_2view.cfg
r724 r852 156 156 #============ Lossless ================ 157 157 TransquantBypassEnableFlag: 0 # Value of PPS flag. 158 CUTransquantBypassFlag Value: 0 # Constant lossless-value signaling per CU, if TransquantBypassEnableFlag is 1.158 CUTransquantBypassFlagForce: 0 # Constant lossless-value signaling per CU, if TransquantBypassEnableFlag is 1. 159 159 160 160 #============ Rate Control ====================== -
branches/HTM-10.0-dev0/cfg/3D-HEVC/baseCfg_3view+depth.cfg
r833 r852 213 213 #============ Lossless ================ 214 214 TransquantBypassEnableFlag: 0 # Value of PPS flag. 215 CUTransquantBypassFlag Value: 0 # Constant lossless-value signaling per CU, if TransquantBypassEnableFlag is 1.215 CUTransquantBypassFlagForce: 0 # Constant lossless-value signaling per CU, if TransquantBypassEnableFlag is 1. 216 216 217 217 #============ Rate Control ====================== -
branches/HTM-10.0-dev0/cfg/3D-HEVC/baseCfg_3view.cfg
r622 r852 171 171 #============ Lossless ================ 172 172 TransquantBypassEnableFlag: 0 # Value of PPS flag. 173 CUTransquantBypassFlag Value: 0 # Constant lossless-value signaling per CU, if TransquantBypassEnableFlag is 1.173 CUTransquantBypassFlagForce: 0 # Constant lossless-value signaling per CU, if TransquantBypassEnableFlag is 1. 174 174 175 175 #============ Rate Control ====================== -
branches/HTM-10.0-dev0/cfg/3D-HEVC/fullCfg.cfg
r735 r852 219 219 #============ Lossless ================ 220 220 TransquantBypassEnableFlag: 0 # Value of PPS flag. 221 CUTransquantBypassFlag Value: 0 # Constant lossless-value signaling per CU, if TransquantBypassEnableFlag is 1.221 CUTransquantBypassFlagForce: 0 # Constant lossless-value signaling per CU, if TransquantBypassEnableFlag is 1. 222 222 223 223 #============ Rate Control ====================== -
branches/HTM-10.0-dev0/cfg/HEVC/HM/encoder_intra_main.cfg
r655 r852 97 97 #============ Lossless ================ 98 98 TransquantBypassEnableFlag: 0 # Value of PPS flag. 99 CUTransquantBypassFlag Value: 0 # Constant lossless-value signaling per CU, if TransquantBypassEnableFlag is 1.99 CUTransquantBypassFlagForce: 0 # Constant lossless-value signaling per CU, if TransquantBypassEnableFlag is 1. 100 100 101 101 ### DO NOT ADD ANYTHING BELOW THIS LINE ### -
branches/HTM-10.0-dev0/cfg/HEVC/HM/encoder_intra_main10.cfg
r655 r852 97 97 #============ Lossless ================ 98 98 TransquantBypassEnableFlag: 0 # Value of PPS flag. 99 CUTransquantBypassFlag Value: 0 # Constant lossless-value signaling per CU, if TransquantBypassEnableFlag is 1.99 CUTransquantBypassFlagForce: 0 # Constant lossless-value signaling per CU, if TransquantBypassEnableFlag is 1. 100 100 101 101 -
branches/HTM-10.0-dev0/cfg/HEVC/HM/encoder_lowdelay_P_main.cfg
r655 r852 102 102 #============ Lossless ================ 103 103 TransquantBypassEnableFlag: 0 # Value of PPS flag. 104 CUTransquantBypassFlag Value: 0 # Constant lossless-value signaling per CU, if TransquantBypassEnableFlag is 1.104 CUTransquantBypassFlagForce: 0 # Constant lossless-value signaling per CU, if TransquantBypassEnableFlag is 1. 105 105 106 106 #============ Rate Control ====================== -
branches/HTM-10.0-dev0/cfg/HEVC/HM/encoder_lowdelay_P_main10.cfg
r655 r852 102 102 #============ Lossless ================ 103 103 TransquantBypassEnableFlag: 0 # Value of PPS flag. 104 CUTransquantBypassFlag Value: 0 # Constant lossless-value signaling per CU, if TransquantBypassEnableFlag is 1.104 CUTransquantBypassFlagForce: 0 # Constant lossless-value signaling per CU, if TransquantBypassEnableFlag is 1. 105 105 106 106 #============ Rate Control ====================== -
branches/HTM-10.0-dev0/cfg/HEVC/HM/encoder_lowdelay_main.cfg
r655 r852 102 102 #============ Lossless ================ 103 103 TransquantBypassEnableFlag: 0 # Value of PPS flag. 104 CUTransquantBypassFlag Value: 0 # Constant lossless-value signaling per CU, if TransquantBypassEnableFlag is 1.104 CUTransquantBypassFlagForce: 0 # Constant lossless-value signaling per CU, if TransquantBypassEnableFlag is 1. 105 105 106 106 #============ Rate Control ====================== -
branches/HTM-10.0-dev0/cfg/HEVC/HM/encoder_lowdelay_main10.cfg
r655 r852 102 102 #============ Lossless ================ 103 103 TransquantBypassEnableFlag: 0 # Value of PPS flag. 104 CUTransquantBypassFlag Value: 0 # Constant lossless-value signaling per CU, if TransquantBypassEnableFlag is 1.104 CUTransquantBypassFlagForce: 0 # Constant lossless-value signaling per CU, if TransquantBypassEnableFlag is 1. 105 105 106 106 #============ Rate Control ====================== -
branches/HTM-10.0-dev0/cfg/HEVC/HM/encoder_randomaccess_main.cfg
r655 r852 106 106 #============ Lossless ================ 107 107 TransquantBypassEnableFlag: 0 # Value of PPS flag. 108 CUTransquantBypassFlag Value: 0 # Constant lossless-value signaling per CU, if TransquantBypassEnableFlag is 1.108 CUTransquantBypassFlagForce: 0 # Constant lossless-value signaling per CU, if TransquantBypassEnableFlag is 1. 109 109 110 110 #============ Rate Control ====================== -
branches/HTM-10.0-dev0/cfg/HEVC/HM/encoder_randomaccess_main10.cfg
r655 r852 106 106 #============ Lossless ================ 107 107 TransquantBypassEnableFlag: 0 # Value of PPS flag. 108 CUTransquantBypassFlag Value: 0 # Constant lossless-value signaling per CU, if TransquantBypassEnableFlag is 1.108 CUTransquantBypassFlagForce: 0 # Constant lossless-value signaling per CU, if TransquantBypassEnableFlag is 1. 109 109 110 110 #============ Rate Control ====================== -
branches/HTM-10.0-dev0/cfg/HEVC/HM/per-sequence/Kimono.cfg
r655 r852 8 8 FramesToBeEncoded : 240 # Number of frames to be coded 9 9 10 Level : 4 .010 Level : 4 -
branches/HTM-10.0-dev0/cfg/HEVC/HM/per-sequence/ParkScene.cfg
r655 r852 8 8 FramesToBeEncoded : 240 # Number of frames to be coded 9 9 10 Level : 4 .010 Level : 4 -
branches/HTM-10.0-dev0/cfg/MV-HEVC/baseCfg_2view.cfg
r622 r852 150 150 #============ Lossless ================ 151 151 TransquantBypassEnableFlag: 0 # Value of PPS flag. 152 CUTransquantBypassFlag Value: 0 # Constant lossless-value signaling per CU, if TransquantBypassEnableFlag is 1.152 CUTransquantBypassFlagForce: 0 # Constant lossless-value signaling per CU, if TransquantBypassEnableFlag is 1. 153 153 154 154 #============ Rate Control ====================== -
branches/HTM-10.0-dev0/cfg/MV-HEVC/baseCfg_3view.cfg
r622 r852 167 167 #============ Lossless ================ 168 168 TransquantBypassEnableFlag: 0 # Value of PPS flag. 169 CUTransquantBypassFlag Value: 0 # Constant lossless-value signaling per CU, if TransquantBypassEnableFlag is 1.169 CUTransquantBypassFlagForce: 0 # Constant lossless-value signaling per CU, if TransquantBypassEnableFlag is 1. 170 170 171 171 #============ Rate Control ====================== -
branches/HTM-10.0-dev0/cfg/MV-HEVC/fullCfg.cfg
r622 r852 164 164 #============ Lossless ================ 165 165 TransquantBypassEnableFlag: 0 # Value of PPS flag. 166 CUTransquantBypassFlag Value: 0 # Constant lossless-value signaling per CU, if TransquantBypassEnableFlag is 1.166 CUTransquantBypassFlagForce: 0 # Constant lossless-value signaling per CU, if TransquantBypassEnableFlag is 1. 167 167 168 168 #============ Rate Control ====================== -
branches/HTM-10.0-dev0/doc/Doxyfile
r608 r852 33 33 # if some version control system is used. 34 34 35 PROJECT_NUMBER = HM-1 1.035 PROJECT_NUMBER = HM-13.0 36 36 37 37 # Using the PROJECT_BRIEF tag one can provide an optional one line description -
branches/HTM-10.0-dev0/doc/mainpage.h
r608 r852 25 25 * granted under this license. 26 26 * 27 * Copyright (c) 2010-201 2, ITU/ISO/IEC27 * Copyright (c) 2010-2014, ITU/ISO/IEC 28 28 * All rights reserved. 29 29 * -
branches/HTM-10.0-dev0/doc/software-manual.tex
r608 r852 99 99 \author{% 100 100 Frank Bossen 101 \email{ bossen@docomoinnovations.com}101 \email{frank@bossentech.com} 102 102 \and 103 103 David Flynn 104 \email{d avidf@rd.bbc.co.uk}104 \email{dflynn@blackberry.com} 105 105 \and 106 106 Karsten S\"uhring … … 118 118 \begin{abstract} 119 119 This document is a user manual describing usage of reference software 120 for the HEVC project. It applies to version 1 1.0120 for the HEVC project. It applies to version 13.0 121 121 of the software. 122 122 \end{abstract} … … 952 952 953 953 954 955 %%956 %% Entropy coding parameters957 %%958 \begin{OptionTable}{Entropy coding parameters}959 \Option{SBACRD} &960 \ShortOption{\None} &961 \Default{true} &962 Enables or disables the use of bit counts from arithmetic coder in963 rate-distortion decisions.964 \\965 \end{OptionTable}966 967 968 954 %% 969 955 %% Slice coding parameters … … 1183 1169 transquant_bypass_enable_flag that is transmitted in the PPS. 1184 1170 1185 See CUTransquantBypassFlag Value for further details.1186 \\ 1187 1188 \Option{CUTransquantBypassFlag Value} &1171 See CUTransquantBypassFlagForce for further details. 1172 \\ 1173 1174 \Option{CUTransquantBypassFlagForce} & 1189 1175 \ShortOption{\None} & 1190 1176 \Default{0} & 1191 1177 Controls the per CU transformation, quantization and filtering 1192 1178 mode decision. 1193 This option co rresponds tothe value of the per CU cu_transquant_bypass_flag.1194 \par 1195 \begin{tabular}{cp{0.45\textwidth}} 1196 0 & Bypass is not performed on any CU\\1197 1 & Bypass is performed on all CUs\\1179 This option controls the value of the per CU cu_transquant_bypass_flag. 1180 \par 1181 \begin{tabular}{cp{0.45\textwidth}} 1182 0 & Bypass is searched on a CU-by-CU basis and will be used if the cost is lower than not bypassing. \\ 1183 1 & Bypass is forced for all CUs. \\ 1198 1184 \end{tabular} 1199 1185 … … 1204 1190 \ShortOption{\None} & 1205 1191 \Default{false} & 1206 Enables or disables the use of PCM. 1192 Enables or disables the use of PCM. The encoder will use cost measures on a CU-by-CU basis to determine if PCM mode is to be applied. 1207 1193 \\ 1208 1194 … … 1924 1910 \section{Using the decoder} 1925 1911 \begin{verbatim} 1926 T appDecoder -b str.bin -o dec.yuv [options]1912 TAppDecoder -b str.bin -o dec.yuv [options] 1927 1913 \end{verbatim} 1928 1914 -
branches/HTM-10.0-dev0/source/App/TAppDecoder/TAppDecCfg.cpp
r773 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/App/TAppDecoder/TAppDecCfg.h
r773 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/App/TAppDecoder/TAppDecTop.cpp
r773 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 165 165 Bool firstSlice = true; 166 166 #endif 167 167 Bool loopFiltered = false; 168 168 169 while (!!bitstreamFile) 169 170 { … … 278 279 bitstreamFile.seekg(location-streamoff(3)); 279 280 bytestream.reset(); 281 #if H_MV_ENC_DEC_TRAC 280 282 #if ENC_DEC_TRACE 281 #if H_MV_ENC_DEC_TRAC282 283 const Bool resetCounter = false; 283 284 if ( resetCounter ) … … 287 288 else 288 289 { 289 g_disableHLSTrace = true; // Trancing of second parsing of SH is not carried out 290 } 291 #else 292 g_nSymbolCounter = symCount; 293 #endif 294 #endif 295 } 296 } 297 } 298 if (bNewPicture || !bitstreamFile) 299 { 300 #if H_MV 301 assert( decIdxLastPic != -1 ); 302 m_tDecTop[decIdxLastPic]->endPicDecoding(poc, pcListPic, m_targetDecLayerIdSet ); 303 #else 304 m_cTDecTop.executeLoopFilters(poc, pcListPic); 305 #endif 290 g_disableHLSTrace = true; // Tracing of second parsing of SH is not carried out 291 } 292 #endif 293 #endif 294 } 295 } 296 } 297 if (bNewPicture || !bitstreamFile || nalu.m_nalUnitType == NAL_UNIT_EOS ) 298 { 299 if (!loopFiltered || bitstreamFile) 300 { 301 #if H_MV 302 assert( decIdxLastPic != -1 ); 303 m_tDecTop[decIdxLastPic]->endPicDecoding(poc, pcListPic, m_targetDecLayerIdSet ); 304 #else 305 m_cTDecTop.executeLoopFilters(poc, pcListPic); 306 #endif 307 } 308 loopFiltered = (nalu.m_nalUnitType == NAL_UNIT_EOS); 306 309 } 307 310 #if H_3D … … 351 354 #endif 352 355 } 356 if (nalu.m_nalUnitType == NAL_UNIT_EOS) 357 { 358 #if H_MV 359 xFlushOutput( pcListPic, decIdxLastPic ); 360 #else 361 xFlushOutput( pcListPic ); 362 #endif 363 } 353 364 // write reconstruction to file 354 365 if(bNewPicture) … … 462 473 #endif 463 474 { 475 476 if (pcListPic->empty()) 477 { 478 return; 479 } 480 464 481 TComList<TComPic*>::iterator iterPic = pcListPic->begin(); 465 482 Int numPicsNotYetDisplayed = 0; … … 647 664 #endif 648 665 { 649 if(!pcListPic )666 if(!pcListPic || pcListPic->empty()) 650 667 { 651 668 return; -
branches/HTM-10.0-dev0/source/App/TAppDecoder/TAppDecTop.h
r773 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/App/TAppDecoder/decmain.cpp
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/App/TAppEncoder/TAppEncCfg.cpp
r833 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 444 444 ("QuadtreeTUMaxDepthIntra", m_uiQuadtreeTUMaxDepthIntra, 1u, "Depth of TU tree for intra CUs") 445 445 ("QuadtreeTUMaxDepthInter", m_uiQuadtreeTUMaxDepthInter, 2u, "Depth of TU tree for inter CUs") 446 #if H_MV 446 447 // Coding structure parameters 447 #if H_MV448 448 ("IntraPeriod,-ip", m_iIntraPeriod,std::vector<Int>(1,-1), "Intra period in frames, (-1: only first frame), per layer") 449 449 #else 450 // Coding structure paramters 450 451 ("IntraPeriod,-ip", m_iIntraPeriod, -1, "Intra period in frames, (-1: only first frame)") 451 452 #endif … … 492 493 ("RDOQTS", m_useRDOQTS, true ) 493 494 ("RDpenalty", m_rdPenalty, 0, "RD-penalty for 32x32 TU for intra in non-intra slices. 0:disbaled 1:RD-penalty 2:maximum RD-penalty") 494 // Entropy coding parameters495 ("SBACRD", m_bUseSBACRD, true, "SBAC based RD estimation")496 495 497 496 // Deblocking filter parameters … … 539 538 ("MaxNumOffsetsPerPic", m_maxNumOffsetsPerPic, 2048, "Max number of SAO offset per picture (Default: 2048)") 540 539 ("SAOLcuBoundary", m_saoLcuBoundary, false, "0: right/bottom LCU boundary areas skipped from SAO parameter estimation, 1: non-deblocked pixels are used for those areas") 541 ("SAOLcuBasedOptimization", m_saoLcuBasedOptimization, true, "0: SAO picture-based optimization, 1: SAO LCU-based optimization ")542 540 ("SliceMode", m_sliceMode, 0, "0: Disable all Recon slice limits, 1: Enforce max # of LCUs, 2: Enforce max # of bytes, 3:specify tiles per dependent slice") 543 541 ("SliceArgument", m_sliceArgument, 0, "Depending on SliceMode being:" … … 559 557 ("PCMInputBitDepthFlag", m_bPCMInputBitDepthFlag, true) 560 558 ("PCMFilterDisableFlag", m_bPCMFilterDisableFlag, false) 561 562 ("LosslessCuEnabled", m_useLossless, false)563 559 564 560 ("WeightedPredP,-wpP", m_useWeightedPred, false, "Use weighted prediction in P slices") … … 590 586 ("CFM", m_bUseCbfFastMode, false, "Cbf fast mode setting") 591 587 ("ESD", m_useEarlySkipDetection, false, "Early SKIP detection setting") 592 #if RATE_CONTROL_LAMBDA_DOMAIN593 588 ( "RateControl", m_RCEnableRateControl, false, "Rate control: enable rate control" ) 594 589 ( "TargetBitrate", m_RCTargetBitrate, 0, "Rate control: target bitrate" ) 595 #if M0036_RC_IMPROVEMENT596 590 ( "KeepHierarchicalBit", m_RCKeepHierarchicalBit, 0, "Rate control: 0: equal bit allocation; 1: fixed ratio bit allocation; 2: adaptive ratio bit allocation" ) 597 #else598 ( "KeepHierarchicalBit", m_RCKeepHierarchicalBit, false, "Rate control: keep hierarchical bit allocation in rate control algorithm" )599 #endif600 591 ( "LCULevelRateControl", m_RCLCULevelRC, true, "Rate control: true: LCU level RC; false: picture level RC" ) 601 592 ( "RCLCUSeparateModel", m_RCUseLCUSeparateModel, true, "Rate control: use LCU level separate R-lambda model" ) … … 610 601 ("DepthMADPred, -dm", m_depthMADPred, (UInt)0, "Depth based MAD prediction on/off") 611 602 #endif 612 #else613 ("RateCtrl,-rc", m_enableRateCtrl, false, "Rate control on/off")614 ("TargetBitrate,-tbr", m_targetBitrate, 0, "Input target bitrate")615 ("NumLCUInUnit,-nu", m_numLCUInUnit, 0, "Number of LCUs in an Unit")616 617 #if KWU_RC_VIEWRC_E0227618 ("ViewWiseTargetBits, -vtbr" , m_viewTargetBits, std::vector<Int>(1, 32), "View-wise target bit-rate setting")619 ("TargetBitAssign, -ta", m_viewWiseRateCtrl, false, "View-wise rate control on/off")620 #endif621 #if KWU_RC_MADPRED_E0227622 ("DepthMADPred, -dm", m_depthMADPred, (UInt)0, "Depth based MAD prediction on/off")623 #endif624 #endif625 626 603 #if H_MV 627 604 … … 653 630 654 631 ("TransquantBypassEnableFlag", m_TransquantBypassEnableFlag, false, "transquant_bypass_enable_flag indicator in PPS") 655 ("CUTransquantBypassFlag Value", m_CUTransquantBypassFlagValue, false, "Fixed cu_transquant_bypass_flag value, when transquant_bypass_enable_flag is enabled")632 ("CUTransquantBypassFlagForce", m_CUTransquantBypassFlagForce, false, "Force transquant bypass mode, when transquant_bypass_enable_flag is enabled") 656 633 ("RecalculateQPAccordingToLambda", m_recalculateQPAccordingToLambda, false, "Recalculate QP values according to lambda values. Do not suggest to be enabled in all intra case") 657 634 ("StrongIntraSmoothing,-sis", m_useStrongIntraSmoothing, true, "Enable strong intra smoothing for 32x32 blocks") … … 2021 1998 m_maxTempLayer = m_GOPList[i].m_temporalId+1; 2022 1999 } 2023 xConfirmPara(m_GOPList[i].m_sliceType!='B'&&m_GOPList[i].m_sliceType!='P' , "Slice type must be equal to B or P");2000 xConfirmPara(m_GOPList[i].m_sliceType!='B'&&m_GOPList[i].m_sliceType!='P'&&m_GOPList[i].m_sliceType!='I', "Slice type must be equal to B or P or I"); 2024 2001 } 2025 2002 for(Int i=0; i<MAX_TLAYER; i++) … … 2172 2149 } 2173 2150 2174 #if RATE_CONTROL_LAMBDA_DOMAIN2175 2151 if ( m_RCEnableRateControl ) 2176 2152 { … … 2185 2161 xConfirmPara( m_uiDeltaQpRD > 0, "Rate control cannot be used together with slice level multiple-QP optimization!\n" ); 2186 2162 } 2187 #else2188 if(m_enableRateCtrl)2189 {2190 Int numLCUInWidth = (m_iSourceWidth / m_uiMaxCUWidth) + (( m_iSourceWidth % m_uiMaxCUWidth ) ? 1 : 0);2191 Int numLCUInHeight = (m_iSourceHeight / m_uiMaxCUHeight)+ (( m_iSourceHeight % m_uiMaxCUHeight) ? 1 : 0);2192 Int numLCUInPic = numLCUInWidth * numLCUInHeight;2193 2194 xConfirmPara( (numLCUInPic % m_numLCUInUnit) != 0, "total number of LCUs in a frame should be completely divided by NumLCUInUnit" );2195 2196 #if !KWU_FIX_URQ2197 m_iMaxDeltaQP = MAX_DELTA_QP;2198 #endif2199 m_iMaxCuDQPDepth = MAX_CUDQP_DEPTH;2200 }2201 #endif2202 2163 #if H_MV 2203 2164 // VPS VUI … … 2223 2184 #endif 2224 2185 2225 xConfirmPara(!m_TransquantBypassEnableFlag && m_CUTransquantBypassFlag Value, "CUTransquantBypassFlagValue cannot be 1 when TransquantBypassEnableFlag is 0");2186 xConfirmPara(!m_TransquantBypassEnableFlag && m_CUTransquantBypassFlagForce, "CUTransquantBypassFlagForce cannot be 1 when TransquantBypassEnableFlag is 0"); 2226 2187 2227 2188 xConfirmPara(m_log2ParallelMergeLevel < 2, "Log2ParallelMergeLevel should be larger than or equal to 2"); … … 2343 2304 printf("Internal bit depth : (Y:%d, C:%d)\n", m_internalBitDepthY, m_internalBitDepthC ); 2344 2305 printf("PCM sample bit depth : (Y:%d, C:%d)\n", g_uiPCMBitDepthLuma, g_uiPCMBitDepthChroma ); 2345 #if RATE_CONTROL_LAMBDA_DOMAIN2346 2306 printf("RateControl : %d\n", m_RCEnableRateControl ); 2347 2307 if(m_RCEnableRateControl) … … 2373 2333 #endif 2374 2334 } 2375 #else2376 printf("RateControl : %d\n", m_enableRateCtrl);2377 if(m_enableRateCtrl)2378 {2379 printf("TargetBitrate : %d\n", m_targetBitrate);2380 printf("NumLCUInUnit : %d\n", m_numLCUInUnit);2381 2382 #if KWU_RC_MADPRED_E02272383 printf("Depth based MAD prediction : %d\n", m_depthMADPred);2384 #endif2385 #if KWU_RC_VIEWRC_E02272386 printf("View-wise Rate control : %d\n", m_viewWiseRateCtrl);2387 if(m_viewWiseRateCtrl)2388 {2389 2390 printf("ViewWiseTargetBits : ");2391 for (Int i = 0 ; i < m_iNumberOfViews ; i++)2392 printf("%d ", m_viewTargetBits[i]);2393 printf("\n");2394 }2395 else2396 {2397 printf("TargetBitrate : %d\n", m_targetBitrate );2398 }2399 #endif2400 }2401 #endif2402 2335 printf("Max Num Merge Candidates : %d\n", m_maxNumMergeCand); 2403 2336 #if H_3D … … 2429 2362 printf("IBD:%d ", g_bitDepthY > m_inputBitDepthY || g_bitDepthC > m_inputBitDepthC); 2430 2363 printf("HAD:%d ", m_bUseHADME ); 2431 printf("SRD:%d ", m_bUseSBACRD );2432 2364 printf("RDQ:%d ", m_useRDOQ ); 2433 2365 printf("RDQTS:%d ", m_useRDOQTS ); … … 2458 2390 #endif 2459 2391 printf("PCM:%d ", (m_usePCM && (1<<m_uiPCMLog2MinSize) <= m_uiMaxCUWidth)? 1 : 0); 2460 printf("SAOLcuBasedOptimization:%d ", (m_saoLcuBasedOptimization)?(1):(0)); 2461 2462 printf("LosslessCuEnabled:%d ", (m_useLossless)? 1:0 ); 2392 if (m_TransquantBypassEnableFlag && m_CUTransquantBypassFlagForce) 2393 { 2394 printf("TransQuantBypassEnabled: =1 "); 2395 } 2396 else 2397 { 2398 printf("TransQuantBypassEnabled:%d ", (m_TransquantBypassEnableFlag)? 1:0 ); 2399 } 2463 2400 printf("WPP:%d ", (Int)m_useWeightedPred); 2464 2401 printf("WPB:%d ", (Int)m_useWeightedBiPred); -
branches/HTM-10.0-dev0/source/App/TAppEncoder/TAppEncCfg.h
r833 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 259 259 Bool m_bPCMInputBitDepthFlag; ///< 0: PCM bit-depth is internal bit-depth. 1: PCM bit-depth is input bit-depth. 260 260 261 // coding tool (lossless) 262 Bool m_useLossless; ///< flag for using lossless coding 261 // coding tool (SAO) 263 262 #if H_MV 264 263 std::vector<Bool> m_bUseSAO; … … 268 267 Int m_maxNumOffsetsPerPic; ///< SAO maximun number of offset per picture 269 268 Bool m_saoLcuBoundary; ///< SAO parameter estimation using non-deblocked pixels for LCU bottom and right boundary areas 270 Bool m_saoLcuBasedOptimization; ///< SAO LCU-based optimization271 269 // coding tools (loop filter) 272 270 #if H_MV … … 288 286 289 287 // coding tools (encoder-only parameters) 290 Bool m_bUseSBACRD; ///< flag for using RD optimization based on SBAC291 288 Bool m_bUseASR; ///< flag for using adaptive motion search range 292 289 Bool m_bUseHADME; ///< flag for using HAD in sub-pel ME … … 372 369 Int m_TMVPModeId; 373 370 Int m_signHideFlag; 374 #if RATE_CONTROL_LAMBDA_DOMAIN375 371 Bool m_RCEnableRateControl; ///< enable rate control or not 376 372 Int m_RCTargetBitrate; ///< target bitrate when rate control is enabled 377 #if M0036_RC_IMPROVEMENT378 373 Int m_RCKeepHierarchicalBit; ///< 0: equal bit allocation; 1: fixed ratio bit allocation; 2: adaptive ratio bit allocation 379 #else380 Bool m_RCKeepHierarchicalBit; ///< whether keeping hierarchical bit allocation structure or not381 #endif382 374 Bool m_RCLCULevelRC; ///< true: LCU level rate control; false: picture level rate control 383 375 Bool m_RCUseLCUSeparateModel; ///< use separate R-lambda model at LCU level … … 392 384 UInt m_depthMADPred; 393 385 #endif 394 #else395 Bool m_enableRateCtrl; ///< Flag for using rate control algorithm396 Int m_targetBitrate; ///< target bitrate397 Int m_numLCUInUnit; ///< Total number of LCUs in a frame should be completely divided by the NumLCUInUnit398 399 #if KWU_RC_VIEWRC_E0227400 vector<Int> m_viewTargetBits;401 Bool m_viewWiseRateCtrl; ///< Flag for using view-wise rate control402 #endif403 #if KWU_RC_MADPRED_E0227404 UInt m_depthMADPred;405 #endif406 #endif407 386 Int m_useScalingListId; ///< using quantization matrix 408 387 Char* m_scalingListFile; ///< quantization matrix file name 409 388 410 389 Bool m_TransquantBypassEnableFlag; ///< transquant_bypass_enable_flag setting in PPS. 411 Bool m_CUTransquantBypassFlag Value; ///< if transquant_bypass_enable_flag, the fixed value to use for the per-CU cu_transquant_bypass_flag.390 Bool m_CUTransquantBypassFlagForce; ///< if transquant_bypass_enable_flag, then, if true, all CU transquant bypass flags will be set to true. 412 391 413 392 Bool m_recalculateQPAccordingToLambda; ///< recalculate QP value according to the lambda value -
branches/HTM-10.0-dev0/source/App/TAppEncoder/TAppEncTop.cpp
r833 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 309 309 #endif 310 310 311 Int lowestQP;312 lowestQP = - 6*(g_bitDepthY - 8); // XXX: check313 314 #if H_MV315 if ((m_iMaxDeltaQP == 0 ) && (m_iQP[layerIdInVps] == lowestQP) && (m_useLossless == true))316 #else317 if ((m_iMaxDeltaQP == 0 ) && (m_iQP == lowestQP) && (m_useLossless == true))318 #endif319 {320 m_bUseAdaptiveQP = false;321 }322 311 m_cTEncTop.setUseAdaptiveQP ( m_bUseAdaptiveQP ); 323 312 m_cTEncTop.setQPAdaptationRange ( m_iQPAdaptationRange ); 324 313 325 314 //====== Tool list ======== 326 m_cTEncTop.setUseSBACRD ( m_bUseSBACRD );327 315 m_cTEncTop.setDeltaQpRD ( m_uiDeltaQpRD ); 328 316 m_cTEncTop.setUseASR ( m_bUseASR ); 329 317 m_cTEncTop.setUseHADME ( m_bUseHADME ); 330 m_cTEncTop.setUseLossless ( m_useLossless );331 318 #if H_MV 332 319 m_cTEncTop.setdQPs ( m_aidQP[layerIdInVps] ); … … 396 383 397 384 m_cTEncTop.setSaoLcuBoundary (m_saoLcuBoundary); 398 m_cTEncTop.setSaoLcuBasedOptimization (m_saoLcuBasedOptimization);399 385 m_cTEncTop.setPCMInputBitDepthFlag ( m_bPCMInputBitDepthFlag); 400 386 m_cTEncTop.setPCMFilterDisableFlag ( m_bPCMFilterDisableFlag); … … 461 447 m_cTEncTop.setScalingListFile ( m_scalingListFile ); 462 448 m_cTEncTop.setSignHideFlag(m_signHideFlag); 463 #if RATE_CONTROL_LAMBDA_DOMAIN464 449 #if KWU_RC_VIEWRC_E0227 || KWU_RC_MADPRED_E0227 465 450 if(!m_cTEncTop.getIsDepth()) //only for texture … … 482 467 m_cTEncTop.setInitialQP ( m_RCInitialQP ); 483 468 m_cTEncTop.setForceIntraQP ( m_RCForceIntraQP ); 484 485 469 #if KWU_RC_MADPRED_E0227 486 470 if(m_cTEncTop.getUseRateCtrl() && !m_cTEncTop.getIsDepth()) 487 471 { 488 472 m_cTEncTop.setUseDepthMADPred(layerIdInVps ? m_depthMADPred : 0); 489 490 473 if(m_cTEncTop.getUseDepthMADPred()) 491 474 { … … 498 481 { 499 482 m_cTEncTop.setUseViewWiseRateCtrl(m_viewWiseRateCtrl); 500 501 483 if(m_iNumberOfViews == 1) 502 484 { … … 552 534 } 553 535 #endif 554 #else555 #if KWU_RC_VIEWRC_E0227 || KWU_RC_MADPRED_E0227556 if(!m_cTEncTop.getIsDepth()) //only for texture557 {558 m_cTEncTop.setUseRateCtrl ( m_enableRateCtrl );559 m_cTEncTop.setTargetBitrate ( m_targetBitrate );560 m_cTEncTop.setNumLCUInUnit ( m_numLCUInUnit);561 }562 else563 {564 m_cTEncTop.setUseRateCtrl ( 0 );565 }566 #else567 m_cTEncTop.setUseRateCtrl ( m_enableRateCtrl );568 m_cTEncTop.setTargetBitrate ( m_targetBitrate );569 m_cTEncTop.setNumLCUInUnit ( m_numLCUInUnit);570 #endif571 572 573 #if KWU_RC_MADPRED_E0227574 if(m_cTEncTop.getUseRateCtrl() && !m_cTEncTop.getIsDepth())575 {576 m_cTEncTop.setUseDepthMADPred(layerIdInVps ? m_depthMADPred : 0);577 578 if(m_cTEncTop.getUseDepthMADPred())579 {580 m_cTEncTop.setCamParam(&m_cCameraData);581 }582 }583 #endif584 585 #if KWU_RC_VIEWRC_E0227586 if(m_cTEncTop.getUseRateCtrl() && !m_cTEncTop.getIsDepth())587 {588 m_cTEncTop.setUseViewWiseRateCtrl(m_viewWiseRateCtrl);589 if(m_iNumberOfViews == 1)590 {591 if(m_viewWiseRateCtrl)592 {593 m_cTEncTop.setTargetBitrate(m_viewTargetBits[layerIdInVps>>1]);594 }595 else596 {597 m_cTEncTop.setTargetBitrate ( m_targetBitrate );598 }599 }600 else601 {602 if(m_viewWiseRateCtrl)603 {604 m_cTEncTop.setTargetBitrate(m_viewTargetBits[layerIdInVps>>1]);605 }606 else607 {608 if(m_iNumberOfViews == 2)609 {610 if(m_cTEncTop.getViewId() == 0)611 {612 m_cTEncTop.setTargetBitrate ( (m_targetBitrate*80)/100 );613 }614 else if(m_cTEncTop.getViewId() == 1)615 {616 m_cTEncTop.setTargetBitrate ( (m_targetBitrate*20)/100 );617 }618 }619 else if(m_iNumberOfViews == 3)620 {621 if(m_cTEncTop.getViewId() == 0)622 {623 m_cTEncTop.setTargetBitrate ( (m_targetBitrate*66)/100 );624 }625 else if(m_cTEncTop.getViewId() == 1)626 {627 m_cTEncTop.setTargetBitrate ( (m_targetBitrate*17)/100 );628 }629 else if(m_cTEncTop.getViewId() == 2)630 {631 m_cTEncTop.setTargetBitrate ( (m_targetBitrate*17)/100 );632 }633 }634 else635 {636 m_cTEncTop.setTargetBitrate ( m_targetBitrate );637 }638 }639 }640 }641 #endif642 #endif643 536 m_cTEncTop.setTransquantBypassEnableFlag(m_TransquantBypassEnableFlag); 644 m_cTEncTop.setCUTransquantBypassFlag Value(m_CUTransquantBypassFlagValue);537 m_cTEncTop.setCUTransquantBypassFlagForceValue(m_CUTransquantBypassFlagForce); 645 538 m_cTEncTop.setUseRecalculateQPAccordingToLambda( m_recalculateQPAccordingToLambda ); 646 539 m_cTEncTop.setUseStrongIntraSmoothing( m_useStrongIntraSmoothing ); … … 932 825 } 933 826 934 #if !RATE_CONTROL_LAMBDA_DOMAIN && KWU_FIX_URQ935 for(Int layer=0; layer < m_numberOfLayers; layer++ )936 {937 if(m_acTEncTopList[layer]->getUseRateCtrl() && !m_acTEncTopList[layer]->getIsDepth())938 {939 m_acTEncTopList[layer]->getRateCtrl()->updateRCGOPStatus();940 }941 }942 #endif943 944 827 gopSize = maxGopSize; 945 828 } … … 1203 1086 rateStatsAccum(au, stats); 1204 1087 } 1205 #endif 1088 #endif 1206 1089 } 1207 1090 } … … 1221 1104 case NAL_UNIT_CODED_SLICE_TRAIL_R: 1222 1105 case NAL_UNIT_CODED_SLICE_TRAIL_N: 1223 case NAL_UNIT_CODED_SLICE_T LA_R:1106 case NAL_UNIT_CODED_SLICE_TSA_R: 1224 1107 case NAL_UNIT_CODED_SLICE_TSA_N: 1225 1108 case NAL_UNIT_CODED_SLICE_STSA_R: … … 1963 1846 } 1964 1847 #endif 1965 1966 1848 //! \} -
branches/HTM-10.0-dev0/source/App/TAppEncoder/TAppEncTop.h
r773 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/App/TAppEncoder/encmain.cpp
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/App/utils/BitrateTargeting/ExtractBitrates.cpp
r56 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-201 2, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/App/utils/BitrateTargeting/ExtractBitrates.h
r56 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-201 2, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/App/utils/BitrateTargeting/ExtractBitratesMain.cpp
r56 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-201 2, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/App/utils/BitrateTargeting/GuessLambdaModifiers.cpp
r56 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-201 2, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/App/utils/BitrateTargeting/GuessLambdaModifiers.h
r56 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-201 2, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/App/utils/BitrateTargeting/GuessLambdaModifiersMain.cpp
r56 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-201 2, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/App/utils/BitrateTargeting/RuntimeError.h
r56 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-201 2, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/App/utils/BitrateTargeting/encode.shl
r56 r852 4 4 # granted under this license. 5 5 # 6 # Copyright (c) 2010-201 2, ITU/ISO/IEC6 # Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 # All rights reserved. 8 8 # -
branches/HTM-10.0-dev0/source/App/utils/BitrateTargeting/encodeCommand.sh
r56 r852 6 6 # granted under this license. 7 7 # 8 # Copyright (c) 2010-201 2, ITU/ISO/IEC8 # Copyright (c) 2010-2014, ITU/ISO/IEC 9 9 # All rights reserved. 10 10 # -
branches/HTM-10.0-dev0/source/App/utils/BitrateTargeting/makefile
r56 r852 4 4 # granted under this license. 5 5 # 6 # Copyright (c) 2010-201 2, ITU/ISO/IEC6 # Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 # All rights reserved. 8 8 # -
branches/HTM-10.0-dev0/source/App/utils/BitrateTargeting/targetBitrates.sh
r56 r852 6 6 # granted under this license. 7 7 # 8 # Copyright (c) 2010-201 2, ITU/ISO/IEC8 # Copyright (c) 2010-2014, ITU/ISO/IEC 9 9 # All rights reserved. 10 10 # -
branches/HTM-10.0-dev0/source/App/utils/annexBbytecount.cpp
r56 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-201 2, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/App/utils/convert_NtoMbit_YCbCr.cpp
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-201 2, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/TAppCommon/program_options_lite.cpp
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 38 38 #include <list> 39 39 #include <map> 40 #include <algorithm> 40 41 #include "program_options_lite.h" 41 42 #include "../TLibCommon/TypeDef.h" -
branches/HTM-10.0-dev0/source/Lib/TAppCommon/program_options_lite.h
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/TLibCommon/AccessUnit.h
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/TLibCommon/CommonDef.h
r849 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 61 61 #if H_MV 62 62 #define NV_VERSION "10.0" ///< Current software version 63 #define HM_VERSION "1 2.0" ///<63 #define HM_VERSION "13.0" ///< 64 64 #else 65 #define NV_VERSION "1 2.0" ///< Current software version65 #define NV_VERSION "13.0" ///< Current software version 66 66 #endif 67 67 … … 247 247 248 248 NAL_UNIT_CODED_SLICE_TSA_N, // 2 249 NAL_UNIT_CODED_SLICE_T LA_R, // 3249 NAL_UNIT_CODED_SLICE_TSA_R, // 3 250 250 251 251 NAL_UNIT_CODED_SLICE_STSA_N, // 4 -
branches/HTM-10.0-dev0/source/Lib/TLibCommon/ContextModel.cpp
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/TLibCommon/ContextModel.h
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/TLibCommon/ContextModel3DBuffer.cpp
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/TLibCommon/ContextModel3DBuffer.h
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/TLibCommon/ContextTables.h
r833 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 42 42 //! \ingroup TLibCommon 43 43 //! \{ 44 #define FIX827 1 ///< Fix for issue #827: CABAC init tables45 #define FIX712 1 ///< Fix for issue #712: CABAC init tables46 44 47 45 // ==================================================================================================================== … … 58 56 59 57 #define NUM_PART_SIZE_CTX 4 ///< number of context models for partition size 60 #define NUM_CU_AMP_CTX 1 ///< number of context models for partition size (AMP)61 58 #define NUM_PRED_MODE_CTX 1 ///< number of context models for prediction mode 62 59 … … 69 66 #define NUM_REF_NO_CTX 2 ///< number of context models for reference index 70 67 #define NUM_TRANS_SUBDIV_FLAG_CTX 3 ///< number of context models for transform subdivision flags 71 #define NUM_QT_CBF_CTX 5///< number of context models for QT CBF68 #define NUM_QT_CBF_CTX 4 ///< number of context models for QT CBF 72 69 #define NUM_QT_ROOT_CBF_CTX 1 ///< number of context models for QT ROOT CBF 73 70 #define NUM_DELTA_QP_CTX 3 ///< number of context models for dQP … … 88 85 #define NUM_ABS_FLAG_CTX_CHROMA 2 ///< number of context models for greater than 2 flag of chroma 89 86 90 #define NUM_MVP_IDX_CTX 2///< number of context models for MVP index87 #define NUM_MVP_IDX_CTX 1 ///< number of context models for MVP index 91 88 92 89 #define NUM_SAO_MERGE_FLAG_CTX 1 ///< number of context models for SAO merge flags … … 199 196 INIT_PART_SIZE[3][NUM_PART_SIZE_CTX] = 200 197 { 201 { 154, 139, CNU, CNU, }, 202 { 154, 139, CNU, CNU, }, 203 { 184, CNU, CNU, CNU, }, 204 }; 205 206 static const UChar 207 INIT_CU_AMP_POS[3][NUM_CU_AMP_CTX] = 208 { 209 { 154, }, 210 { 154, }, 211 { CNU, }, 198 { 154, 139, 154, 154 }, 199 { 154, 139, 154, 154 }, 200 { 184, CNU, CNU, CNU }, 212 201 }; 213 202 … … 271 260 INIT_QT_CBF[3][2*NUM_QT_CBF_CTX] = 272 261 { 273 { 153, 111, CNU, CNU, CNU, 149, 92, 167, CNU, CNU, },274 { 153, 111, CNU, CNU, CNU, 149, 107, 167, CNU, CNU, },275 { 111, 141, CNU, CNU, CNU, 94, 138, 182, CNU, CNU, },262 { 153, 111, CNU, CNU, 149, 92, 167, 154 }, 263 { 153, 111, CNU, CNU, 149, 107, 167, 154 }, 264 { 111, 141, CNU, CNU, 94, 138, 182, 154 }, 276 265 }; 277 266 … … 339 328 INIT_MVP_IDX[3][NUM_MVP_IDX_CTX] = 340 329 { 341 { 168 , CNU, },342 { 168 , CNU, },343 { CNU , CNU,},330 { 168 }, 331 { 168 }, 332 { CNU }, 344 333 }; 345 334 … … 355 344 INIT_SAO_TYPE_IDX[3][NUM_SAO_TYPE_IDX_CTX] = 356 345 { 357 #if FIX827358 346 { 160, }, 359 347 { 185, }, 360 348 { 200, }, 361 #else362 { 200, },363 { 185, },364 { 160, },365 #endif366 349 }; 367 350 … … 369 352 INIT_TRANS_SUBDIV_FLAG[3][NUM_TRANS_SUBDIV_FLAG_CTX] = 370 353 { 371 #if FIX712372 354 { 224, 167, 122, }, 373 355 { 124, 138, 94, }, 374 356 { 153, 138, 138, }, 375 #else376 { 153, 138, 138, },377 { 124, 138, 94, },378 { 224, 167, 122, },379 #endif380 357 }; 381 358 -
branches/HTM-10.0-dev0/source/Lib/TLibCommon/NAL.h
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 79 79 return m_nalUnitType == NAL_UNIT_CODED_SLICE_TRAIL_R 80 80 || m_nalUnitType == NAL_UNIT_CODED_SLICE_TRAIL_N 81 || m_nalUnitType == NAL_UNIT_CODED_SLICE_T LA_R81 || m_nalUnitType == NAL_UNIT_CODED_SLICE_TSA_R 82 82 || m_nalUnitType == NAL_UNIT_CODED_SLICE_TSA_N 83 83 || m_nalUnitType == NAL_UNIT_CODED_SLICE_STSA_R -
branches/HTM-10.0-dev0/source/Lib/TLibCommon/SEI.cpp
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/TLibCommon/SEI.h
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/TLibCommon/TComBitCounter.h
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/TLibCommon/TComBitStream.cpp
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/TLibCommon/TComBitStream.h
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/TLibCommon/TComCABACTables.cpp
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/TLibCommon/TComCABACTables.h
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/TLibCommon/TComDataCU.cpp
r833 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 488 488 } 489 489 490 const NDBFBlockInfo& NDBFBlockInfo::operator= (const NDBFBlockInfo& src)491 {492 this->tileID = src.tileID;493 this->sliceID= src.sliceID;494 this->startSU= src.startSU;495 this->endSU = src.endSU;496 this->widthSU= src.widthSU;497 this->heightSU=src.heightSU;498 this->posX = src.posX;499 this->posY = src.posY;500 this->width = src.width;501 this->height = src.height;502 ::memcpy(this->isBorderAvailable, src.isBorderAvailable, sizeof(Bool)*((Int)NUM_SGU_BORDER));503 this->allBordersAvailable = src.allBordersAvailable;504 505 return *this;506 }507 508 509 490 // ==================================================================================================================== 510 491 // Public member functions … … 801 782 *- set last-coded qp value according to input last-coded qp 802 783 */ 803 Void TComDataCU::initEstData( UInt uiDepth, Int qp )784 Void TComDataCU::initEstData( UInt uiDepth, Int qp, Bool bTransquantBypass ) 804 785 { 805 786 m_dTotalCost = MAX_DOUBLE; … … 829 810 m_pePartSize[ui] = SIZE_NONE; 830 811 m_pePredMode[ui] = MODE_NONE; 831 m_CUTransquantBypass[ui] = false;812 m_CUTransquantBypass[ui] = bTransquantBypass; 832 813 m_pbIPCMFlag[ui] = 0; 833 814 m_phQP[ui] = qp; … … 5980 5961 xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxLT, MD_ABOVE_LEFT); 5981 5962 } 5982 bAdded = bAddedSmvp; 5983 if (pInfo->iN==2) bAdded = true; 5984 5985 if(!bAdded) 5963 5964 if (!bAddedSmvp) 5986 5965 { 5987 5966 bAdded = xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxRT, MD_ABOVE_RIGHT); … … 6641 6620 { 6642 6621 return getPic()->getPicSym()->getInverseCUOrderMap(m_uiCUAddr)*(1<<(m_pcSlice->getSPS()->getMaxCUDepth()<<1))+m_uiAbsIdxInLCU; 6643 }6644 6645 /** Set neighboring blocks availabilities for non-deblocked filtering6646 * \param numLCUInPicWidth number of LCUs in picture width6647 * \param numLCUInPicHeight number of LCUs in picture height6648 * \param numSUInLCUWidth number of SUs in LCU width6649 * \param numSUInLCUHeight number of SUs in LCU height6650 * \param picWidth picture width6651 * \param picHeight picture height6652 * \param bIndependentSliceBoundaryEnabled true for independent slice boundary enabled6653 * \param bTopTileBoundary true means that top boundary coincides tile boundary6654 * \param bDownTileBoundary true means that bottom boundary coincides tile boundary6655 * \param bLeftTileBoundary true means that left boundary coincides tile boundary6656 * \param bRightTileBoundary true means that right boundary coincides tile boundary6657 * \param bIndependentTileBoundaryEnabled true for independent tile boundary enabled6658 */6659 Void TComDataCU::setNDBFilterBlockBorderAvailability(UInt numLCUInPicWidth, UInt /*numLCUInPicHeight*/, UInt numSUInLCUWidth, UInt numSUInLCUHeight, UInt picWidth, UInt picHeight6660 ,std::vector<Bool>& LFCrossSliceBoundary6661 ,Bool bTopTileBoundary, Bool bDownTileBoundary, Bool bLeftTileBoundary, Bool bRightTileBoundary6662 ,Bool bIndependentTileBoundaryEnabled)6663 {6664 UInt numSUInLCU = numSUInLCUWidth*numSUInLCUHeight;6665 Int* pSliceIDMapLCU = m_piSliceSUMap;6666 Bool onlyOneSliceInPic = ((Int)LFCrossSliceBoundary.size() == 1);6667 UInt uiLPelX, uiTPelY;6668 UInt width, height;6669 Bool bPicRBoundary, bPicBBoundary, bPicTBoundary, bPicLBoundary;6670 Bool bLCURBoundary= false, bLCUBBoundary= false, bLCUTBoundary= false, bLCULBoundary= false;6671 Bool* pbAvailBorder;6672 Bool* pbAvail;6673 UInt rTLSU, rBRSU, widthSU, heightSU;6674 UInt zRefSU;6675 Int* pRefID;6676 Int* pRefMapLCU;6677 UInt rTRefSU= 0, rBRefSU= 0, rLRefSU= 0, rRRefSU= 0;6678 Int* pRRefMapLCU= NULL;6679 Int* pLRefMapLCU= NULL;6680 Int* pTRefMapLCU= NULL;6681 Int* pBRefMapLCU= NULL;6682 Int sliceID;6683 UInt numSGU = (UInt)m_vNDFBlock.size();6684 6685 for(Int i=0; i< numSGU; i++)6686 {6687 NDBFBlockInfo& rSGU = m_vNDFBlock[i];6688 6689 sliceID = rSGU.sliceID;6690 uiLPelX = rSGU.posX;6691 uiTPelY = rSGU.posY;6692 width = rSGU.width;6693 height = rSGU.height;6694 rTLSU = g_auiZscanToRaster[ rSGU.startSU ];6695 rBRSU = g_auiZscanToRaster[ rSGU.endSU ];6696 widthSU = rSGU.widthSU;6697 heightSU = rSGU.heightSU;6698 6699 pbAvailBorder = rSGU.isBorderAvailable;6700 6701 bPicTBoundary= (uiTPelY == 0 )?(true):(false);6702 bPicLBoundary= (uiLPelX == 0 )?(true):(false);6703 bPicRBoundary= (!(uiLPelX+ width < picWidth ) )?(true):(false);6704 bPicBBoundary= (!(uiTPelY + height < picHeight))?(true):(false);6705 6706 bLCULBoundary = (rTLSU % numSUInLCUWidth == 0)?(true):(false);6707 bLCURBoundary = ( (rTLSU+ widthSU) % numSUInLCUWidth == 0)?(true):(false);6708 bLCUTBoundary = ( (UInt)(rTLSU / numSUInLCUWidth)== 0)?(true):(false);6709 bLCUBBoundary = ( (UInt)(rBRSU / numSUInLCUWidth) == (numSUInLCUHeight-1) )?(true):(false);6710 6711 // SGU_L6712 pbAvail = &(pbAvailBorder[SGU_L]);6713 if(bPicLBoundary)6714 {6715 *pbAvail = false;6716 }6717 else if (onlyOneSliceInPic)6718 {6719 *pbAvail = true;6720 }6721 else6722 {6723 // bLCULBoundary = (rTLSU % uiNumSUInLCUWidth == 0)?(true):(false);6724 if(bLCULBoundary)6725 {6726 rLRefSU = rTLSU + numSUInLCUWidth -1;6727 zRefSU = g_auiRasterToZscan[rLRefSU];6728 pRefMapLCU = pLRefMapLCU= (pSliceIDMapLCU - numSUInLCU);6729 }6730 else6731 {6732 zRefSU = g_auiRasterToZscan[rTLSU - 1];6733 pRefMapLCU = pSliceIDMapLCU;6734 }6735 pRefID = pRefMapLCU + zRefSU;6736 *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));6737 }6738 6739 // SGU_R6740 pbAvail = &(pbAvailBorder[SGU_R]);6741 if(bPicRBoundary)6742 {6743 *pbAvail = false;6744 }6745 else if (onlyOneSliceInPic)6746 {6747 *pbAvail = true;6748 }6749 else6750 {6751 // bLCURBoundary = ( (rTLSU+ uiWidthSU) % uiNumSUInLCUWidth == 0)?(true):(false);6752 if(bLCURBoundary)6753 {6754 rRRefSU = rTLSU + widthSU - numSUInLCUWidth;6755 zRefSU = g_auiRasterToZscan[rRRefSU];6756 pRefMapLCU = pRRefMapLCU= (pSliceIDMapLCU + numSUInLCU);6757 }6758 else6759 {6760 zRefSU = g_auiRasterToZscan[rTLSU + widthSU];6761 pRefMapLCU = pSliceIDMapLCU;6762 }6763 pRefID = pRefMapLCU + zRefSU;6764 *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));6765 }6766 6767 // SGU_T6768 pbAvail = &(pbAvailBorder[SGU_T]);6769 if(bPicTBoundary)6770 {6771 *pbAvail = false;6772 }6773 else if (onlyOneSliceInPic)6774 {6775 *pbAvail = true;6776 }6777 else6778 {6779 // bLCUTBoundary = ( (UInt)(rTLSU / uiNumSUInLCUWidth)== 0)?(true):(false);6780 if(bLCUTBoundary)6781 {6782 rTRefSU = numSUInLCU - (numSUInLCUWidth - rTLSU);6783 zRefSU = g_auiRasterToZscan[rTRefSU];6784 pRefMapLCU = pTRefMapLCU= (pSliceIDMapLCU - (numLCUInPicWidth*numSUInLCU));6785 }6786 else6787 {6788 zRefSU = g_auiRasterToZscan[rTLSU - numSUInLCUWidth];6789 pRefMapLCU = pSliceIDMapLCU;6790 }6791 pRefID = pRefMapLCU + zRefSU;6792 *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));6793 }6794 6795 // SGU_B6796 pbAvail = &(pbAvailBorder[SGU_B]);6797 if(bPicBBoundary)6798 {6799 *pbAvail = false;6800 }6801 else if (onlyOneSliceInPic)6802 {6803 *pbAvail = true;6804 }6805 else6806 {6807 // bLCUBBoundary = ( (UInt)(rBRSU / uiNumSUInLCUWidth) == (uiNumSUInLCUHeight-1) )?(true):(false);6808 if(bLCUBBoundary)6809 {6810 rBRefSU = rTLSU % numSUInLCUWidth;6811 zRefSU = g_auiRasterToZscan[rBRefSU];6812 pRefMapLCU = pBRefMapLCU= (pSliceIDMapLCU + (numLCUInPicWidth*numSUInLCU));6813 }6814 else6815 {6816 zRefSU = g_auiRasterToZscan[rTLSU + (heightSU*numSUInLCUWidth)];6817 pRefMapLCU = pSliceIDMapLCU;6818 }6819 pRefID = pRefMapLCU + zRefSU;6820 *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));6821 }6822 6823 // SGU_TL6824 pbAvail = &(pbAvailBorder[SGU_TL]);6825 if(bPicTBoundary || bPicLBoundary)6826 {6827 *pbAvail = false;6828 }6829 else if (onlyOneSliceInPic)6830 {6831 *pbAvail = true;6832 }6833 else6834 {6835 if(bLCUTBoundary && bLCULBoundary)6836 {6837 zRefSU = numSUInLCU -1;6838 pRefMapLCU = pSliceIDMapLCU - ( (numLCUInPicWidth+1)*numSUInLCU);6839 }6840 else if(bLCUTBoundary)6841 {6842 zRefSU = g_auiRasterToZscan[ rTRefSU- 1];6843 pRefMapLCU = pTRefMapLCU;6844 }6845 else if(bLCULBoundary)6846 {6847 zRefSU = g_auiRasterToZscan[ rLRefSU- numSUInLCUWidth ];6848 pRefMapLCU = pLRefMapLCU;6849 }6850 else //inside LCU6851 {6852 zRefSU = g_auiRasterToZscan[ rTLSU - numSUInLCUWidth -1];6853 pRefMapLCU = pSliceIDMapLCU;6854 }6855 pRefID = pRefMapLCU + zRefSU;6856 *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));6857 }6858 6859 // SGU_TR6860 pbAvail = &(pbAvailBorder[SGU_TR]);6861 if(bPicTBoundary || bPicRBoundary)6862 {6863 *pbAvail = false;6864 }6865 else if (onlyOneSliceInPic)6866 {6867 *pbAvail = true;6868 }6869 else6870 {6871 if(bLCUTBoundary && bLCURBoundary)6872 {6873 zRefSU = g_auiRasterToZscan[numSUInLCU - numSUInLCUWidth];6874 pRefMapLCU = pSliceIDMapLCU - ( (numLCUInPicWidth-1)*numSUInLCU);6875 }6876 else if(bLCUTBoundary)6877 {6878 zRefSU = g_auiRasterToZscan[ rTRefSU+ widthSU];6879 pRefMapLCU = pTRefMapLCU;6880 }6881 else if(bLCURBoundary)6882 {6883 zRefSU = g_auiRasterToZscan[ rRRefSU- numSUInLCUWidth ];6884 pRefMapLCU = pRRefMapLCU;6885 }6886 else //inside LCU6887 {6888 zRefSU = g_auiRasterToZscan[ rTLSU - numSUInLCUWidth +widthSU];6889 pRefMapLCU = pSliceIDMapLCU;6890 }6891 pRefID = pRefMapLCU + zRefSU;6892 *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));6893 }6894 6895 // SGU_BL6896 pbAvail = &(pbAvailBorder[SGU_BL]);6897 if(bPicBBoundary || bPicLBoundary)6898 {6899 *pbAvail = false;6900 }6901 else if (onlyOneSliceInPic)6902 {6903 *pbAvail = true;6904 }6905 else6906 {6907 if(bLCUBBoundary && bLCULBoundary)6908 {6909 zRefSU = g_auiRasterToZscan[numSUInLCUWidth - 1];6910 pRefMapLCU = pSliceIDMapLCU + ( (numLCUInPicWidth-1)*numSUInLCU);6911 }6912 else if(bLCUBBoundary)6913 {6914 zRefSU = g_auiRasterToZscan[ rBRefSU - 1];6915 pRefMapLCU = pBRefMapLCU;6916 }6917 else if(bLCULBoundary)6918 {6919 zRefSU = g_auiRasterToZscan[ rLRefSU+ heightSU*numSUInLCUWidth ];6920 pRefMapLCU = pLRefMapLCU;6921 }6922 else //inside LCU6923 {6924 zRefSU = g_auiRasterToZscan[ rTLSU + heightSU*numSUInLCUWidth -1];6925 pRefMapLCU = pSliceIDMapLCU;6926 }6927 pRefID = pRefMapLCU + zRefSU;6928 *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));6929 }6930 6931 // SGU_BR6932 pbAvail = &(pbAvailBorder[SGU_BR]);6933 if(bPicBBoundary || bPicRBoundary)6934 {6935 *pbAvail = false;6936 }6937 else if (onlyOneSliceInPic)6938 {6939 *pbAvail = true;6940 }6941 else6942 {6943 if(bLCUBBoundary && bLCURBoundary)6944 {6945 zRefSU = 0;6946 pRefMapLCU = pSliceIDMapLCU+ ( (numLCUInPicWidth+1)*numSUInLCU);6947 }6948 else if(bLCUBBoundary)6949 {6950 zRefSU = g_auiRasterToZscan[ rBRefSU + widthSU];6951 pRefMapLCU = pBRefMapLCU;6952 }6953 else if(bLCURBoundary)6954 {6955 zRefSU = g_auiRasterToZscan[ rRRefSU + (heightSU*numSUInLCUWidth)];6956 pRefMapLCU = pRRefMapLCU;6957 }6958 else //inside LCU6959 {6960 zRefSU = g_auiRasterToZscan[ rTLSU + (heightSU*numSUInLCUWidth)+ widthSU];6961 pRefMapLCU = pSliceIDMapLCU;6962 }6963 pRefID = pRefMapLCU + zRefSU;6964 *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));6965 }6966 6967 if(bIndependentTileBoundaryEnabled)6968 {6969 //left LCU boundary6970 if(!bPicLBoundary && bLCULBoundary)6971 {6972 if(bLeftTileBoundary)6973 {6974 pbAvailBorder[SGU_L] = pbAvailBorder[SGU_TL] = pbAvailBorder[SGU_BL] = false;6975 }6976 }6977 //right LCU boundary6978 if(!bPicRBoundary && bLCURBoundary)6979 {6980 if(bRightTileBoundary)6981 {6982 pbAvailBorder[SGU_R] = pbAvailBorder[SGU_TR] = pbAvailBorder[SGU_BR] = false;6983 }6984 }6985 //top LCU boundary6986 if(!bPicTBoundary && bLCUTBoundary)6987 {6988 if(bTopTileBoundary)6989 {6990 pbAvailBorder[SGU_T] = pbAvailBorder[SGU_TL] = pbAvailBorder[SGU_TR] = false;6991 }6992 }6993 //down LCU boundary6994 if(!bPicBBoundary && bLCUBBoundary)6995 {6996 if(bDownTileBoundary)6997 {6998 pbAvailBorder[SGU_B] = pbAvailBorder[SGU_BL] = pbAvailBorder[SGU_BR] = false;6999 }7000 }7001 }7002 rSGU.allBordersAvailable = true;7003 for(Int b=0; b< NUM_SGU_BORDER; b++)7004 {7005 if(pbAvailBorder[b] == false)7006 {7007 rSGU.allBordersAvailable = false;7008 break;7009 }7010 }7011 }7012 6622 } 7013 6623 -
branches/HTM-10.0-dev0/source/Lib/TLibCommon/TComDataCU.h
r833 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 59 59 //! \{ 60 60 61 // ====================================================================================================================62 // Non-deblocking in-loop filter processing block data structure63 // ====================================================================================================================64 65 /// Non-deblocking filter processing block border tag66 enum NDBFBlockBorderTag67 {68 SGU_L = 0,69 SGU_R,70 SGU_T,71 SGU_B,72 SGU_TL,73 SGU_TR,74 SGU_BL,75 SGU_BR,76 NUM_SGU_BORDER77 };78 79 /// Non-deblocking filter processing block information80 struct NDBFBlockInfo81 {82 Int tileID; //!< tile ID83 Int sliceID; //!< slice ID84 UInt startSU; //!< starting SU z-scan address in LCU85 UInt endSU; //!< ending SU z-scan address in LCU86 UInt widthSU; //!< number of SUs in width87 UInt heightSU; //!< number of SUs in height88 UInt posX; //!< top-left X coordinate in picture89 UInt posY; //!< top-left Y coordinate in picture90 UInt width; //!< number of pixels in width91 UInt height; //!< number of pixels in height92 Bool isBorderAvailable[NUM_SGU_BORDER]; //!< the border availabilities93 Bool allBordersAvailable;94 95 NDBFBlockInfo():tileID(0), sliceID(0), startSU(0), endSU(0) {} //!< constructor96 const NDBFBlockInfo& operator= (const NDBFBlockInfo& src); //!< "=" operator97 };98 61 99 62 #if H_3D_DBBP … … 176 139 Pel* m_pcIPCMSampleCr; ///< PCM sample buffer (Cr) 177 140 178 Int* m_piSliceSUMap; ///< pointer of slice ID map179 std::vector<NDBFBlockInfo> m_vNDFBlock;180 181 141 // ------------------------------------------------------------------------------------------------------------------- 182 142 // neighbour access variables … … 342 302 343 303 Void initCU ( TComPic* pcPic, UInt uiCUAddr ); 344 Void initEstData ( UInt uiDepth, Int qp );304 Void initEstData ( UInt uiDepth, Int qp, Bool bTransquantBypass ); 345 305 Void initSubCU ( TComDataCU* pcCU, UInt uiPartUnitIdx, UInt uiDepth, Int qp ); 346 306 Void setOutsideCUPart ( UInt uiAbsPartIdx, UInt uiDepth ); … … 522 482 DisInfo getDvInfo (UInt uiIdx) { return m_pDvInfo[uiIdx]; } 523 483 #endif 524 /// get slice ID for SU525 Int getSUSliceID (UInt uiIdx) {return m_piSliceSUMap[uiIdx]; }526 527 /// get the pointer of slice ID map528 Int* getSliceSUMap () {return m_piSliceSUMap; }529 530 /// set the pointer of slice ID map531 Void setSliceSUMap (Int *pi) {m_piSliceSUMap = pi; }532 533 std::vector<NDBFBlockInfo>* getNDBFilterBlocks() {return &m_vNDFBlock;}534 Void setNDBFilterBlockBorderAvailability(UInt numLCUInPicWidth, UInt numLCUInPicHeight, UInt numSUInLCUWidth, UInt numSUInLCUHeight, UInt picWidth, UInt picHeight535 ,std::vector<Bool>& LFCrossSliceBoundary536 ,Bool bTopTileBoundary, Bool bDownTileBoundary, Bool bLeftTileBoundary, Bool bRightTileBoundary537 ,Bool bIndependentTileBoundaryEnabled );538 484 #if H_3D_NBDV 539 485 Void xDeriveRightBottomNbIdx(Int &uiLCUIdxRBNb, Int &uiPartIdxRBNb ); -
branches/HTM-10.0-dev0/source/Lib/TLibCommon/TComInterpolationFilter.cpp
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/TLibCommon/TComInterpolationFilter.h
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/TLibCommon/TComList.h
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/TLibCommon/TComLoopFilter.cpp
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/TLibCommon/TComLoopFilter.h
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/TLibCommon/TComMotionInfo.cpp
r773 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/TLibCommon/TComMotionInfo.h
r833 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/TLibCommon/TComMv.h
r655 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/TLibCommon/TComPattern.cpp
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/TLibCommon/TComPattern.h
r655 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/TLibCommon/TComPic.cpp
r738 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 56 56 , m_bNeededForOutput (false) 57 57 , m_uiCurrSliceIdx (0) 58 , m_pSliceSUMap (NULL)59 , m_pbValidSlice (NULL)60 , m_sliceGranularityForNDBFilter (0)61 , m_bIndependentSliceBoundaryForNDBFilter (false)62 , m_bIndependentTileBoundaryForNDBFilter (false)63 , m_pNDBFilterYuvTmp (NULL)64 58 , m_bCheckLTMSB (false) 65 59 #if H_MV … … 117 111 memcpy(m_numReorderPics, numReorderPics, MAX_TLAYER*sizeof(Int)); 118 112 119 /* initialize the texture to depth reference status */120 113 #if H_3D_FCO 114 /* initialize the texture to depth reference status */ 121 115 for (int j=0; j<2; j++) 122 116 { … … 174 168 } 175 169 176 /** Create non-deblocked filter information 177 * \param pSliceStartAddress array for storing slice start addresses 178 * \param numSlices number of slices in picture 179 * \param sliceGranularityDepth slice granularity 180 * \param bNDBFilterCrossSliceBoundary cross-slice-boundary in-loop filtering; true for "cross". 181 * \param numTiles number of tiles in picture 182 * \param bNDBFilterCrossTileBoundary cross-tile-boundary in-loop filtering; true for "cross". 183 */ 184 Void TComPic::createNonDBFilterInfo(std::vector<Int> sliceStartAddress, Int sliceGranularityDepth 185 ,std::vector<Bool>* LFCrossSliceBoundary 186 ,Int numTiles 187 ,Bool bNDBFilterCrossTileBoundary) 188 { 189 UInt maxNumSUInLCU = getNumPartInCU(); 190 UInt numLCUInPic = getNumCUsInFrame(); 191 UInt picWidth = getSlice(0)->getSPS()->getPicWidthInLumaSamples(); 192 UInt picHeight = getSlice(0)->getSPS()->getPicHeightInLumaSamples(); 193 Int numLCUsInPicWidth = getFrameWidthInCU(); 194 Int numLCUsInPicHeight= getFrameHeightInCU(); 195 UInt maxNumSUInLCUWidth = getNumPartInWidth(); 196 UInt maxNumSUInLCUHeight= getNumPartInHeight(); 197 Int numSlices = (Int) sliceStartAddress.size() - 1; 198 m_bIndependentSliceBoundaryForNDBFilter = false; 199 if(numSlices > 1) 200 { 201 for(Int s=0; s< numSlices; s++) 202 { 203 if((*LFCrossSliceBoundary)[s] == false) 204 { 205 m_bIndependentSliceBoundaryForNDBFilter = true; 206 } 207 } 208 } 209 m_sliceGranularityForNDBFilter = sliceGranularityDepth; 210 m_bIndependentTileBoundaryForNDBFilter = (bNDBFilterCrossTileBoundary)?(false) :((numTiles > 1)?(true):(false)); 211 212 m_pbValidSlice = new Bool[numSlices]; 213 for(Int s=0; s< numSlices; s++) 214 { 215 m_pbValidSlice[s] = true; 216 } 217 m_pSliceSUMap = new Int[maxNumSUInLCU * numLCUInPic]; 218 219 //initialization 220 for(UInt i=0; i< (maxNumSUInLCU * numLCUInPic); i++ ) 221 { 222 m_pSliceSUMap[i] = -1; 223 } 224 for( UInt CUAddr = 0; CUAddr < numLCUInPic ; CUAddr++ ) 225 { 226 TComDataCU* pcCU = getCU( CUAddr ); 227 pcCU->setSliceSUMap(m_pSliceSUMap + (CUAddr* maxNumSUInLCU)); 228 pcCU->getNDBFilterBlocks()->clear(); 229 } 230 m_vSliceCUDataLink.clear(); 231 232 m_vSliceCUDataLink.resize(numSlices); 233 234 UInt startAddr, endAddr, firstCUInStartLCU, startLCU, endLCU, lastCUInEndLCU, uiAddr; 235 UInt LPelX, TPelY, LCUX, LCUY; 236 UInt currSU; 237 UInt startSU, endSU; 238 239 for(Int s=0; s< numSlices; s++) 240 { 241 //1st step: decide the real start address 242 startAddr = sliceStartAddress[s]; 243 endAddr = sliceStartAddress[s+1] -1; 244 245 startLCU = startAddr / maxNumSUInLCU; 246 firstCUInStartLCU = startAddr % maxNumSUInLCU; 247 248 endLCU = endAddr / maxNumSUInLCU; 249 lastCUInEndLCU = endAddr % maxNumSUInLCU; 250 251 uiAddr = m_apcPicSym->getCUOrderMap(startLCU); 252 253 LCUX = getCU(uiAddr)->getCUPelX(); 254 LCUY = getCU(uiAddr)->getCUPelY(); 255 LPelX = LCUX + g_auiRasterToPelX[ g_auiZscanToRaster[firstCUInStartLCU] ]; 256 TPelY = LCUY + g_auiRasterToPelY[ g_auiZscanToRaster[firstCUInStartLCU] ]; 257 currSU = firstCUInStartLCU; 258 259 Bool bMoveToNextLCU = false; 260 Bool bSliceInOneLCU = (startLCU == endLCU); 261 262 while(!( LPelX < picWidth ) || !( TPelY < picHeight )) 263 { 264 currSU ++; 265 266 if(bSliceInOneLCU) 267 { 268 if(currSU > lastCUInEndLCU) 269 { 270 m_pbValidSlice[s] = false; 271 break; 272 } 273 } 274 275 if(currSU >= maxNumSUInLCU ) 276 { 277 bMoveToNextLCU = true; 278 break; 279 } 280 281 LPelX = LCUX + g_auiRasterToPelX[ g_auiZscanToRaster[currSU] ]; 282 TPelY = LCUY + g_auiRasterToPelY[ g_auiZscanToRaster[currSU] ]; 283 284 } 285 286 287 if(!m_pbValidSlice[s]) 288 { 289 continue; 290 } 291 292 if(currSU != firstCUInStartLCU) 293 { 294 if(!bMoveToNextLCU) 295 { 296 firstCUInStartLCU = currSU; 297 } 298 else 299 { 300 startLCU++; 301 firstCUInStartLCU = 0; 302 assert( startLCU < getNumCUsInFrame()); 303 } 304 assert(startLCU*maxNumSUInLCU + firstCUInStartLCU < endAddr); 305 } 306 307 308 //2nd step: assign NonDBFilterInfo to each processing block 309 for(UInt i= startLCU; i <= endLCU; i++) 310 { 311 startSU = (i == startLCU)?(firstCUInStartLCU):(0); 312 endSU = (i == endLCU )?(lastCUInEndLCU ):(maxNumSUInLCU -1); 313 314 uiAddr = m_apcPicSym->getCUOrderMap(i); 315 Int iTileID= m_apcPicSym->getTileIdxMap(uiAddr); 316 317 TComDataCU* pcCU = getCU(uiAddr); 318 m_vSliceCUDataLink[s].push_back(pcCU); 319 320 createNonDBFilterInfoLCU(iTileID, s, pcCU, startSU, endSU, m_sliceGranularityForNDBFilter, picWidth, picHeight); 321 } 322 } 323 324 //step 3: border availability 325 for(Int s=0; s< numSlices; s++) 326 { 327 if(!m_pbValidSlice[s]) 328 { 329 continue; 330 } 331 332 for(Int i=0; i< m_vSliceCUDataLink[s].size(); i++) 333 { 334 TComDataCU* pcCU = m_vSliceCUDataLink[s][i]; 335 uiAddr = pcCU->getAddr(); 336 337 if(pcCU->getPic()==0) 338 { 339 continue; 340 } 341 Int iTileID= m_apcPicSym->getTileIdxMap(uiAddr); 342 Bool bTopTileBoundary = false, bDownTileBoundary= false, bLeftTileBoundary= false, bRightTileBoundary= false; 343 344 if(m_bIndependentTileBoundaryForNDBFilter) 345 { 346 //left 347 if( uiAddr % numLCUsInPicWidth != 0) 348 { 349 bLeftTileBoundary = ( m_apcPicSym->getTileIdxMap(uiAddr -1) != iTileID )?true:false; 350 } 351 //right 352 if( (uiAddr % numLCUsInPicWidth) != (numLCUsInPicWidth -1) ) 353 { 354 bRightTileBoundary = ( m_apcPicSym->getTileIdxMap(uiAddr +1) != iTileID)?true:false; 355 } 356 //top 357 if( uiAddr >= numLCUsInPicWidth) 358 { 359 bTopTileBoundary = (m_apcPicSym->getTileIdxMap(uiAddr - numLCUsInPicWidth) != iTileID )?true:false; 360 } 361 //down 362 if( uiAddr + numLCUsInPicWidth < numLCUInPic ) 363 { 364 bDownTileBoundary = (m_apcPicSym->getTileIdxMap(uiAddr + numLCUsInPicWidth) != iTileID)?true:false; 365 } 366 367 } 368 369 pcCU->setNDBFilterBlockBorderAvailability(numLCUsInPicWidth, numLCUsInPicHeight, maxNumSUInLCUWidth, maxNumSUInLCUHeight,picWidth, picHeight 370 , *LFCrossSliceBoundary 371 ,bTopTileBoundary, bDownTileBoundary, bLeftTileBoundary, bRightTileBoundary 372 ,m_bIndependentTileBoundaryForNDBFilter); 373 374 } 375 376 } 377 378 if( m_bIndependentSliceBoundaryForNDBFilter || m_bIndependentTileBoundaryForNDBFilter) 379 { 380 m_pNDBFilterYuvTmp = new TComPicYuv(); 381 m_pNDBFilterYuvTmp->create(picWidth, picHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth); 382 } 383 384 } 385 386 /** Create non-deblocked filter information for LCU 387 * \param tileID tile index 388 * \param sliceID slice index 389 * \param pcCU CU data pointer 390 * \param startSU start SU index in LCU 391 * \param endSU end SU index in LCU 392 * \param sliceGranularyDepth slice granularity 393 * \param picWidth picture width 394 * \param picHeight picture height 395 */ 396 Void TComPic::createNonDBFilterInfoLCU(Int tileID, Int sliceID, TComDataCU* pcCU, UInt startSU, UInt endSU, Int sliceGranularyDepth, UInt picWidth, UInt picHeight) 397 { 398 UInt LCUX = pcCU->getCUPelX(); 399 UInt LCUY = pcCU->getCUPelY(); 400 Int* pCUSliceMap = pcCU->getSliceSUMap(); 401 UInt maxNumSUInLCU = getNumPartInCU(); 402 UInt maxNumSUInSGU = maxNumSUInLCU >> (sliceGranularyDepth << 1); 403 UInt maxNumSUInLCUWidth = getNumPartInWidth(); 404 UInt LPelX, TPelY; 405 UInt currSU; 406 407 408 //get the number of valid NBFilterBLock 409 currSU = startSU; 410 while(currSU <= endSU) 411 { 412 LPelX = LCUX + g_auiRasterToPelX[ g_auiZscanToRaster[currSU] ]; 413 TPelY = LCUY + g_auiRasterToPelY[ g_auiZscanToRaster[currSU] ]; 414 415 while(!( LPelX < picWidth ) || !( TPelY < picHeight )) 416 { 417 currSU += maxNumSUInSGU; 418 if(currSU >= maxNumSUInLCU || currSU > endSU) 419 { 420 break; 421 } 422 LPelX = LCUX + g_auiRasterToPelX[ g_auiZscanToRaster[currSU] ]; 423 TPelY = LCUY + g_auiRasterToPelY[ g_auiZscanToRaster[currSU] ]; 424 } 425 426 if(currSU >= maxNumSUInLCU || currSU > endSU) 427 { 428 break; 429 } 430 431 NDBFBlockInfo NDBFBlock; 432 433 NDBFBlock.tileID = tileID; 434 NDBFBlock.sliceID = sliceID; 435 NDBFBlock.posY = TPelY; 436 NDBFBlock.posX = LPelX; 437 NDBFBlock.startSU = currSU; 438 439 UInt uiLastValidSU = currSU; 440 UInt uiIdx, uiLPelX_su, uiTPelY_su; 441 for(uiIdx = currSU; uiIdx < currSU + maxNumSUInSGU; uiIdx++) 442 { 443 if(uiIdx > endSU) 444 { 445 break; 446 } 447 uiLPelX_su = LCUX + g_auiRasterToPelX[ g_auiZscanToRaster[uiIdx] ]; 448 uiTPelY_su = LCUY + g_auiRasterToPelY[ g_auiZscanToRaster[uiIdx] ]; 449 if( !(uiLPelX_su < picWidth ) || !( uiTPelY_su < picHeight )) 450 { 451 continue; 452 } 453 pCUSliceMap[uiIdx] = sliceID; 454 uiLastValidSU = uiIdx; 455 } 456 NDBFBlock.endSU = uiLastValidSU; 457 458 UInt rTLSU = g_auiZscanToRaster[ NDBFBlock.startSU ]; 459 UInt rBRSU = g_auiZscanToRaster[ NDBFBlock.endSU ]; 460 NDBFBlock.widthSU = (rBRSU % maxNumSUInLCUWidth) - (rTLSU % maxNumSUInLCUWidth)+ 1; 461 NDBFBlock.heightSU = (UInt)(rBRSU / maxNumSUInLCUWidth) - (UInt)(rTLSU / maxNumSUInLCUWidth)+ 1; 462 NDBFBlock.width = NDBFBlock.widthSU * getMinCUWidth(); 463 NDBFBlock.height = NDBFBlock.heightSU * getMinCUHeight(); 464 465 pcCU->getNDBFilterBlocks()->push_back(NDBFBlock); 466 467 currSU += maxNumSUInSGU; 468 } 469 470 } 471 472 /** destroy non-deblocked filter information for LCU 473 */ 474 Void TComPic::destroyNonDBFilterInfo() 475 { 476 if(m_pbValidSlice != NULL) 477 { 478 delete[] m_pbValidSlice; 479 m_pbValidSlice = NULL; 480 } 481 482 if(m_pSliceSUMap != NULL) 483 { 484 delete[] m_pSliceSUMap; 485 m_pSliceSUMap = NULL; 486 } 487 for( UInt CUAddr = 0; CUAddr < getNumCUsInFrame() ; CUAddr++ ) 488 { 489 TComDataCU* pcCU = getCU( CUAddr ); 490 pcCU->getNDBFilterBlocks()->clear(); 491 } 492 493 if( m_bIndependentSliceBoundaryForNDBFilter || m_bIndependentTileBoundaryForNDBFilter) 494 { 495 m_pNDBFilterYuvTmp->destroy(); 496 delete m_pNDBFilterYuvTmp; 497 m_pNDBFilterYuvTmp = NULL; 498 } 499 500 } 170 Bool TComPic::getSAOMergeAvailability(Int currAddr, Int mergeAddr) 171 { 172 Bool mergeCtbInSliceSeg = (mergeAddr >= getPicSym()->getCUOrderMap(getCU(currAddr)->getSlice()->getSliceCurStartCUAddr()/getNumPartInCU())); 173 Bool mergeCtbInTile = (getPicSym()->getTileIdxMap(mergeAddr) == getPicSym()->getTileIdxMap(currAddr)); 174 return (mergeCtbInSliceSeg && mergeCtbInTile); 175 } 176 501 177 #if H_MV 502 178 Void TComPic::print( Bool legend ) -
branches/HTM-10.0-dev0/source/Lib/TLibCommon/TComPic.h
r655 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 70 70 Bool m_bNeededForOutput; 71 71 UInt m_uiCurrSliceIdx; // Index of current slice 72 Int* m_pSliceSUMap;73 Bool* m_pbValidSlice;74 Int m_sliceGranularityForNDBFilter;75 Bool m_bIndependentSliceBoundaryForNDBFilter;76 Bool m_bIndependentTileBoundaryForNDBFilter;77 TComPicYuv* m_pNDBFilterYuvTmp; //!< temporary picture buffer when non-cross slice/tile boundary in-loop filtering is enabled78 72 Bool m_bCheckLTMSB; 79 73 … … 198 192 Window& getDefDisplayWindow() { return m_defaultDisplayWindow; } 199 193 200 Void createNonDBFilterInfo (std::vector<Int> sliceStartAddress, Int sliceGranularityDepth 201 ,std::vector<Bool>* LFCrossSliceBoundary 202 ,Int numTiles = 1 203 ,Bool bNDBFilterCrossTileBoundary = true); 204 Void createNonDBFilterInfoLCU(Int tileID, Int sliceID, TComDataCU* pcCU, UInt startSU, UInt endSU, Int sliceGranularyDepth, UInt picWidth, UInt picHeight); 205 Void destroyNonDBFilterInfo(); 206 207 Bool getValidSlice (Int sliceID) {return m_pbValidSlice[sliceID];} 208 Bool getIndependentSliceBoundaryForNDBFilter () {return m_bIndependentSliceBoundaryForNDBFilter;} 209 Bool getIndependentTileBoundaryForNDBFilter () {return m_bIndependentTileBoundaryForNDBFilter; } 210 TComPicYuv* getYuvPicBufferForIndependentBoundaryProcessing() {return m_pNDBFilterYuvTmp;} 211 std::vector<TComDataCU*>& getOneSliceCUDataForNDBFilter (Int sliceID) { return m_vSliceCUDataLink[sliceID];} 212 194 Bool getSAOMergeAvailability(Int currAddr, Int mergeAddr); 213 195 214 196 /* field coding parameters*/ -
branches/HTM-10.0-dev0/source/Lib/TLibCommon/TComPicSym.cpp
r655 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 67 67 ,m_puiTileIdxMap(NULL) 68 68 ,m_puiInverseCUOrderMap(NULL) 69 ,m_saoBlkParams(NULL) 69 70 {}; 70 71 … … 122 123 m_puiInverseCUOrderMap[i] = i; 123 124 } 124 m_saoParam = NULL; 125 126 m_saoBlkParams = new SAOBlkParam[m_uiNumCUsInFrame]; 125 127 } 126 128 … … 163 165 m_puiInverseCUOrderMap = NULL; 164 166 165 if (m_saoParam) 166 { 167 TComSampleAdaptiveOffset::freeSaoParam(m_saoParam); 168 delete m_saoParam; 169 m_saoParam = NULL; 167 if(m_saoBlkParams) 168 { 169 delete[] m_saoBlkParams; m_saoBlkParams = NULL; 170 170 } 171 171 } … … 308 308 } 309 309 310 Void TComPicSym::allocSaoParam(TComSampleAdaptiveOffset *sao) 311 { 312 m_saoParam = new SAOParam; 313 sao->allocSaoParam(m_saoParam); 310 Void TComPicSym::deriveLoopFilterBoundaryAvailibility(Int ctu, 311 Bool& isLeftAvail, 312 Bool& isRightAvail, 313 Bool& isAboveAvail, 314 Bool& isBelowAvail, 315 Bool& isAboveLeftAvail, 316 Bool& isAboveRightAvail, 317 Bool& isBelowLeftAvail, 318 Bool& isBelowRightAvail 319 ) 320 { 321 322 isLeftAvail = (ctu % m_uiWidthInCU != 0); 323 isRightAvail = (ctu % m_uiWidthInCU != m_uiWidthInCU-1); 324 isAboveAvail = (ctu >= m_uiWidthInCU ); 325 isBelowAvail = (ctu < m_uiNumCUsInFrame - m_uiWidthInCU); 326 isAboveLeftAvail = (isAboveAvail && isLeftAvail); 327 isAboveRightAvail= (isAboveAvail && isRightAvail); 328 isBelowLeftAvail = (isBelowAvail && isLeftAvail); 329 isBelowRightAvail= (isBelowAvail && isRightAvail); 330 331 Bool isLoopFiltAcrossTilePPS = getCU(ctu)->getSlice()->getPPS()->getLoopFilterAcrossTilesEnabledFlag(); 332 333 { 334 TComDataCU* ctuCurr = getCU(ctu); 335 TComDataCU* ctuLeft = isLeftAvail ?getCU(ctu-1):NULL; 336 TComDataCU* ctuRight = isRightAvail?getCU(ctu+1):NULL; 337 TComDataCU* ctuAbove = isAboveAvail?getCU(ctu-m_uiWidthInCU):NULL; 338 TComDataCU* ctuBelow = isBelowAvail?getCU(ctu+m_uiWidthInCU):NULL; 339 TComDataCU* ctuAboveLeft = isAboveLeftAvail ? getCU(ctu-m_uiWidthInCU-1):NULL; 340 TComDataCU* ctuAboveRigtht= isAboveRightAvail? getCU(ctu-m_uiWidthInCU+1):NULL; 341 TComDataCU* ctuBelowLeft = isBelowLeftAvail ? getCU(ctu+m_uiWidthInCU-1):NULL; 342 TComDataCU* ctuBelowRight = isBelowRightAvail? getCU(ctu+m_uiWidthInCU+1):NULL; 343 344 { 345 //left 346 if(ctuLeft != NULL) 347 { 348 isLeftAvail = (ctuCurr->getSlice()->getSliceCurStartCUAddr() != ctuLeft->getSlice()->getSliceCurStartCUAddr())?ctuCurr->getSlice()->getLFCrossSliceBoundaryFlag():true; 349 } 350 //above 351 if(ctuAbove != NULL) 352 { 353 isAboveAvail = (ctuCurr->getSlice()->getSliceCurStartCUAddr() != ctuAbove->getSlice()->getSliceCurStartCUAddr())?ctuCurr->getSlice()->getLFCrossSliceBoundaryFlag():true; 354 } 355 //right 356 if(ctuRight != NULL) 357 { 358 isRightAvail = (ctuCurr->getSlice()->getSliceCurStartCUAddr() != ctuRight->getSlice()->getSliceCurStartCUAddr())?ctuRight->getSlice()->getLFCrossSliceBoundaryFlag():true; 359 } 360 //below 361 if(ctuBelow != NULL) 362 { 363 isBelowAvail = (ctuCurr->getSlice()->getSliceCurStartCUAddr() != ctuBelow->getSlice()->getSliceCurStartCUAddr())?ctuBelow->getSlice()->getLFCrossSliceBoundaryFlag():true; 364 } 365 //above-left 366 if(ctuAboveLeft != NULL) 367 { 368 isAboveLeftAvail = (ctuCurr->getSlice()->getSliceCurStartCUAddr() != ctuAboveLeft->getSlice()->getSliceCurStartCUAddr())?ctuCurr->getSlice()->getLFCrossSliceBoundaryFlag():true; 369 } 370 //below-right 371 if(ctuBelowRight != NULL) 372 { 373 isBelowRightAvail = (ctuCurr->getSlice()->getSliceCurStartCUAddr() != ctuBelowRight->getSlice()->getSliceCurStartCUAddr())?ctuBelowRight->getSlice()->getLFCrossSliceBoundaryFlag():true; 374 } 375 376 377 //above-right 378 if(ctuAboveRigtht != NULL) 379 { 380 Int curSliceStartEncOrder = ctuCurr->getSlice()->getSliceCurStartCUAddr(); 381 Int aboveRigthtSliceStartEncOrder = ctuAboveRigtht->getSlice()->getSliceCurStartCUAddr(); 382 383 isAboveRightAvail = (curSliceStartEncOrder == aboveRigthtSliceStartEncOrder)?(true): 384 ( 385 (curSliceStartEncOrder > aboveRigthtSliceStartEncOrder)?(ctuCurr->getSlice()->getLFCrossSliceBoundaryFlag()) 386 :(ctuAboveRigtht->getSlice()->getLFCrossSliceBoundaryFlag()) 387 ); 388 } 389 //below-left 390 if(ctuBelowLeft != NULL) 391 { 392 Int curSliceStartEncOrder = ctuCurr->getSlice()->getSliceCurStartCUAddr(); 393 Int belowLeftSliceStartEncOrder = ctuBelowLeft->getSlice()->getSliceCurStartCUAddr(); 394 395 isBelowLeftAvail = (curSliceStartEncOrder == belowLeftSliceStartEncOrder)?(true): 396 ( 397 (curSliceStartEncOrder > belowLeftSliceStartEncOrder)?(ctuCurr->getSlice()->getLFCrossSliceBoundaryFlag()) 398 :(ctuBelowLeft->getSlice()->getLFCrossSliceBoundaryFlag()) 399 ); 400 } 401 } 402 403 if(!isLoopFiltAcrossTilePPS) 404 { 405 isLeftAvail = (!isLeftAvail ) ?false:(getTileIdxMap( ctuLeft->getAddr() ) == getTileIdxMap( ctu )); 406 isAboveAvail = (!isAboveAvail ) ?false:(getTileIdxMap( ctuAbove->getAddr() ) == getTileIdxMap( ctu )); 407 isRightAvail = (!isRightAvail ) ?false:(getTileIdxMap( ctuRight->getAddr() ) == getTileIdxMap( ctu )); 408 isBelowAvail = (!isBelowAvail ) ?false:(getTileIdxMap( ctuBelow->getAddr() ) == getTileIdxMap( ctu )); 409 isAboveLeftAvail = (!isAboveLeftAvail ) ?false:(getTileIdxMap( ctuAboveLeft->getAddr() ) == getTileIdxMap( ctu )); 410 isAboveRightAvail= (!isAboveRightAvail) ?false:(getTileIdxMap( ctuAboveRigtht->getAddr() ) == getTileIdxMap( ctu )); 411 isBelowLeftAvail = (!isBelowLeftAvail ) ?false:(getTileIdxMap( ctuBelowLeft->getAddr() ) == getTileIdxMap( ctu )); 412 isBelowRightAvail= (!isBelowRightAvail) ?false:(getTileIdxMap( ctuBelowRight->getAddr() ) == getTileIdxMap( ctu )); 413 } 414 } 415 314 416 } 315 417 -
branches/HTM-10.0-dev0/source/Lib/TLibCommon/TComPicSym.h
r655 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 107 107 UInt* m_puiInverseCUOrderMap; 108 108 109 SAO Param *m_saoParam;109 SAOBlkParam *m_saoBlkParams; 110 110 public: 111 111 Void create ( Int iPicWidth, Int iPicHeight, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth ); … … 144 144 Void xInitTiles(); 145 145 UInt xCalculateNxtCUAddr( UInt uiCurrCUAddr ); 146 Void allocSaoParam(TComSampleAdaptiveOffset *sao); 147 SAOParam *getSaoParam() { return m_saoParam; } 146 SAOBlkParam* getSAOBlkParam() { return m_saoBlkParams;} 147 Void deriveLoopFilterBoundaryAvailibility(Int ctu, Bool& isLeftAvail,Bool& isRightAvail,Bool& isAboveAvail,Bool& isBelowAvail,Bool& isAboveLeftAvail,Bool& isAboveRightAvail,Bool& isBelowLeftAvail,Bool& isBelowRightAvail); 148 149 148 150 };// END CLASS DEFINITION TComPicSym 149 151 -
branches/HTM-10.0-dev0/source/Lib/TLibCommon/TComPicYuv.cpp
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/TLibCommon/TComPicYuv.h
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/TLibCommon/TComPicYuvMD5.cpp
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/TLibCommon/TComPrediction.cpp
r833 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/TLibCommon/TComPrediction.h
r833 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/TLibCommon/TComRdCost.cpp
r833 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 51 51 Double TComRdCost::m_dDisparityCoeff = 1.0; 52 52 #endif 53 54 53 TComRdCost::TComRdCost() 55 54 { … … 354 353 } 355 354 #endif 356 357 355 // initialize 358 356 rcDistParam.iSubShift = 0; … … 395 393 } 396 394 #endif 397 398 395 // initialize 399 396 rcDistParam.iSubShift = 0; … … 401 398 402 399 // Setting the Distortion Parameter for Inter (subpel ME with step) 403 #if NS_HAD404 Void TComRdCost::setDistParam( TComPattern* pcPatternKey, Pel* piRefY, Int iRefStride, Int iStep, DistParam& rcDistParam, Bool bHADME, Bool bUseNSHAD )405 #else406 400 Void TComRdCost::setDistParam( TComPattern* pcPatternKey, Pel* piRefY, Int iRefStride, Int iStep, DistParam& rcDistParam, Bool bHADME ) 407 #endif408 401 { 409 402 // set Original & Curr Pointer / Stride … … 420 413 rcDistParam.iCols = pcPatternKey->getROIYWidth(); 421 414 rcDistParam.iRows = pcPatternKey->getROIYHeight(); 422 #if NS_HAD423 rcDistParam.bUseNSHAD = bUseNSHAD;424 #endif425 415 426 416 // set distortion function … … 454 444 } 455 445 #endif 456 457 446 // initialize 458 447 rcDistParam.iSubShift = 0; … … 460 449 461 450 Void 462 #if NS_HAD463 TComRdCost::setDistParam( DistParam& rcDP, Pel* p1, Int iStride1, Pel* p2, Int iStride2, Int iWidth, Int iHeight, Bool bHadamard, Bool bUseNSHAD )464 #else465 451 TComRdCost::setDistParam( DistParam& rcDP, Int bitDepth, Pel* p1, Int iStride1, Pel* p2, Int iStride2, Int iWidth, Int iHeight, Bool bHadamard ) 466 #endif467 452 { 468 453 rcDP.pOrg = p1; … … 476 461 rcDP.bitDepth = bitDepth; 477 462 rcDP.DistFunc = m_afpDistortFunc[ ( bHadamard ? DF_HADS : DF_SADS ) + g_aucConvertToBit[ iWidth ] + 1 ]; 478 479 463 #if H_3D_DBBP 480 464 if( m_bUseMask ) … … 482 466 rcDP.DistFunc = (bHadamard)?TComRdCost::xGetMaskedHADs:TComRdCost::xGetMaskedSAD; 483 467 } 484 #endif485 486 #if NS_HAD487 rcDP.bUseNSHAD = bUseNSHAD;488 468 #endif 489 469 } … … 506 486 } 507 487 } 508 else if ( ( (iWidth % 4) == 0 ) && ( (iHeight % 4) == 0 ) ) 509 { 488 else 489 { 490 assert(iWidth % 4 == 0 && iHeight % 4 == 0); 491 510 492 for ( y=0; y<iHeight; y+= 4 ) 511 493 { … … 518 500 } 519 501 } 520 else521 {522 for ( y=0; y<iHeight; y+= 2 )523 {524 for ( x=0; x<iWidth; x+= 2 )525 {526 uiSum += xCalcHADs8x8( &pi0[x], &pi1[x], iStride0, iStride1, 1 );527 }528 pi0 += iStride0*2;529 pi1 += iStride1*2;530 }531 }532 502 533 503 return uiSum >> DISTORTION_PRECISION_ADJUSTMENT(bitDepth-8); … … 572 542 573 543 574 #if WEIGHTED_CHROMA_DISTORTION575 544 UInt TComRdCost::getDistPart(Int bitDepth, Pel* piCur, Int iCurStride, Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, TextType eText, DFunc eDFunc) 576 #else577 UInt TComRdCost::getDistPart(Int bitDepth, Pel* piCur, Int iCurStride, Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, DFunc eDFunc )578 #endif579 545 { 580 546 DistParam cDtParam; … … 596 562 cDtParam.bUseSDCMRSAD = false; 597 563 #endif 598 #if WEIGHTED_CHROMA_DISTORTION599 564 if (eText == TEXT_CHROMA_U) 600 565 { … … 609 574 return cDtParam.DistFunc( &cDtParam ); 610 575 } 611 #else612 return cDtParam.DistFunc( &cDtParam );613 #endif614 576 } 615 577 #if H_3D_VSO … … 664 626 #endif 665 627 666 #if (RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT) ||KWU_RC_MADPRED_E0227628 #if KWU_RC_MADPRED_E0227 667 629 UInt TComRdCost::getSADPart ( Int bitDepth, Pel* pelCur, Int curStride, Pel* pelOrg, Int orgStride, UInt width, UInt height ) 668 630 { … … 908 870 } 909 871 #endif 910 911 872 // -------------------------------------------------------------------------------------------------------------------- 912 873 // SAD … … 3467 3428 } 3468 3429 3469 #if NS_HAD3470 UInt TComRdCost::xCalcHADs16x4( Pel *piOrg, Pel *piCur, Int iStrideOrg, Int iStrideCur, Int iStep )3471 {3472 Int k, i, j, jj, sad=0;3473 Int diff[64], m1[4][16], m2[4][16];3474 assert( iStep == 1 );3475 for( k = 0; k < 64; k += 16 )3476 {3477 diff[k+0] = piOrg[0] - piCur[0];3478 diff[k+1] = piOrg[1] - piCur[1];3479 diff[k+2] = piOrg[2] - piCur[2];3480 diff[k+3] = piOrg[3] - piCur[3];3481 diff[k+4] = piOrg[4] - piCur[4];3482 diff[k+5] = piOrg[5] - piCur[5];3483 diff[k+6] = piOrg[6] - piCur[6];3484 diff[k+7] = piOrg[7] - piCur[7];3485 3486 diff[k+8] = piOrg[8] - piCur[8] ;3487 diff[k+9] = piOrg[9] - piCur[9] ;3488 diff[k+10] = piOrg[10] - piCur[10];3489 diff[k+11] = piOrg[11] - piCur[11];3490 diff[k+12] = piOrg[12] - piCur[12];3491 diff[k+13] = piOrg[13] - piCur[13];3492 diff[k+14] = piOrg[14] - piCur[14];3493 diff[k+15] = piOrg[15] - piCur[15];3494 3495 piCur += iStrideCur;3496 piOrg += iStrideOrg;3497 }3498 3499 //horizontal3500 for (j=0; j < 4; j++)3501 {3502 jj = j << 4;3503 3504 m2[j][0] = diff[jj ] + diff[jj+8];3505 m2[j][1] = diff[jj+1] + diff[jj+9];3506 m2[j][2] = diff[jj+2] + diff[jj+10];3507 m2[j][3] = diff[jj+3] + diff[jj+11];3508 m2[j][4] = diff[jj+4] + diff[jj+12];3509 m2[j][5] = diff[jj+5] + diff[jj+13];3510 m2[j][6] = diff[jj+6] + diff[jj+14];3511 m2[j][7] = diff[jj+7] + diff[jj+15];3512 m2[j][8] = diff[jj ] - diff[jj+8];3513 m2[j][9] = diff[jj+1] - diff[jj+9];3514 m2[j][10] = diff[jj+2] - diff[jj+10];3515 m2[j][11] = diff[jj+3] - diff[jj+11];3516 m2[j][12] = diff[jj+4] - diff[jj+12];3517 m2[j][13] = diff[jj+5] - diff[jj+13];3518 m2[j][14] = diff[jj+6] - diff[jj+14];3519 m2[j][15] = diff[jj+7] - diff[jj+15];3520 3521 m1[j][0] = m2[j][0] + m2[j][4];3522 m1[j][1] = m2[j][1] + m2[j][5];3523 m1[j][2] = m2[j][2] + m2[j][6];3524 m1[j][3] = m2[j][3] + m2[j][7];3525 m1[j][4] = m2[j][0] - m2[j][4];3526 m1[j][5] = m2[j][1] - m2[j][5];3527 m1[j][6] = m2[j][2] - m2[j][6];3528 m1[j][7] = m2[j][3] - m2[j][7];3529 m1[j][8] = m2[j][8] + m2[j][12];3530 m1[j][9] = m2[j][9] + m2[j][13];3531 m1[j][10] = m2[j][10] + m2[j][14];3532 m1[j][11] = m2[j][11] + m2[j][15];3533 m1[j][12] = m2[j][8] - m2[j][12];3534 m1[j][13] = m2[j][9] - m2[j][13];3535 m1[j][14] = m2[j][10] - m2[j][14];3536 m1[j][15] = m2[j][11] - m2[j][15];3537 3538 m2[j][0] = m1[j][0] + m1[j][2];3539 m2[j][1] = m1[j][1] + m1[j][3];3540 m2[j][2] = m1[j][0] - m1[j][2];3541 m2[j][3] = m1[j][1] - m1[j][3];3542 m2[j][4] = m1[j][4] + m1[j][6];3543 m2[j][5] = m1[j][5] + m1[j][7];3544 m2[j][6] = m1[j][4] - m1[j][6];3545 m2[j][7] = m1[j][5] - m1[j][7];3546 m2[j][8] = m1[j][8] + m1[j][10];3547 m2[j][9] = m1[j][9] + m1[j][11];3548 m2[j][10] = m1[j][8] - m1[j][10];3549 m2[j][11] = m1[j][9] - m1[j][11];3550 m2[j][12] = m1[j][12] + m1[j][14];3551 m2[j][13] = m1[j][13] + m1[j][15];3552 m2[j][14] = m1[j][12] - m1[j][14];3553 m2[j][15] = m1[j][13] - m1[j][15];3554 3555 m1[j][0] = m2[j][0] + m2[j][1];3556 m1[j][1] = m2[j][0] - m2[j][1];3557 m1[j][2] = m2[j][2] + m2[j][3];3558 m1[j][3] = m2[j][2] - m2[j][3];3559 m1[j][4] = m2[j][4] + m2[j][5];3560 m1[j][5] = m2[j][4] - m2[j][5];3561 m1[j][6] = m2[j][6] + m2[j][7];3562 m1[j][7] = m2[j][6] - m2[j][7];3563 m1[j][8] = m2[j][8] + m2[j][9];3564 m1[j][9] = m2[j][8] - m2[j][9];3565 m1[j][10] = m2[j][10] + m2[j][11];3566 m1[j][11] = m2[j][10] - m2[j][11];3567 m1[j][12] = m2[j][12] + m2[j][13];3568 m1[j][13] = m2[j][12] - m2[j][13];3569 m1[j][14] = m2[j][14] + m2[j][15];3570 m1[j][15] = m2[j][14] - m2[j][15];3571 }3572 3573 //vertical3574 for (i=0; i < 16; i++)3575 {3576 m2[0][i] = m1[0][i] + m1[2][i];3577 m2[1][i] = m1[1][i] + m1[3][i];3578 m2[2][i] = m1[0][i] - m1[2][i];3579 m2[3][i] = m1[1][i] - m1[3][i];3580 3581 m1[0][i] = m2[0][i] + m2[1][i];3582 m1[1][i] = m2[0][i] - m2[1][i];3583 m1[2][i] = m2[2][i] + m2[3][i];3584 m1[3][i] = m2[2][i] - m2[3][i];3585 }3586 3587 for (i = 0; i < 4; i++)3588 {3589 for (j = 0; j < 16; j++)3590 {3591 sad += abs(m1[i][j]);3592 }3593 }3594 3595 sad=((sad+2)>>2);3596 3597 return sad;3598 }3599 3600 UInt TComRdCost::xCalcHADs4x16( Pel *piOrg, Pel *piCur, Int iStrideOrg, Int iStrideCur, Int iStep )3601 {3602 Int k, i, j, jj, sad=0;3603 Int diff[64], m1[16][4], m2[16][4], m3[16][4];3604 assert( iStep == 1 );3605 for( k = 0; k < 64; k += 4 )3606 {3607 diff[k+0] = piOrg[0] - piCur[0];3608 diff[k+1] = piOrg[1] - piCur[1];3609 diff[k+2] = piOrg[2] - piCur[2];3610 diff[k+3] = piOrg[3] - piCur[3];3611 3612 piCur += iStrideCur;3613 piOrg += iStrideOrg;3614 }3615 3616 //horizontal3617 for (j=0; j < 16; j++)3618 {3619 jj = j << 2;3620 m2[j][0] = diff[jj ] + diff[jj+2];3621 m2[j][1] = diff[jj+1] + diff[jj+3];3622 m2[j][2] = diff[jj ] - diff[jj+2];3623 m2[j][3] = diff[jj+1] - diff[jj+3];3624 3625 m1[j][0] = m2[j][0] + m2[j][1];3626 m1[j][1] = m2[j][0] - m2[j][1];3627 m1[j][2] = m2[j][2] + m2[j][3];3628 m1[j][3] = m2[j][2] - m2[j][3];3629 }3630 3631 //vertical3632 for (i=0; i < 4; i++)3633 {3634 m2[0][i] = m1[0][i] + m1[8][i];3635 m2[1][i] = m1[1][i] + m1[9][i];3636 m2[2][i] = m1[2][i] + m1[10][i];3637 m2[3][i] = m1[3][i] + m1[11][i];3638 m2[4][i] = m1[4][i] + m1[12][i];3639 m2[5][i] = m1[5][i] + m1[13][i];3640 m2[6][i] = m1[6][i] + m1[14][i];3641 m2[7][i] = m1[7][i] + m1[15][i];3642 m2[8][i] = m1[0][i] - m1[8][i];3643 m2[9][i] = m1[1][i] - m1[9][i];3644 m2[10][i] = m1[2][i] - m1[10][i];3645 m2[11][i] = m1[3][i] - m1[11][i];3646 m2[12][i] = m1[4][i] - m1[12][i];3647 m2[13][i] = m1[5][i] - m1[13][i];3648 m2[14][i] = m1[6][i] - m1[14][i];3649 m2[15][i] = m1[7][i] - m1[15][i];3650 3651 m3[0][i] = m2[0][i] + m2[4][i];3652 m3[1][i] = m2[1][i] + m2[5][i];3653 m3[2][i] = m2[2][i] + m2[6][i];3654 m3[3][i] = m2[3][i] + m2[7][i];3655 m3[4][i] = m2[0][i] - m2[4][i];3656 m3[5][i] = m2[1][i] - m2[5][i];3657 m3[6][i] = m2[2][i] - m2[6][i];3658 m3[7][i] = m2[3][i] - m2[7][i];3659 m3[8][i] = m2[8][i] + m2[12][i];3660 m3[9][i] = m2[9][i] + m2[13][i];3661 m3[10][i] = m2[10][i] + m2[14][i];3662 m3[11][i] = m2[11][i] + m2[15][i];3663 m3[12][i] = m2[8][i] - m2[12][i];3664 m3[13][i] = m2[9][i] - m2[13][i];3665 m3[14][i] = m2[10][i] - m2[14][i];3666 m3[15][i] = m2[11][i] - m2[15][i];3667 3668 m1[0][i] = m3[0][i] + m3[2][i];3669 m1[1][i] = m3[1][i] + m3[3][i];3670 m1[2][i] = m3[0][i] - m3[2][i];3671 m1[3][i] = m3[1][i] - m3[3][i];3672 m1[4][i] = m3[4][i] + m3[6][i];3673 m1[5][i] = m3[5][i] + m3[7][i];3674 m1[6][i] = m3[4][i] - m3[6][i];3675 m1[7][i] = m3[5][i] - m3[7][i];3676 m1[8][i] = m3[8][i] + m3[10][i];3677 m1[9][i] = m3[9][i] + m3[11][i];3678 m1[10][i] = m3[8][i] - m3[10][i];3679 m1[11][i] = m3[9][i] - m3[11][i];3680 m1[12][i] = m3[12][i] + m3[14][i];3681 m1[13][i] = m3[13][i] + m3[15][i];3682 m1[14][i] = m3[12][i] - m3[14][i];3683 m1[15][i] = m3[13][i] - m3[15][i];3684 3685 m2[0][i] = m1[0][i] + m1[1][i];3686 m2[1][i] = m1[0][i] - m1[1][i];3687 m2[2][i] = m1[2][i] + m1[3][i];3688 m2[3][i] = m1[2][i] - m1[3][i];3689 m2[4][i] = m1[4][i] + m1[5][i];3690 m2[5][i] = m1[4][i] - m1[5][i];3691 m2[6][i] = m1[6][i] + m1[7][i];3692 m2[7][i] = m1[6][i] - m1[7][i];3693 m2[8][i] = m1[8][i] + m1[9][i];3694 m2[9][i] = m1[8][i] - m1[9][i];3695 m2[10][i] = m1[10][i] + m1[11][i];3696 m2[11][i] = m1[10][i] - m1[11][i];3697 m2[12][i] = m1[12][i] + m1[13][i];3698 m2[13][i] = m1[12][i] - m1[13][i];3699 m2[14][i] = m1[14][i] + m1[15][i];3700 m2[15][i] = m1[14][i] - m1[15][i];3701 }3702 3703 for (i = 0; i < 16; i++)3704 {3705 for (j = 0; j < 4; j++)3706 {3707 sad += abs(m2[i][j]);3708 }3709 }3710 3711 sad=((sad+2)>>2);3712 3713 return sad;3714 }3715 #endif3716 3717 3430 UInt TComRdCost::xGetHADs4( DistParam* pcDtParam ) 3718 3431 { … … 3809 3522 UInt uiSum = 0; 3810 3523 3811 #if NS_HAD3812 if( ( ( iRows % 8 == 0) && (iCols % 8 == 0) && ( iRows == iCols ) ) || ( ( iRows % 8 == 0 ) && (iCols % 8 == 0) && !pcDtParam->bUseNSHAD ) )3813 #else3814 3524 if( ( iRows % 8 == 0) && (iCols % 8 == 0) ) 3815 #endif3816 3525 { 3817 3526 Int iOffsetOrg = iStrideOrg<<3; … … 3827 3536 } 3828 3537 } 3829 #if NS_HAD3830 else if ( ( iCols > 8 ) && ( iCols > iRows ) && pcDtParam->bUseNSHAD )3831 {3832 Int iOffsetOrg = iStrideOrg<<2;3833 Int iOffsetCur = iStrideCur<<2;3834 for ( y=0; y<iRows; y+= 4 )3835 {3836 for ( x=0; x<iCols; x+= 16 )3837 {3838 uiSum += xCalcHADs16x4( &piOrg[x], &piCur[x*iStep], iStrideOrg, iStrideCur, iStep );3839 }3840 piOrg += iOffsetOrg;3841 piCur += iOffsetCur;3842 }3843 }3844 else if ( ( iRows > 8 ) && ( iCols < iRows ) && pcDtParam->bUseNSHAD )3845 {3846 Int iOffsetOrg = iStrideOrg<<4;3847 Int iOffsetCur = iStrideCur<<4;3848 for ( y=0; y<iRows; y+= 16 )3849 {3850 for ( x=0; x<iCols; x+= 4 )3851 {3852 uiSum += xCalcHADs4x16( &piOrg[x], &piCur[x*iStep], iStrideOrg, iStrideCur, iStep );3853 }3854 piOrg += iOffsetOrg;3855 piCur += iOffsetCur;3856 }3857 }3858 #endif3859 3538 else if( ( iRows % 4 == 0) && (iCols % 4 == 0) ) 3860 3539 { -
branches/HTM-10.0-dev0/source/Lib/TLibCommon/TComRdCost.h
r833 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 107 107 UInt uiComp; // uiComp = 0 (luma Y), 1 (chroma U), 2 (chroma V) 108 108 109 #if NS_HAD110 Bool bUseNSHAD;111 #endif112 113 109 // (vertical) subsampling shift (for reducing complexity) 114 110 // - 0 = no subsampling, 1 = even rows, 2 = every 4th, etc. … … 127 123 iSubShift = 0; 128 124 bitDepth = 0; 129 #if NS_HAD130 bUseNSHAD = false;131 #endif132 125 #if H_3D_VSO 133 126 // SAIT_VSO_EST_A0033 … … 155 148 #endif 156 149 157 #if WEIGHTED_CHROMA_DISTORTION158 150 Double m_cbDistortionWeight; 159 151 Double m_crDistortionWeight; 160 #endif161 152 Double m_dLambda; 162 153 Double m_sqrtLambda; … … 201 192 202 193 203 #if WEIGHTED_CHROMA_DISTORTION204 194 Void setCbDistortionWeight ( Double cbDistortionWeight) { m_cbDistortionWeight = cbDistortionWeight; }; 205 195 Void setCrDistortionWeight ( Double crDistortionWeight) { m_crDistortionWeight = crDistortionWeight; }; 206 #endif207 196 Void setLambda ( Double dLambda ); 208 197 Void setFrameLambda ( Double dLambda ) { m_dFrameLambda = dLambda; } … … 215 204 #endif 216 205 217 #if RATE_CONTROL_LAMBDA_DOMAIN218 206 Double getLambda() { return m_dLambda; } 219 #if M0036_RC_IMPROVEMENT220 207 Double getChromaWeight () {return((m_cbDistortionWeight+m_crDistortionWeight)/2.0);} 221 #endif222 #endif223 208 224 209 // Distortion Functions … … 227 212 Void setDistParam( UInt uiBlkWidth, UInt uiBlkHeight, DFunc eDFunc, DistParam& rcDistParam ); 228 213 Void setDistParam( TComPattern* pcPatternKey, Pel* piRefY, Int iRefStride, DistParam& rcDistParam ); 229 #if NS_HAD230 Void setDistParam( TComPattern* pcPatternKey, Pel* piRefY, Int iRefStride, Int iStep, DistParam& rcDistParam, Bool bHADME=false, Bool bUseNSHAD=false );231 Void setDistParam( DistParam& rcDP, Int bitDepth, Pel* p1, Int iStride1, Pel* p2, Int iStride2, Int iWidth, Int iHeight, Bool bHadamard = false, Bool bUseNSHAD=false );232 #else233 214 Void setDistParam( TComPattern* pcPatternKey, Pel* piRefY, Int iRefStride, Int iStep, DistParam& rcDistParam, Bool bHADME=false ); 234 215 Void setDistParam( DistParam& rcDP, Int bitDepth, Pel* p1, Int iStride1, Pel* p2, Int iStride2, Int iWidth, Int iHeight, Bool bHadamard = false ); 235 #endif236 216 237 217 #if H_3D_DBBP … … 337 317 static UInt xCalcHADs4x4 ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep ); 338 318 static UInt xCalcHADs8x8 ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep ); 339 #if NS_HAD340 static UInt xCalcHADs16x4 ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep );341 static UInt xCalcHADs4x16 ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep );342 #endif343 344 319 #if H_3D_DBBP 345 320 static UInt xGetMaskedSSE ( DistParam* pcDtParam ); … … 350 325 351 326 public: 352 #if WEIGHTED_CHROMA_DISTORTION353 327 UInt getDistPart(Int bitDepth, Pel* piCur, Int iCurStride, Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, TextType eText = TEXT_LUMA, DFunc eDFunc = DF_SSE ); 354 #else 355 UInt getDistPart(Int bitDepth, Pel* piCur, Int iCurStride, Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, DFunc eDFunc = DF_SSE ); 356 #endif 357 358 #if (RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT) || KWU_RC_MADPRED_E0227 328 329 #if KWU_RC_MADPRED_E0227 359 330 UInt getSADPart ( Int bitDepth, Pel* pelCur, Int curStride, Pel* pelOrg, Int orgStride, UInt width, UInt height ); 360 331 #endif -
branches/HTM-10.0-dev0/source/Lib/TLibCommon/TComRdCostWeightPrediction.cpp
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/TLibCommon/TComRdCostWeightPrediction.h
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/TLibCommon/TComRom.cpp
r773 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 327 327 UInt g_uiPCMBitDepthChroma = 8; // PCM bit-depth 328 328 329 #if H_3D_DIM_DMM 329 330 // ==================================================================================================================== 330 331 // Depth coding modes 331 332 // ==================================================================================================================== 332 #if H_3D_DIM_DMM333 333 const WedgeResolution g_dmmWedgeResolution[6] = 334 334 { … … 372 372 Bool g_traceTU = true; 373 373 Bool g_disableHLSTrace = false; 374 UInt64 g_stopAtCounter = 48;374 UInt64 g_stopAtCounter = 0; 375 375 Bool g_traceCopyBack = false; 376 376 Bool g_decTraceDispDer = false; 377 377 Bool g_decTraceMvFromMerge = false; 378 Bool g_stopAtPos = false; 379 Bool g_outputPos = false; 378 380 #endif 379 381 #endif … … 395 397 const UInt g_uiMinInGroup[ 10 ] = {0,1,2,3,4,6,8,12,16,24}; 396 398 const UInt g_uiGroupIdx[ 32 ] = {0,1,2,3,4,4,5,5,6,6,6,6,7,7,7,7,8,8,8,8,8,8,8,8,9,9,9,9,9,9,9,9}; 397 398 // Rice parameters for absolute transform levels399 const UInt g_auiGoRiceRange[5] =400 {401 7, 14, 26, 46, 78402 };403 404 const UInt g_auiGoRicePrefixLen[5] =405 {406 8, 7, 6, 5, 4407 };408 399 409 400 Void initSigLastScan(UInt* pBuffD, UInt* pBuffH, UInt* pBuffV, Int iWidth, Int iHeight) … … 573 564 #if H_MV_ENC_DEC_TRAC 574 565 #if ENC_DEC_TRACE 566 Void stopAtPos( Int poc, Int layerId, Int cuPelX, Int cuPelY, Int cuWidth, Int cuHeight ) 567 { 568 569 if ( g_outputPos ) 570 { 571 std::cout << "POC\t" << poc 572 << "\tLayerId\t" << layerId 573 << "\tCuPelX\t" << cuPelX 574 << "\tCuPelY\t" << cuPelY 575 << "\tCuWidth\t" << cuWidth 576 << "\tCuHeight\t" << cuHeight 577 << std::endl; 578 } 579 580 Bool stopFlag = false; 581 if ( g_stopAtPos && poc == 0 && layerId == 1 ) 582 { 583 Bool stopAtCU = true; 584 if ( stopAtCU ) // Stop at CU with specific size 585 { 586 stopFlag = ( cuPelX == 888 ) && ( cuPelY == 248 ) && ( cuWidth == 8 ) && ( cuHeight == 8); 587 } 588 else 589 { // Stop at specific position 590 Int xPos = 888; 591 Int yPos = 248; 592 593 Int cuPelXEnd = cuPelX + cuWidth - 1; 594 Int cuPelYEnd = cuPelY + cuHeight - 1; 595 596 stopFlag = (cuPelX <= xPos ) && (cuPelXEnd >= xPos ) && (cuPelY <= yPos ) && (cuPelYEnd >= yPos ); 597 } 598 } 599 600 if ( stopFlag ) 601 { // Set breakpoint here. 602 std::cout << "Stop position. Break point here." << std::endl; 603 } 604 } 605 575 606 Void writeToTraceFile( const Char* symbolName, Int val, Bool doIt ) 576 607 { -
branches/HTM-10.0-dev0/source/Lib/TLibCommon/TComRom.h
r773 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 126 126 extern const UInt g_uiMinInGroup[ 10 ]; 127 127 128 extern const UInt g_auiGoRiceRange[5]; //!< maximum value coded with Rice codes129 extern const UInt g_auiGoRicePrefixLen[5]; //!< prefix length for each maximum value130 131 128 extern const UInt g_sigLastScan8x8[ 3 ][ 4 ]; //!< coefficient group scan order for 8x8 TUs 132 129 extern UInt g_sigLastScanCG32x32[ 64 ]; … … 222 219 extern UInt64 g_stopAtCounter; // Counter to set breakpoint. 223 220 extern Bool g_traceCopyBack; // Output samples on copy back 224 extern Bool g_decTraceDispDer; // Trace derived disparity vectors (decoder only)221 extern Bool g_decTraceDispDer; // Trace derived disparity vectors (decoder only) 225 222 extern Bool g_decTraceMvFromMerge; // Trace motion vectors obtained from merge (decoder only) 223 extern Bool g_stopAtPos; // Stop at position 224 extern Bool g_outputPos; // Output position 226 225 227 226 #define DTRACE_CU(x,y) writeToTraceFile( x,y, g_traceCU ); … … 232 231 #define DTRACE_TU_S(x) writeToTraceFile( x, g_traceTU ); 233 232 234 235 233 Void writeToTraceFile( const Char* symbolName, Int val, Bool doIt ); 236 234 Void writeToTraceFile( const Char* symbolName, Bool doIt ); 235 Void stopAtPos ( Int poc, Int layerId, Int cuPelX, Int cuPelY, Int cuWidth, Int cuHeight ); 237 236 #endif 238 237 #else -
branches/HTM-10.0-dev0/source/Lib/TLibCommon/TComSampleAdaptiveOffset.cpp
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-201 3, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 41 41 #include <stdio.h> 42 42 #include <math.h> 43 44 43 //! \ingroup TLibCommon 45 44 //! \{ 46 47 SAOParam::~SAOParam() 48 { 49 for (Int i = 0 ; i<3; i++) 50 { 51 if (psSaoPart[i]) 52 { 53 delete [] psSaoPart[i]; 54 } 55 } 56 } 57 58 // ==================================================================================================================== 59 // Tables 60 // ==================================================================================================================== 45 UInt g_saoMaxOffsetQVal[NUM_SAO_COMPONENTS]; 46 47 SAOOffset::SAOOffset() 48 { 49 reset(); 50 } 51 52 SAOOffset::~SAOOffset() 53 { 54 55 } 56 57 Void SAOOffset::reset() 58 { 59 modeIdc = SAO_MODE_OFF; 60 typeIdc = -1; 61 typeAuxInfo = -1; 62 ::memset(offset, 0, sizeof(Int)* MAX_NUM_SAO_CLASSES); 63 } 64 65 const SAOOffset& SAOOffset::operator= (const SAOOffset& src) 66 { 67 modeIdc = src.modeIdc; 68 typeIdc = src.typeIdc; 69 typeAuxInfo = src.typeAuxInfo; 70 ::memcpy(offset, src.offset, sizeof(Int)* MAX_NUM_SAO_CLASSES); 71 72 return *this; 73 } 74 75 76 SAOBlkParam::SAOBlkParam() 77 { 78 reset(); 79 } 80 81 SAOBlkParam::~SAOBlkParam() 82 { 83 84 } 85 86 Void SAOBlkParam::reset() 87 { 88 for(Int compIdx=0; compIdx< 3; compIdx++) 89 { 90 offsetParam[compIdx].reset(); 91 } 92 } 93 94 const SAOBlkParam& SAOBlkParam::operator= (const SAOBlkParam& src) 95 { 96 for(Int compIdx=0; compIdx< 3; compIdx++) 97 { 98 offsetParam[compIdx] = src.offsetParam[compIdx]; 99 } 100 return *this; 101 102 } 61 103 62 104 TComSampleAdaptiveOffset::TComSampleAdaptiveOffset() 63 105 { 64 m_pClipTable = NULL; 65 m_pClipTableBase = NULL; 66 m_pChromaClipTable = NULL; 67 m_pChromaClipTableBase = NULL; 68 m_iOffsetBo = NULL; 69 m_iChromaOffsetBo = NULL; 70 m_lumaTableBo = NULL; 71 m_chromaTableBo = NULL; 72 m_iUpBuff1 = NULL; 73 m_iUpBuff2 = NULL; 74 m_iUpBufft = NULL; 75 ipSwap = NULL; 76 77 m_pTmpU1 = NULL; 78 m_pTmpU2 = NULL; 79 m_pTmpL1 = NULL; 80 m_pTmpL2 = NULL; 81 } 106 m_tempPicYuv = NULL; 107 for(Int compIdx=0; compIdx < NUM_SAO_COMPONENTS; compIdx++) 108 { 109 m_offsetClipTable[compIdx] = NULL; 110 } 111 m_signTable = NULL; 112 113 114 m_lineBufWidth = 0; 115 m_signLineBuf1 = NULL; 116 m_signLineBuf2 = NULL; 117 } 118 82 119 83 120 TComSampleAdaptiveOffset::~TComSampleAdaptiveOffset() 84 121 { 85 86 } 87 88 const Int TComSampleAdaptiveOffset::m_aiNumCulPartsLevel[5] = 89 { 90 1, //level 0 91 5, //level 1 92 21, //level 2 93 85, //level 3 94 341, //level 4 95 }; 96 97 const UInt TComSampleAdaptiveOffset::m_auiEoTable[9] = 98 { 99 1, //0 100 2, //1 101 0, //2 102 3, //3 103 4, //4 104 0, //5 105 0, //6 106 0, //7 107 0 108 }; 109 110 const Int TComSampleAdaptiveOffset::m_iNumClass[MAX_NUM_SAO_TYPE] = 111 { 112 SAO_EO_LEN, 113 SAO_EO_LEN, 114 SAO_EO_LEN, 115 SAO_EO_LEN, 116 SAO_BO_LEN 117 }; 118 119 const UInt TComSampleAdaptiveOffset::m_uiMaxDepth = SAO_MAX_DEPTH; 120 121 122 /** convert Level Row Col to Idx 123 * \param level, row, col 124 */ 125 Int TComSampleAdaptiveOffset::convertLevelRowCol2Idx(Int level, Int row, Int col) 126 { 127 Int idx; 128 if (level == 0) 129 { 130 idx = 0; 131 } 132 else if (level == 1) 133 { 134 idx = 1 + row*2 + col; 135 } 136 else if (level == 2) 137 { 138 idx = 5 + row*4 + col; 139 } 140 else if (level == 3) 141 { 142 idx = 21 + row*8 + col; 143 } 144 else // (level == 4) 145 { 146 idx = 85 + row*16 + col; 147 } 148 return idx; 149 } 150 151 /** create SampleAdaptiveOffset memory. 152 * \param 153 */ 154 Void TComSampleAdaptiveOffset::create( UInt uiSourceWidth, UInt uiSourceHeight, UInt uiMaxCUWidth, UInt uiMaxCUHeight ) 155 { 156 m_iPicWidth = uiSourceWidth; 157 m_iPicHeight = uiSourceHeight; 158 159 m_uiMaxCUWidth = uiMaxCUWidth; 160 m_uiMaxCUHeight = uiMaxCUHeight; 161 162 m_iNumCuInWidth = m_iPicWidth / m_uiMaxCUWidth; 163 m_iNumCuInWidth += ( m_iPicWidth % m_uiMaxCUWidth ) ? 1 : 0; 164 165 m_iNumCuInHeight = m_iPicHeight / m_uiMaxCUHeight; 166 m_iNumCuInHeight += ( m_iPicHeight % m_uiMaxCUHeight ) ? 1 : 0; 167 168 Int iMaxSplitLevelHeight = (Int)(logf((Float)m_iNumCuInHeight)/logf(2.0)); 169 Int iMaxSplitLevelWidth = (Int)(logf((Float)m_iNumCuInWidth )/logf(2.0)); 170 171 m_uiMaxSplitLevel = (iMaxSplitLevelHeight < iMaxSplitLevelWidth)?(iMaxSplitLevelHeight):(iMaxSplitLevelWidth); 172 m_uiMaxSplitLevel = (m_uiMaxSplitLevel< m_uiMaxDepth)?(m_uiMaxSplitLevel):(m_uiMaxDepth); 173 /* various structures are overloaded to store per component data. 174 * m_iNumTotalParts must allow for sufficient storage in any allocated arrays */ 175 m_iNumTotalParts = max(3,m_aiNumCulPartsLevel[m_uiMaxSplitLevel]); 176 177 UInt uiPixelRangeY = 1 << g_bitDepthY; 178 UInt uiBoRangeShiftY = g_bitDepthY - SAO_BO_BITS; 179 180 m_lumaTableBo = new Pel [uiPixelRangeY]; 181 for (Int k2=0; k2<uiPixelRangeY; k2++) 182 { 183 m_lumaTableBo[k2] = 1 + (k2>>uiBoRangeShiftY); 184 } 185 186 UInt uiPixelRangeC = 1 << g_bitDepthC; 187 UInt uiBoRangeShiftC = g_bitDepthC - SAO_BO_BITS; 188 189 m_chromaTableBo = new Pel [uiPixelRangeC]; 190 for (Int k2=0; k2<uiPixelRangeC; k2++) 191 { 192 m_chromaTableBo[k2] = 1 + (k2>>uiBoRangeShiftC); 193 } 194 195 m_iUpBuff1 = new Int[m_iPicWidth+2]; 196 m_iUpBuff2 = new Int[m_iPicWidth+2]; 197 m_iUpBufft = new Int[m_iPicWidth+2]; 198 199 m_iUpBuff1++; 200 m_iUpBuff2++; 201 m_iUpBufft++; 202 Pel i; 203 204 UInt uiMaxY = (1 << g_bitDepthY) - 1;; 205 UInt uiMinY = 0; 206 207 Int iCRangeExt = uiMaxY>>1; 208 209 m_pClipTableBase = new Pel[uiMaxY+2*iCRangeExt]; 210 m_iOffsetBo = new Int[uiMaxY+2*iCRangeExt]; 211 212 for(i=0;i<(uiMinY+iCRangeExt);i++) 213 { 214 m_pClipTableBase[i] = uiMinY; 215 } 216 217 for(i=uiMinY+iCRangeExt;i<(uiMaxY+ iCRangeExt);i++) 218 { 219 m_pClipTableBase[i] = i-iCRangeExt; 220 } 221 222 for(i=uiMaxY+iCRangeExt;i<(uiMaxY+2*iCRangeExt);i++) 223 { 224 m_pClipTableBase[i] = uiMaxY; 225 } 226 227 m_pClipTable = &(m_pClipTableBase[iCRangeExt]); 228 229 UInt uiMaxC = (1 << g_bitDepthC) - 1; 230 UInt uiMinC = 0; 231 232 Int iCRangeExtC = uiMaxC>>1; 233 234 m_pChromaClipTableBase = new Pel[uiMaxC+2*iCRangeExtC]; 235 m_iChromaOffsetBo = new Int[uiMaxC+2*iCRangeExtC]; 236 237 for(i=0;i<(uiMinC+iCRangeExtC);i++) 238 { 239 m_pChromaClipTableBase[i] = uiMinC; 240 } 241 242 for(i=uiMinC+iCRangeExtC;i<(uiMaxC+ iCRangeExtC);i++) 243 { 244 m_pChromaClipTableBase[i] = i-iCRangeExtC; 245 } 246 247 for(i=uiMaxC+iCRangeExtC;i<(uiMaxC+2*iCRangeExtC);i++) 248 { 249 m_pChromaClipTableBase[i] = uiMaxC; 250 } 251 252 m_pChromaClipTable = &(m_pChromaClipTableBase[iCRangeExtC]); 253 254 m_pTmpL1 = new Pel [m_uiMaxCUHeight+1]; 255 m_pTmpL2 = new Pel [m_uiMaxCUHeight+1]; 256 m_pTmpU1 = new Pel [m_iPicWidth]; 257 m_pTmpU2 = new Pel [m_iPicWidth]; 258 } 259 260 /** destroy SampleAdaptiveOffset memory. 261 * \param 262 */ 122 destroy(); 123 124 if (m_signLineBuf1) delete[] m_signLineBuf1; m_signLineBuf1 = NULL; 125 if (m_signLineBuf2) delete[] m_signLineBuf2; m_signLineBuf2 = NULL; 126 } 127 128 Void TComSampleAdaptiveOffset::create( Int picWidth, Int picHeight, UInt maxCUWidth, UInt maxCUHeight, UInt maxCUDepth ) 129 { 130 destroy(); 131 132 m_picWidth = picWidth; 133 m_picHeight= picHeight; 134 m_maxCUWidth= maxCUWidth; 135 m_maxCUHeight= maxCUHeight; 136 137 m_numCTUInWidth = (m_picWidth/m_maxCUWidth) + ((m_picWidth % m_maxCUWidth)?1:0); 138 m_numCTUInHeight= (m_picHeight/m_maxCUHeight) + ((m_picHeight % m_maxCUHeight)?1:0); 139 m_numCTUsPic = m_numCTUInHeight*m_numCTUInWidth; 140 141 //temporary picture buffer 142 if ( !m_tempPicYuv ) 143 { 144 m_tempPicYuv = new TComPicYuv; 145 m_tempPicYuv->create( m_picWidth, m_picHeight, m_maxCUWidth, m_maxCUHeight, maxCUDepth ); 146 } 147 148 //bit-depth related 149 for(Int compIdx =0; compIdx < NUM_SAO_COMPONENTS; compIdx++) 150 { 151 Int bitDepthSample = (compIdx == SAO_Y)?g_bitDepthY:g_bitDepthC; 152 m_offsetStepLog2 [compIdx] = max(bitDepthSample - MAX_SAO_TRUNCATED_BITDEPTH, 0); 153 g_saoMaxOffsetQVal[compIdx] = (1<<(min(bitDepthSample,MAX_SAO_TRUNCATED_BITDEPTH)-5))-1; //Table 9-32, inclusive 154 } 155 156 //look-up table for clipping 157 for(Int compIdx =0; compIdx < NUM_SAO_COMPONENTS; compIdx++) 158 { 159 Int bitDepthSample = (compIdx == SAO_Y)?g_bitDepthY:g_bitDepthC; //exclusive 160 Int maxSampleValue = (1<< bitDepthSample); //exclusive 161 Int maxOffsetValue = (g_saoMaxOffsetQVal[compIdx] << m_offsetStepLog2[compIdx]); 162 163 m_offsetClipTable[compIdx] = new Int[(maxSampleValue + maxOffsetValue -1)+ (maxOffsetValue)+1 ]; //positive & negative range plus 0 164 m_offsetClip[compIdx] = &(m_offsetClipTable[compIdx][maxOffsetValue]); 165 166 //assign clipped values 167 Int* offsetClipPtr = m_offsetClip[compIdx]; 168 for(Int k=0; k< maxSampleValue; k++) 169 { 170 *(offsetClipPtr + k) = k; 171 } 172 for(Int k=0; k< maxOffsetValue; k++ ) 173 { 174 *(offsetClipPtr + maxSampleValue+ k) = maxSampleValue-1; 175 *(offsetClipPtr -k -1 ) = 0; 176 } 177 if(compIdx == SAO_Y) //g_bitDepthY is always larger than or equal to g_bitDepthC 178 { 179 m_signTable = new Short[ 2*(maxSampleValue-1) + 1 ]; 180 m_sign = &(m_signTable[maxSampleValue-1]); 181 182 m_sign[0] = 0; 183 for(Int k=1; k< maxSampleValue; k++) 184 { 185 m_sign[k] = 1; 186 m_sign[-k]= -1; 187 } 188 } 189 } 190 191 } 192 263 193 Void TComSampleAdaptiveOffset::destroy() 264 194 { 265 if (m_pClipTableBase) 266 { 267 delete [] m_pClipTableBase; m_pClipTableBase = NULL; 268 } 269 if (m_iOffsetBo) 270 { 271 delete [] m_iOffsetBo; m_iOffsetBo = NULL; 272 } 273 if (m_lumaTableBo) 274 { 275 delete[] m_lumaTableBo; m_lumaTableBo = NULL; 276 } 277 278 if (m_pChromaClipTableBase) 279 { 280 delete [] m_pChromaClipTableBase; m_pChromaClipTableBase = NULL; 281 } 282 if (m_iChromaOffsetBo) 283 { 284 delete [] m_iChromaOffsetBo; m_iChromaOffsetBo = NULL; 285 } 286 if (m_chromaTableBo) 287 { 288 delete[] m_chromaTableBo; m_chromaTableBo = NULL; 289 } 290 291 if (m_iUpBuff1) 292 { 293 m_iUpBuff1--; 294 delete [] m_iUpBuff1; m_iUpBuff1 = NULL; 295 } 296 if (m_iUpBuff2) 297 { 298 m_iUpBuff2--; 299 delete [] m_iUpBuff2; m_iUpBuff2 = NULL; 300 } 301 if (m_iUpBufft) 302 { 303 m_iUpBufft--; 304 delete [] m_iUpBufft; m_iUpBufft = NULL; 305 } 306 if (m_pTmpL1) 307 { 308 delete [] m_pTmpL1; m_pTmpL1 = NULL; 309 } 310 if (m_pTmpL2) 311 { 312 delete [] m_pTmpL2; m_pTmpL2 = NULL; 313 } 314 if (m_pTmpU1) 315 { 316 delete [] m_pTmpU1; m_pTmpU1 = NULL; 317 } 318 if (m_pTmpU2) 319 { 320 delete [] m_pTmpU2; m_pTmpU2 = NULL; 321 } 322 } 323 324 /** allocate memory for SAO parameters 325 * \param *pcSaoParam 326 */ 327 Void TComSampleAdaptiveOffset::allocSaoParam(SAOParam *pcSaoParam) 328 { 329 pcSaoParam->iMaxSplitLevel = m_uiMaxSplitLevel; 330 pcSaoParam->psSaoPart[0] = new SAOQTPart[ m_aiNumCulPartsLevel[pcSaoParam->iMaxSplitLevel] ]; 331 initSAOParam(pcSaoParam, 0, 0, 0, -1, 0, m_iNumCuInWidth-1, 0, m_iNumCuInHeight-1,0); 332 pcSaoParam->psSaoPart[1] = new SAOQTPart[ m_aiNumCulPartsLevel[pcSaoParam->iMaxSplitLevel] ]; 333 pcSaoParam->psSaoPart[2] = new SAOQTPart[ m_aiNumCulPartsLevel[pcSaoParam->iMaxSplitLevel] ]; 334 initSAOParam(pcSaoParam, 0, 0, 0, -1, 0, m_iNumCuInWidth-1, 0, m_iNumCuInHeight-1,1); 335 initSAOParam(pcSaoParam, 0, 0, 0, -1, 0, m_iNumCuInWidth-1, 0, m_iNumCuInHeight-1,2); 336 pcSaoParam->numCuInWidth = m_iNumCuInWidth; 337 pcSaoParam->numCuInHeight = m_iNumCuInHeight; 338 pcSaoParam->saoLcuParam[0] = new SaoLcuParam [m_iNumCuInHeight*m_iNumCuInWidth]; 339 pcSaoParam->saoLcuParam[1] = new SaoLcuParam [m_iNumCuInHeight*m_iNumCuInWidth]; 340 pcSaoParam->saoLcuParam[2] = new SaoLcuParam [m_iNumCuInHeight*m_iNumCuInWidth]; 341 } 342 343 /** initialize SAO parameters 344 * \param *pcSaoParam, iPartLevel, iPartRow, iPartCol, iParentPartIdx, StartCUX, EndCUX, StartCUY, EndCUY, iYCbCr 345 */ 346 Void TComSampleAdaptiveOffset::initSAOParam(SAOParam *pcSaoParam, Int iPartLevel, Int iPartRow, Int iPartCol, Int iParentPartIdx, Int StartCUX, Int EndCUX, Int StartCUY, Int EndCUY, Int iYCbCr) 347 { 348 Int j; 349 Int iPartIdx = convertLevelRowCol2Idx(iPartLevel, iPartRow, iPartCol); 350 351 SAOQTPart* pSaoPart; 352 353 pSaoPart = &(pcSaoParam->psSaoPart[iYCbCr][iPartIdx]); 354 355 pSaoPart->PartIdx = iPartIdx; 356 pSaoPart->PartLevel = iPartLevel; 357 pSaoPart->PartRow = iPartRow; 358 pSaoPart->PartCol = iPartCol; 359 360 pSaoPart->StartCUX = StartCUX; 361 pSaoPart->EndCUX = EndCUX; 362 pSaoPart->StartCUY = StartCUY; 363 pSaoPart->EndCUY = EndCUY; 364 365 pSaoPart->UpPartIdx = iParentPartIdx; 366 pSaoPart->iBestType = -1; 367 pSaoPart->iLength = 0; 368 369 pSaoPart->subTypeIdx = 0; 370 371 for (j=0;j<MAX_NUM_SAO_OFFSETS;j++) 372 { 373 pSaoPart->iOffset[j] = 0; 374 } 375 376 if(pSaoPart->PartLevel != m_uiMaxSplitLevel) 377 { 378 Int DownLevel = (iPartLevel+1 ); 379 Int DownRowStart = (iPartRow << 1); 380 Int DownColStart = (iPartCol << 1); 381 382 Int iDownRowIdx, iDownColIdx; 383 Int NumCUWidth, NumCUHeight; 384 Int NumCULeft; 385 Int NumCUTop; 386 387 Int DownStartCUX, DownStartCUY; 388 Int DownEndCUX, DownEndCUY; 389 390 NumCUWidth = EndCUX - StartCUX +1; 391 NumCUHeight = EndCUY - StartCUY +1; 392 NumCULeft = (NumCUWidth >> 1); 393 NumCUTop = (NumCUHeight >> 1); 394 395 DownStartCUX= StartCUX; 396 DownEndCUX = DownStartCUX + NumCULeft - 1; 397 DownStartCUY= StartCUY; 398 DownEndCUY = DownStartCUY + NumCUTop - 1; 399 iDownRowIdx = DownRowStart + 0; 400 iDownColIdx = DownColStart + 0; 401 402 pSaoPart->DownPartsIdx[0]= convertLevelRowCol2Idx(DownLevel, iDownRowIdx, iDownColIdx); 403 404 initSAOParam(pcSaoParam, DownLevel, iDownRowIdx, iDownColIdx, iPartIdx, DownStartCUX, DownEndCUX, DownStartCUY, DownEndCUY, iYCbCr); 405 406 DownStartCUX = StartCUX + NumCULeft; 407 DownEndCUX = EndCUX; 408 DownStartCUY = StartCUY; 409 DownEndCUY = DownStartCUY + NumCUTop -1; 410 iDownRowIdx = DownRowStart + 0; 411 iDownColIdx = DownColStart + 1; 412 413 pSaoPart->DownPartsIdx[1] = convertLevelRowCol2Idx(DownLevel, iDownRowIdx, iDownColIdx); 414 415 initSAOParam(pcSaoParam, DownLevel, iDownRowIdx, iDownColIdx, iPartIdx, DownStartCUX, DownEndCUX, DownStartCUY, DownEndCUY, iYCbCr); 416 417 DownStartCUX = StartCUX; 418 DownEndCUX = DownStartCUX + NumCULeft -1; 419 DownStartCUY = StartCUY + NumCUTop; 420 DownEndCUY = EndCUY; 421 iDownRowIdx = DownRowStart + 1; 422 iDownColIdx = DownColStart + 0; 423 424 pSaoPart->DownPartsIdx[2] = convertLevelRowCol2Idx(DownLevel, iDownRowIdx, iDownColIdx); 425 426 initSAOParam(pcSaoParam, DownLevel, iDownRowIdx, iDownColIdx, iPartIdx, DownStartCUX, DownEndCUX, DownStartCUY, DownEndCUY, iYCbCr); 427 428 DownStartCUX = StartCUX+ NumCULeft; 429 DownEndCUX = EndCUX; 430 DownStartCUY = StartCUY + NumCUTop; 431 DownEndCUY = EndCUY; 432 iDownRowIdx = DownRowStart + 1; 433 iDownColIdx = DownColStart + 1; 434 435 pSaoPart->DownPartsIdx[3] = convertLevelRowCol2Idx(DownLevel, iDownRowIdx, iDownColIdx); 436 437 initSAOParam(pcSaoParam, DownLevel, iDownRowIdx, iDownColIdx, iPartIdx,DownStartCUX, DownEndCUX, DownStartCUY, DownEndCUY, iYCbCr); 438 } 439 else 440 { 441 pSaoPart->DownPartsIdx[0]=pSaoPart->DownPartsIdx[1]= pSaoPart->DownPartsIdx[2]= pSaoPart->DownPartsIdx[3]= -1; 442 } 443 } 444 445 /** free memory of SAO parameters 446 * \param pcSaoParam 447 */ 448 Void TComSampleAdaptiveOffset::freeSaoParam(SAOParam *pcSaoParam) 449 { 450 delete [] pcSaoParam->psSaoPart[0]; 451 delete [] pcSaoParam->psSaoPart[1]; 452 delete [] pcSaoParam->psSaoPart[2]; 453 pcSaoParam->psSaoPart[0] = 0; 454 pcSaoParam->psSaoPart[1] = 0; 455 pcSaoParam->psSaoPart[2] = 0; 456 if( pcSaoParam->saoLcuParam[0]) 457 { 458 delete [] pcSaoParam->saoLcuParam[0]; pcSaoParam->saoLcuParam[0] = NULL; 459 } 460 if( pcSaoParam->saoLcuParam[1]) 461 { 462 delete [] pcSaoParam->saoLcuParam[1]; pcSaoParam->saoLcuParam[1] = NULL; 463 } 464 if( pcSaoParam->saoLcuParam[2]) 465 { 466 delete [] pcSaoParam->saoLcuParam[2]; pcSaoParam->saoLcuParam[2] = NULL; 467 } 468 } 469 470 /** reset SAO parameters 471 * \param pcSaoParam 472 */ 473 Void TComSampleAdaptiveOffset::resetSAOParam(SAOParam *pcSaoParam) 474 { 475 Int iNumComponet = 3; 476 for(Int c=0; c<iNumComponet; c++) 477 { 478 if (c<2) 479 { 480 pcSaoParam->bSaoFlag[c] = 0; 481 } 482 for(Int i=0; i< m_aiNumCulPartsLevel[m_uiMaxSplitLevel]; i++) 483 { 484 pcSaoParam->psSaoPart[c][i].iBestType = -1; 485 pcSaoParam->psSaoPart[c][i].iLength = 0; 486 pcSaoParam->psSaoPart[c][i].bSplit = false; 487 pcSaoParam->psSaoPart[c][i].bProcessed = false; 488 pcSaoParam->psSaoPart[c][i].dMinCost = MAX_DOUBLE; 489 pcSaoParam->psSaoPart[c][i].iMinDist = MAX_INT; 490 pcSaoParam->psSaoPart[c][i].iMinRate = MAX_INT; 491 pcSaoParam->psSaoPart[c][i].subTypeIdx = 0; 492 for (Int j=0;j<MAX_NUM_SAO_OFFSETS;j++) 493 { 494 pcSaoParam->psSaoPart[c][i].iOffset[j] = 0; 495 pcSaoParam->psSaoPart[c][i].iOffset[j] = 0; 496 pcSaoParam->psSaoPart[c][i].iOffset[j] = 0; 497 } 498 } 499 pcSaoParam->oneUnitFlag[0] = 0; 500 pcSaoParam->oneUnitFlag[1] = 0; 501 pcSaoParam->oneUnitFlag[2] = 0; 502 resetLcuPart(pcSaoParam->saoLcuParam[0]); 503 resetLcuPart(pcSaoParam->saoLcuParam[1]); 504 resetLcuPart(pcSaoParam->saoLcuParam[2]); 505 } 506 } 507 508 /** get the sign of input variable 509 * \param x 510 */ 511 inline Int xSign(Int x) 512 { 513 return ((x >> 31) | ((Int)( (((UInt) -x)) >> 31))); 514 } 515 516 /** initialize variables for SAO process 517 * \param pcPic picture data pointer 518 */ 519 Void TComSampleAdaptiveOffset::createPicSaoInfo(TComPic* pcPic) 520 { 521 m_pcPic = pcPic; 522 m_bUseNIF = ( pcPic->getIndependentSliceBoundaryForNDBFilter() || pcPic->getIndependentTileBoundaryForNDBFilter() ); 523 if(m_bUseNIF) 524 { 525 m_pcYuvTmp = pcPic->getYuvPicBufferForIndependentBoundaryProcessing(); 526 } 527 } 528 529 Void TComSampleAdaptiveOffset::destroyPicSaoInfo() 530 { 531 532 } 533 534 /** sample adaptive offset process for one LCU 535 * \param iAddr, iSaoType, iYCbCr 536 */ 537 Void TComSampleAdaptiveOffset::processSaoCu(Int iAddr, Int iSaoType, Int iYCbCr) 538 { 539 if(!m_bUseNIF) 540 { 541 processSaoCuOrg( iAddr, iSaoType, iYCbCr); 542 } 543 else 544 { 545 Int isChroma = (iYCbCr != 0)? 1:0; 546 Int stride = (iYCbCr != 0)?(m_pcPic->getCStride()):(m_pcPic->getStride()); 547 Pel* pPicRest = getPicYuvAddr(m_pcPic->getPicYuvRec(), iYCbCr); 548 Pel* pPicDec = getPicYuvAddr(m_pcYuvTmp, iYCbCr); 549 550 std::vector<NDBFBlockInfo>& vFilterBlocks = *(m_pcPic->getCU(iAddr)->getNDBFilterBlocks()); 551 552 //variables 553 UInt xPos, yPos, width, height; 554 Bool* pbBorderAvail; 555 UInt posOffset; 556 557 for(Int i=0; i< vFilterBlocks.size(); i++) 558 { 559 xPos = vFilterBlocks[i].posX >> isChroma; 560 yPos = vFilterBlocks[i].posY >> isChroma; 561 width = vFilterBlocks[i].width >> isChroma; 562 height = vFilterBlocks[i].height >> isChroma; 563 pbBorderAvail = vFilterBlocks[i].isBorderAvailable; 564 565 posOffset = (yPos* stride) + xPos; 566 567 processSaoBlock(pPicDec+ posOffset, pPicRest+ posOffset, stride, iSaoType, width, height, pbBorderAvail, iYCbCr); 568 } 569 } 570 } 571 572 /** Perform SAO for non-cross-slice or non-cross-tile process 573 * \param pDec to-be-filtered block buffer pointer 574 * \param pRest filtered block buffer pointer 575 * \param stride picture buffer stride 576 * \param saoType SAO offset type 577 * \param xPos x coordinate 578 * \param yPos y coordinate 579 * \param width block width 580 * \param height block height 581 * \param pbBorderAvail availabilities of block border pixels 582 */ 583 Void TComSampleAdaptiveOffset::processSaoBlock(Pel* pDec, Pel* pRest, Int stride, Int saoType, UInt width, UInt height, Bool* pbBorderAvail, Int iYCbCr) 584 { 585 //variables 586 Int startX, startY, endX, endY, x, y; 587 Int signLeft,signRight,signDown,signDown1; 588 UInt edgeType; 589 Pel *pClipTbl = (iYCbCr==0)?m_pClipTable:m_pChromaClipTable; 590 Int *pOffsetBo = (iYCbCr==0)?m_iOffsetBo: m_iChromaOffsetBo; 591 592 switch (saoType) 593 { 594 case SAO_EO_0: // dir: - 595 { 596 597 startX = (pbBorderAvail[SGU_L]) ? 0 : 1; 598 endX = (pbBorderAvail[SGU_R]) ? width : (width -1); 195 if ( m_tempPicYuv ) 196 { 197 m_tempPicYuv->destroy(); 198 delete m_tempPicYuv; 199 m_tempPicYuv = NULL; 200 } 201 202 for(Int compIdx=0; compIdx < NUM_SAO_COMPONENTS; compIdx++) 203 { 204 if(m_offsetClipTable[compIdx]) 205 { 206 delete[] m_offsetClipTable[compIdx]; m_offsetClipTable[compIdx] = NULL; 207 } 208 } 209 if( m_signTable ) 210 { 211 delete[] m_signTable; m_signTable = NULL; 212 } 213 } 214 215 Void TComSampleAdaptiveOffset::invertQuantOffsets(Int compIdx, Int typeIdc, Int typeAuxInfo, Int* dstOffsets, Int* srcOffsets) 216 { 217 Int codedOffset[MAX_NUM_SAO_CLASSES]; 218 219 ::memcpy(codedOffset, srcOffsets, sizeof(Int)*MAX_NUM_SAO_CLASSES); 220 ::memset(dstOffsets, 0, sizeof(Int)*MAX_NUM_SAO_CLASSES); 221 222 if(typeIdc == SAO_TYPE_START_BO) 223 { 224 for(Int i=0; i< 4; i++) 225 { 226 dstOffsets[(typeAuxInfo+ i)%NUM_SAO_BO_CLASSES] = codedOffset[(typeAuxInfo+ i)%NUM_SAO_BO_CLASSES]*(1<<m_offsetStepLog2[compIdx]); 227 } 228 } 229 else //EO 230 { 231 for(Int i=0; i< NUM_SAO_EO_CLASSES; i++) 232 { 233 dstOffsets[i] = codedOffset[i] *(1<<m_offsetStepLog2[compIdx]); 234 } 235 assert(dstOffsets[SAO_CLASS_EO_PLAIN] == 0); //keep EO plain offset as zero 236 } 237 238 } 239 240 Int TComSampleAdaptiveOffset::getMergeList(TComPic* pic, Int ctu, SAOBlkParam* blkParams, std::vector<SAOBlkParam*>& mergeList) 241 { 242 Int ctuX = ctu % m_numCTUInWidth; 243 Int ctuY = ctu / m_numCTUInWidth; 244 Int mergedCTUPos; 245 Int numValidMergeCandidates = 0; 246 247 for(Int mergeType=0; mergeType< NUM_SAO_MERGE_TYPES; mergeType++) 248 { 249 SAOBlkParam* mergeCandidate = NULL; 250 251 switch(mergeType) 252 { 253 case SAO_MERGE_ABOVE: 254 { 255 if(ctuY > 0) 256 { 257 mergedCTUPos = ctu- m_numCTUInWidth; 258 if( pic->getSAOMergeAvailability(ctu, mergedCTUPos) ) 259 { 260 mergeCandidate = &(blkParams[mergedCTUPos]); 261 } 262 } 263 } 264 break; 265 case SAO_MERGE_LEFT: 266 { 267 if(ctuX > 0) 268 { 269 mergedCTUPos = ctu- 1; 270 if( pic->getSAOMergeAvailability(ctu, mergedCTUPos) ) 271 { 272 mergeCandidate = &(blkParams[mergedCTUPos]); 273 } 274 } 275 } 276 break; 277 default: 278 { 279 printf("not a supported merge type"); 280 assert(0); 281 exit(-1); 282 } 283 } 284 285 mergeList.push_back(mergeCandidate); 286 if (mergeCandidate != NULL) 287 { 288 numValidMergeCandidates++; 289 } 290 } 291 292 return numValidMergeCandidates; 293 } 294 295 296 Void TComSampleAdaptiveOffset::reconstructBlkSAOParam(SAOBlkParam& recParam, std::vector<SAOBlkParam*>& mergeList) 297 { 298 for(Int compIdx=0; compIdx< NUM_SAO_COMPONENTS; compIdx++) 299 { 300 SAOOffset& offsetParam = recParam[compIdx]; 301 302 if(offsetParam.modeIdc == SAO_MODE_OFF) 303 { 304 continue; 305 } 306 307 switch(offsetParam.modeIdc) 308 { 309 case SAO_MODE_NEW: 310 { 311 invertQuantOffsets(compIdx, offsetParam.typeIdc, offsetParam.typeAuxInfo, offsetParam.offset, offsetParam.offset); 312 } 313 break; 314 case SAO_MODE_MERGE: 315 { 316 SAOBlkParam* mergeTarget = mergeList[offsetParam.typeIdc]; 317 assert(mergeTarget != NULL); 318 319 offsetParam = (*mergeTarget)[compIdx]; 320 } 321 break; 322 default: 323 { 324 printf("Not a supported mode"); 325 assert(0); 326 exit(-1); 327 } 328 } 329 } 330 } 331 332 Void TComSampleAdaptiveOffset::reconstructBlkSAOParams(TComPic* pic, SAOBlkParam* saoBlkParams) 333 { 334 m_picSAOEnabled[SAO_Y] = m_picSAOEnabled[SAO_Cb] = m_picSAOEnabled[SAO_Cr] = false; 335 336 for(Int ctu=0; ctu< m_numCTUsPic; ctu++) 337 { 338 std::vector<SAOBlkParam*> mergeList; 339 getMergeList(pic, ctu, saoBlkParams, mergeList); 340 341 reconstructBlkSAOParam(saoBlkParams[ctu], mergeList); 342 343 for(Int compIdx=0; compIdx< NUM_SAO_COMPONENTS; compIdx++) 344 { 345 if(saoBlkParams[ctu][compIdx].modeIdc != SAO_MODE_OFF) 346 { 347 m_picSAOEnabled[compIdx] = true; 348 } 349 } 350 } 351 352 353 } 354 355 356 Void TComSampleAdaptiveOffset::offsetBlock(Int compIdx, Int typeIdx, Int* offset 357 , Pel* srcBlk, Pel* resBlk, Int srcStride, Int resStride, Int width, Int height 358 , Bool isLeftAvail, Bool isRightAvail, Bool isAboveAvail, Bool isBelowAvail, Bool isAboveLeftAvail, Bool isAboveRightAvail, Bool isBelowLeftAvail, Bool isBelowRightAvail) 359 { 360 if(m_lineBufWidth != m_maxCUWidth) 361 { 362 m_lineBufWidth = m_maxCUWidth; 363 364 if (m_signLineBuf1) delete[] m_signLineBuf1; m_signLineBuf1 = NULL; 365 m_signLineBuf1 = new Char[m_lineBufWidth+1]; 366 367 if (m_signLineBuf2) delete[] m_signLineBuf2; m_signLineBuf2 = NULL; 368 m_signLineBuf2 = new Char[m_lineBufWidth+1]; 369 } 370 371 Int* offsetClip = m_offsetClip[compIdx]; 372 373 Int x,y, startX, startY, endX, endY, edgeType; 374 Int firstLineStartX, firstLineEndX, lastLineStartX, lastLineEndX; 375 Char signLeft, signRight, signDown; 376 377 Pel* srcLine = srcBlk; 378 Pel* resLine = resBlk; 379 380 switch(typeIdx) 381 { 382 case SAO_TYPE_EO_0: 383 { 384 offset += 2; 385 startX = isLeftAvail ? 0 : 1; 386 endX = isRightAvail ? width : (width -1); 599 387 for (y=0; y< height; y++) 600 388 { 601 signLeft = xSign(pDec[startX] - pDec[startX-1]);389 signLeft = (Char)m_sign[srcLine[startX] - srcLine[startX-1]]; 602 390 for (x=startX; x< endX; x++) 603 391 { 604 signRight = xSign(pDec[x] - pDec[x+1]);605 edgeType = signRight + signLeft + 2;392 signRight = (Char)m_sign[srcLine[x] - srcLine[x+1]]; 393 edgeType = signRight + signLeft; 606 394 signLeft = -signRight; 607 395 608 pRest[x] = pClipTbl[pDec[x] + m_iOffsetEo[edgeType]];396 resLine[x] = offsetClip[srcLine[x] + offset[edgeType]]; 609 397 } 610 pDec += stride; 611 pRest += stride; 612 } 613 break; 614 } 615 case SAO_EO_1: // dir: | 616 { 617 startY = (pbBorderAvail[SGU_T]) ? 0 : 1; 618 endY = (pbBorderAvail[SGU_B]) ? height : height-1; 619 if (!pbBorderAvail[SGU_T]) 620 { 621 pDec += stride; 622 pRest += stride; 623 } 398 srcLine += srcStride; 399 resLine += resStride; 400 } 401 402 } 403 break; 404 case SAO_TYPE_EO_90: 405 { 406 offset += 2; 407 Char *signUpLine = m_signLineBuf1; 408 409 startY = isAboveAvail ? 0 : 1; 410 endY = isBelowAvail ? height : height-1; 411 if (!isAboveAvail) 412 { 413 srcLine += srcStride; 414 resLine += resStride; 415 } 416 417 Pel* srcLineAbove= srcLine- srcStride; 624 418 for (x=0; x< width; x++) 625 419 { 626 m_iUpBuff1[x] = xSign(pDec[x] - pDec[x-stride]); 627 } 420 signUpLine[x] = (Char)m_sign[srcLine[x] - srcLineAbove[x]]; 421 } 422 423 Pel* srcLineBelow; 628 424 for (y=startY; y<endY; y++) 629 425 { 426 srcLineBelow= srcLine+ srcStride; 427 630 428 for (x=0; x< width; x++) 631 429 { 632 signDown = xSign(pDec[x] - pDec[x+stride]);633 edgeType = signDown + m_iUpBuff1[x] + 2;634 m_iUpBuff1[x]= -signDown;635 636 pRest[x] = pClipTbl[pDec[x] + m_iOffsetEo[edgeType]];430 signDown = (Char)m_sign[srcLine[x] - srcLineBelow[x]]; 431 edgeType = signDown + signUpLine[x]; 432 signUpLine[x]= -signDown; 433 434 resLine[x] = offsetClip[srcLine[x] + offset[edgeType]]; 637 435 } 638 pDec += stride; 639 pRest += stride; 640 } 641 break; 642 } 643 case SAO_EO_2: // dir: 135 644 { 645 Int posShift= stride + 1; 646 647 startX = (pbBorderAvail[SGU_L]) ? 0 : 1 ; 648 endX = (pbBorderAvail[SGU_R]) ? width : (width-1); 649 650 //prepare 2nd line upper sign 651 pDec += stride; 436 srcLine += srcStride; 437 resLine += resStride; 438 } 439 440 } 441 break; 442 case SAO_TYPE_EO_135: 443 { 444 offset += 2; 445 Char *signUpLine, *signDownLine, *signTmpLine; 446 447 signUpLine = m_signLineBuf1; 448 signDownLine= m_signLineBuf2; 449 450 startX = isLeftAvail ? 0 : 1 ; 451 endX = isRightAvail ? width : (width-1); 452 453 //prepare 2nd line's upper sign 454 Pel* srcLineBelow= srcLine+ srcStride; 652 455 for (x=startX; x< endX+1; x++) 653 456 { 654 m_iUpBuff1[x] = xSign(pDec[x] - pDec[x- posShift]);457 signUpLine[x] = (Char)m_sign[srcLineBelow[x] - srcLine[x- 1]]; 655 458 } 656 459 657 460 //1st line 658 pDec -= stride; 659 if(pbBorderAvail[SGU_TL]) 660 { 661 x= 0; 662 edgeType = xSign(pDec[x] - pDec[x- posShift]) - m_iUpBuff1[x+1] + 2; 663 pRest[x] = pClipTbl[pDec[x] + m_iOffsetEo[edgeType]]; 664 665 } 666 if(pbBorderAvail[SGU_T]) 667 { 668 for(x= 1; x< endX; x++) 669 { 670 edgeType = xSign(pDec[x] - pDec[x- posShift]) - m_iUpBuff1[x+1] + 2; 671 pRest[x] = pClipTbl[pDec[x] + m_iOffsetEo[edgeType]]; 672 } 673 } 674 pDec += stride; 675 pRest += stride; 461 Pel* srcLineAbove= srcLine- srcStride; 462 firstLineStartX = isAboveLeftAvail ? 0 : 1; 463 firstLineEndX = isAboveAvail? endX: 1; 464 for(x= firstLineStartX; x< firstLineEndX; x++) 465 { 466 edgeType = m_sign[srcLine[x] - srcLineAbove[x- 1]] - signUpLine[x+1]; 467 resLine[x] = offsetClip[srcLine[x] + offset[edgeType]]; 468 } 469 srcLine += srcStride; 470 resLine += resStride; 676 471 677 472 … … 679 474 for (y= 1; y< height-1; y++) 680 475 { 476 srcLineBelow= srcLine+ srcStride; 477 681 478 for (x=startX; x<endX; x++) 682 479 { 683 signDown 1 = xSign(pDec[x] - pDec[x+ posShift]);684 edgeType = signDown1 + m_iUpBuff1[x] + 2;685 pRest[x] = pClipTbl[pDec[x] + m_iOffsetEo[edgeType]];686 687 m_iUpBufft[x+1] = -signDown1;480 signDown = (Char)m_sign[srcLine[x] - srcLineBelow[x+ 1]] ; 481 edgeType = signDown + signUpLine[x]; 482 resLine[x] = offsetClip[srcLine[x] + offset[edgeType]]; 483 484 signDownLine[x+1] = -signDown; 688 485 } 689 m_iUpBufft[startX] = xSign(pDec[stride+startX] - pDec[startX-1]);690 691 ipSwap = m_iUpBuff1;692 m_iUpBuff1 = m_iUpBufft;693 m_iUpBufft = ipSwap;694 695 pDec += stride;696 pRest += stride;486 signDownLine[startX] = (Char)m_sign[srcLineBelow[startX] - srcLine[startX-1]]; 487 488 signTmpLine = signUpLine; 489 signUpLine = signDownLine; 490 signDownLine = signTmpLine; 491 492 srcLine += srcStride; 493 resLine += resStride; 697 494 } 698 495 699 496 //last line 700 if(pbBorderAvail[SGU_B]) 701 { 702 for(x= startX; x< width-1; x++) 703 { 704 edgeType = xSign(pDec[x] - pDec[x+ posShift]) + m_iUpBuff1[x] + 2; 705 pRest[x] = pClipTbl[pDec[x] + m_iOffsetEo[edgeType]]; 706 } 707 } 708 if(pbBorderAvail[SGU_BR]) 709 { 710 x= width -1; 711 edgeType = xSign(pDec[x] - pDec[x+ posShift]) + m_iUpBuff1[x] + 2; 712 pRest[x] = pClipTbl[pDec[x] + m_iOffsetEo[edgeType]]; 713 } 714 break; 715 } 716 case SAO_EO_3: // dir: 45 717 { 718 Int posShift = stride - 1; 719 startX = (pbBorderAvail[SGU_L]) ? 0 : 1; 720 endX = (pbBorderAvail[SGU_R]) ? width : (width -1); 497 srcLineBelow= srcLine+ srcStride; 498 lastLineStartX = isBelowAvail ? startX : (width -1); 499 lastLineEndX = isBelowRightAvail ? width : (width -1); 500 for(x= lastLineStartX; x< lastLineEndX; x++) 501 { 502 edgeType = m_sign[srcLine[x] - srcLineBelow[x+ 1]] + signUpLine[x]; 503 resLine[x] = offsetClip[srcLine[x] + offset[edgeType]]; 504 505 } 506 } 507 break; 508 case SAO_TYPE_EO_45: 509 { 510 offset += 2; 511 Char *signUpLine = m_signLineBuf1+1; 512 513 startX = isLeftAvail ? 0 : 1; 514 endX = isRightAvail ? width : (width -1); 721 515 722 516 //prepare 2nd line upper sign 723 pDec += stride;517 Pel* srcLineBelow= srcLine+ srcStride; 724 518 for (x=startX-1; x< endX; x++) 725 519 { 726 m_iUpBuff1[x] = xSign(pDec[x] - pDec[x- posShift]);520 signUpLine[x] = (Char)m_sign[srcLineBelow[x] - srcLine[x+1]]; 727 521 } 728 522 729 523 730 524 //first line 731 pDec -= stride; 732 if(pbBorderAvail[SGU_T]) 733 { 734 for(x= startX; x< width -1; x++) 735 { 736 edgeType = xSign(pDec[x] - pDec[x- posShift]) -m_iUpBuff1[x-1] + 2; 737 pRest[x] = pClipTbl[pDec[x] + m_iOffsetEo[edgeType]]; 738 } 739 } 740 if(pbBorderAvail[SGU_TR]) 741 { 742 x= width-1; 743 edgeType = xSign(pDec[x] - pDec[x- posShift]) -m_iUpBuff1[x-1] + 2; 744 pRest[x] = pClipTbl[pDec[x] + m_iOffsetEo[edgeType]]; 745 } 746 pDec += stride; 747 pRest += stride; 525 Pel* srcLineAbove= srcLine- srcStride; 526 firstLineStartX = isAboveAvail ? startX : (width -1 ); 527 firstLineEndX = isAboveRightAvail ? width : (width-1); 528 for(x= firstLineStartX; x< firstLineEndX; x++) 529 { 530 edgeType = m_sign[srcLine[x] - srcLineAbove[x+1]] -signUpLine[x-1]; 531 resLine[x] = offsetClip[srcLine[x] + offset[edgeType]]; 532 } 533 srcLine += srcStride; 534 resLine += resStride; 748 535 749 536 //middle lines 750 537 for (y= 1; y< height-1; y++) 751 538 { 539 srcLineBelow= srcLine+ srcStride; 540 752 541 for(x= startX; x< endX; x++) 753 542 { 754 signDown1 = xSign(pDec[x] - pDec[x+ posShift]) ; 755 edgeType = signDown1 + m_iUpBuff1[x] + 2; 756 757 pRest[x] = pClipTbl[pDec[x] + m_iOffsetEo[edgeType]]; 758 m_iUpBuff1[x-1] = -signDown1; 543 signDown = (Char)m_sign[srcLine[x] - srcLineBelow[x-1]] ; 544 edgeType = signDown + signUpLine[x]; 545 resLine[x] = offsetClip[srcLine[x] + offset[edgeType]]; 546 signUpLine[x-1] = -signDown; 759 547 } 760 m_iUpBuff1[endX-1] = xSign(pDec[endX-1 + stride] - pDec[endX]); 761 762 pDec += stride; 763 pRest += stride; 548 signUpLine[endX-1] = (Char)m_sign[srcLineBelow[endX-1] - srcLine[endX]]; 549 srcLine += srcStride; 550 resLine += resStride; 764 551 } 765 552 766 553 //last line 767 if(pbBorderAvail[SGU_BL]) 768 { 769 x= 0; 770 edgeType = xSign(pDec[x] - pDec[x+ posShift]) + m_iUpBuff1[x] + 2; 771 pRest[x] = pClipTbl[pDec[x] + m_iOffsetEo[edgeType]]; 772 773 } 774 if(pbBorderAvail[SGU_B]) 775 { 776 for(x= 1; x< endX; x++) 777 { 778 edgeType = xSign(pDec[x] - pDec[x+ posShift]) + m_iUpBuff1[x] + 2; 779 pRest[x] = pClipTbl[pDec[x] + m_iOffsetEo[edgeType]]; 780 } 781 } 782 break; 783 } 784 case SAO_BO: 785 { 554 srcLineBelow= srcLine+ srcStride; 555 lastLineStartX = isBelowLeftAvail ? 0 : 1; 556 lastLineEndX = isBelowAvail ? endX : 1; 557 for(x= lastLineStartX; x< lastLineEndX; x++) 558 { 559 edgeType = m_sign[srcLine[x] - srcLineBelow[x-1]] + signUpLine[x]; 560 resLine[x] = offsetClip[srcLine[x] + offset[edgeType]]; 561 562 } 563 } 564 break; 565 case SAO_TYPE_BO: 566 { 567 Int shiftBits = ((compIdx == SAO_Y)?g_bitDepthY:g_bitDepthC)- NUM_SAO_BO_CLASSES_LOG2; 786 568 for (y=0; y< height; y++) 787 569 { 788 570 for (x=0; x< width; x++) 789 571 { 790 pRest[x] = pOffsetBo[pDec[x]];572 resLine[x] = offsetClip[ srcLine[x] + offset[srcLine[x] >> shiftBits] ]; 791 573 } 792 pRest += stride; 793 pDec += stride; 794 } 795 break; 796 } 797 default: break; 798 } 799 800 } 801 802 /** sample adaptive offset process for one LCU crossing LCU boundary 803 * \param iAddr, iSaoType, iYCbCr 804 */ 805 Void TComSampleAdaptiveOffset::processSaoCuOrg(Int iAddr, Int iSaoType, Int iYCbCr) 806 { 807 Int x,y; 808 TComDataCU *pTmpCu = m_pcPic->getCU(iAddr); 809 Pel* pRec; 810 Int iStride; 811 Int iLcuWidth = m_uiMaxCUWidth; 812 Int iLcuHeight = m_uiMaxCUHeight; 813 UInt uiLPelX = pTmpCu->getCUPelX(); 814 UInt uiTPelY = pTmpCu->getCUPelY(); 815 UInt uiRPelX; 816 UInt uiBPelY; 817 Int iSignLeft; 818 Int iSignRight; 819 Int iSignDown; 820 Int iSignDown1; 821 Int iSignDown2; 822 UInt uiEdgeType; 823 Int iPicWidthTmp; 824 Int iPicHeightTmp; 825 Int iStartX; 826 Int iStartY; 827 Int iEndX; 828 Int iEndY; 829 Int iIsChroma = (iYCbCr!=0)? 1:0; 830 Int iShift; 831 Int iCuHeightTmp; 832 Pel *pTmpLSwap; 833 Pel *pTmpL; 834 Pel *pTmpU; 835 Pel *pClipTbl = NULL; 836 Int *pOffsetBo = NULL; 837 838 iPicWidthTmp = m_iPicWidth >> iIsChroma; 839 iPicHeightTmp = m_iPicHeight >> iIsChroma; 840 iLcuWidth = iLcuWidth >> iIsChroma; 841 iLcuHeight = iLcuHeight >> iIsChroma; 842 uiLPelX = uiLPelX >> iIsChroma; 843 uiTPelY = uiTPelY >> iIsChroma; 844 uiRPelX = uiLPelX + iLcuWidth ; 845 uiBPelY = uiTPelY + iLcuHeight ; 846 uiRPelX = uiRPelX > iPicWidthTmp ? iPicWidthTmp : uiRPelX; 847 uiBPelY = uiBPelY > iPicHeightTmp ? iPicHeightTmp : uiBPelY; 848 iLcuWidth = uiRPelX - uiLPelX; 849 iLcuHeight = uiBPelY - uiTPelY; 850 851 if(pTmpCu->getPic()==0) 852 { 853 return; 854 } 855 if (iYCbCr == 0) 856 { 857 pRec = m_pcPic->getPicYuvRec()->getLumaAddr(iAddr); 858 iStride = m_pcPic->getStride(); 859 } 860 else if (iYCbCr == 1) 861 { 862 pRec = m_pcPic->getPicYuvRec()->getCbAddr(iAddr); 863 iStride = m_pcPic->getCStride(); 864 } 865 else 866 { 867 pRec = m_pcPic->getPicYuvRec()->getCrAddr(iAddr); 868 iStride = m_pcPic->getCStride(); 869 } 870 871 // if (iSaoType!=SAO_BO_0 || iSaoType!=SAO_BO_1) 872 { 873 iCuHeightTmp = (m_uiMaxCUHeight >> iIsChroma); 874 iShift = (m_uiMaxCUWidth>> iIsChroma)-1; 875 for (Int i=0;i<iCuHeightTmp+1;i++) 876 { 877 m_pTmpL2[i] = pRec[iShift]; 878 pRec += iStride; 879 } 880 pRec -= (iStride*(iCuHeightTmp+1)); 881 882 pTmpL = m_pTmpL1; 883 pTmpU = &(m_pTmpU1[uiLPelX]); 884 } 885 886 pClipTbl = (iYCbCr==0)? m_pClipTable:m_pChromaClipTable; 887 pOffsetBo = (iYCbCr==0)? m_iOffsetBo:m_iChromaOffsetBo; 888 889 switch (iSaoType) 890 { 891 case SAO_EO_0: // dir: - 892 { 893 iStartX = (uiLPelX == 0) ? 1 : 0; 894 iEndX = (uiRPelX == iPicWidthTmp) ? iLcuWidth-1 : iLcuWidth; 895 for (y=0; y<iLcuHeight; y++) 896 { 897 iSignLeft = xSign(pRec[iStartX] - pTmpL[y]); 898 for (x=iStartX; x< iEndX; x++) 899 { 900 iSignRight = xSign(pRec[x] - pRec[x+1]); 901 uiEdgeType = iSignRight + iSignLeft + 2; 902 iSignLeft = -iSignRight; 903 904 pRec[x] = pClipTbl[pRec[x] + m_iOffsetEo[uiEdgeType]]; 905 } 906 pRec += iStride; 907 } 908 break; 909 } 910 case SAO_EO_1: // dir: | 911 { 912 iStartY = (uiTPelY == 0) ? 1 : 0; 913 iEndY = (uiBPelY == iPicHeightTmp) ? iLcuHeight-1 : iLcuHeight; 914 if (uiTPelY == 0) 915 { 916 pRec += iStride; 917 } 918 for (x=0; x< iLcuWidth; x++) 919 { 920 m_iUpBuff1[x] = xSign(pRec[x] - pTmpU[x]); 921 } 922 for (y=iStartY; y<iEndY; y++) 923 { 924 for (x=0; x<iLcuWidth; x++) 925 { 926 iSignDown = xSign(pRec[x] - pRec[x+iStride]); 927 uiEdgeType = iSignDown + m_iUpBuff1[x] + 2; 928 m_iUpBuff1[x]= -iSignDown; 929 930 pRec[x] = pClipTbl[pRec[x] + m_iOffsetEo[uiEdgeType]]; 931 } 932 pRec += iStride; 933 } 934 break; 935 } 936 case SAO_EO_2: // dir: 135 937 { 938 iStartX = (uiLPelX == 0) ? 1 : 0; 939 iEndX = (uiRPelX == iPicWidthTmp) ? iLcuWidth-1 : iLcuWidth; 940 941 iStartY = (uiTPelY == 0) ? 1 : 0; 942 iEndY = (uiBPelY == iPicHeightTmp) ? iLcuHeight-1 : iLcuHeight; 943 944 if (uiTPelY == 0) 945 { 946 pRec += iStride; 947 } 948 949 for (x=iStartX; x<iEndX; x++) 950 { 951 m_iUpBuff1[x] = xSign(pRec[x] - pTmpU[x-1]); 952 } 953 for (y=iStartY; y<iEndY; y++) 954 { 955 iSignDown2 = xSign(pRec[iStride+iStartX] - pTmpL[y]); 956 for (x=iStartX; x<iEndX; x++) 957 { 958 iSignDown1 = xSign(pRec[x] - pRec[x+iStride+1]) ; 959 uiEdgeType = iSignDown1 + m_iUpBuff1[x] + 2; 960 m_iUpBufft[x+1] = -iSignDown1; 961 pRec[x] = pClipTbl[pRec[x] + m_iOffsetEo[uiEdgeType]]; 962 } 963 m_iUpBufft[iStartX] = iSignDown2; 964 965 ipSwap = m_iUpBuff1; 966 m_iUpBuff1 = m_iUpBufft; 967 m_iUpBufft = ipSwap; 968 969 pRec += iStride; 970 } 971 break; 972 } 973 case SAO_EO_3: // dir: 45 974 { 975 iStartX = (uiLPelX == 0) ? 1 : 0; 976 iEndX = (uiRPelX == iPicWidthTmp) ? iLcuWidth-1 : iLcuWidth; 977 978 iStartY = (uiTPelY == 0) ? 1 : 0; 979 iEndY = (uiBPelY == iPicHeightTmp) ? iLcuHeight-1 : iLcuHeight; 980 981 if (iStartY == 1) 982 { 983 pRec += iStride; 984 } 985 986 for (x=iStartX-1; x<iEndX; x++) 987 { 988 m_iUpBuff1[x] = xSign(pRec[x] - pTmpU[x+1]); 989 } 990 for (y=iStartY; y<iEndY; y++) 991 { 992 x=iStartX; 993 iSignDown1 = xSign(pRec[x] - pTmpL[y+1]) ; 994 uiEdgeType = iSignDown1 + m_iUpBuff1[x] + 2; 995 m_iUpBuff1[x-1] = -iSignDown1; 996 pRec[x] = pClipTbl[pRec[x] + m_iOffsetEo[uiEdgeType]]; 997 for (x=iStartX+1; x<iEndX; x++) 998 { 999 iSignDown1 = xSign(pRec[x] - pRec[x+iStride-1]) ; 1000 uiEdgeType = iSignDown1 + m_iUpBuff1[x] + 2; 1001 m_iUpBuff1[x-1] = -iSignDown1; 1002 pRec[x] = pClipTbl[pRec[x] + m_iOffsetEo[uiEdgeType]]; 1003 } 1004 m_iUpBuff1[iEndX-1] = xSign(pRec[iEndX-1 + iStride] - pRec[iEndX]); 1005 1006 pRec += iStride; 1007 } 1008 break; 1009 } 1010 case SAO_BO: 1011 { 1012 for (y=0; y<iLcuHeight; y++) 1013 { 1014 for (x=0; x<iLcuWidth; x++) 1015 { 1016 pRec[x] = pOffsetBo[pRec[x]]; 1017 } 1018 pRec += iStride; 1019 } 1020 break; 1021 } 1022 default: break; 1023 } 1024 // if (iSaoType!=SAO_BO_0 || iSaoType!=SAO_BO_1) 1025 { 1026 pTmpLSwap = m_pTmpL1; 1027 m_pTmpL1 = m_pTmpL2; 1028 m_pTmpL2 = pTmpLSwap; 1029 } 1030 } 1031 /** Sample adaptive offset process 1032 * \param pcPic, pcSaoParam 1033 */ 1034 Void TComSampleAdaptiveOffset::SAOProcess(SAOParam* pcSaoParam) 1035 { 1036 { 1037 m_uiSaoBitIncreaseY = max(g_bitDepthY - 10, 0); 1038 m_uiSaoBitIncreaseC = max(g_bitDepthC - 10, 0); 1039 1040 if(m_bUseNIF) 1041 { 1042 m_pcPic->getPicYuvRec()->copyToPic(m_pcYuvTmp); 1043 } 1044 if (m_saoLcuBasedOptimization) 1045 { 1046 pcSaoParam->oneUnitFlag[0] = 0; 1047 pcSaoParam->oneUnitFlag[1] = 0; 1048 pcSaoParam->oneUnitFlag[2] = 0; 1049 } 1050 Int iY = 0; 1051 { 1052 processSaoUnitAll( pcSaoParam->saoLcuParam[iY], pcSaoParam->oneUnitFlag[iY], iY); 1053 } 1054 { 1055 processSaoUnitAll( pcSaoParam->saoLcuParam[1], pcSaoParam->oneUnitFlag[1], 1);//Cb 1056 processSaoUnitAll( pcSaoParam->saoLcuParam[2], pcSaoParam->oneUnitFlag[2], 2);//Cr 1057 } 1058 m_pcPic = NULL; 1059 } 1060 } 1061 1062 Pel* TComSampleAdaptiveOffset::getPicYuvAddr(TComPicYuv* pcPicYuv, Int iYCbCr, Int iAddr) 1063 { 1064 switch (iYCbCr) 1065 { 1066 case 0: 1067 return pcPicYuv->getLumaAddr(iAddr); 1068 break; 1069 case 1: 1070 return pcPicYuv->getCbAddr(iAddr); 1071 break; 1072 case 2: 1073 return pcPicYuv->getCrAddr(iAddr); 574 srcLine += srcStride; 575 resLine += resStride; 576 } 577 } 1074 578 break; 1075 579 default: 1076 return NULL; 580 { 581 printf("Not a supported SAO types\n"); 582 assert(0); 583 exit(-1); 584 } 585 } 586 587 588 } 589 590 Void TComSampleAdaptiveOffset::offsetCTU(Int ctu, TComPicYuv* srcYuv, TComPicYuv* resYuv, SAOBlkParam& saoblkParam, TComPic* pPic) 591 { 592 Bool isLeftAvail,isRightAvail,isAboveAvail,isBelowAvail,isAboveLeftAvail,isAboveRightAvail,isBelowLeftAvail,isBelowRightAvail; 593 594 if( 595 (saoblkParam[SAO_Y ].modeIdc == SAO_MODE_OFF) && 596 (saoblkParam[SAO_Cb].modeIdc == SAO_MODE_OFF) && 597 (saoblkParam[SAO_Cr].modeIdc == SAO_MODE_OFF) 598 ) 599 { 600 return; 601 } 602 603 //block boundary availability 604 pPic->getPicSym()->deriveLoopFilterBoundaryAvailibility(ctu, isLeftAvail,isRightAvail,isAboveAvail,isBelowAvail,isAboveLeftAvail,isAboveRightAvail,isBelowLeftAvail,isBelowRightAvail); 605 606 Int yPos = (ctu / m_numCTUInWidth)*m_maxCUHeight; 607 Int xPos = (ctu % m_numCTUInWidth)*m_maxCUWidth; 608 Int height = (yPos + m_maxCUHeight > m_picHeight)?(m_picHeight- yPos):m_maxCUHeight; 609 Int width = (xPos + m_maxCUWidth > m_picWidth )?(m_picWidth - xPos):m_maxCUWidth; 610 611 for(Int compIdx= 0; compIdx < NUM_SAO_COMPONENTS; compIdx++) 612 { 613 SAOOffset& ctbOffset = saoblkParam[compIdx]; 614 615 if(ctbOffset.modeIdc != SAO_MODE_OFF) 616 { 617 Bool isLuma = (compIdx == SAO_Y); 618 Int formatShift= isLuma?0:1; 619 620 Int blkWidth = (width >> formatShift); 621 Int blkHeight = (height >> formatShift); 622 Int blkYPos = (yPos >> formatShift); 623 Int blkXPos = (xPos >> formatShift); 624 625 Int srcStride = isLuma?srcYuv->getStride():srcYuv->getCStride(); 626 Pel* srcBlk = getPicBuf(srcYuv, compIdx)+ (yPos >> formatShift)*srcStride+ (xPos >> formatShift); 627 628 Int resStride = isLuma?resYuv->getStride():resYuv->getCStride(); 629 Pel* resBlk = getPicBuf(resYuv, compIdx)+ blkYPos*resStride+ blkXPos; 630 631 offsetBlock( compIdx, ctbOffset.typeIdc, ctbOffset.offset 632 , srcBlk, resBlk, srcStride, resStride, blkWidth, blkHeight 633 , isLeftAvail, isRightAvail 634 , isAboveAvail, isBelowAvail 635 , isAboveLeftAvail, isAboveRightAvail 636 , isBelowLeftAvail, isBelowRightAvail 637 ); 638 } 639 } //compIdx 640 641 } 642 643 644 Void TComSampleAdaptiveOffset::SAOProcess(TComPic* pDecPic) 645 { 646 if(!m_picSAOEnabled[SAO_Y] && !m_picSAOEnabled[SAO_Cb] && !m_picSAOEnabled[SAO_Cr]) 647 { 648 return; 649 } 650 TComPicYuv* resYuv = pDecPic->getPicYuvRec(); 651 TComPicYuv* srcYuv = m_tempPicYuv; 652 resYuv->copyToPic(srcYuv); 653 for(Int ctu= 0; ctu < m_numCTUsPic; ctu++) 654 { 655 offsetCTU(ctu, srcYuv, resYuv, (pDecPic->getPicSym()->getSAOBlkParam())[ctu], pDecPic); 656 } //ctu 657 } 658 659 660 Pel* TComSampleAdaptiveOffset::getPicBuf(TComPicYuv* pPicYuv, Int compIdx) 661 { 662 Pel* pBuf = NULL; 663 switch(compIdx) 664 { 665 case SAO_Y: 666 { 667 pBuf = pPicYuv->getLumaAddr(); 668 } 1077 669 break; 1078 } 1079 } 1080 /** Process SAO all units 1081 * \param saoLcuParam SAO LCU parameters 1082 * \param oneUnitFlag one unit flag 1083 * \param yCbCr color componet index 1084 */ 1085 Void TComSampleAdaptiveOffset::processSaoUnitAll(SaoLcuParam* saoLcuParam, Bool oneUnitFlag, Int yCbCr) 1086 { 1087 Pel *pRec; 1088 Int picWidthTmp; 1089 1090 if (yCbCr == 0) 1091 { 1092 pRec = m_pcPic->getPicYuvRec()->getLumaAddr(); 1093 picWidthTmp = m_iPicWidth; 1094 } 1095 else if (yCbCr == 1) 1096 { 1097 pRec = m_pcPic->getPicYuvRec()->getCbAddr(); 1098 picWidthTmp = m_iPicWidth>>1; 1099 } 1100 else 1101 { 1102 pRec = m_pcPic->getPicYuvRec()->getCrAddr(); 1103 picWidthTmp = m_iPicWidth>>1; 1104 } 1105 1106 memcpy(m_pTmpU1, pRec, sizeof(Pel)*picWidthTmp); 1107 1108 Int i; 1109 UInt edgeType; 1110 Pel* ppLumaTable = NULL; 1111 Pel* pClipTable = NULL; 1112 Int* pOffsetBo = NULL; 1113 Int typeIdx; 1114 1115 Int offset[LUMA_GROUP_NUM+1]; 1116 Int idxX; 1117 Int idxY; 1118 Int addr; 1119 Int frameWidthInCU = m_pcPic->getFrameWidthInCU(); 1120 Int frameHeightInCU = m_pcPic->getFrameHeightInCU(); 1121 Int stride; 1122 Pel *tmpUSwap; 1123 Int isChroma = (yCbCr == 0) ? 0:1; 1124 Bool mergeLeftFlag; 1125 Int saoBitIncrease = (yCbCr == 0) ? m_uiSaoBitIncreaseY : m_uiSaoBitIncreaseC; 1126 1127 pOffsetBo = (yCbCr==0) ? m_iOffsetBo : m_iChromaOffsetBo; 1128 1129 offset[0] = 0; 1130 for (idxY = 0; idxY< frameHeightInCU; idxY++) 1131 { 1132 addr = idxY * frameWidthInCU; 1133 if (yCbCr == 0) 1134 { 1135 pRec = m_pcPic->getPicYuvRec()->getLumaAddr(addr); 1136 stride = m_pcPic->getStride(); 1137 picWidthTmp = m_iPicWidth; 1138 } 1139 else if (yCbCr == 1) 1140 { 1141 pRec = m_pcPic->getPicYuvRec()->getCbAddr(addr); 1142 stride = m_pcPic->getCStride(); 1143 picWidthTmp = m_iPicWidth>>1; 1144 } 1145 else 1146 { 1147 pRec = m_pcPic->getPicYuvRec()->getCrAddr(addr); 1148 stride = m_pcPic->getCStride(); 1149 picWidthTmp = m_iPicWidth>>1; 1150 } 1151 1152 // pRec += iStride*(m_uiMaxCUHeight-1); 1153 for (i=0;i<(m_uiMaxCUHeight>>isChroma)+1;i++) 1154 { 1155 m_pTmpL1[i] = pRec[0]; 1156 pRec+=stride; 1157 } 1158 pRec-=(stride<<1); 1159 1160 memcpy(m_pTmpU2, pRec, sizeof(Pel)*picWidthTmp); 1161 1162 for (idxX = 0; idxX < frameWidthInCU; idxX++) 1163 { 1164 addr = idxY * frameWidthInCU + idxX; 1165 1166 if (oneUnitFlag) 1167 { 1168 typeIdx = saoLcuParam[0].typeIdx; 1169 mergeLeftFlag = (addr == 0)? 0:1; 1170 } 1171 else 1172 { 1173 typeIdx = saoLcuParam[addr].typeIdx; 1174 mergeLeftFlag = saoLcuParam[addr].mergeLeftFlag; 1175 } 1176 if (typeIdx>=0) 1177 { 1178 if (!mergeLeftFlag) 1179 { 1180 1181 if (typeIdx == SAO_BO) 1182 { 1183 for (i=0; i<SAO_MAX_BO_CLASSES+1;i++) 1184 { 1185 offset[i] = 0; 1186 } 1187 for (i=0; i<saoLcuParam[addr].length; i++) 1188 { 1189 offset[ (saoLcuParam[addr].subTypeIdx +i)%SAO_MAX_BO_CLASSES +1] = saoLcuParam[addr].offset[i] << saoBitIncrease; 1190 } 1191 1192 ppLumaTable = (yCbCr==0)?m_lumaTableBo:m_chromaTableBo; 1193 pClipTable = (yCbCr==0)?m_pClipTable:m_pChromaClipTable; 1194 1195 Int bitDepth = (yCbCr==0) ? g_bitDepthY : g_bitDepthC; 1196 for (i=0;i<(1<<bitDepth);i++) 1197 { 1198 pOffsetBo[i] = pClipTable[i + offset[ppLumaTable[i]]]; 1199 } 1200 1201 } 1202 if (typeIdx == SAO_EO_0 || typeIdx == SAO_EO_1 || typeIdx == SAO_EO_2 || typeIdx == SAO_EO_3) 1203 { 1204 for (i=0;i<saoLcuParam[addr].length;i++) 1205 { 1206 offset[i+1] = saoLcuParam[addr].offset[i] << saoBitIncrease; 1207 } 1208 for (edgeType=0;edgeType<6;edgeType++) 1209 { 1210 m_iOffsetEo[edgeType]= offset[m_auiEoTable[edgeType]]; 1211 } 1212 } 1213 } 1214 processSaoCu(addr, typeIdx, yCbCr); 1215 } 1216 else 1217 { 1218 if (idxX != (frameWidthInCU-1)) 1219 { 1220 if (yCbCr == 0) 1221 { 1222 pRec = m_pcPic->getPicYuvRec()->getLumaAddr(addr); 1223 stride = m_pcPic->getStride(); 1224 } 1225 else if (yCbCr == 1) 1226 { 1227 pRec = m_pcPic->getPicYuvRec()->getCbAddr(addr); 1228 stride = m_pcPic->getCStride(); 1229 } 1230 else 1231 { 1232 pRec = m_pcPic->getPicYuvRec()->getCrAddr(addr); 1233 stride = m_pcPic->getCStride(); 1234 } 1235 Int widthShift = m_uiMaxCUWidth>>isChroma; 1236 for (i=0;i<(m_uiMaxCUHeight>>isChroma)+1;i++) 1237 { 1238 m_pTmpL1[i] = pRec[widthShift-1]; 1239 pRec+=stride; 1240 } 1241 } 1242 } 1243 } 1244 tmpUSwap = m_pTmpU1; 1245 m_pTmpU1 = m_pTmpU2; 1246 m_pTmpU2 = tmpUSwap; 1247 } 1248 1249 } 1250 /** Reset SAO LCU part 1251 * \param saoLcuParam 1252 */ 1253 Void TComSampleAdaptiveOffset::resetLcuPart(SaoLcuParam* saoLcuParam) 1254 { 1255 Int i,j; 1256 for (i=0;i<m_iNumCuInWidth*m_iNumCuInHeight;i++) 1257 { 1258 saoLcuParam[i].mergeUpFlag = 1; 1259 saoLcuParam[i].mergeLeftFlag = 0; 1260 saoLcuParam[i].partIdx = 0; 1261 saoLcuParam[i].typeIdx = -1; 1262 for (j=0;j<MAX_NUM_SAO_OFFSETS;j++) 1263 { 1264 saoLcuParam[i].offset[j] = 0; 1265 } 1266 saoLcuParam[i].subTypeIdx = 0; 1267 } 1268 } 1269 1270 /** convert QP part to SAO unit 1271 * \param saoParam SAO parameter 1272 * \param partIdx SAO part index 1273 * \param yCbCr color component index 1274 */ 1275 Void TComSampleAdaptiveOffset::convertQT2SaoUnit(SAOParam *saoParam, UInt partIdx, Int yCbCr) 1276 { 1277 1278 SAOQTPart* saoPart= &(saoParam->psSaoPart[yCbCr][partIdx]); 1279 if (!saoPart->bSplit) 1280 { 1281 convertOnePart2SaoUnit(saoParam, partIdx, yCbCr); 1282 return; 1283 } 1284 1285 if (saoPart->PartLevel < m_uiMaxSplitLevel) 1286 { 1287 convertQT2SaoUnit(saoParam, saoPart->DownPartsIdx[0], yCbCr); 1288 convertQT2SaoUnit(saoParam, saoPart->DownPartsIdx[1], yCbCr); 1289 convertQT2SaoUnit(saoParam, saoPart->DownPartsIdx[2], yCbCr); 1290 convertQT2SaoUnit(saoParam, saoPart->DownPartsIdx[3], yCbCr); 1291 } 1292 } 1293 /** convert one SAO part to SAO unit 1294 * \param saoParam SAO parameter 1295 * \param partIdx SAO part index 1296 * \param yCbCr color component index 1297 */ 1298 Void TComSampleAdaptiveOffset::convertOnePart2SaoUnit(SAOParam *saoParam, UInt partIdx, Int yCbCr) 1299 { 1300 Int j; 1301 Int idxX; 1302 Int idxY; 1303 Int addr; 1304 Int frameWidthInCU = m_pcPic->getFrameWidthInCU(); 1305 SAOQTPart* saoQTPart = saoParam->psSaoPart[yCbCr]; 1306 SaoLcuParam* saoLcuParam = saoParam->saoLcuParam[yCbCr]; 1307 1308 for (idxY = saoQTPart[partIdx].StartCUY; idxY<= saoQTPart[partIdx].EndCUY; idxY++) 1309 { 1310 for (idxX = saoQTPart[partIdx].StartCUX; idxX<= saoQTPart[partIdx].EndCUX; idxX++) 1311 { 1312 addr = idxY * frameWidthInCU + idxX; 1313 saoLcuParam[addr].partIdxTmp = (Int)partIdx; 1314 saoLcuParam[addr].typeIdx = saoQTPart[partIdx].iBestType; 1315 saoLcuParam[addr].subTypeIdx = saoQTPart[partIdx].subTypeIdx; 1316 if (saoLcuParam[addr].typeIdx!=-1) 1317 { 1318 saoLcuParam[addr].length = saoQTPart[partIdx].iLength; 1319 for (j=0;j<MAX_NUM_SAO_OFFSETS;j++) 1320 { 1321 saoLcuParam[addr].offset[j] = saoQTPart[partIdx].iOffset[j]; 1322 } 1323 } 1324 else 1325 { 1326 saoLcuParam[addr].length = 0; 1327 saoLcuParam[addr].subTypeIdx = saoQTPart[partIdx].subTypeIdx; 1328 for (j=0;j<MAX_NUM_SAO_OFFSETS;j++) 1329 { 1330 saoLcuParam[addr].offset[j] = 0; 1331 } 1332 } 1333 } 1334 } 1335 } 1336 1337 Void TComSampleAdaptiveOffset::resetSaoUnit(SaoLcuParam* saoUnit) 1338 { 1339 saoUnit->partIdx = 0; 1340 saoUnit->partIdxTmp = 0; 1341 saoUnit->mergeLeftFlag = 0; 1342 saoUnit->mergeUpFlag = 0; 1343 saoUnit->typeIdx = -1; 1344 saoUnit->length = 0; 1345 saoUnit->subTypeIdx = 0; 1346 1347 for (Int i=0;i<4;i++) 1348 { 1349 saoUnit->offset[i] = 0; 1350 } 1351 } 1352 1353 Void TComSampleAdaptiveOffset::copySaoUnit(SaoLcuParam* saoUnitDst, SaoLcuParam* saoUnitSrc ) 1354 { 1355 saoUnitDst->mergeLeftFlag = saoUnitSrc->mergeLeftFlag; 1356 saoUnitDst->mergeUpFlag = saoUnitSrc->mergeUpFlag; 1357 saoUnitDst->typeIdx = saoUnitSrc->typeIdx; 1358 saoUnitDst->length = saoUnitSrc->length; 1359 1360 saoUnitDst->subTypeIdx = saoUnitSrc->subTypeIdx; 1361 for (Int i=0;i<4;i++) 1362 { 1363 saoUnitDst->offset[i] = saoUnitSrc->offset[i]; 1364 } 1365 } 1366 1367 /** PCM LF disable process. 670 case SAO_Cb: 671 { 672 pBuf = pPicYuv->getCbAddr(); 673 } 674 break; 675 case SAO_Cr: 676 { 677 pBuf = pPicYuv->getCrAddr(); 678 } 679 break; 680 default: 681 { 682 printf("Not a legal component ID for SAO\n"); 683 assert(0); 684 exit(-1); 685 } 686 } 687 688 return pBuf; 689 } 690 691 /** PCM LF disable process. 1368 692 * \param pcPic picture (TComPic) pointer 1369 693 * \returns Void -
branches/HTM-10.0-dev0/source/Lib/TLibCommon/TComSampleAdaptiveOffset.h
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-201 3, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 49 49 // ==================================================================================================================== 50 50 51 #define SAO_MAX_DEPTH 4 52 #define SAO_BO_BITS 5 53 #define LUMA_GROUP_NUM (1<<SAO_BO_BITS) 54 #define MAX_NUM_SAO_OFFSETS 4 55 #define MAX_NUM_SAO_CLASS 33 51 #define MAX_SAO_TRUNCATED_BITDEPTH 10 56 52 // ==================================================================================================================== 57 53 // Class definition 58 54 // ==================================================================================================================== 55 extern UInt g_saoMaxOffsetQVal[NUM_SAO_COMPONENTS]; 59 56 60 /// Sample Adaptive Offset class61 57 class TComSampleAdaptiveOffset 62 58 { 59 public: 60 TComSampleAdaptiveOffset(); 61 virtual ~TComSampleAdaptiveOffset(); 62 Void SAOProcess(TComPic* pDecPic); 63 Void create( Int picWidth, Int picHeight, UInt maxCUWidth, UInt maxCUHeight, UInt maxCUDepth ); 64 Void destroy(); 65 Void reconstructBlkSAOParams(TComPic* pic, SAOBlkParam* saoBlkParams); 66 Void PCMLFDisableProcess (TComPic* pcPic); 63 67 protected: 64 TComPic* m_pcPic; 68 Void offsetBlock(Int compIdx, Int typeIdx, Int* offset, Pel* srcBlk, Pel* resBlk, Int srcStride, Int resStride, Int width, Int height 69 , Bool isLeftAvail, Bool isRightAvail, Bool isAboveAvail, Bool isBelowAvail, Bool isAboveLeftAvail, Bool isAboveRightAvail, Bool isBelowLeftAvail, Bool isBelowRightAvail); 70 Pel* getPicBuf(TComPicYuv* pPicYuv, Int compIdx); 71 Void invertQuantOffsets(Int compIdx, Int typeIdc, Int typeAuxInfo, Int* dstOffsets, Int* srcOffsets); 72 Void reconstructBlkSAOParam(SAOBlkParam& recParam, std::vector<SAOBlkParam*>& mergeList); 73 Int getMergeList(TComPic* pic, Int ctu, SAOBlkParam* blkParams, std::vector<SAOBlkParam*>& mergeList); 74 Void offsetCTU(Int ctu, TComPicYuv* srcYuv, TComPicYuv* resYuv, SAOBlkParam& saoblkParam, TComPic* pPic); 75 Void xPCMRestoration(TComPic* pcPic); 76 Void xPCMCURestoration ( TComDataCU* pcCU, UInt uiAbsZorderIdx, UInt uiDepth ); 77 Void xPCMSampleRestoration (TComDataCU* pcCU, UInt uiAbsZorderIdx, UInt uiDepth, TextType ttText); 78 protected: 79 UInt m_offsetStepLog2[NUM_SAO_COMPONENTS]; //offset step 80 Int* m_offsetClip[NUM_SAO_COMPONENTS]; //clip table for fast operation 81 Short* m_sign; //sign table for fast operation 82 TComPicYuv* m_tempPicYuv; //temporary buffer 83 Int m_picWidth; 84 Int m_picHeight; 85 Int m_maxCUWidth; 86 Int m_maxCUHeight; 87 Int m_numCTUInWidth; 88 Int m_numCTUInHeight; 89 Int m_numCTUsPic; 90 91 92 Int m_lineBufWidth; 93 Char* m_signLineBuf1; 94 Char* m_signLineBuf2; 95 private: 96 Bool m_picSAOEnabled[NUM_SAO_COMPONENTS]; 97 Int* m_offsetClipTable[NUM_SAO_COMPONENTS]; 98 Short* m_signTable; 65 99 66 static const UInt m_uiMaxDepth;67 static const Int m_aiNumCulPartsLevel[5];68 static const UInt m_auiEoTable[9];69 Int *m_iOffsetBo;70 Int *m_iChromaOffsetBo;71 Int m_iOffsetEo[LUMA_GROUP_NUM];72 73 Int m_iPicWidth;74 Int m_iPicHeight;75 UInt m_uiMaxSplitLevel;76 UInt m_uiMaxCUWidth;77 UInt m_uiMaxCUHeight;78 Int m_iNumCuInWidth;79 Int m_iNumCuInHeight;80 Int m_iNumTotalParts;81 static const Int m_iNumClass[MAX_NUM_SAO_TYPE];82 83 UInt m_uiSaoBitIncreaseY;84 UInt m_uiSaoBitIncreaseC; //for chroma85 UInt m_uiQP;86 87 Pel *m_pClipTable;88 Pel *m_pClipTableBase;89 Pel *m_lumaTableBo;90 Pel *m_pChromaClipTable;91 Pel *m_pChromaClipTableBase;92 Pel *m_chromaTableBo;93 Int *m_iUpBuff1;94 Int *m_iUpBuff2;95 Int *m_iUpBufft;96 Int *ipSwap;97 Bool m_bUseNIF; //!< true for performing non-cross slice boundary ALF98 TComPicYuv* m_pcYuvTmp; //!< temporary picture buffer pointer when non-across slice/tile boundary SAO is enabled99 100 Pel* m_pTmpU1;101 Pel* m_pTmpU2;102 Pel* m_pTmpL1;103 Pel* m_pTmpL2;104 Int m_maxNumOffsetsPerPic;105 Bool m_saoLcuBoundary;106 Bool m_saoLcuBasedOptimization;107 108 Void xPCMRestoration (TComPic* pcPic);109 Void xPCMCURestoration (TComDataCU* pcCU, UInt uiAbsZorderIdx, UInt uiDepth);110 Void xPCMSampleRestoration (TComDataCU* pcCU, UInt uiAbsZorderIdx, UInt uiDepth, TextType ttText);111 public:112 TComSampleAdaptiveOffset ();113 virtual ~TComSampleAdaptiveOffset();114 115 Void create( UInt uiSourceWidth, UInt uiSourceHeight, UInt uiMaxCUWidth, UInt uiMaxCUHeight );116 Void destroy ();117 118 Int convertLevelRowCol2Idx(Int level, Int row, Int col);119 120 Void initSAOParam (SAOParam *pcSaoParam, Int iPartLevel, Int iPartRow, Int iPartCol, Int iParentPartIdx, Int StartCUX, Int EndCUX, Int StartCUY, Int EndCUY, Int iYCbCr);121 Void allocSaoParam (SAOParam* pcSaoParam);122 Void resetSAOParam (SAOParam *pcSaoParam);123 static Void freeSaoParam (SAOParam *pcSaoParam);124 125 Void SAOProcess(SAOParam* pcSaoParam);126 Void processSaoCu(Int iAddr, Int iSaoType, Int iYCbCr);127 Pel* getPicYuvAddr(TComPicYuv* pcPicYuv, Int iYCbCr,Int iAddr = 0);128 129 Void processSaoCuOrg(Int iAddr, Int iPartIdx, Int iYCbCr); //!< LCU-basd SAO process without slice granularity130 Void createPicSaoInfo(TComPic* pcPic);131 Void destroyPicSaoInfo();132 Void processSaoBlock(Pel* pDec, Pel* pRest, Int stride, Int iSaoType, UInt width, UInt height, Bool* pbBorderAvail, Int iYCbCr);133 134 Void resetLcuPart(SaoLcuParam* saoLcuParam);135 Void convertQT2SaoUnit(SAOParam* saoParam, UInt partIdx, Int yCbCr);136 Void convertOnePart2SaoUnit(SAOParam *saoParam, UInt partIdx, Int yCbCr);137 Void processSaoUnitAll(SaoLcuParam* saoLcuParam, Bool oneUnitFlag, Int yCbCr);138 Void setSaoLcuBoundary (Bool bVal) {m_saoLcuBoundary = bVal;}139 Bool getSaoLcuBoundary () {return m_saoLcuBoundary;}140 Void setSaoLcuBasedOptimization (Bool bVal) {m_saoLcuBasedOptimization = bVal;}141 Bool getSaoLcuBasedOptimization () {return m_saoLcuBasedOptimization;}142 Void resetSaoUnit(SaoLcuParam* saoUnit);143 Void copySaoUnit(SaoLcuParam* saoUnitDst, SaoLcuParam* saoUnitSrc );144 Void PCMLFDisableProcess ( TComPic* pcPic); ///< interface function for ALF process145 100 }; 146 101 -
branches/HTM-10.0-dev0/source/Lib/TLibCommon/TComSlice.cpp
r833 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 71 71 , m_colFromL0Flag ( 1 ) 72 72 , m_colRefIdx ( 0 ) 73 #if SAO_CHROMA_LAMBDA74 , m_dLambdaLuma( 0.0 )75 , m_dLambdaChroma( 0.0 )76 #else77 , m_dLambda ( 0.0 )78 #endif79 73 , m_uiTLayer ( 0 ) 80 74 , m_bTLayerSwitchingFlag ( false ) … … 130 124 initEqualRef(); 131 125 126 for (Int component = 0; component < 3; component++) 127 { 128 m_lambdas[component] = 0.0; 129 } 130 132 131 for ( Int idx = 0; idx < MAX_NUM_REF; idx++ ) 133 132 { … … 148 147 initWpAcDcParam(); 149 148 m_saoEnabledFlag = false; 149 m_saoEnabledFlagChroma = false; 150 150 #if H_MV 151 151 for (Int i = 0; i < MAX_NUM_LAYERS; i++ ) … … 370 370 } 371 371 } 372 372 373 #if !H_MV 373 #if FIX1071374 374 Void TComSlice::setRefPicList( TComList<TComPic*>& rcListPic, Bool checkNumPocTotalCurr ) 375 #else 376 Void TComSlice::setRefPicList( TComList<TComPic*>& rcListPic ) 377 #endif 378 { 379 #if FIX1071 375 { 380 376 if (!checkNumPocTotalCurr) 381 #endif382 377 { 383 378 if (m_eSliceType == I_SLICE) … … 449 444 TComPic* rpsCurrList1[MAX_NUM_REF+1]; 450 445 Int numPocTotalCurr = NumPocStCurr0 + NumPocStCurr1 + NumPocLtCurr; 451 452 #if FIX1071453 446 if (checkNumPocTotalCurr) 454 447 { … … 474 467 m_aiNumRefIdx[1] = getNumRefIdx(REF_PIC_LIST_1); 475 468 } 476 #endif477 469 478 470 Int cIdx = 0; … … 873 865 { 874 866 TComPic* rpcPic; 867 #if !FIX1172 875 868 setAssociatedIRAPPOC(pocCRA); 869 #endif 876 870 Int pocCurr = getPOC(); 877 871 … … 993 987 m_colFromL0Flag = pSrc->m_colFromL0Flag; 994 988 m_colRefIdx = pSrc->m_colRefIdx; 995 #if SAO_CHROMA_LAMBDA 996 m_dLambdaLuma = pSrc->m_dLambdaLuma; 997 m_dLambdaChroma = pSrc->m_dLambdaChroma; 998 #else 999 m_dLambda = pSrc->m_dLambda; 1000 #endif 989 setLambdas(pSrc->getLambdas()); 1001 990 for (i = 0; i < 2; i++) 1002 991 { … … 1177 1166 { 1178 1167 rpcPic = *(iterPic++); 1168 #if BUGFIX_INTRAPERIOD 1169 if(!rpcPic->getReconMark()) 1170 { 1171 continue; 1172 } 1173 #endif 1179 1174 if (rpcPic->getPOC() == this->getPOC()) 1180 1175 { … … 1342 1337 assert(rpcPic->getSlice( 0 )->isReferenced()==0||rpcPic->getUsedByCurr()==0||rpcPic->getTLayer()<=this->getTLayer()); 1343 1338 //check that pictures of higher or equal temporal layer are not in the RPS if the current picture is a TSA picture 1344 if(this->getNalUnitType() == NAL_UNIT_CODED_SLICE_T LA_R || this->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N)1339 if(this->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_R || this->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N) 1345 1340 { 1346 1341 assert(rpcPic->getSlice( 0 )->isReferenced()==0||rpcPic->getTLayer()<this->getTLayer()); … … 1501 1496 /** Function for constructing an explicit Reference Picture Set out of the available pictures in a referenced Reference Picture Set 1502 1497 */ 1503 #if FIX10711504 1498 Void TComSlice::createExplicitReferencePictureSetFromReference( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool isRAP) 1505 #else1506 Void TComSlice::createExplicitReferencePictureSetFromReference( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet)1507 #endif1508 1499 { 1509 1500 TComPic* rpcPic; … … 1530 1521 // and should be added to the explicit Reference Picture Set 1531 1522 pcRPS->setDeltaPOC(k, pReferencePictureSet->getDeltaPOC(i)); 1532 #if FIX10711533 1523 pcRPS->setUsed(k, pReferencePictureSet->getUsed(i) && (!isRAP)); 1534 #else1535 pcRPS->setUsed(k, pReferencePictureSet->getUsed(i));1536 #endif1537 1524 if(pcRPS->getDeltaPOC(k) < 0) 1538 1525 { … … 1955 1942 for ( i = 0; i < iNumViews ; i++ ) 1956 1943 { 1944 m_bCamParInSliceHeader[i] = false; 1957 1945 m_aaaiCodedScale[i] = new Int*[ 2 ]; 1958 1946 m_aaaiCodedOffset[i] = new Int*[ 2 ]; … … 2181 2169 , m_qpBDOffsetY ( 0) 2182 2170 , m_qpBDOffsetC ( 0) 2183 , m_useLossless (false)2184 2171 , m_uiPCMBitDepthLuma ( 8) 2185 2172 , m_uiPCMBitDepthChroma ( 8) … … 2861 2848 for(UInt listId=0;listId<g_scalingListNum[sizeId];listId++) 2862 2849 { 2863 getScalingList()->processDefaultMa rix(sizeId, listId);2850 getScalingList()->processDefaultMatrix(sizeId, listId); 2864 2851 } 2865 2852 } … … 3584 3571 * \param Index of input matrix 3585 3572 */ 3586 Void TComScalingList::processDefaultMa rix(UInt sizeId, UInt listId)3573 Void TComScalingList::processDefaultMatrix(UInt sizeId, UInt listId) 3587 3574 { 3588 3575 ::memcpy(getScalingListAddress(sizeId, listId),getScalingListDefaultAddress(sizeId,listId),sizeof(Int)*min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId])); … … 3601 3588 if(getScalingListDC(sizeId,listId) == 0) 3602 3589 { 3603 processDefaultMa rix(sizeId, listId);3590 processDefaultMatrix(sizeId, listId); 3604 3591 } 3605 3592 } -
branches/HTM-10.0-dev0/source/Lib/TLibCommon/TComSlice.h
r833 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 161 161 UInt getRefMatrixId (UInt sizeId, UInt listId) { return m_refMatrixId[sizeId][listId]; } //!< get reference matrix ID 162 162 Int* getScalingListDefaultAddress (UInt sizeId, UInt listId); //!< get default matrix coefficient 163 Void processDefaultMa rix (UInt sizeId, UInt listId);163 Void processDefaultMatrix (UInt sizeId, UInt listId); 164 164 Void setScalingListDC (UInt sizeId, UInt listId, UInt u) { m_scalingListDC[sizeId][listId] = u; } //!< set DC value 165 165 … … 851 851 UInt getNumReorderPics(UInt tLayer) { return m_numReorderPics[tLayer]; } 852 852 853 Void setMaxDecPicBuffering(UInt v, UInt tLayer) { m_uiMaxDecPicBuffering[tLayer] = v; }853 Void setMaxDecPicBuffering(UInt v, UInt tLayer) { assert(tLayer < MAX_TLAYER); m_uiMaxDecPicBuffering[tLayer] = v; } 854 854 UInt getMaxDecPicBuffering(UInt tLayer) { return m_uiMaxDecPicBuffering[tLayer]; } 855 855 … … 1419 1419 Int m_qpBDOffsetY; 1420 1420 Int m_qpBDOffsetC; 1421 1422 Bool m_useLossless;1423 1421 1424 1422 UInt m_uiPCMBitDepthLuma; … … 1553 1551 UInt getMaxTrSize () { return m_uiMaxTrSize; } 1554 1552 1555 // Tool list1556 Bool getUseLossless () { return m_useLossless; }1557 Void setUseLossless ( Bool b ) { m_useLossless = b; }1558 1559 1553 // AMP accuracy 1560 1554 Int getAMPAcc ( UInt uiDepth ) { return m_iAMPAcc[uiDepth]; } … … 1592 1586 TComScalingList* getScalingList () { return m_scalingList; } //!< get ScalingList class pointer in SPS 1593 1587 UInt getMaxDecPicBuffering (UInt tlayer) { return m_uiMaxDecPicBuffering[tlayer]; } 1594 Void setMaxDecPicBuffering ( UInt ui, UInt tlayer ) { m_uiMaxDecPicBuffering[tlayer] = ui; }1588 Void setMaxDecPicBuffering ( UInt ui, UInt tlayer ) { assert(tlayer < MAX_TLAYER); m_uiMaxDecPicBuffering[tlayer] = ui; } 1595 1589 UInt getMaxLatencyIncrease (UInt tlayer) { return m_uiMaxLatencyIncrease[tlayer]; } 1596 1590 Void setMaxLatencyIncrease ( UInt ui , UInt tlayer) { m_uiMaxLatencyIncrease[tlayer] = ui; } … … 1988 1982 UInt m_maxNumMergeCand; 1989 1983 1990 1991 #if SAO_CHROMA_LAMBDA 1992 Double m_dLambdaLuma; 1993 Double m_dLambdaChroma; 1994 #else 1995 Double m_dLambda; 1996 #endif 1984 Double m_lambdas[3]; 1997 1985 1998 1986 Bool m_abEqualRef [2][MAX_NUM_REF][MAX_NUM_REF]; … … 2205 2193 Void setRefPicList ( std::vector<TComPic*> rpsCurrList[2], std::vector<Bool> usedAsLongTerm[2], Int numPocTotalCurr, Bool checkNumPocTotalCurr = false ); 2206 2194 #else 2207 #if FIX10712208 2195 Void setRefPicList ( TComList<TComPic*>& rcListPic, Bool checkNumPocTotalCurr = false ); 2209 #else2210 Void setRefPicList ( TComList<TComPic*>& rcListPic );2211 #endif2212 2196 #endif 2213 2197 Void setRefPOCList (); … … 2221 2205 Bool isInterP () { return m_eSliceType == P_SLICE; } 2222 2206 2223 #if SAO_CHROMA_LAMBDA 2224 Void setLambda( Double d, Double e ) { m_dLambdaLuma = d; m_dLambdaChroma = e;} 2225 Double getLambdaLuma() { return m_dLambdaLuma; } 2226 Double getLambdaChroma() { return m_dLambdaChroma; } 2227 #else 2228 Void setLambda( Double d ) { m_dLambda = d; } 2229 Double getLambda() { return m_dLambda; } 2230 #endif 2207 Void setLambdas ( const Double lambdas[3] ) { for (Int component = 0; component < 3; component++) m_lambdas[component] = lambdas[component]; } 2208 const Double* getLambdas() const { return m_lambdas; } 2231 2209 2232 2210 Void initEqualRef(); … … 2262 2240 Bool isStepwiseTemporalLayerSwitchingPointCandidate( TComList<TComPic*>& rcListPic ); 2263 2241 Int checkThatAllRefPicsAreAvailable( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool printErrors, Int pocRandomAccess = 0); 2264 #if FIX10712265 2242 Void createExplicitReferencePictureSetFromReference( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool isRAP); 2266 #else2267 Void createExplicitReferencePictureSetFromReference( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet);2268 #endif2269 2243 2270 2244 Void setMaxNumMergeCand (UInt val ) { m_maxNumMergeCand = val; } -
branches/HTM-10.0-dev0/source/Lib/TLibCommon/TComTrQuant.cpp
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 1068 1068 UInt uiLog2TrSize = g_aucConvertToBit[ iWidth ] + 2; 1069 1069 Int scalingListType = (pcCU->isIntra(uiAbsPartIdx) ? 0 : 3) + g_eTTable[(Int)eTType]; 1070 assert(scalingListType < 6);1070 assert(scalingListType < SCALING_LIST_NUM); 1071 1071 Int *piQuantCoeff = 0; 1072 1072 piQuantCoeff = getQuantCoeff(scalingListType,m_cQP.m_iRem,uiLog2TrSize-2); … … 1307 1307 Pel* pResi = rpcResidual + uiAddr; 1308 1308 Int scalingListType = (pcCU->isIntra(uiAbsPartIdx) ? 0 : 3) + g_eTTable[(Int)eTxt]; 1309 assert(scalingListType < 6);1309 assert(scalingListType < SCALING_LIST_NUM); 1310 1310 invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), eTxt, REG_DCT, pResi, uiStride, rpcCoeff, uiWidth, uiHeight, scalingListType, pcCU->getTransformSkip(uiAbsPartIdx, eTxt) ); 1311 1311 } … … 1508 1508 const UInt uiMaxNumCoeff = uiWidth * uiHeight; 1509 1509 Int scalingListType = (pcCU->isIntra(uiAbsPartIdx) ? 0 : 3) + g_eTTable[(Int)eTType]; 1510 assert(scalingListType < 6);1510 assert(scalingListType < SCALING_LIST_NUM); 1511 1511 1512 1512 Int iQBits = QUANT_SHIFT + m_cQP.m_iPer + iTransformShift; // Right shift of non-RDOQ quantizer; level = (coeff*uiQ + offset)>>q_bits … … 1927 1927 Int64 costUp = rdFactor * ( - deltaU[uiBlkPos] ) + rateIncUp[uiBlkPos] ; 1928 1928 Int64 costDown = rdFactor * ( deltaU[uiBlkPos] ) + rateIncDown[uiBlkPos] 1929 - ( abs(piDstCoeff[uiBlkPos])==1?((1<<15)+sigRateDelta[uiBlkPos]):0);1929 - ((abs(piDstCoeff[uiBlkPos]) == 1) ? sigRateDelta[uiBlkPos] : 0); 1930 1930 1931 1931 if(lastCG==1 && lastNZPosInCG==n && abs(piDstCoeff[uiBlkPos])==1) … … 2146 2146 { 2147 2147 Double dErr = Double( lLevelDouble - ( uiAbsLevel << iQBits ) ); 2148 Double dCurrCost = dErr * dErr * dTemp + xGetIC RateCost( uiAbsLevel, ui16CtxNumOne, ui16CtxNumAbs, ui16AbsGoRice, c1Idx, c2Idx);2148 Double dCurrCost = dErr * dErr * dTemp + xGetICost(xGetICRate( uiAbsLevel, ui16CtxNumOne, ui16CtxNumAbs, ui16AbsGoRice, c1Idx, c2Idx )); 2149 2149 dCurrCost += dCurrCostSig; 2150 2150 … … 2167 2167 * \returns cost of given absolute transform level 2168 2168 */ 2169 __inline Double TComTrQuant::xGetICRateCost( UInt uiAbsLevel,2169 __inline Int TComTrQuant::xGetICRate ( UInt uiAbsLevel, 2170 2170 UShort ui16CtxNumOne, 2171 2171 UShort ui16CtxNumAbs, … … 2175 2175 ) const 2176 2176 { 2177 Double iRate = xGetIEPRate();2177 Int iRate = Int(xGetIEPRate()); 2178 2178 UInt baseLevel = (c1Idx < C1FLAG_NUMBER)? (2 + (c2Idx < C2FLAG_NUMBER)) : 1; 2179 2179 … … 2219 2219 else 2220 2220 { 2221 assert (0); 2222 } 2223 return xGetICost( iRate ); 2224 } 2225 2226 __inline Int TComTrQuant::xGetICRate ( UInt uiAbsLevel, 2227 UShort ui16CtxNumOne, 2228 UShort ui16CtxNumAbs, 2229 UShort ui16AbsGoRice 2230 , UInt c1Idx, 2231 UInt c2Idx 2232 ) const 2233 { 2234 Int iRate = 0; 2235 UInt baseLevel = (c1Idx < C1FLAG_NUMBER)? (2 + (c2Idx < C2FLAG_NUMBER)) : 1; 2236 2237 if ( uiAbsLevel >= baseLevel ) 2238 { 2239 UInt uiSymbol = uiAbsLevel - baseLevel; 2240 UInt uiMaxVlc = g_auiGoRiceRange[ ui16AbsGoRice ]; 2241 Bool bExpGolomb = ( uiSymbol > uiMaxVlc ); 2242 2243 if( bExpGolomb ) 2244 { 2245 uiAbsLevel = uiSymbol - uiMaxVlc; 2246 Int iEGS = 1; for( UInt uiMax = 2; uiAbsLevel >= uiMax; uiMax <<= 1, iEGS += 2 ); 2247 iRate += iEGS << 15; 2248 uiSymbol = min<UInt>( uiSymbol, ( uiMaxVlc + 1 ) ); 2249 } 2250 2251 UShort ui16PrefLen = UShort( uiSymbol >> ui16AbsGoRice ) + 1; 2252 UShort ui16NumBins = min<UInt>( ui16PrefLen, g_auiGoRicePrefixLen[ ui16AbsGoRice ] ) + ui16AbsGoRice; 2253 2254 iRate += ui16NumBins << 15; 2255 2256 if (c1Idx < C1FLAG_NUMBER) 2257 { 2258 iRate += m_pcEstBitsSbac->m_greaterOneBits[ ui16CtxNumOne ][ 1 ]; 2259 2260 if (c2Idx < C2FLAG_NUMBER) 2261 { 2262 iRate += m_pcEstBitsSbac->m_levelAbsBits[ ui16CtxNumAbs ][ 1 ]; 2263 } 2264 } 2265 } 2266 else 2267 if( uiAbsLevel == 0 ) 2268 { 2269 return 0; 2270 } 2271 else if( uiAbsLevel == 1 ) 2272 { 2273 iRate += m_pcEstBitsSbac->m_greaterOneBits[ ui16CtxNumOne ][ 0 ]; 2274 } 2275 else if( uiAbsLevel == 2 ) 2276 { 2277 iRate += m_pcEstBitsSbac->m_greaterOneBits[ ui16CtxNumOne ][ 1 ]; 2278 iRate += m_pcEstBitsSbac->m_levelAbsBits[ ui16CtxNumAbs ][ 0 ]; 2279 } 2280 else 2281 { 2282 assert(0); 2221 iRate = 0; 2283 2222 } 2284 2223 return iRate; -
branches/HTM-10.0-dev0/source/Lib/TLibCommon/TComTrQuant.h
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 150 150 151 151 #if RDOQ_CHROMA_LAMBDA 152 Void setLambda (Double dLambdaLuma, Double dLambdaChroma) { m_dLambdaLuma = dLambdaLuma; m_dLambdaChroma = dLambdaChroma; }153 Void selectLambda(TextType eTType) { m_dLambda = (eTType == TEXT_LUMA) ? m_ dLambdaLuma : m_dLambdaChroma; }152 Void setLambdas ( const Double lambdas[3] ) { for (Int component = 0; component < 3; component++) m_lambdas[component] = lambdas[component]; } 153 Void selectLambda(TextType eTType) { m_dLambda = (eTType == TEXT_LUMA) ? m_lambdas[0] : ((eTType == TEXT_CHROMA_U) ? m_lambdas[1] : m_lambdas[2]); } 154 154 #else 155 155 Void setLambda(Double dLambda) { m_dLambda = dLambda;} … … 207 207 QpParam m_cQP; 208 208 #if RDOQ_CHROMA_LAMBDA 209 Double m_dLambdaLuma; 210 Double m_dLambdaChroma; 209 Double m_lambdas[3]; 211 210 #endif 212 211 Double m_dLambda; … … 273 272 Double dTemp, 274 273 Bool bLast ) const; 275 __inline Double xGetICRateCost ( UInt uiAbsLevel,276 UShort ui16CtxNumOne,277 UShort ui16CtxNumAbs,278 UShort ui16AbsGoRice279 , UInt c1Idx,280 UInt c2Idx281 ) const;282 274 __inline Int xGetICRate ( UInt uiAbsLevel, 283 275 UShort ui16CtxNumOne, -
branches/HTM-10.0-dev0/source/Lib/TLibCommon/TComWeightPrediction.cpp
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/TLibCommon/TComWeightPrediction.h
r655 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/TLibCommon/TComYuv.cpp
r622 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 110 110 { 111 111 ::memcpy( pDst, pSrc, sizeof(Pel)*iWidth); 112 113 112 #if ENC_DEC_TRACE && H_MV_ENC_DEC_TRAC 114 113 if ( g_traceCopyBack && g_nSymbolCounter >= g_stopAtCounter ) … … 121 120 } 122 121 #endif 123 124 122 pDst += iDstStride; 125 123 pSrc += iSrcStride; … … 616 614 { 617 615 #if DISABLING_CLIP_FOR_BIPREDME 618 pDst[x ] = (pDst[x ]<<1) - pSrc[x ];616 pDst[x ] = 2 * pDst[x] - pSrc[x]; 619 617 #else 620 pDst[x ] = Clip ( (pDst[x ]<<1) - pSrc[x ]);618 pDst[x ] = ClipY(2 * pDst[x] - pSrc[x]); 621 619 #endif 622 620 } … … 636 634 { 637 635 #if DISABLING_CLIP_FOR_BIPREDME 638 pDstU[x ] = (pDstU[x ]<<1) - pSrcU[x ];639 pDstV[x ] = (pDstV[x ]<<1) - pSrcV[x ];636 pDstU[x ] = 2 * pDstU[x] - pSrcU[x]; 637 pDstV[x ] = 2 * pDstV[x] - pSrcV[x]; 640 638 #else 641 pDstU[x ] = Clip ( (pDstU[x ]<<1) - pSrcU[x ]);642 pDstV[x ] = Clip ( (pDstV[x ]<<1) - pSrcV[x ]);639 pDstU[x ] = ClipC(2 * pDstU[x] - pSrcU[x]); 640 pDstV[x ] = ClipC(2 * pDstV[x] - pSrcV[x]); 643 641 #endif 644 642 } … … 649 647 } 650 648 } 651 652 649 #if H_3D 653 650 Void TComYuv::addClipPartLuma( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize ) … … 843 840 #endif 844 841 #endif 842 845 843 //! \} -
branches/HTM-10.0-dev0/source/Lib/TLibCommon/TComYuv.h
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/TLibCommon/TypeDef.h
r833 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 323 323 #define MTK_NBDV_IVREF_FIX_G0067 1 // Disable IvMC, VSP when IVREF is not available, JCT3V-G0067 324 324 #endif 325 326 ///////////////////////////////////////////////////////////////////////////////////////// 327 /////////////////////////////////// HTM-10.1 Integrations ////////////////////////////// 328 ///////////////////////////////////////////////////////////////////////////////////////// 329 #define UPDATE_HM13 1 330 #if H_3D 331 #define H_3D_FIX_G0148_BRACE 1 332 #endif 325 333 ///////////////////////////////////////////////////////////////////////////////////////// 326 334 /////////////////////////////////// HM RELATED DEFINES //////////////////////////////// 327 335 ///////////////////////////////////////////////////////////////////////////////////////// 328 329 #define FIX1071 1 ///< fix for issue #1071 336 #define BUGFIX_INTRAPERIOD 1 337 #define SAO_ENCODE_ALLOW_USE_PREDEBLOCK 1 338 339 #define FIX1172 1 ///< fix ticket #1172 330 340 331 341 #define MAX_NUM_PICS_IN_SOP 1024 … … 342 352 #else 343 353 #define MAX_VPS_NUH_RESERVED_ZERO_LAYER_ID_PLUS1 1 344 #endif345 346 #define RATE_CONTROL_LAMBDA_DOMAIN 1 ///< JCTVC-K0103, rate control by R-lambda model347 #define M0036_RC_IMPROVEMENT 1 ///< JCTVC-M0036, improvement for R-lambda model based rate control348 #define TICKET_1090_FIX 1349 350 #if KWU_FIX_URQ351 #if RATE_CONTROL_LAMBDA_DOMAIN352 #define RC_FIX 1 /// suggested fix for M0036353 #define RATE_CONTROL_INTRA 1 ///< JCTVC-M0257, rate control for intra354 #endif355 #else356 #define RC_FIX 1 /// suggested fix for M0036357 #define RATE_CONTROL_INTRA 1 ///< JCTVC-M0257, rate control for intra358 354 #endif 359 355 … … 389 385 #define C1FLAG_NUMBER 8 // maximum number of largerThan1 flag coded in one chunk : 16 in HM5 390 386 #define C2FLAG_NUMBER 1 // maximum number of largerThan2 flag coded in one chunk: 16 in HM5 391 392 #define REMOVE_SAO_LCU_ENC_CONSTRAINTS_3 1 ///< disable the encoder constraint that conditionally disable SAO for chroma for entire slice in interleaved mode393 394 387 #define SAO_ENCODING_CHOICE 1 ///< I0184: picture early termination 395 388 #if SAO_ENCODING_CHOICE … … 405 398 #define MAX_NUM_PPS 64 406 399 407 408 409 #define WEIGHTED_CHROMA_DISTORTION 1 ///< F386: weighting of chroma for RDO410 400 #define RDOQ_CHROMA_LAMBDA 1 ///< F386: weighting of chroma for RDOQ 411 #define SAO_CHROMA_LAMBDA 1 ///< F386: weighting of chroma for SAO412 401 413 402 #define MIN_SCAN_POS_CROSS 4 … … 423 412 #define LEVEL_RANGE 30 ///< G382: max coefficient level in statistics collection 424 413 #endif 425 426 #define NS_HAD 0427 414 428 415 #define HHI_RQT_INTRA_SPEEDUP 1 ///< tests one best mode with full rqt … … 492 479 #endif 493 480 494 #define SCALING_LIST_OUTPUT_RESULT 0 //JCTVC-G880/JCTVC-G1016 quantization matrices495 496 481 #define CABAC_INIT_PRESENT_FLAG 1 497 482 … … 503 488 typedef bool Bool; 504 489 490 #ifdef __arm__ 491 typedef signed char Char; 492 #else 505 493 typedef char Char; 494 #endif 506 495 typedef unsigned char UChar; 507 496 typedef short Short; … … 570 559 }; 571 560 572 #define NUM_DOWN_PART 4 573 574 enum SAOTypeLen 575 { 576 SAO_EO_LEN = 4, 577 SAO_BO_LEN = 4, 578 SAO_MAX_BO_CLASSES = 32 579 }; 580 581 enum SAOType 582 { 583 SAO_EO_0 = 0, 584 SAO_EO_1, 585 SAO_EO_2, 586 SAO_EO_3, 587 SAO_BO, 588 MAX_NUM_SAO_TYPE 589 }; 590 591 typedef struct _SaoQTPart 592 { 593 Int iBestType; 594 Int iLength; 595 Int subTypeIdx ; ///< indicates EO class or BO band position 596 Int iOffset[4]; 597 Int StartCUX; 598 Int StartCUY; 599 Int EndCUX; 600 Int EndCUY; 601 602 Int PartIdx; 603 Int PartLevel; 604 Int PartCol; 605 Int PartRow; 606 607 Int DownPartsIdx[NUM_DOWN_PART]; 608 Int UpPartIdx; 609 610 Bool bSplit; 611 612 //---- encoder only start -----// 613 Bool bProcessed; 614 Double dMinCost; 615 Int64 iMinDist; 616 Int iMinRate; 617 //---- encoder only end -----// 618 } SAOQTPart; 619 620 typedef struct _SaoLcuParam 621 { 622 Bool mergeUpFlag; 623 Bool mergeLeftFlag; 624 Int typeIdx; 625 Int subTypeIdx; ///< indicates EO class or BO band position 626 Int offset[4]; 627 Int partIdx; 628 Int partIdxTmp; 629 Int length; 630 } SaoLcuParam; 631 632 struct SAOParam 633 { 634 Bool bSaoFlag[2]; 635 SAOQTPart* psSaoPart[3]; 636 Int iMaxSplitLevel; 637 Bool oneUnitFlag[3]; 638 SaoLcuParam* saoLcuParam[3]; 639 Int numCuInHeight; 640 Int numCuInWidth; 641 ~SAOParam(); 561 enum SAOComponentIdx 562 { 563 SAO_Y =0, 564 SAO_Cb, 565 SAO_Cr, 566 NUM_SAO_COMPONENTS 567 }; 568 569 enum SAOMode //mode 570 { 571 SAO_MODE_OFF = 0, 572 SAO_MODE_NEW, 573 SAO_MODE_MERGE, 574 NUM_SAO_MODES 575 }; 576 577 enum SAOModeMergeTypes 578 { 579 SAO_MERGE_LEFT =0, 580 SAO_MERGE_ABOVE, 581 NUM_SAO_MERGE_TYPES 582 }; 583 584 585 enum SAOModeNewTypes 586 { 587 SAO_TYPE_START_EO =0, 588 SAO_TYPE_EO_0 = SAO_TYPE_START_EO, 589 SAO_TYPE_EO_90, 590 SAO_TYPE_EO_135, 591 SAO_TYPE_EO_45, 592 593 SAO_TYPE_START_BO, 594 SAO_TYPE_BO = SAO_TYPE_START_BO, 595 596 NUM_SAO_NEW_TYPES 597 }; 598 #define NUM_SAO_EO_TYPES_LOG2 2 599 600 enum SAOEOClasses 601 { 602 SAO_CLASS_EO_FULL_VALLEY = 0, 603 SAO_CLASS_EO_HALF_VALLEY = 1, 604 SAO_CLASS_EO_PLAIN = 2, 605 SAO_CLASS_EO_HALF_PEAK = 3, 606 SAO_CLASS_EO_FULL_PEAK = 4, 607 NUM_SAO_EO_CLASSES, 608 }; 609 610 611 #define NUM_SAO_BO_CLASSES_LOG2 5 612 enum SAOBOClasses 613 { 614 //SAO_CLASS_BO_BAND0 = 0, 615 //SAO_CLASS_BO_BAND1, 616 //SAO_CLASS_BO_BAND2, 617 //... 618 //SAO_CLASS_BO_BAND31, 619 620 NUM_SAO_BO_CLASSES = (1<<NUM_SAO_BO_CLASSES_LOG2), 621 }; 622 #define MAX_NUM_SAO_CLASSES 32 //(NUM_SAO_EO_GROUPS > NUM_SAO_BO_GROUPS)?NUM_SAO_EO_GROUPS:NUM_SAO_BO_GROUPS 623 624 struct SAOOffset 625 { 626 Int modeIdc; //NEW, MERGE, OFF 627 Int typeIdc; //NEW: EO_0, EO_90, EO_135, EO_45, BO. MERGE: left, above 628 Int typeAuxInfo; //BO: starting band index 629 Int offset[MAX_NUM_SAO_CLASSES]; 630 631 SAOOffset(); 632 ~SAOOffset(); 633 Void reset(); 634 635 const SAOOffset& operator= (const SAOOffset& src); 636 }; 637 638 struct SAOBlkParam 639 { 640 641 SAOBlkParam(); 642 ~SAOBlkParam(); 643 Void reset(); 644 const SAOBlkParam& operator= (const SAOBlkParam& src); 645 SAOOffset& operator[](Int compIdx){ return offsetParam[compIdx];} 646 private: 647 SAOOffset offsetParam[NUM_SAO_COMPONENTS]; 648 642 649 }; 643 650 -
branches/HTM-10.0-dev0/source/Lib/TLibDecoder/AnnexBread.cpp
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/TLibDecoder/AnnexBread.h
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/TLibDecoder/NALread.cpp
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 70 70 break; 71 71 } 72 assert(*it_read <= 0x03); 72 73 } 73 74 zeroCount = (*it_read == 0x00) ? zeroCount+1 : 0; … … 126 127 else 127 128 { 128 assert( nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_T LA_R129 assert( nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_TSA_R 129 130 && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_TSA_N 130 131 && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_STSA_R -
branches/HTM-10.0-dev0/source/Lib/TLibDecoder/NALread.h
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/TLibDecoder/SEIread.cpp
r655 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 443 443 if( !pHRD->getSubPicCpbParamsPresentFlag() ) 444 444 { 445 READ_FLAG( code, "rap_cpb_params_present_flag" ); sei.m_rapCpbParamsPresentFlag = code; 445 READ_FLAG( code, "irap_cpb_params_present_flag" ); sei.m_rapCpbParamsPresentFlag = code; 446 } 447 if( sei.m_rapCpbParamsPresentFlag ) 448 { 449 READ_CODE( pHRD->getCpbRemovalDelayLengthMinus1() + 1, code, "cpb_delay_offset" ); sei.m_cpbDelayOffset = code; 450 READ_CODE( pHRD->getDpbOutputDelayLengthMinus1() + 1, code, "dpb_delay_offset" ); sei.m_dpbDelayOffset = code; 446 451 } 447 452 //read splicing flag and cpb_removal_delay_delta … … 450 455 READ_CODE( ( pHRD->getCpbRemovalDelayLengthMinus1() + 1 ), code, "au_cpb_removal_delay_delta_minus1" ); 451 456 sei.m_auCpbRemovalDelayDelta = code + 1; 452 if( sei.m_rapCpbParamsPresentFlag )453 {454 READ_CODE( pHRD->getCpbRemovalDelayLengthMinus1() + 1, code, "cpb_delay_offset" ); sei.m_cpbDelayOffset = code;455 READ_CODE( pHRD->getDpbOutputDelayLengthMinus1() + 1, code, "dpb_delay_offset" ); sei.m_dpbDelayOffset = code;456 }457 457 for( nalOrVcl = 0; nalOrVcl < 2; nalOrVcl ++ ) 458 458 { -
branches/HTM-10.0-dev0/source/Lib/TLibDecoder/SEIread.h
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/TLibDecoder/SyntaxElementParser.cpp
r655 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-201 3, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/TLibDecoder/SyntaxElementParser.h
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/TLibDecoder/TDecBinCoder.h
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/TLibDecoder/TDecBinCoderCABAC.cpp
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/TLibDecoder/TDecBinCoderCABAC.h
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/TLibDecoder/TDecCAVLC.cpp
r833 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-201 3, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 848 848 READ_UVLC( uiCode, "log2_diff_max_min_coding_block_size" ); 849 849 pcSPS->setLog2DiffMaxMinCodingBlockSize(uiCode); 850 851 if (pcSPS->getPTL()->getGeneralPTL()->getLevelIdc() >= Level::LEVEL5) 852 { 853 assert(log2MinCUSize + pcSPS->getLog2DiffMaxMinCodingBlockSize() >= 5); 854 } 855 850 856 Int maxCUDepthDelta = uiCode; 851 857 pcSPS->setMaxCUWidth ( 1<<(log2MinCUSize + maxCUDepthDelta) ); -
branches/HTM-10.0-dev0/source/Lib/TLibDecoder/TDecCAVLC.h
r833 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/TLibDecoder/TDecCu.cpp
r833 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 37 37 38 38 #include "TDecCu.h" 39 40 39 //! \ingroup TLibDecoder 41 40 //! \{ … … 639 638 640 639 m_ppcCU[uiDepth]->copySubCU( pcCU, uiAbsPartIdx, uiDepth ); 641 640 641 #if H_MV_ENC_DEC_TRAC 642 #if ENC_DEC_TRACE 643 stopAtPos ( m_ppcCU[uiDepth]->getSlice()->getPOC(), 644 m_ppcCU[uiDepth]->getSlice()->getLayerId(), 645 m_ppcCU[uiDepth]->getCUPelX(), 646 m_ppcCU[uiDepth]->getCUPelY(), 647 m_ppcCU[uiDepth]->getWidth(0), 648 m_ppcCU[uiDepth]->getHeight(0) ); 649 #endif 650 #endif 651 642 652 switch( m_ppcCU[uiDepth]->getPredictionMode(0) ) 643 653 { … … 917 927 } 918 928 #endif 919 929 930 #if H_3D && UPDATE_HM13 931 Bool useDltFlag = (isDimMode( uiLumaPredMode ) || uiLumaPredMode == HOR_IDX || uiLumaPredMode == VER_IDX || uiLumaPredMode == DC_IDX) && pcCU->getSlice()->getIsDepth() && pcCU->getSlice()->getPPS()->getDLT()->getUseDLTFlag(pcCU->getSlice()->getLayerIdInVps()); 932 933 if ( pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, uiTrDepth ) || useDltFlag ) 934 #else 935 if ( pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, uiTrDepth ) ) 936 #endif 937 { 920 938 //===== inverse transform ===== 921 939 m_pcTrQuant->setQPforQuant ( pcCU->getQP(0), TEXT_LUMA, pcCU->getSlice()->getSPS()->getQpBDOffsetY(), 0 ); 922 940 923 941 Int scalingListType = (pcCU->isIntra(uiAbsPartIdx) ? 0 : 3) + g_eTTable[(Int)TEXT_LUMA]; 924 assert(scalingListType < 6);942 assert(scalingListType < SCALING_LIST_NUM); 925 943 m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), TEXT_LUMA, pcCU->getLumaIntraDir( uiAbsPartIdx ), piResi, uiStride, pcCoeff, uiWidth, uiHeight, scalingListType, useTransformSkip ); 926 944 … … 936 954 { 937 955 #if H_3D 956 #if UPDATE_HM13 957 if ( useDltFlag ) 958 #else 938 959 if( (isDimMode( uiLumaPredMode ) || uiLumaPredMode == HOR_IDX || uiLumaPredMode == VER_IDX || uiLumaPredMode == DC_IDX) && pcCU->getSlice()->getIsDepth() && pcCU->getSlice()->getPPS()->getDLT()->getUseDLTFlag(pcCU->getSlice()->getLayerIdInVps()) ) 960 #endif 939 961 { 940 962 pReco [ uiX ] = pcCU->getSlice()->getPPS()->getDLT()->idx2DepthValue( pcCU->getSlice()->getLayerIdInVps(), Clip3( 0, pcCU->getSlice()->getPPS()->getDLT()->getNumDepthValues( pcCU->getSlice()->getLayerIdInVps() ) - 1, pcCU->getSlice()->getPPS()->getDLT()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), pPred[ uiX ] ) + pResi[ uiX ] ) ); … … 953 975 pReco += uiStride; 954 976 pRecIPred += uiRecIPredStride; 977 } 978 } 979 else 980 { 981 //===== reconstruction ===== 982 Pel* pPred = piPred; 983 Pel* pReco = piReco; 984 Pel* pRecIPred = piRecIPred; 985 for ( Int y = 0; y < uiHeight; y++ ) 986 { 987 for ( Int x = 0; x < uiWidth; x++ ) 988 { 989 pReco [ x ] = pPred[ x ]; 990 pRecIPred[ x ] = pReco[ x ]; 991 } 992 pPred += uiStride; 993 pReco += uiStride; 994 pRecIPred += uiRecIPredStride; 995 } 955 996 } 956 997 } … … 1022 1063 } 1023 1064 1065 if ( pcCU->getCbf( uiAbsPartIdx, eText, uiTrDepth ) ) 1066 { 1024 1067 //===== inverse transform ===== 1025 1068 Int curChromaQpOffset; … … 1035 1078 1036 1079 Int scalingListType = (pcCU->isIntra(uiAbsPartIdx) ? 0 : 3) + g_eTTable[(Int)eText]; 1037 assert(scalingListType < 6);1080 assert(scalingListType < SCALING_LIST_NUM); 1038 1081 m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), eText, REG_DCT, piResi, uiStride, pcCoeff, uiWidth, uiHeight, scalingListType, useTransformSkipChroma ); 1039 1082 … … 1054 1097 pReco += uiStride; 1055 1098 pRecIPred += uiRecIPredStride; 1099 } 1100 } 1101 else 1102 { 1103 //===== reconstruction ===== 1104 Pel* pPred = piPred; 1105 Pel* pReco = piReco; 1106 Pel* pRecIPred = piRecIPred; 1107 for ( Int y = 0; y < uiHeight; y++ ) 1108 { 1109 for ( Int x = 0; x < uiWidth; x++ ) 1110 { 1111 pReco [ x ] = pPred[ x ]; 1112 pRecIPred[ x ] = pReco[ x ]; 1113 } 1114 pPred += uiStride; 1115 pReco += uiStride; 1116 pRecIPred += uiRecIPredStride; 1117 } 1056 1118 } 1057 1119 } -
branches/HTM-10.0-dev0/source/Lib/TLibDecoder/TDecCu.h
r833 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/TLibDecoder/TDecEntropy.cpp
r833 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 580 580 } 581 581 582 Void TDecEntropy::xDecodeTransform( TComDataCU* pcCU, UInt offsetLuma, UInt offsetChroma, UInt uiAbsPartIdx, UInt uiDepth, UInt width, UInt height, UInt uiTrIdx, Bool& bCodeDQP )582 Void TDecEntropy::xDecodeTransform( TComDataCU* pcCU, UInt offsetLuma, UInt offsetChroma, UInt uiAbsPartIdx, UInt uiDepth, UInt width, UInt height, UInt uiTrIdx, Bool& bCodeDQP, Int quadtreeTULog2MinSizeInCU) 583 583 { 584 584 UInt uiSubdiv; … … 604 604 else if( (pcCU->getSlice()->getSPS()->getQuadtreeTUMaxDepthInter() == 1) && (pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTER) && ( pcCU->getPartitionSize(uiAbsPartIdx) != SIZE_2Nx2N ) && (uiDepth == pcCU->getDepth(uiAbsPartIdx)) ) 605 605 { 606 uiSubdiv = (uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx));606 uiSubdiv = (uiLog2TrafoSize > quadtreeTULog2MinSizeInCU); 607 607 } 608 608 else if( uiLog2TrafoSize > pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() ) … … 614 614 uiSubdiv = 0; 615 615 } 616 else if( uiLog2TrafoSize == pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx))616 else if( uiLog2TrafoSize == quadtreeTULog2MinSizeInCU ) 617 617 { 618 618 uiSubdiv = 0; … … 620 620 else 621 621 { 622 assert( uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx));622 assert( uiLog2TrafoSize > quadtreeTULog2MinSizeInCU ); 623 623 m_pcEntropyDecoderIf->parseTransformSubdivFlag( uiSubdiv, 5 - uiLog2TrafoSize ); 624 624 } … … 666 666 for( Int i = 0; i < 4; i++ ) 667 667 { 668 xDecodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP );668 xDecodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP, quadtreeTULog2MinSizeInCU ); 669 669 uiYCbf |= pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, uiTrDepth+1 ); 670 670 uiUCbf |= pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth+1 ); … … 886 886 887 887 } 888 xDecodeTransform( pcCU, uiLumaOffset, uiChromaOffset, uiAbsPartIdx, uiDepth, uiWidth, uiHeight, 0, bCodeDQP ); 888 889 Int getQuadtreeTULog2MinSizeInCU = pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx); 890 891 xDecodeTransform( pcCU, uiLumaOffset, uiChromaOffset, uiAbsPartIdx, uiDepth, uiWidth, uiHeight, 0, bCodeDQP, getQuadtreeTULog2MinSizeInCU ); 889 892 } 890 893 -
branches/HTM-10.0-dev0/source/Lib/TLibDecoder/TDecEntropy.h
r833 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 210 210 211 211 private: 212 Void xDecodeTransform ( TComDataCU* pcCU, UInt offsetLuma, UInt offsetChroma, UInt uiAbsPartIdx, UInt uiDepth, UInt width, UInt height, UInt uiTrIdx, Bool& bCodeDQP );212 Void xDecodeTransform ( TComDataCU* pcCU, UInt offsetLuma, UInt offsetChroma, UInt uiAbsPartIdx, UInt uiDepth, UInt width, UInt height, UInt uiTrIdx, Bool& bCodeDQP, Int getQuadtreeTULog2MinSizeInCU ); 213 213 214 214 public: -
branches/HTM-10.0-dev0/source/Lib/TLibDecoder/TDecGop.cpp
r655 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 43 43 #include "libmd5/MD5.h" 44 44 #include "TLibCommon/SEI.h" 45 46 45 #include <time.h> 47 46 … … 112 111 //-- For time output for each slice 113 112 long iBeforeTime = clock(); 114 115 UInt uiStartCUAddr = pcSlice->getSliceSegmentCurStartCUAddr();116 117 UInt uiSliceStartCuAddr = pcSlice->getSliceCurStartCUAddr();118 if(uiSliceStartCuAddr == uiStartCUAddr)119 {120 m_sliceStartCUAddress.push_back(uiSliceStartCuAddr);121 }122 123 113 m_pcSbacDecoder->init( (TDecBinIf*)m_pcBinCABAC ); 124 114 m_pcEntropyDecoder->setEntropyDecoder (m_pcSbacDecoder); … … 147 137 m_pcEntropyDecoder->setBitstream ( ppcSubstreams[0] ); 148 138 m_pcEntropyDecoder->resetEntropy (pcSlice); 149 150 if(uiSliceStartCuAddr == uiStartCUAddr)151 {152 m_LFCrossSliceBoundaryFlag.push_back( pcSlice->getLFCrossSliceBoundaryFlag());153 }154 139 #if H_3D_NBDV 155 140 if(pcSlice->getViewIndex() && !pcSlice->getIsDepth()) //Notes from QC: this condition shall be changed once the configuration is completed, e.g. in pcSlice->getSPS()->getMultiviewMvPredMode() || ARP in prev. HTM. Remove this comment once it is done. … … 199 184 m_pcLoopFilter->setCfg(bLFCrossTileBoundary); 200 185 m_pcLoopFilter->loopFilterPic( rpcPic ); 201 202 if(pcSlice->getSPS()->getUseSAO())203 {204 m_sliceStartCUAddress.push_back(rpcPic->getNumCUsInFrame()* rpcPic->getNumPartInCU());205 rpcPic->createNonDBFilterInfo(m_sliceStartCUAddress, 0, &m_LFCrossSliceBoundaryFlag, rpcPic->getPicSym()->getNumTiles(), bLFCrossTileBoundary);206 }207 208 186 if( pcSlice->getSPS()->getUseSAO() ) 209 187 { 210 { 211 SAOParam *saoParam = rpcPic->getPicSym()->getSaoParam(); 212 saoParam->bSaoFlag[0] = pcSlice->getSaoEnabledFlag(); 213 saoParam->bSaoFlag[1] = pcSlice->getSaoEnabledFlagChroma(); 214 m_pcSAO->setSaoLcuBasedOptimization(1); 215 m_pcSAO->createPicSaoInfo(rpcPic); 216 m_pcSAO->SAOProcess(saoParam); 217 m_pcSAO->PCMLFDisableProcess(rpcPic); 218 m_pcSAO->destroyPicSaoInfo(); 219 } 220 } 221 222 if(pcSlice->getSPS()->getUseSAO()) 223 { 224 rpcPic->destroyNonDBFilterInfo(); 188 m_pcSAO->reconstructBlkSAOParams(rpcPic, rpcPic->getPicSym()->getSAOBlkParam()); 189 m_pcSAO->SAOProcess(rpcPic); 190 m_pcSAO->PCMLFDisableProcess(rpcPic); 225 191 } 226 192 #if H_3D … … 284 250 rpcPic->setOutputMark(true); 285 251 rpcPic->setReconMark(true); 286 m_sliceStartCUAddress.clear();287 m_LFCrossSliceBoundaryFlag.clear();288 252 } 289 253 -
branches/HTM-10.0-dev0/source/Lib/TLibDecoder/TDecGop.h
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 83 83 Int m_decodedPictureHashSEIEnabled; ///< Checksum(3)/CRC(2)/MD5(1)/disable(0) acting on decoded picture hash SEI message 84 84 85 //! list that contains the CU address of each slice plus the end address86 std::vector<Int> m_sliceStartCUAddress;87 std::vector<Bool> m_LFCrossSliceBoundaryFlag;88 89 85 public: 90 86 TDecGop(); -
branches/HTM-10.0-dev0/source/Lib/TLibDecoder/TDecSbac.cpp
r833 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 78 78 , m_cCUAbsSCModel ( 1, 1, NUM_ABS_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) 79 79 , m_cMVPIdxSCModel ( 1, 1, NUM_MVP_IDX_CTX , m_contextModels + m_numContextModels, m_numContextModels) 80 , m_cCUAMPSCModel ( 1, 1, NUM_CU_AMP_CTX , m_contextModels + m_numContextModels, m_numContextModels)81 80 , m_cSaoMergeSCModel ( 1, 1, NUM_SAO_MERGE_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) 82 81 , m_cSaoTypeIdxSCModel ( 1, 1, NUM_SAO_TYPE_IDX_CTX , m_contextModels + m_numContextModels, m_numContextModels) … … 155 154 #endif 156 155 m_cCUPartSizeSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_PART_SIZE ); 157 m_cCUAMPSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_CU_AMP_POS );158 156 m_cCUPredModeSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_PRED_MODE ); 159 157 m_cCUIntraPredSCModel.initBuffer ( sliceType, qp, (UChar*)INIT_INTRA_PRED_MODE ); … … 236 234 #endif 237 235 m_cCUPartSizeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_PART_SIZE ); 238 m_cCUAMPSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CU_AMP_POS );239 236 m_cCUPredModeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_PRED_MODE ); 240 237 m_cCUIntraPredSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_INTRA_PRED_MODE ); … … 906 903 if (eMode == SIZE_2NxN) 907 904 { 908 m_pcTDecBinIf->decodeBin(uiSymbol, m_cCUAMPSCModel.get( 0, 0, 0));905 m_pcTDecBinIf->decodeBin(uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, 3 )); 909 906 if (uiSymbol == 0) 910 907 { … … 915 912 else if (eMode == SIZE_Nx2N) 916 913 { 917 m_pcTDecBinIf->decodeBin(uiSymbol, m_cCUAMPSCModel.get( 0, 0, 0));914 m_pcTDecBinIf->decodeBin(uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, 3 )); 918 915 if (uiSymbol == 0) 919 916 { … … 2009 2006 if (uiCode == 0) 2010 2007 { 2011 ruiVal = 5;2008 ruiVal = 1; 2012 2009 } 2013 2010 else 2014 2011 { 2015 ruiVal = 1; 2016 } 2017 } 2018 } 2019 2020 inline Void copySaoOneLcuParam(SaoLcuParam* psDst, SaoLcuParam* psSrc) 2021 { 2022 Int i; 2023 psDst->partIdx = psSrc->partIdx; 2024 psDst->typeIdx = psSrc->typeIdx; 2025 if (psDst->typeIdx != -1) 2026 { 2027 psDst->subTypeIdx = psSrc->subTypeIdx ; 2028 psDst->length = psSrc->length; 2029 for (i=0;i<psDst->length;i++) 2030 { 2031 psDst->offset[i] = psSrc->offset[i]; 2032 } 2033 } 2034 else 2035 { 2036 psDst->length = 0; 2037 for (i=0;i<SAO_BO_LEN;i++) 2038 { 2039 psDst->offset[i] = 0; 2040 } 2041 } 2042 } 2043 2044 Void TDecSbac::parseSaoOffset(SaoLcuParam* psSaoLcuParam, UInt compIdx) 2012 ruiVal = 2; 2013 } 2014 } 2015 } 2016 2017 Void TDecSbac::parseSaoSign(UInt& val) 2018 { 2019 m_pcTDecBinIf->decodeBinEP ( val ); 2020 } 2021 2022 Void TDecSbac::parseSAOBlkParam (SAOBlkParam& saoBlkParam 2023 , Bool* sliceEnabled 2024 , Bool leftMergeAvail 2025 , Bool aboveMergeAvail 2026 ) 2045 2027 { 2046 2028 UInt uiSymbol; 2047 static Int iTypeLength[MAX_NUM_SAO_TYPE] = 2048 { 2049 SAO_EO_LEN, 2050 SAO_EO_LEN, 2051 SAO_EO_LEN, 2052 SAO_EO_LEN, 2053 SAO_BO_LEN 2054 }; 2055 2056 if (compIdx==2) 2057 { 2058 uiSymbol = (UInt)( psSaoLcuParam->typeIdx + 1); 2059 } 2060 else 2061 { 2062 parseSaoTypeIdx(uiSymbol); 2063 } 2064 psSaoLcuParam->typeIdx = (Int)uiSymbol - 1; 2065 if (uiSymbol) 2066 { 2067 psSaoLcuParam->length = iTypeLength[psSaoLcuParam->typeIdx]; 2068 2069 Int bitDepth = compIdx ? g_bitDepthC : g_bitDepthY; 2070 Int offsetTh = 1 << min(bitDepth - 5,5); 2071 2072 if( psSaoLcuParam->typeIdx == SAO_BO ) 2073 { 2074 for(Int i=0; i< psSaoLcuParam->length; i++) 2075 { 2076 parseSaoMaxUvlc(uiSymbol, offsetTh -1 ); 2077 psSaoLcuParam->offset[i] = uiSymbol; 2029 2030 Bool isLeftMerge = false; 2031 Bool isAboveMerge= false; 2032 2033 if(leftMergeAvail) 2034 { 2035 parseSaoMerge(uiSymbol); //sao_merge_left_flag 2036 isLeftMerge = (uiSymbol?true:false); 2037 } 2038 2039 if( aboveMergeAvail && !isLeftMerge) 2040 { 2041 parseSaoMerge(uiSymbol); //sao_merge_up_flag 2042 isAboveMerge = (uiSymbol?true:false); 2043 } 2044 2045 if(isLeftMerge || isAboveMerge) //merge mode 2046 { 2047 saoBlkParam[SAO_Y].modeIdc = saoBlkParam[SAO_Cb].modeIdc = saoBlkParam[SAO_Cr].modeIdc = SAO_MODE_MERGE; 2048 saoBlkParam[SAO_Y].typeIdc = saoBlkParam[SAO_Cb].typeIdc = saoBlkParam[SAO_Cr].typeIdc = (isLeftMerge)?SAO_MERGE_LEFT:SAO_MERGE_ABOVE; 2078 2049 } 2079 for(Int i=0; i< psSaoLcuParam->length; i++) 2080 { 2081 if (psSaoLcuParam->offset[i] != 0) 2082 { 2083 m_pcTDecBinIf->decodeBinEP ( uiSymbol); 2084 if (uiSymbol) 2050 else //new or off mode 2051 { 2052 for(Int compIdx=0; compIdx < NUM_SAO_COMPONENTS; compIdx++) 2053 { 2054 SAOOffset& ctbParam = saoBlkParam[compIdx]; 2055 2056 if(!sliceEnabled[compIdx]) 2085 2057 { 2086 psSaoLcuParam->offset[i] = -psSaoLcuParam->offset[i] ; 2087 } 2088 } 2089 } 2090 parseSaoUflc(5, uiSymbol ); 2091 psSaoLcuParam->subTypeIdx = uiSymbol; 2092 } 2093 else if( psSaoLcuParam->typeIdx < 4 ) 2094 { 2095 parseSaoMaxUvlc(uiSymbol, offsetTh -1 ); psSaoLcuParam->offset[0] = uiSymbol; 2096 parseSaoMaxUvlc(uiSymbol, offsetTh -1 ); psSaoLcuParam->offset[1] = uiSymbol; 2097 parseSaoMaxUvlc(uiSymbol, offsetTh -1 ); psSaoLcuParam->offset[2] = -(Int)uiSymbol; 2098 parseSaoMaxUvlc(uiSymbol, offsetTh -1 ); psSaoLcuParam->offset[3] = -(Int)uiSymbol; 2099 if (compIdx != 2) 2058 //off 2059 ctbParam.modeIdc = SAO_MODE_OFF; 2060 continue; 2061 } 2062 2063 //type 2064 if(compIdx == SAO_Y || compIdx == SAO_Cb) 2065 { 2066 parseSaoTypeIdx(uiSymbol); //sao_type_idx_luma or sao_type_idx_chroma 2067 2068 assert(uiSymbol ==0 || uiSymbol ==1 || uiSymbol ==2); 2069 2070 if(uiSymbol ==0) //OFF 2100 2071 { 2101 parseSaoUflc(2, uiSymbol ); 2102 psSaoLcuParam->subTypeIdx = uiSymbol; 2103 psSaoLcuParam->typeIdx += psSaoLcuParam->subTypeIdx; 2104 } 2072 ctbParam.modeIdc = SAO_MODE_OFF; 2105 2073 } 2106 } 2107 else 2108 { 2109 psSaoLcuParam->length = 0; 2110 } 2111 } 2112 2113 Void TDecSbac::parseSaoOneLcuInterleaving(Int rx, Int ry, SAOParam* pSaoParam, TComDataCU* pcCU, Int iCUAddrInSlice, Int iCUAddrUpInSlice, Int allowMergeLeft, Int allowMergeUp) 2114 { 2115 Int iAddr = pcCU->getAddr(); 2116 UInt uiSymbol; 2117 for (Int iCompIdx=0; iCompIdx<3; iCompIdx++) 2118 { 2119 pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeUpFlag = 0; 2120 pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeLeftFlag = 0; 2121 pSaoParam->saoLcuParam[iCompIdx][iAddr].subTypeIdx = 0; 2122 pSaoParam->saoLcuParam[iCompIdx][iAddr].typeIdx = -1; 2123 pSaoParam->saoLcuParam[iCompIdx][iAddr].offset[0] = 0; 2124 pSaoParam->saoLcuParam[iCompIdx][iAddr].offset[1] = 0; 2125 pSaoParam->saoLcuParam[iCompIdx][iAddr].offset[2] = 0; 2126 pSaoParam->saoLcuParam[iCompIdx][iAddr].offset[3] = 0; 2127 2128 } 2129 if (pSaoParam->bSaoFlag[0] || pSaoParam->bSaoFlag[1] ) 2130 { 2131 if (rx>0 && iCUAddrInSlice!=0 && allowMergeLeft) 2132 { 2133 parseSaoMerge(uiSymbol); 2134 pSaoParam->saoLcuParam[0][iAddr].mergeLeftFlag = (Bool)uiSymbol; 2135 } 2136 if (pSaoParam->saoLcuParam[0][iAddr].mergeLeftFlag==0) 2137 { 2138 if ((ry > 0) && (iCUAddrUpInSlice>=0) && allowMergeUp) 2139 { 2140 parseSaoMerge(uiSymbol); 2141 pSaoParam->saoLcuParam[0][iAddr].mergeUpFlag = (Bool)uiSymbol; 2142 } 2143 } 2144 } 2145 2146 for (Int iCompIdx=0; iCompIdx<3; iCompIdx++) 2147 { 2148 if ((iCompIdx == 0 && pSaoParam->bSaoFlag[0]) || (iCompIdx > 0 && pSaoParam->bSaoFlag[1]) ) 2149 { 2150 if (rx>0 && iCUAddrInSlice!=0 && allowMergeLeft) 2151 { 2152 pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeLeftFlag = pSaoParam->saoLcuParam[0][iAddr].mergeLeftFlag; 2153 } 2154 else 2155 { 2156 pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeLeftFlag = 0; 2157 } 2158 2159 if (pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeLeftFlag==0) 2160 { 2161 if ((ry > 0) && (iCUAddrUpInSlice>=0) && allowMergeUp) 2162 { 2163 pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeUpFlag = pSaoParam->saoLcuParam[0][iAddr].mergeUpFlag; 2074 else if(uiSymbol == 1) //BO 2075 { 2076 ctbParam.modeIdc = SAO_MODE_NEW; 2077 ctbParam.typeIdc = SAO_TYPE_START_BO; 2078 } 2079 else //2, EO 2080 { 2081 ctbParam.modeIdc = SAO_MODE_NEW; 2082 ctbParam.typeIdc = SAO_TYPE_START_EO; 2083 } 2084 2085 } 2086 else //Cr, follow Cb SAO type 2087 { 2088 ctbParam.modeIdc = saoBlkParam[SAO_Cb].modeIdc; 2089 ctbParam.typeIdc = saoBlkParam[SAO_Cb].typeIdc; 2090 } 2091 2092 if(ctbParam.modeIdc == SAO_MODE_NEW) 2093 { 2094 Int offset[4]; 2095 for(Int i=0; i< 4; i++) 2096 { 2097 parseSaoMaxUvlc(uiSymbol, g_saoMaxOffsetQVal[compIdx] ); //sao_offset_abs 2098 offset[i] = (Int)uiSymbol; 2099 } 2100 2101 if(ctbParam.typeIdc == SAO_TYPE_START_BO) 2102 { 2103 for(Int i=0; i< 4; i++) 2104 { 2105 if(offset[i] != 0) 2106 { 2107 parseSaoSign(uiSymbol); //sao_offset_sign 2108 if(uiSymbol) 2109 { 2110 offset[i] = -offset[i]; 2111 } 2112 } 2113 } 2114 parseSaoUflc(NUM_SAO_BO_CLASSES_LOG2, uiSymbol ); //sao_band_position 2115 ctbParam.typeAuxInfo = uiSymbol; 2116 2117 for(Int i=0; i<4; i++) 2118 { 2119 ctbParam.offset[(ctbParam.typeAuxInfo+i)%MAX_NUM_SAO_CLASSES] = offset[i]; 2120 } 2121 2122 } 2123 else //EO 2124 { 2125 ctbParam.typeAuxInfo = 0; 2126 2127 if(compIdx == SAO_Y || compIdx == SAO_Cb) 2128 { 2129 parseSaoUflc(NUM_SAO_EO_TYPES_LOG2, uiSymbol ); //sao_eo_class_luma or sao_eo_class_chroma 2130 ctbParam.typeIdc += uiSymbol; 2164 2131 } 2165 2132 else 2166 2133 { 2167 pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeUpFlag = 0; 2168 } 2169 if (!pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeUpFlag) 2170 { 2171 pSaoParam->saoLcuParam[2][iAddr].typeIdx = pSaoParam->saoLcuParam[1][iAddr].typeIdx; 2172 parseSaoOffset(&(pSaoParam->saoLcuParam[iCompIdx][iAddr]), iCompIdx); 2173 } 2174 else 2175 { 2176 copySaoOneLcuParam(&pSaoParam->saoLcuParam[iCompIdx][iAddr], &pSaoParam->saoLcuParam[iCompIdx][iAddr-pSaoParam->numCuInWidth]); 2177 } 2178 } 2179 else 2180 { 2181 copySaoOneLcuParam(&pSaoParam->saoLcuParam[iCompIdx][iAddr], &pSaoParam->saoLcuParam[iCompIdx][iAddr-1]); 2182 } 2183 } 2184 else 2185 { 2186 pSaoParam->saoLcuParam[iCompIdx][iAddr].typeIdx = -1; 2187 pSaoParam->saoLcuParam[iCompIdx][iAddr].subTypeIdx = 0; 2134 ctbParam.typeIdc = saoBlkParam[SAO_Cb].typeIdc; 2135 } 2136 ctbParam.offset[SAO_CLASS_EO_FULL_VALLEY] = offset[0]; 2137 ctbParam.offset[SAO_CLASS_EO_HALF_VALLEY] = offset[1]; 2138 ctbParam.offset[SAO_CLASS_EO_PLAIN ] = 0; 2139 ctbParam.offset[SAO_CLASS_EO_HALF_PEAK ] = -offset[2]; 2140 ctbParam.offset[SAO_CLASS_EO_FULL_PEAK ] = -offset[3]; 2141 } 2142 } 2188 2143 } 2189 2144 } … … 2424 2379 #endif 2425 2380 2381 2382 2426 2383 //! \} -
branches/HTM-10.0-dev0/source/Lib/TLibDecoder/TDecSbac.h
r833 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 94 94 Void parseSaoTypeIdx ( UInt& ruiVal ); 95 95 Void parseSaoUflc ( UInt uiLength, UInt& ruiVal ); 96 Void parseSaoOneLcuInterleaving(Int rx, Int ry, SAOParam* pSaoParam, TComDataCU* pcCU, Int iCUAddrInSlice, Int iCUAddrUpInSlice, Int allowMergeLeft, Int allowMergeUp);97 Void parseSaoOffset (SaoLcuParam* psSaoLcuParam, UInt compIdx);96 Void parseSAOBlkParam (SAOBlkParam& saoBlkParam, Bool* sliceEnabled, Bool leftMergeAvail, Bool aboveMergeAvail); 97 Void parseSaoSign(UInt& val); 98 98 private: 99 99 Void xReadUnarySymbol ( UInt& ruiSymbol, ContextModel* pcSCModel, Int iOffset ); … … 209 209 ContextModel3DBuffer m_cMVPIdxSCModel; 210 210 211 ContextModel3DBuffer m_cCUAMPSCModel;212 211 ContextModel3DBuffer m_cSaoMergeSCModel; 213 212 ContextModel3DBuffer m_cSaoTypeIdxSCModel; -
branches/HTM-10.0-dev0/source/Lib/TLibDecoder/TDecSlice.cpp
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 313 313 g_bJustDoIt = g_bEncDecTraceEnable; 314 314 #endif 315 if ( pcSlice->getSPS()->getUseSAO() && (pcSlice->getSaoEnabledFlag()||pcSlice->getSaoEnabledFlagChroma()) ) 316 { 317 SAOParam *saoParam = rpcPic->getPicSym()->getSaoParam(); 318 saoParam->bSaoFlag[0] = pcSlice->getSaoEnabledFlag(); 319 if (iCUAddr == iStartCUAddr) 320 { 321 saoParam->bSaoFlag[1] = pcSlice->getSaoEnabledFlagChroma(); 322 } 323 Int numCuInWidth = saoParam->numCuInWidth; 324 Int cuAddrInSlice = iCUAddr - rpcPic->getPicSym()->getCUOrderMap(pcSlice->getSliceCurStartCUAddr()/rpcPic->getNumPartInCU()); 325 Int cuAddrUpInSlice = cuAddrInSlice - numCuInWidth; 326 Int rx = iCUAddr % numCuInWidth; 327 Int ry = iCUAddr / numCuInWidth; 328 Int allowMergeLeft = 1; 329 Int allowMergeUp = 1; 330 if (rx!=0) 331 { 332 if (rpcPic->getPicSym()->getTileIdxMap(iCUAddr-1) != rpcPic->getPicSym()->getTileIdxMap(iCUAddr)) 333 { 334 allowMergeLeft = 0; 335 } 336 } 337 if (ry!=0) 338 { 339 if (rpcPic->getPicSym()->getTileIdxMap(iCUAddr-numCuInWidth) != rpcPic->getPicSym()->getTileIdxMap(iCUAddr)) 340 { 341 allowMergeUp = 0; 342 } 343 } 344 pcSbacDecoder->parseSaoOneLcuInterleaving(rx, ry, saoParam,pcCU, cuAddrInSlice, cuAddrUpInSlice, allowMergeLeft, allowMergeUp); 345 } 346 else if ( pcSlice->getSPS()->getUseSAO() ) 347 { 348 Int addr = pcCU->getAddr(); 349 SAOParam *saoParam = rpcPic->getPicSym()->getSaoParam(); 350 for (Int cIdx=0; cIdx<3; cIdx++) 351 { 352 SaoLcuParam *saoLcuParam = &(saoParam->saoLcuParam[cIdx][addr]); 353 if ( ((cIdx == 0) && !pcSlice->getSaoEnabledFlag()) || ((cIdx == 1 || cIdx == 2) && !pcSlice->getSaoEnabledFlagChroma())) 354 { 355 saoLcuParam->mergeUpFlag = 0; 356 saoLcuParam->mergeLeftFlag = 0; 357 saoLcuParam->subTypeIdx = 0; 358 saoLcuParam->typeIdx = -1; 359 saoLcuParam->offset[0] = 0; 360 saoLcuParam->offset[1] = 0; 361 saoLcuParam->offset[2] = 0; 362 saoLcuParam->offset[3] = 0; 363 } 315 316 if ( pcSlice->getSPS()->getUseSAO() ) 317 { 318 SAOBlkParam& saoblkParam = (rpcPic->getPicSym()->getSAOBlkParam())[iCUAddr]; 319 if (pcSlice->getSaoEnabledFlag()||pcSlice->getSaoEnabledFlagChroma()) 320 { 321 Bool sliceEnabled[NUM_SAO_COMPONENTS]; 322 sliceEnabled[SAO_Y] = pcSlice->getSaoEnabledFlag(); 323 sliceEnabled[SAO_Cb]= sliceEnabled[SAO_Cr]= pcSlice->getSaoEnabledFlagChroma(); 324 325 Bool leftMergeAvail = false; 326 Bool aboveMergeAvail= false; 327 328 //merge left condition 329 Int rx = (iCUAddr % uiWidthInLCUs); 330 if(rx > 0) 331 { 332 leftMergeAvail = rpcPic->getSAOMergeAvailability(iCUAddr, iCUAddr-1); 333 } 334 //merge up condition 335 Int ry = (iCUAddr / uiWidthInLCUs); 336 if(ry > 0) 337 { 338 aboveMergeAvail = rpcPic->getSAOMergeAvailability(iCUAddr, iCUAddr-uiWidthInLCUs); 339 } 340 341 pcSbacDecoder->parseSAOBlkParam( saoblkParam, sliceEnabled, leftMergeAvail, aboveMergeAvail); 342 } 343 else 344 { 345 saoblkParam[SAO_Y ].modeIdc = SAO_MODE_OFF; 346 saoblkParam[SAO_Cb].modeIdc = SAO_MODE_OFF; 347 saoblkParam[SAO_Cr].modeIdc = SAO_MODE_OFF; 364 348 } 365 349 } -
branches/HTM-10.0-dev0/source/Lib/TLibDecoder/TDecSlice.h
r655 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/TLibDecoder/TDecTop.cpp
r773 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 467 467 rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 468 468 conformanceWindow, defaultDisplayWindow, numReorderPics, true); 469 rpcPic->getPicSym()->allocSaoParam(&m_cSAO);470 469 m_cListPic.pushBack( rpcPic ); 471 470 … … 505 504 rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 506 505 conformanceWindow, defaultDisplayWindow, numReorderPics, true); 507 rpcPic->getPicSym()->allocSaoParam(&m_cSAO);508 506 } 509 507 … … 662 660 663 661 m_cSAO.destroy(); 664 m_cSAO.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), sps->getMaxCUWidth(), sps->getMaxCUHeight() );662 m_cSAO.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth() ); 665 663 m_cLoopFilter.create( sps->getMaxCUDepth() ); 666 664 } … … 670 668 { 671 669 assert( nalu.m_layerId == m_layerId ); 672 673 670 #else 674 671 Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay ) … … 682 679 m_uiSliceIdx = 0; 683 680 } 681 else 682 { 683 m_apcSlicePilot->copySliceInfo( pcPic->getPicSym()->getSlice(m_uiSliceIdx-1) ); 684 } 684 685 m_apcSlicePilot->setSliceIdx(m_uiSliceIdx); 685 if (!m_bFirstSliceInPicture)686 {687 m_apcSlicePilot->copySliceInfo( pcPic->getPicSym()->getSlice(m_uiSliceIdx-1) );688 }689 686 690 687 m_apcSlicePilot->setNalUnitType(nalu.m_nalUnitType); … … 994 991 #endif 995 992 #else 996 #if FIX1071997 993 pcSlice->setRefPicList( m_cListPic, true ); 998 #else999 pcSlice->setRefPicList( m_cListPic );1000 #endif1001 1002 994 #endif 1003 995 … … 1215 1207 case NAL_UNIT_CODED_SLICE_TRAIL_R: 1216 1208 case NAL_UNIT_CODED_SLICE_TRAIL_N: 1217 case NAL_UNIT_CODED_SLICE_T LA_R:1209 case NAL_UNIT_CODED_SLICE_TSA_R: 1218 1210 case NAL_UNIT_CODED_SLICE_TSA_N: 1219 1211 case NAL_UNIT_CODED_SLICE_STSA_R: … … 1235 1227 #endif 1236 1228 break; 1229 case NAL_UNIT_EOS: 1230 m_associatedIRAPType = NAL_UNIT_INVALID; 1231 m_pocCRA = 0; 1232 m_pocRandomAccess = MAX_INT; 1233 m_prevPOC = MAX_INT; 1234 m_bFirstSliceInPicture = true; 1235 m_bFirstSliceInSequence = true; 1236 m_prevSliceSkipped = false; 1237 m_skippedPOC = 0; 1238 return false; 1239 1240 case NAL_UNIT_ACCESS_UNIT_DELIMITER: 1241 // TODO: process AU delimiter 1242 return false; 1243 1244 case NAL_UNIT_EOB: 1245 return false; 1246 1247 1248 case NAL_UNIT_RESERVED_VCL_N10: 1249 case NAL_UNIT_RESERVED_VCL_R11: 1250 case NAL_UNIT_RESERVED_VCL_N12: 1251 case NAL_UNIT_RESERVED_VCL_R13: 1252 case NAL_UNIT_RESERVED_VCL_N14: 1253 case NAL_UNIT_RESERVED_VCL_R15: 1254 1255 case NAL_UNIT_RESERVED_IRAP_VCL22: 1256 case NAL_UNIT_RESERVED_IRAP_VCL23: 1257 1258 case NAL_UNIT_RESERVED_VCL24: 1259 case NAL_UNIT_RESERVED_VCL25: 1260 case NAL_UNIT_RESERVED_VCL26: 1261 case NAL_UNIT_RESERVED_VCL27: 1262 case NAL_UNIT_RESERVED_VCL28: 1263 case NAL_UNIT_RESERVED_VCL29: 1264 case NAL_UNIT_RESERVED_VCL30: 1265 case NAL_UNIT_RESERVED_VCL31: 1266 1267 case NAL_UNIT_FILLER_DATA: 1268 case NAL_UNIT_RESERVED_NVCL41: 1269 case NAL_UNIT_RESERVED_NVCL42: 1270 case NAL_UNIT_RESERVED_NVCL43: 1271 case NAL_UNIT_RESERVED_NVCL44: 1272 case NAL_UNIT_RESERVED_NVCL45: 1273 case NAL_UNIT_RESERVED_NVCL46: 1274 case NAL_UNIT_RESERVED_NVCL47: 1275 case NAL_UNIT_UNSPECIFIED_48: 1276 case NAL_UNIT_UNSPECIFIED_49: 1277 case NAL_UNIT_UNSPECIFIED_50: 1278 case NAL_UNIT_UNSPECIFIED_51: 1279 case NAL_UNIT_UNSPECIFIED_52: 1280 case NAL_UNIT_UNSPECIFIED_53: 1281 case NAL_UNIT_UNSPECIFIED_54: 1282 case NAL_UNIT_UNSPECIFIED_55: 1283 case NAL_UNIT_UNSPECIFIED_56: 1284 case NAL_UNIT_UNSPECIFIED_57: 1285 case NAL_UNIT_UNSPECIFIED_58: 1286 case NAL_UNIT_UNSPECIFIED_59: 1287 case NAL_UNIT_UNSPECIFIED_60: 1288 case NAL_UNIT_UNSPECIFIED_61: 1289 case NAL_UNIT_UNSPECIFIED_62: 1290 case NAL_UNIT_UNSPECIFIED_63: 1237 1291 default: 1238 assert ( 1);1292 assert (0); 1239 1293 } 1240 1294 -
branches/HTM-10.0-dev0/source/Lib/TLibDecoder/TDecTop.h
r833 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/TLibEncoder/AnnexBwrite.h
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/TLibEncoder/NALwrite.cpp
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/TLibEncoder/NALwrite.h
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/TLibEncoder/SEIwrite.cpp
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 307 307 if( !hrd->getSubPicCpbParamsPresentFlag() ) 308 308 { 309 WRITE_FLAG( sei.m_rapCpbParamsPresentFlag, "rap_cpb_params_present_flag" ); 309 WRITE_FLAG( sei.m_rapCpbParamsPresentFlag, "irap_cpb_params_present_flag" ); 310 } 311 if( sei.m_rapCpbParamsPresentFlag ) 312 { 313 WRITE_CODE( sei.m_cpbDelayOffset, hrd->getCpbRemovalDelayLengthMinus1() + 1, "cpb_delay_offset" ); 314 WRITE_CODE( sei.m_dpbDelayOffset, hrd->getDpbOutputDelayLengthMinus1() + 1, "dpb_delay_offset" ); 310 315 } 311 316 WRITE_FLAG( sei.m_concatenationFlag, "concatenation_flag"); 312 317 WRITE_CODE( sei.m_auCpbRemovalDelayDelta - 1, ( hrd->getCpbRemovalDelayLengthMinus1() + 1 ), "au_cpb_removal_delay_delta_minus1" ); 313 if( sei.m_rapCpbParamsPresentFlag )314 {315 WRITE_CODE( sei.m_cpbDelayOffset, hrd->getCpbRemovalDelayLengthMinus1() + 1, "cpb_delay_offset" );316 WRITE_CODE( sei.m_dpbDelayOffset, hrd->getDpbOutputDelayLengthMinus1() + 1, "dpb_delay_offset" );317 }318 318 for( nalOrVcl = 0; nalOrVcl < 2; nalOrVcl ++ ) 319 319 { -
branches/HTM-10.0-dev0/source/Lib/TLibEncoder/SEIwrite.h
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/TLibEncoder/SyntaxElementWriter.cpp
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/TLibEncoder/SyntaxElementWriter.h
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/TLibEncoder/TEncAnalyze.cpp
r655 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/TLibEncoder/TEncAnalyze.h
r655 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/TLibEncoder/TEncBinCoder.h
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/TLibEncoder/TEncBinCoderCABAC.cpp
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/TLibEncoder/TEncBinCoderCABAC.h
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/TLibEncoder/TEncBinCoderCABACCounter.cpp
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/TLibEncoder/TEncBinCoderCABACCounter.h
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/TLibEncoder/TEncCavlc.cpp
r833 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 256 256 if( pcPPS->getScalingListPresentFlag() ) 257 257 { 258 #if SCALING_LIST_OUTPUT_RESULT259 printf("PPS\n");260 #endif261 258 codeScalingList( m_pcSlice->getScalingList() ); 262 259 } … … 742 739 if(pcSPS->getScalingListPresentFlag()) 743 740 { 744 #if SCALING_LIST_OUTPUT_RESULT745 printf("SPS\n");746 #endif747 741 codeScalingList( m_pcSlice->getScalingList() ); 748 742 } … … 1688 1682 TComReferencePictureSet* rps = pcSlice->getRPS(); 1689 1683 1690 #if FIX10711691 1684 // check for bitstream restriction stating that: 1692 1685 // If the current picture is a BLA or CRA picture, the value of NumPocTotalCurr shall be equal to 0. … … 1699 1692 } 1700 1693 } 1701 #endif1702 1694 1703 1695 if(pcSlice->getRPSidx() < 0) … … 1833 1825 { 1834 1826 WRITE_FLAG( pcSlice->getSaoEnabledFlag(), "slice_sao_luma_flag" ); 1835 { 1836 SAOParam *saoParam = pcSlice->getPic()->getPicSym()->getSaoParam(); 1837 WRITE_FLAG( saoParam->bSaoFlag[1], "slice_sao_chroma_flag" ); 1838 } 1827 WRITE_FLAG( pcSlice->getSaoEnabledFlagChroma(), "slice_sao_chroma_flag" ); 1839 1828 } 1840 1829 } … … 2429 2418 Bool scalingListPredModeFlag; 2430 2419 2431 #if SCALING_LIST_OUTPUT_RESULT2432 Int startBit;2433 Int startTotalBit;2434 startBit = m_pcBitIf->getNumberOfWrittenBits();2435 startTotalBit = m_pcBitIf->getNumberOfWrittenBits();2436 #endif2437 2438 2420 //for each size 2439 2421 for(sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++) … … 2441 2423 for(listId = 0; listId < g_scalingListNum[sizeId]; listId++) 2442 2424 { 2443 #if SCALING_LIST_OUTPUT_RESULT2444 startBit = m_pcBitIf->getNumberOfWrittenBits();2445 #endif2446 2425 scalingListPredModeFlag = scalingList->checkPredMode( sizeId, listId ); 2447 2426 WRITE_FLAG( scalingListPredModeFlag, "scaling_list_pred_mode_flag" ); … … 2454 2433 xCodeScalingList(scalingList, sizeId, listId); 2455 2434 } 2456 #if SCALING_LIST_OUTPUT_RESULT 2457 printf("Matrix [%d][%d] Bit %d\n",sizeId,listId,m_pcBitIf->getNumberOfWrittenBits() - startBit); 2458 #endif 2459 } 2460 } 2461 #if SCALING_LIST_OUTPUT_RESULT 2462 printf("Total Bit %d\n",m_pcBitIf->getNumberOfWrittenBits()-startTotalBit); 2463 #endif 2435 } 2436 } 2464 2437 return; 2465 2438 } -
branches/HTM-10.0-dev0/source/Lib/TLibEncoder/TEncCavlc.h
r833 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 120 120 121 121 Void codeMVPIdx ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ); 122 Void codeSAOSign ( UInt code ) { printf("Not supported\n"); assert (0); } 123 Void codeSaoMaxUvlc ( UInt code, UInt maxSymbol ){printf("Not supported\n"); assert (0);} 124 Void codeSaoMerge ( UInt uiCode ){printf("Not supported\n"); assert (0);} 125 Void codeSaoTypeIdx ( UInt uiCode ){printf("Not supported\n"); assert (0);} 126 Void codeSaoUflc ( UInt uiLength, UInt uiCode ){ assert(uiCode < 32); printf("Not supported\n"); assert (0);} 127 122 Void codeSAOBlkParam(SAOBlkParam& saoBlkParam, Bool* sliceEnabled, Bool leftMergeAvail, Bool aboveMergeAvail, Bool onlyEstMergeInfo = false){printf("only supported in CABAC"); assert(0); exit(-1);} 128 123 Void codeCUTransquantBypassFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ); 129 124 Void codeSkipFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx ); -
branches/HTM-10.0-dev0/source/Lib/TLibEncoder/TEncCfg.h
r833 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 177 177 Int m_maxNumOffsetsPerPic; 178 178 Bool m_saoLcuBoundary; 179 Bool m_saoLcuBasedOptimization;180 181 //====== Lossless ========182 Bool m_useLossless;183 179 //====== Motion search ======== 184 180 Int m_iFastSearch; // 0:Full search 1:Diamond 2:PMVFAST … … 201 197 202 198 //====== Tool list ======== 203 Bool m_bUseSBACRD;204 199 Bool m_bUseASR; 205 200 Bool m_bUseHADME; … … 292 287 Int m_TMVPModeId; 293 288 Int m_signHideFlag; 294 #if RATE_CONTROL_LAMBDA_DOMAIN295 289 Bool m_RCEnableRateControl; 296 290 Int m_RCTargetBitrate; 297 #if M0036_RC_IMPROVEMENT298 291 Int m_RCKeepHierarchicalBit; 299 #else300 Bool m_RCKeepHierarchicalBit;301 #endif302 292 Bool m_RCLCULevelRC; 303 293 Bool m_RCUseLCUSeparateModel; … … 311 301 Bool m_bViewWiseRateCtrl; 312 302 #endif 313 #else314 Bool m_enableRateCtrl; ///< Flag for using rate control algorithm315 Int m_targetBitrate; ///< target bitrate316 Int m_numLCUInUnit; ///< Total number of LCUs in a frame should be divided by the NumLCUInUnit317 318 #if KWU_RC_MADPRED_E0227319 UInt m_depthMADPred;320 #endif321 #if KWU_RC_VIEWRC_E0227322 Bool m_bViewWiseRateCtrl;323 #endif324 #endif325 303 Bool m_TransquantBypassEnableFlag; ///< transquant_bypass_enable_flag setting in PPS. 326 Bool m_CUTransquantBypassFlag Value; ///< if transquant_bypass_enable_flag, the fixed value to use for the per-CU cu_transquant_bypass_flag.304 Bool m_CUTransquantBypassFlagForce; ///< if transquant_bypass_enable_flag, then, if true, all CU transquant bypass flags will be set to true. 327 305 #if H_MV 328 306 TComVPS* m_cVPS; ///< pointer to VPS, same for all layers … … 573 551 Void setQPAdaptationRange ( Int i ) { m_iQPAdaptationRange = i; } 574 552 575 //====== Lossless ========576 Void setUseLossless (Bool b ) { m_useLossless = b; }577 553 //====== Sequence ======== 578 554 Int getFrameRate () { return m_iFrameRate; } … … 617 593 Bool getUseAdaptiveQP () { return m_bUseAdaptiveQP; } 618 594 Int getQPAdaptationRange () { return m_iQPAdaptationRange; } 619 //====== Lossless ========620 Bool getUseLossless () { return m_useLossless; }621 595 622 596 //==== Tool list ======== 623 Void setUseSBACRD ( Bool b ) { m_bUseSBACRD = b; }624 597 Void setUseASR ( Bool b ) { m_bUseASR = b; } 625 598 Void setUseHADME ( Bool b ) { m_bUseHADME = b; } … … 640 613 Void setdQPs ( Int* p ) { m_aidQP = p; } 641 614 Void setDeltaQpRD ( UInt u ) {m_uiDeltaQpRD = u; } 642 Bool getUseSBACRD () { return m_bUseSBACRD; }643 615 Bool getUseASR () { return m_bUseASR; } 644 616 Bool getUseHADME () { return m_bUseHADME; } … … 684 656 Void setSaoLcuBoundary (Bool val) { m_saoLcuBoundary = val; } 685 657 Bool getSaoLcuBoundary () { return m_saoLcuBoundary; } 686 Void setSaoLcuBasedOptimization (Bool val) { m_saoLcuBasedOptimization = val; }687 Bool getSaoLcuBasedOptimization () { return m_saoLcuBasedOptimization; }688 658 Void setLFCrossTileBoundaryFlag ( Bool val ) { m_loopFilterAcrossTilesEnabledFlag = val; } 689 659 Bool getLFCrossTileBoundaryFlag () { return m_loopFilterAcrossTilesEnabledFlag; } … … 825 795 Void setSignHideFlag( Int signHideFlag ) { m_signHideFlag = signHideFlag; } 826 796 Int getSignHideFlag() { return m_signHideFlag; } 827 #if RATE_CONTROL_LAMBDA_DOMAIN828 797 Bool getUseRateCtrl () { return m_RCEnableRateControl; } 829 798 Void setUseRateCtrl ( Bool b ) { m_RCEnableRateControl = b; } 830 799 Int getTargetBitrate () { return m_RCTargetBitrate; } 831 800 Void setTargetBitrate ( Int bitrate ) { m_RCTargetBitrate = bitrate; } 832 #if M0036_RC_IMPROVEMENT833 801 Int getKeepHierBit () { return m_RCKeepHierarchicalBit; } 834 802 Void setKeepHierBit ( Int i ) { m_RCKeepHierarchicalBit = i; } 835 #else836 Bool getKeepHierBit () { return m_RCKeepHierarchicalBit; }837 Void setKeepHierBit ( Bool b ) { m_RCKeepHierarchicalBit = b; }838 #endif839 803 Bool getLCULevelRC () { return m_RCLCULevelRC; } 840 804 Void setLCULevelRC ( Bool b ) { m_RCLCULevelRC = b; } … … 854 818 Void setUseViewWiseRateCtrl (Bool b) { m_bViewWiseRateCtrl = b; } 855 819 #endif 856 #else857 Bool getUseRateCtrl () { return m_enableRateCtrl; }858 Void setUseRateCtrl (Bool flag) { m_enableRateCtrl = flag; }859 Int getTargetBitrate () { return m_targetBitrate; }860 Void setTargetBitrate (Int target) { m_targetBitrate = target; }861 Int getNumLCUInUnit () { return m_numLCUInUnit; }862 Void setNumLCUInUnit (Int numLCUs) { m_numLCUInUnit = numLCUs; }863 864 #if KWU_RC_MADPRED_E0227865 UInt getUseDepthMADPred () { return m_depthMADPred; }866 Void setUseDepthMADPred (UInt b) { m_depthMADPred = b; }867 #endif868 #if KWU_RC_VIEWRC_E0227869 Bool getUseViewWiseRateCtrl () { return m_bViewWiseRateCtrl; }870 Void setUseViewWiseRateCtrl (Bool b) { m_bViewWiseRateCtrl = b; }871 #endif872 #endif873 820 Bool getTransquantBypassEnableFlag() { return m_TransquantBypassEnableFlag; } 874 821 Void setTransquantBypassEnableFlag(Bool flag) { m_TransquantBypassEnableFlag = flag; } 875 Bool getCUTransquantBypassFlag Value() { return m_CUTransquantBypassFlagValue; }876 Void setCUTransquantBypassFlag Value(Bool flag) { m_CUTransquantBypassFlagValue = flag; }822 Bool getCUTransquantBypassFlagForceValue() { return m_CUTransquantBypassFlagForce; } 823 Void setCUTransquantBypassFlagForceValue(Bool flag) { m_CUTransquantBypassFlagForce = flag; } 877 824 #if H_MV 878 825 Void setVPS ( TComVPS *p ) { m_cVPS = p; } -
branches/HTM-10.0-dev0/source/Lib/TLibEncoder/TEncCu.cpp
r833 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 40 40 #include "TEncCu.h" 41 41 #include "TEncAnalyze.h" 42 43 42 #include <cmath> 44 43 #include <algorithm> … … 109 108 110 109 m_bEncodeDQP = false; 111 #if RATE_CONTROL_LAMBDA_DOMAIN 112 #if !M0036_RC_IMPROVEMENT 113 m_LCUPredictionSAD = 0; 114 m_addSADDepth = 0; 115 m_temporalSAD = 0; 116 #endif 117 #if M0036_RC_IMPROVEMENT && KWU_RC_MADPRED_E0227 118 m_LCUPredictionSAD = 0; 119 m_addSADDepth = 0; 120 m_temporalSAD = 0; 121 m_spatialSAD = 0; 122 #endif 123 #endif 124 #if !RATE_CONTROL_LAMBDA_DOMAIN && KWU_RC_MADPRED_E0227 110 #if KWU_RC_MADPRED_E0227 125 111 m_LCUPredictionSAD = 0; 126 112 m_addSADDepth = 0; … … 273 259 m_pcRDGoOnSbacCoder = pcEncTop->getRDGoOnSbacCoder(); 274 260 275 m_bUseSBACRD = pcEncTop->getUseSBACRD();276 261 m_pcRateCtrl = pcEncTop->getRateCtrl(); 277 262 } … … 289 274 m_ppcTempCU[0]->initCU( rpcCU->getPic(), rpcCU->getAddr() ); 290 275 291 #if RATE_CONTROL_LAMBDA_DOMAIN292 #if !M0036_RC_IMPROVEMENT293 m_addSADDepth = 0;294 m_LCUPredictionSAD = 0;295 m_temporalSAD = 0;296 #endif297 #if M0036_RC_IMPROVEMENT && KWU_RC_MADPRED_E0227298 m_LCUPredictionSAD = 0;299 m_addSADDepth = 0;300 m_temporalSAD = 0;301 m_spatialSAD = 0;302 #endif303 #endif304 276 #if KWU_RC_MADPRED_E0227 305 277 m_LCUPredictionSAD = 0; … … 449 421 // get Original YUV data from picture 450 422 m_ppcOrigYuv[uiDepth]->copyFromPicYuv( pcPic->getPicYuvOrg(), rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU() ); 451 452 // variables for fast encoder decision 423 453 424 #if H_3D_QTLPC 454 425 Bool bTrySplit = true; … … 478 449 UInt uiBPelY = uiTPelY + rpcBestCU->getHeight(0) - 1; 479 450 451 #if H_MV_ENC_DEC_TRAC 452 #if ENC_DEC_TRACE 453 stopAtPos ( rpcBestCU->getSlice()->getPOC(), 454 rpcBestCU->getSlice()->getLayerId(), 455 rpcBestCU->getCUPelX(), 456 rpcBestCU->getCUPelY(), 457 rpcBestCU->getWidth(0), 458 rpcBestCU->getHeight(0) ); 459 #endif 460 #endif 461 480 462 Int iBaseQP = xComputeQP( rpcBestCU, uiDepth ); 481 463 Int iMinQP; 482 464 Int iMaxQP; 483 465 Bool isAddLowestQP = false; 484 Int lowestQP = -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY();485 466 486 467 if( (g_uiMaxCUWidth>>uiDepth) >= rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() ) … … 489 470 iMinQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP-idQP ); 490 471 iMaxQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP+idQP ); 491 if ( (rpcTempCU->getSlice()->getSPS()->getUseLossless()) && (lowestQP < iMinQP) && rpcTempCU->getSlice()->getPPS()->getUseDQP() )492 {493 isAddLowestQP = true;494 iMinQP = iMinQP - 1;495 }496 472 } 497 473 else … … 501 477 } 502 478 503 #if RATE_CONTROL_LAMBDA_DOMAIN504 479 if ( m_pcEncCfg->getUseRateCtrl() ) 505 480 { … … 507 482 iMaxQP = m_pcRateCtrl->getRCQP(); 508 483 } 509 #else 510 if(m_pcEncCfg->getUseRateCtrl()) 511 { 512 Int qp = m_pcRateCtrl->getUnitQP(); 513 iMinQP = Clip3( MIN_QP, MAX_QP, qp); 514 iMaxQP = Clip3( MIN_QP, MAX_QP, qp); 515 } 516 #endif 484 // transquant-bypass (TQB) processing loop variable initialisation --- 485 486 const Int lowestQP = iMinQP; // For TQB, use this QP which is the lowest non TQB QP tested (rather than QP'=0) - that way delta QPs are smaller, and TQB can be tested at all CU levels. 487 488 if ( (rpcTempCU->getSlice()->getPPS()->getTransquantBypassEnableFlag()) ) 489 { 490 isAddLowestQP = true; // mark that the first iteration is to cost TQB mode. 491 iMinQP = iMinQP - 1; // increase loop variable range by 1, to allow testing of TQB mode along with other QPs 492 if ( m_pcEncCfg->getCUTransquantBypassFlagForceValue() ) 493 { 494 iMaxQP = iMinQP; 495 } 496 } 497 517 498 #if H_3D_IC 518 499 Bool bICEnabled = rpcTempCU->getSlice()->getViewIndex() && ( rpcTempCU->getSlice()->getSliceType() == P_SLICE || rpcTempCU->getSlice()->getSliceType() == B_SLICE ) && !rpcTempCU->getSlice()->getIsDepth(); … … 534 515 for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++) 535 516 { 536 if (isAddLowestQP && (iQP == iMinQP)) 517 const Bool bIsLosslessMode = isAddLowestQP && (iQP == iMinQP); 518 519 if (bIsLosslessMode) 537 520 { 538 521 iQP = lowestQP; 539 522 } 540 // variables for fast encoder decision 523 541 524 #if H_3D_QTLPC 542 525 bTrySplit = true; 543 526 #endif 544 527 545 rpcTempCU->initEstData( uiDepth, iQP );528 rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); 546 529 #if H_3D_QTLPC 547 530 //logic for setting bTrySplit using the partition information that is stored of the texture colocated CU … … 647 630 #endif 648 631 #if H_3D_FAST_TEXTURE_ENCODING 649 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N, bFMD ); rpcTempCU->initEstData( uiDepth, iQP );//by Competition for inter_2Nx2N 650 #else 651 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N ); rpcTempCU->initEstData( uiDepth, iQP );//by Competition for inter_2Nx2N 632 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N, bFMD ); rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );//by Competition for inter_2Nx2N 633 #else 634 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N ); 635 rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );//by Competition for inter_2Nx2N 652 636 #endif 653 637 #if H_3D_VSP … … 663 647 bFMD = bIVFMerge && rpcBestCU->isSkipped(0); 664 648 #endif 665 rpcTempCU->initEstData( uiDepth, iQP );649 rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); 666 650 #if H_3D_VSP 667 651 rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); … … 675 659 #endif 676 660 #if H_3D_FAST_TEXTURE_ENCODING 677 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N, bFMD ); rpcTempCU->initEstData( uiDepth, iQP ); 678 #else 679 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N ); rpcTempCU->initEstData( uiDepth, iQP ); 661 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N, bFMD ); rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); 662 #else 663 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N ); 664 rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); 680 665 #endif 681 666 #if H_3D_VSP … … 687 672 { 688 673 xCheckRDCostInterDBBP( rpcBestCU, rpcTempCU, false ); 689 rpcTempCU->initEstData( uiDepth, iQP );674 rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); 690 675 #if H_3D_VSP 691 676 rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); … … 710 695 } 711 696 #endif 712 if ( isAddLowestQP && (iQP == lowestQP))697 if ( bIsLosslessMode ) 713 698 { 714 699 iQP = iMinQP; … … 716 701 } 717 702 718 #if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT703 #if KWU_RC_MADPRED_E0227 719 704 if ( uiDepth <= m_addSADDepth ) 720 705 { … … 723 708 } 724 709 #endif 725 #if RATE_CONTROL_LAMBDA_DOMAIN && M0036_RC_IMPROVEMENT && KWU_RC_MADPRED_E0227726 if ( uiDepth <= m_addSADDepth )727 {728 m_LCUPredictionSAD += m_temporalSAD;729 m_addSADDepth = uiDepth;730 }731 #endif732 #if !RATE_CONTROL_LAMBDA_DOMAIN && KWU_RC_MADPRED_E0227733 if ( uiDepth <= m_addSADDepth )734 {735 m_LCUPredictionSAD += m_temporalSAD;736 m_addSADDepth = uiDepth;737 }738 #endif739 #if !RATE_CONTROL_LAMBDA_DOMAIN && KWU_FIX_URQ740 if(m_pcEncCfg->getUseRateCtrl())741 {742 Int qp = m_pcRateCtrl->getUnitQP();743 iMinQP = Clip3( MIN_QP, MAX_QP, qp);744 iMaxQP = Clip3( MIN_QP, MAX_QP, qp);745 }746 #endif747 748 710 #if H_3D_DIM_ENC 749 711 if( rpcBestCU->getSlice()->getIsDepth() && rpcBestCU->getSlice()->isIRAP() ) … … 757 719 for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++) 758 720 { 759 if (isAddLowestQP && (iQP == iMinQP)) 721 const Bool bIsLosslessMode = isAddLowestQP && (iQP == iMinQP); 722 723 if (bIsLosslessMode) 760 724 { 761 725 iQP = lowestQP; 762 726 } 763 rpcTempCU->initEstData( uiDepth, iQP );727 rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); 764 728 765 729 // do inter modes, NxN, 2NxN, and Nx2N … … 780 744 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_NxN ); 781 745 #endif 782 rpcTempCU->initEstData( uiDepth, iQP );746 rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); 783 747 #if H_3D_VSP 784 748 rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); … … 799 763 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_Nx2N ); 800 764 #endif 801 rpcTempCU->initEstData( uiDepth, iQP );765 rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); 802 766 #if H_3D_VSP 803 767 rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); … … 819 783 xCheckRDCostInter ( rpcBestCU, rpcTempCU, SIZE_2NxN ); 820 784 #endif 821 rpcTempCU->initEstData( uiDepth, iQP );785 rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); 822 786 #if H_3D_VSP 823 787 rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); … … 858 822 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU ); 859 823 #endif 860 rpcTempCU->initEstData( uiDepth, iQP );824 rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); 861 825 #if H_3D_VSP 862 826 rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); … … 878 842 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD ); 879 843 #endif 880 rpcTempCU->initEstData( uiDepth, iQP );844 rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); 881 845 #if H_3D_VSP 882 846 rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); … … 902 866 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU, true ); 903 867 #endif 904 rpcTempCU->initEstData( uiDepth, iQP );868 rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); 905 869 #if H_3D_VSP 906 870 rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); … … 922 886 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD, true ); 923 887 #endif 924 rpcTempCU->initEstData( uiDepth, iQP );888 rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); 925 889 #if H_3D_VSP 926 890 rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); … … 948 912 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N ); 949 913 #endif 950 rpcTempCU->initEstData( uiDepth, iQP );914 rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); 951 915 #if H_3D_VSP 952 916 rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); … … 968 932 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N ); 969 933 #endif 970 rpcTempCU->initEstData( uiDepth, iQP );934 rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); 971 935 #if H_3D_VSP 972 936 rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); … … 988 952 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N, true ); 989 953 #endif 990 rpcTempCU->initEstData( uiDepth, iQP );954 rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); 991 955 #if H_3D_VSP 992 956 rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); … … 1008 972 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N, true ); 1009 973 #endif 1010 rpcTempCU->initEstData( uiDepth, iQP );974 rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); 1011 975 #if H_3D_VSP 1012 976 rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); … … 1022 986 #endif 1023 987 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU ); 1024 rpcTempCU->initEstData( uiDepth, iQP );988 rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); 1025 989 #if H_3D_VSP 1026 990 rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); 1027 991 #endif 1028 992 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD ); 1029 rpcTempCU->initEstData( uiDepth, iQP );993 rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); 1030 994 #if H_3D_VSP 1031 995 rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); … … 1037 1001 #endif 1038 1002 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N ); 1039 rpcTempCU->initEstData( uiDepth, iQP );1003 rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); 1040 1004 #if H_3D_VSP 1041 1005 rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); 1042 1006 #endif 1043 1007 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N ); 1044 rpcTempCU->initEstData( uiDepth, iQP );1008 rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); 1045 1009 #if H_3D_VSP 1046 1010 rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); … … 1072 1036 xCheckRDCostIntra( rpcBestCU, rpcTempCU, SIZE_2Nx2N ); 1073 1037 1074 #if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT &&KWU_RC_MADPRED_E02271038 #if KWU_RC_MADPRED_E0227 1075 1039 if ( uiDepth <= m_addSADDepth ) 1076 1040 { … … 1079 1043 } 1080 1044 #endif 1081 #if RATE_CONTROL_LAMBDA_DOMAIN && M0036_RC_IMPROVEMENT && KWU_RC_MADPRED_E0227 1082 if ( uiDepth <= m_addSADDepth ) 1083 { 1084 m_LCUPredictionSAD += m_spatialSAD; 1085 m_addSADDepth = uiDepth; 1086 } 1087 #endif 1088 1089 #if !RATE_CONTROL_LAMBDA_DOMAIN && KWU_RC_MADPRED_E0227 1090 if ( uiDepth <= m_addSADDepth ) 1091 { 1092 m_LCUPredictionSAD += m_spatialSAD; 1093 m_addSADDepth = uiDepth; 1094 } 1095 #endif 1096 rpcTempCU->initEstData( uiDepth, iQP ); 1045 1046 rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); 1097 1047 if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) 1098 1048 { … … 1104 1054 { 1105 1055 xCheckRDCostIntra( rpcBestCU, rpcTempCU, SIZE_NxN ); 1106 rpcTempCU->initEstData( uiDepth, iQP );1056 rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); 1107 1057 } 1108 1058 #if H_3D_QTLPC … … 1126 1076 { 1127 1077 xCheckIntraPCM (rpcBestCU, rpcTempCU); 1128 rpcTempCU->initEstData( uiDepth, iQP );1078 rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); 1129 1079 } 1130 1080 } … … 1132 1082 } 1133 1083 #endif 1134 if ( isAddLowestQP && (iQP == lowestQP))1084 if (bIsLosslessMode) 1135 1085 { 1136 1086 iQP = iMinQP; … … 1142 1092 m_pcEntropyCoder->encodeSplitFlag( rpcBestCU, 0, uiDepth, true ); 1143 1093 rpcBestCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // split bits 1144 if(m_pcEncCfg->getUseSBACRD())1145 {1146 1094 rpcBestCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); 1147 } 1148 1149 #if H_3D_VSO // M8 1095 #if H_3D_VSO // M8 1150 1096 if ( m_pcRdCost->getUseVSO() ) 1151 1097 rpcBestCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcBestCU->getTotalBits(), rpcBestCU->getTotalDistortion() ); … … 1173 1119 { 1174 1120 bBoundary = true; 1175 #if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT1176 m_addSADDepth++;1177 #endif1178 1121 } 1179 1122 … … 1188 1131 iMinQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP-idQP ); 1189 1132 iMaxQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP+idQP ); 1190 if ( (rpcTempCU->getSlice()->getSPS()->getUseLossless()) && (lowestQP < iMinQP) && rpcTempCU->getSlice()->getPPS()->getUseDQP() )1191 {1192 isAddLowestQP = true;1193 iMinQP = iMinQP - 1;1194 }1195 1133 } 1196 1134 else if( (g_uiMaxCUWidth>>uiDepth) > rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() ) … … 1214 1152 iMaxQP = iStartQP; 1215 1153 } 1216 #if RATE_CONTROL_LAMBDA_DOMAIN1217 1154 if ( m_pcEncCfg->getUseRateCtrl() ) 1218 1155 { … … 1220 1157 iMaxQP = m_pcRateCtrl->getRCQP(); 1221 1158 } 1222 #else 1223 if(m_pcEncCfg->getUseRateCtrl()) 1224 { 1225 Int qp = m_pcRateCtrl->getUnitQP(); 1226 iMinQP = Clip3( MIN_QP, MAX_QP, qp); 1227 iMaxQP = Clip3( MIN_QP, MAX_QP, qp); 1228 } 1229 #endif 1159 1160 if ( m_pcEncCfg->getCUTransquantBypassFlagForceValue() ) 1161 { 1162 iMaxQP = iMinQP; // If all blocks are forced into using transquant bypass, do not loop here. 1163 } 1230 1164 for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++) 1231 1165 { 1232 if (isAddLowestQP && (iQP == iMinQP)) 1233 { 1234 iQP = lowestQP; 1235 } 1236 rpcTempCU->initEstData( uiDepth, iQP ); 1166 const Bool bIsLosslessMode = false; // False at this level. Next level down may set it to true. 1167 rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); 1237 1168 1238 1169 // further split … … 1267 1198 if(bInSlice && ( pcSubBestPartCU->getCUPelX() < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( pcSubBestPartCU->getCUPelY() < pcSlice->getSPS()->getPicHeightInLumaSamples() ) ) 1268 1199 { 1269 if ( m_bUseSBACRD )1200 if ( 0 == uiPartUnitIdx) //initialize RD with previous depth buffer 1270 1201 { 1271 if ( 0 == uiPartUnitIdx) //initialize RD with previous depth buffer 1272 { 1273 m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]); 1274 } 1275 else 1276 { 1277 m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]); 1278 } 1202 m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]); 1203 } 1204 else 1205 { 1206 m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]); 1279 1207 } 1280 1208 … … 1308 1236 1309 1237 rpcTempCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // split bits 1310 if(m_pcEncCfg->getUseSBACRD()) 1311 { 1312 rpcTempCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); 1313 } 1238 rpcTempCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); 1314 1239 } 1315 1316 1240 #if H_3D_VSO // M10 1317 1241 if ( m_pcRdCost->getUseVSO() ) … … 1319 1243 else 1320 1244 #endif 1321 rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );1245 rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); 1322 1246 1323 1247 if( (g_uiMaxCUWidth>>uiDepth) == rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() && rpcTempCU->getSlice()->getPPS()->getUseDQP()) … … 1327 1251 { 1328 1252 if( ( pcPic->getCU( rpcTempCU->getAddr() )->getSliceSegmentStartCU(uiBlkIdx+rpcTempCU->getZorderIdxInCU()) == rpcTempCU->getSlice()->getSliceSegmentCurStartCUAddr() ) && 1329 1253 ( rpcTempCU->getCbf( uiBlkIdx, TEXT_LUMA ) || rpcTempCU->getCbf( uiBlkIdx, TEXT_CHROMA_U ) || rpcTempCU->getCbf( uiBlkIdx, TEXT_CHROMA_V ) ) ) 1330 1254 { 1331 1255 hasResidual = true; … … 1349 1273 m_pcEntropyCoder->encodeQP( rpcTempCU, uiTargetPartIdx, false ); 1350 1274 rpcTempCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // dQP bits 1351 if(m_pcEncCfg->getUseSBACRD()) 1352 { 1353 rpcTempCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); 1354 } 1275 rpcTempCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); 1355 1276 #if H_3D_VSO // M11 1356 1277 if ( m_pcRdCost->getUseLambdaScaleVSO()) … … 1358 1279 else 1359 1280 #endif 1360 rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );1281 rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); 1361 1282 #endif 1362 1283 … … 1371 1292 } 1372 1293 1373 if( m_bUseSBACRD ) 1374 { 1375 m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]); 1376 } 1294 m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]); 1377 1295 Bool isEndOfSlice = rpcBestCU->getSlice()->getSliceMode()==FIXED_NUMBER_OF_BYTES 1378 1296 && (rpcBestCU->getTotalBits()>rpcBestCU->getSlice()->getSliceArgument()<<3); 1379 1297 Bool isEndOfSliceSegment = rpcBestCU->getSlice()->getSliceSegmentMode()==FIXED_NUMBER_OF_BYTES 1380 1298 && (rpcBestCU->getTotalBits()>rpcBestCU->getSlice()->getSliceSegmentArgument()<<3); 1381 1299 if(isEndOfSlice||isEndOfSliceSegment) 1382 1300 { … … 1385 1303 xCheckBestMode( rpcBestCU, rpcTempCU, uiDepth); // RD compare current larger prediction 1386 1304 } // with sub partitioned prediction. 1387 if (isAddLowestQP && (iQP == lowestQP)) 1388 { 1389 iQP = iMinQP; 1390 } 1391 } 1392 1305 } 1393 1306 1394 1307 #if H_3D_VSO // M12 … … 1402 1315 } 1403 1316 #endif 1404 1405 1317 rpcBestCU->copyToPic(uiDepth); // Copy Best data to Picture for next partition prediction. 1406 1318 … … 1683 1595 } 1684 1596 1685 #if RATE_CONTROL_INTRA1686 1597 Int xCalcHADs8x8_ISlice(Pel *piOrg, Int iStrideOrg) 1687 1598 { … … 1798 1709 return(iSumHad); 1799 1710 } 1800 #endif1801 1711 1802 1712 /** check RD costs for a CU block encoded with merge … … 1816 1726 #endif 1817 1727 Int numValidMergeCand = 0; 1728 const Bool bTransquantBypassFlag = rpcTempCU->getCUTransquantBypass(0); 1818 1729 1819 1730 for( UInt ui = 0; ui < rpcTempCU->getSlice()->getMaxNumMergeCand(); ++ui ) … … 1840 1751 #else 1841 1752 rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); // interprets depth relative to LCU level 1842 rpcTempCU->setCUTransquantBypassSubParts( m_pcEncCfg->getCUTransquantBypassFlagValue(), 0, uhDepth );1843 1753 #endif 1844 1754 … … 1876 1786 #endif 1877 1787 #if H_3D_ARP 1878 for( UInt ui = 0; ui < rpcTempCU->getSlice()->getMaxNumMergeCand(); ++ui )1879 #else 1880 for( UInt ui = 0; ui < numValidMergeCand; ++ui )1788 for( UInt ui = 0; ui < rpcTempCU->getSlice()->getMaxNumMergeCand(); ++ui ) 1789 #else 1790 for( UInt ui = 0; ui < numValidMergeCand; ++ui ) 1881 1791 #endif 1882 1792 { … … 1910 1820 memset( mergeCandBuffer, 0, MRG_MAX_NUM_CANDS_MEM*sizeof(Int) ); 1911 1821 rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); // interprets depth relative to LCU level 1822 #if !UPDATE_HM13 1912 1823 rpcTempCU->setCUTransquantBypassSubParts( m_pcEncCfg->getCUTransquantBypassFlagValue(), 0, uhDepth ); 1824 #endif 1913 1825 rpcTempCU->setARPWSubParts( (UChar)nARPW , 0 , uhDepth ); 1914 1826 #if H_3D_IC … … 1949 1861 #endif 1950 1862 1951 for( UInt uiNoResidual = 0; uiNoResidual < iteration; ++uiNoResidual )1952 {1953 for( UInt uiMergeCand = 0; uiMergeCand < numValidMergeCand; ++uiMergeCand )1954 {1863 for( UInt uiNoResidual = 0; uiNoResidual < iteration; ++uiNoResidual ) 1864 { 1865 for( UInt uiMergeCand = 0; uiMergeCand < numValidMergeCand; ++uiMergeCand ) 1866 { 1955 1867 #if H_3D_IC 1956 1868 if( rpcTempCU->getSlice()->getApplyIC() && rpcTempCU->getSlice()->getIcSkipParseFlag() ) … … 1964 1876 if(!(uiNoResidual==1 && mergeCandBuffer[uiMergeCand]==1)) 1965 1877 { 1966 if( !(bestIsSkip && uiNoResidual == 0) )1967 {1968 // set MC parameters1969 rpcTempCU->setPredModeSubParts( MODE_INTER, 0, uhDepth ); // interprets depth relative to LCU level1970 rpcTempCU->setCUTransquantBypassSubParts( m_pcEncCfg->getCUTransquantBypassFlagValue(), 0, uhDepth );1971 rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); // interprets depth relative to LCU level1878 if( !(bestIsSkip && uiNoResidual == 0) ) 1879 { 1880 // set MC parameters 1881 rpcTempCU->setPredModeSubParts( MODE_INTER, 0, uhDepth ); // interprets depth relative to LCU level 1882 rpcTempCU->setCUTransquantBypassSubParts( bTransquantBypassFlag, 0, uhDepth ); 1883 rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); // interprets depth relative to LCU level 1972 1884 #if H_3D_IC 1973 rpcTempCU->setICFlagSubParts( bICFlag, 0, 0, uhDepth );1885 rpcTempCU->setICFlagSubParts( bICFlag, 0, 0, uhDepth ); 1974 1886 #endif 1975 1887 #if H_3D_ARP 1976 rpcTempCU->setARPWSubParts( (UChar)nARPW , 0 , uhDepth );1977 #endif 1978 rpcTempCU->setMergeFlagSubParts( true, 0, 0, uhDepth ); // interprets depth relative to LCU level1979 rpcTempCU->setMergeIndexSubParts( uiMergeCand, 0, 0, uhDepth ); // interprets depth relative to LCU level1888 rpcTempCU->setARPWSubParts( (UChar)nARPW , 0 , uhDepth ); 1889 #endif 1890 rpcTempCU->setMergeFlagSubParts( true, 0, 0, uhDepth ); // interprets depth relative to LCU level 1891 rpcTempCU->setMergeIndexSubParts( uiMergeCand, 0, 0, uhDepth ); // interprets depth relative to LCU level 1980 1892 #if H_3D_VSP 1981 rpcTempCU->setVSPFlagSubParts( vspFlag[uiMergeCand], 0, 0, uhDepth ); 1982 rpcTempCU->setDvInfoSubParts(inheritedVSPDisInfo[uiMergeCand].m_acDvInfo, 0, 0, uhDepth ); 1983 #endif 1984 1893 rpcTempCU->setVSPFlagSubParts( vspFlag[uiMergeCand], 0, 0, uhDepth ); 1894 rpcTempCU->setDvInfoSubParts(inheritedVSPDisInfo[uiMergeCand].m_acDvInfo, 0, 0, uhDepth ); 1895 #endif 1985 1896 #if MTK_DDD_G0063 1986 if( rpcTempCU->getSlice()->getIsDepth() && rpcTempCU->getSlice()->getViewIndex() != 0 && iDDDCand == uiMergeCand )1987 {1897 if( rpcTempCU->getSlice()->getIsDepth() && rpcTempCU->getSlice()->getViewIndex() != 0 && iDDDCand == uiMergeCand ) 1898 { 1988 1899 rpcTempCU->setUseDDD( true, 0, 0, uhDepth ); 1989 1900 rpcTempCU->setDDDepthSubParts( ucDDDepth, 0, 0, uhDepth ); 1990 }1991 else1992 {1993 rpcTempCU->setUseDDD( false, 0, 0, uhDepth );1994 }1995 #endif1996 1997 #if H_3D_SPIVMP1998 rpcTempCU->setSPIVMPFlagSubParts(bSPIVMPFlag[uiMergeCand], 0, 0, uhDepth);1999 if (bSPIVMPFlag[uiMergeCand])2000 {2001 UInt uiSPAddr;2002 Int iWidth = rpcTempCU->getWidth(0);2003 Int iHeight = rpcTempCU->getHeight(0);2004 2005 Int iNumSPInOneLine, iNumSP, iSPWidth, iSPHeight;2006 2007 rpcTempCU->getSPPara(iWidth, iHeight, iNumSP, iNumSPInOneLine, iSPWidth, iSPHeight);2008 2009 for (Int iPartitionIdx = 0; iPartitionIdx < iNumSP; iPartitionIdx++)2010 {2011 rpcTempCU->getSPAbsPartIdx(0, iSPWidth, iSPHeight, iPartitionIdx, iNumSPInOneLine, uiSPAddr);2012 rpcTempCU->setInterDirSP(puhInterDirSP[iPartitionIdx], uiSPAddr, iSPWidth, iSPHeight);2013 rpcTempCU->getCUMvField( REF_PIC_LIST_0 )->setMvFieldSP(rpcTempCU, uiSPAddr, pcMvFieldSP[2*iPartitionIdx], iSPWidth, iSPHeight);2014 rpcTempCU->getCUMvField( REF_PIC_LIST_1 )->setMvFieldSP(rpcTempCU, uiSPAddr, pcMvFieldSP[2*iPartitionIdx + 1], iSPWidth, iSPHeight);2015 }2016 }2017 else2018 #endif2019 #if NTT_STORE_SPDV_VSP_G01482020 if ( vspFlag[uiMergeCand] )2021 {2022 UInt partAddr;2023 Int vspSize;2024 Int width, height;2025 rpcTempCU->getPartIndexAndSize( 0, partAddr, width, height );2026 2027 if( uhInterDirNeighbours[ uiMergeCand ] & 0x01 )2028 {2029 rpcTempCU->setMvFieldPUForVSP( rpcTempCU, partAddr, width, height, REF_PIC_LIST_0, cMvFieldNeighbours[ 2*uiMergeCand + 0 ].getRefIdx(), vspSize );2030 rpcTempCU->setVSPFlag( partAddr, vspSize );2031 1901 } 2032 1902 else 2033 1903 { 2034 rpcTempCU-> getCUMvField( REF_PIC_LIST_0 )->setAllMvField( cMvFieldNeighbours[0 + 2*uiMergeCand], SIZE_2Nx2N, 0, 0 ); // interprets depth relative to rpcTempCU level1904 rpcTempCU->setUseDDD( false, 0, 0, uhDepth ); 2035 1905 } 2036 if( uhInterDirNeighbours[ uiMergeCand ] & 0x02 ) 1906 #endif 1907 #if H_3D_SPIVMP 1908 rpcTempCU->setSPIVMPFlagSubParts(bSPIVMPFlag[uiMergeCand], 0, 0, uhDepth); 1909 if (bSPIVMPFlag[uiMergeCand]) 2037 1910 { 2038 rpcTempCU->setMvFieldPUForVSP( rpcTempCU, partAddr, width, height, REF_PIC_LIST_1 , cMvFieldNeighbours[ 2*uiMergeCand + 1 ].getRefIdx(), vspSize ); 2039 rpcTempCU->setVSPFlag( partAddr, vspSize ); 1911 UInt uiSPAddr; 1912 Int iWidth = rpcTempCU->getWidth(0); 1913 Int iHeight = rpcTempCU->getHeight(0); 1914 Int iNumSPInOneLine, iNumSP, iSPWidth, iSPHeight; 1915 rpcTempCU->getSPPara(iWidth, iHeight, iNumSP, iNumSPInOneLine, iSPWidth, iSPHeight); 1916 for (Int iPartitionIdx = 0; iPartitionIdx < iNumSP; iPartitionIdx++) 1917 { 1918 rpcTempCU->getSPAbsPartIdx(0, iSPWidth, iSPHeight, iPartitionIdx, iNumSPInOneLine, uiSPAddr); 1919 rpcTempCU->setInterDirSP(puhInterDirSP[iPartitionIdx], uiSPAddr, iSPWidth, iSPHeight); 1920 rpcTempCU->getCUMvField( REF_PIC_LIST_0 )->setMvFieldSP(rpcTempCU, uiSPAddr, pcMvFieldSP[2*iPartitionIdx], iSPWidth, iSPHeight); 1921 rpcTempCU->getCUMvField( REF_PIC_LIST_1 )->setMvFieldSP(rpcTempCU, uiSPAddr, pcMvFieldSP[2*iPartitionIdx + 1], iSPWidth, iSPHeight); 1922 } 2040 1923 } 2041 1924 else 1925 #endif 1926 #if NTT_STORE_SPDV_VSP_G0148 2042 1927 { 2043 rpcTempCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( cMvFieldNeighbours[1 + 2*uiMergeCand], SIZE_2Nx2N, 0, 0 ); // interprets depth relative to rpcTempCU level 1928 if ( vspFlag[uiMergeCand] ) 1929 { 1930 UInt partAddr; 1931 Int vspSize; 1932 Int width, height; 1933 rpcTempCU->getPartIndexAndSize( 0, partAddr, width, height ); 1934 if( uhInterDirNeighbours[ uiMergeCand ] & 0x01 ) 1935 { 1936 rpcTempCU->setMvFieldPUForVSP( rpcTempCU, partAddr, width, height, REF_PIC_LIST_0, cMvFieldNeighbours[ 2*uiMergeCand + 0 ].getRefIdx(), vspSize ); 1937 rpcTempCU->setVSPFlag( partAddr, vspSize ); 1938 } 1939 else 1940 { 1941 rpcTempCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( cMvFieldNeighbours[0 + 2*uiMergeCand], SIZE_2Nx2N, 0, 0 ); // interprets depth relative to rpcTempCU level 1942 } 1943 if( uhInterDirNeighbours[ uiMergeCand ] & 0x02 ) 1944 { 1945 rpcTempCU->setMvFieldPUForVSP( rpcTempCU, partAddr, width, height, REF_PIC_LIST_1 , cMvFieldNeighbours[ 2*uiMergeCand + 1 ].getRefIdx(), vspSize ); 1946 rpcTempCU->setVSPFlag( partAddr, vspSize ); 1947 } 1948 else 1949 { 1950 rpcTempCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( cMvFieldNeighbours[1 + 2*uiMergeCand], SIZE_2Nx2N, 0, 0 ); // interprets depth relative to rpcTempCU level 1951 } 1952 rpcTempCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeCand], 0, 0, uhDepth ); // interprets depth relative to LCU level 1953 } 1954 else 1955 { 1956 #endif 1957 rpcTempCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeCand], 0, 0, uhDepth ); // interprets depth relative to LCU level 1958 rpcTempCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( cMvFieldNeighbours[0 + 2*uiMergeCand], SIZE_2Nx2N, 0, 0 ); // interprets depth relative to rpcTempCU level 1959 rpcTempCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( cMvFieldNeighbours[1 + 2*uiMergeCand], SIZE_2Nx2N, 0, 0 ); // interprets depth relative to rpcTempCU level 1960 #if NTT_STORE_SPDV_VSP_G0148 1961 } 2044 1962 } 2045 2046 rpcTempCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeCand], 0, 0, uhDepth ); // interprets depth relative to LCU level 2047 } 2048 else 2049 #endif 2050 { 2051 rpcTempCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeCand], 0, 0, uhDepth ); // interprets depth relative to LCU level 2052 rpcTempCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( cMvFieldNeighbours[0 + 2*uiMergeCand], SIZE_2Nx2N, 0, 0 ); // interprets depth relative to rpcTempCU level 2053 rpcTempCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( cMvFieldNeighbours[1 + 2*uiMergeCand], SIZE_2Nx2N, 0, 0 ); // interprets depth relative to rpcTempCU level 2054 } 2055 // do MC 2056 m_pcPredSearch->motionCompensation ( rpcTempCU, m_ppcPredYuvTemp[uhDepth] ); 2057 // estimate residual and encode everything 1963 #endif 1964 // do MC 1965 m_pcPredSearch->motionCompensation ( rpcTempCU, m_ppcPredYuvTemp[uhDepth] ); 1966 // estimate residual and encode everything 2058 1967 #if H_3D_VSO //M2 2059 if( m_pcRdCost->getUseRenModel() )2060 { //Reset2061 UInt uiWidth = m_ppcOrigYuv[uhDepth]->getWidth ();2062 UInt uiHeight = m_ppcOrigYuv[uhDepth]->getHeight ();2063 Pel* piSrc = m_ppcOrigYuv[uhDepth]->getLumaAddr ();2064 UInt uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride ();2065 m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight );2066 }2067 #endif 2068 m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU,2069 m_ppcOrigYuv [uhDepth],2070 m_ppcPredYuvTemp[uhDepth],2071 m_ppcResiYuvTemp[uhDepth],2072 m_ppcResiYuvBest[uhDepth],2073 m_ppcRecoYuvTemp[uhDepth],2074 (uiNoResidual? true:false));2075 2076 2077 if ( uiNoResidual == 0 && rpcTempCU->getQtRootCbf(0) == 0 )2078 {2079 // If no residual when allowing for one, then set mark to not try case where residual is forced to 02080 mergeCandBuffer[uiMergeCand] = 1;2081 }2082 2083 rpcTempCU->setSkipFlagSubParts( rpcTempCU->getQtRootCbf(0) == 0, 0, uhDepth );1968 if( m_pcRdCost->getUseRenModel() ) 1969 { //Reset 1970 UInt uiWidth = m_ppcOrigYuv[uhDepth]->getWidth (); 1971 UInt uiHeight = m_ppcOrigYuv[uhDepth]->getHeight (); 1972 Pel* piSrc = m_ppcOrigYuv[uhDepth]->getLumaAddr (); 1973 UInt uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride (); 1974 m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); 1975 } 1976 #endif 1977 m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, 1978 m_ppcOrigYuv [uhDepth], 1979 m_ppcPredYuvTemp[uhDepth], 1980 m_ppcResiYuvTemp[uhDepth], 1981 m_ppcResiYuvBest[uhDepth], 1982 m_ppcRecoYuvTemp[uhDepth], 1983 (uiNoResidual? true:false)); 1984 1985 1986 if ( uiNoResidual == 0 && rpcTempCU->getQtRootCbf(0) == 0 ) 1987 { 1988 // If no residual when allowing for one, then set mark to not try case where residual is forced to 0 1989 mergeCandBuffer[uiMergeCand] = 1; 1990 } 1991 1992 rpcTempCU->setSkipFlagSubParts( rpcTempCU->getQtRootCbf(0) == 0, 0, uhDepth ); 2084 1993 #if NTT_STORE_SPDV_VSP_G0148 // possible bug fix 2085 if( rpcTempCU->getSkipFlag(0) )2086 {2087 rpcTempCU->setTrIdxSubParts(0, 0, uhDepth);2088 }1994 if( rpcTempCU->getSkipFlag(0) ) 1995 { 1996 rpcTempCU->setTrIdxSubParts(0, 0, uhDepth); 1997 } 2089 1998 #endif 2090 1999 #if H_3D_INTER_SDC 2091 TComDataCU *rpcTempCUPre = rpcTempCU;2092 #endif 2093 Int orgQP = rpcTempCU->getQP( 0 );2094 xCheckDQP( rpcTempCU );2095 xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth);2000 TComDataCU *rpcTempCUPre = rpcTempCU; 2001 #endif 2002 Int orgQP = rpcTempCU->getQP( 0 ); 2003 xCheckDQP( rpcTempCU ); 2004 xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth); 2096 2005 #if H_3D_INTER_SDC 2097 if( rpcTempCU->getSlice()->getVPS()->getInterSDCFlag( rpcTempCU->getSlice()->getLayerIdInVps() ) && rpcTempCU->getSlice()->getIsDepth() && !uiNoResidual )2098 {2006 if( rpcTempCU->getSlice()->getVPS()->getInterSDCFlag( rpcTempCU->getSlice()->getLayerIdInVps() ) && rpcTempCU->getSlice()->getIsDepth() && !uiNoResidual ) 2007 { 2099 2008 #if SEC_INTER_SDC_G0101 2100 for( Int uiOffest = -2 ; uiOffest <= 2 ; uiOffest++ ) 2101 { 2009 for( Int uiOffest = -2 ; uiOffest <= 2 ; uiOffest++ ) 2010 { 2011 if( rpcTempCU != rpcTempCUPre ) 2012 { 2013 rpcTempCU->initEstData( uhDepth, orgQP, bTransquantBypassFlag ); 2014 rpcTempCU->copyPartFrom( rpcBestCU, 0, uhDepth ); 2015 } 2016 rpcTempCU->setSkipFlagSubParts( false, 0, uhDepth ); 2017 rpcTempCU->setTrIdxSubParts( 0, 0, uhDepth ); 2018 rpcTempCU->setCbfSubParts( 1, 1, 1, 0, uhDepth ); 2019 #if H_3D_VSO //M2 2020 if( m_pcRdCost->getUseRenModel() ) 2021 { //Reset 2022 UInt uiWidth = m_ppcOrigYuv[uhDepth]->getWidth (); 2023 UInt uiHeight = m_ppcOrigYuv[uhDepth]->getHeight (); 2024 Pel* piSrc = m_ppcOrigYuv[uhDepth]->getLumaAddr (); 2025 UInt uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride (); 2026 m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); 2027 } 2028 #endif 2029 m_pcPredSearch->encodeResAndCalcRdInterSDCCU( rpcTempCU, 2030 m_ppcOrigYuv[uhDepth], 2031 ( rpcTempCU != rpcTempCUPre ) ? m_ppcPredYuvBest[uhDepth] : m_ppcPredYuvTemp[uhDepth], 2032 m_ppcResiYuvTemp[uhDepth], 2033 m_ppcRecoYuvTemp[uhDepth], 2034 uiOffest, 2035 uhDepth ); 2036 2037 xCheckDQP( rpcTempCU ); 2038 xCheckBestMode( rpcBestCU, rpcTempCU, uhDepth ); 2039 } 2040 #else 2102 2041 if( rpcTempCU != rpcTempCUPre ) 2103 2042 { 2104 rpcTempCU->initEstData( uhDepth, orgQP );2043 rpcTempCU->initEstData( uhDepth, orgQP, bTransquantBypassFlag ); 2105 2044 rpcTempCU->copyPartFrom( rpcBestCU, 0, uhDepth ); 2106 2045 } … … 2122 2061 ( rpcTempCU != rpcTempCUPre ) ? m_ppcPredYuvBest[uhDepth] : m_ppcPredYuvTemp[uhDepth], 2123 2062 m_ppcResiYuvTemp[uhDepth], 2124 m_ppcRecoYuvTemp[uhDepth], 2125 uiOffest, 2063 m_ppcRecoYuvTemp[uhDepth], 2126 2064 uhDepth ); 2127 2065 2128 2066 xCheckDQP( rpcTempCU ); 2129 2067 xCheckBestMode( rpcBestCU, rpcTempCU, uhDepth ); 2068 #endif 2130 2069 } 2131 #else 2132 if( rpcTempCU != rpcTempCUPre ) 2070 #endif 2071 rpcTempCU->initEstData( uhDepth, orgQP, bTransquantBypassFlag ); 2072 2073 if( m_pcEncCfg->getUseFastDecisionForMerge() && !bestIsSkip ) 2133 2074 { 2134 rpcTempCU->initEstData( uhDepth, orgQP ); 2135 rpcTempCU->copyPartFrom( rpcBestCU, 0, uhDepth ); 2075 #if H_3D_INTER_SDC 2076 if( rpcTempCU->getSlice()->getVPS()->getInterSDCFlag( rpcTempCU->getSlice()->getLayerIdInVps() ) ) 2077 { 2078 bestIsSkip = !rpcBestCU->getSDCFlag( 0 ) && ( rpcBestCU->getQtRootCbf(0) == 0 ); 2079 } 2080 else 2081 { 2082 #endif 2083 bestIsSkip = rpcBestCU->getQtRootCbf(0) == 0; 2084 #if H_3D_INTER_SDC 2085 } 2086 #endif 2136 2087 } 2137 rpcTempCU->setSkipFlagSubParts( false, 0, uhDepth );2138 rpcTempCU->setTrIdxSubParts( 0, 0, uhDepth );2139 rpcTempCU->setCbfSubParts( 1, 1, 1, 0, uhDepth );2140 #if H_3D_VSO //M22141 if( m_pcRdCost->getUseRenModel() )2142 { //Reset2143 UInt uiWidth = m_ppcOrigYuv[uhDepth]->getWidth ();2144 UInt uiHeight = m_ppcOrigYuv[uhDepth]->getHeight ();2145 Pel* piSrc = m_ppcOrigYuv[uhDepth]->getLumaAddr ();2146 UInt uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride ();2147 m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight );2148 }2149 #endif2150 m_pcPredSearch->encodeResAndCalcRdInterSDCCU( rpcTempCU,2151 m_ppcOrigYuv[uhDepth],2152 ( rpcTempCU != rpcTempCUPre ) ? m_ppcPredYuvBest[uhDepth] : m_ppcPredYuvTemp[uhDepth],2153 m_ppcResiYuvTemp[uhDepth],2154 m_ppcRecoYuvTemp[uhDepth],2155 uhDepth );2156 2157 xCheckDQP( rpcTempCU );2158 xCheckBestMode( rpcBestCU, rpcTempCU, uhDepth );2159 #endif2160 }2161 #endif2162 rpcTempCU->initEstData( uhDepth, orgQP );2163 2164 if( m_pcEncCfg->getUseFastDecisionForMerge() && !bestIsSkip )2165 {2166 #if H_3D_INTER_SDC2167 if( rpcTempCU->getSlice()->getVPS()->getInterSDCFlag( rpcTempCU->getSlice()->getLayerIdInVps() ) )2168 {2169 bestIsSkip = !rpcBestCU->getSDCFlag( 0 ) && ( rpcBestCU->getQtRootCbf(0) == 0 );2170 }2171 else2172 {2173 #endif2174 bestIsSkip = rpcBestCU->getQtRootCbf(0) == 0;2175 #if H_3D_INTER_SDC2176 }2177 #endif2178 }2179 }2180 }2181 }2182 2183 if(uiNoResidual == 0 && m_pcEncCfg->getUseEarlySkipDetection())2184 {2185 if(rpcBestCU->getQtRootCbf( 0 ) == 0)2186 {2187 if( rpcBestCU->getMergeFlag( 0 ))2188 {2189 *earlyDetectionSkipMode = true;2190 }2191 else2192 {2193 Int absoulte_MV=0;2194 for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )2195 {2196 if ( rpcBestCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 )2197 {2198 TComCUMvField* pcCUMvField = rpcBestCU->getCUMvField(RefPicList( uiRefListIdx ));2199 Int iHor = pcCUMvField->getMvd( 0 ).getAbsHor();2200 Int iVer = pcCUMvField->getMvd( 0 ).getAbsVer();2201 absoulte_MV+=iHor+iVer;2202 2088 } 2203 2089 } 2204 2205 if(absoulte_MV == 0) 2090 } 2091 2092 if(uiNoResidual == 0 && m_pcEncCfg->getUseEarlySkipDetection()) 2093 { 2094 if(rpcBestCU->getQtRootCbf( 0 ) == 0) 2206 2095 { 2207 *earlyDetectionSkipMode = true; 2096 if( rpcBestCU->getMergeFlag( 0 )) 2097 { 2098 *earlyDetectionSkipMode = true; 2099 } 2100 else 2101 { 2102 Int absoulte_MV=0; 2103 for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ ) 2104 { 2105 if ( rpcBestCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 ) 2106 { 2107 TComCUMvField* pcCUMvField = rpcBestCU->getCUMvField(RefPicList( uiRefListIdx )); 2108 Int iHor = pcCUMvField->getMvd( 0 ).getAbsHor(); 2109 Int iVer = pcCUMvField->getMvd( 0 ).getAbsVer(); 2110 absoulte_MV+=iHor+iVer; 2111 } 2112 } 2113 2114 if(absoulte_MV == 0) 2115 { 2116 *earlyDetectionSkipMode = true; 2117 } 2118 } 2208 2119 } 2209 2120 } 2210 2121 } 2211 }2212 }2213 2122 #if H_3D_SPIVMP 2214 delete[] pcMvFieldSP;2215 delete[] puhInterDirSP;2123 delete[] pcMvFieldSP; 2124 delete[] puhInterDirSP; 2216 2125 #endif 2217 2126 #if H_3D_ARP 2218 }2127 } 2219 2128 #endif 2220 2129 } … … 2231 2140 #endif 2232 2141 { 2142 2143 #if UPDATE_HM13 2144 #if H_3D 2145 const Bool bTransquantBypassFlag = rpcTempCU->getCUTransquantBypass(0); 2146 #endif 2147 #endif 2233 2148 #if H_3D_FAST_TEXTURE_ENCODING 2234 2149 if(!(bFMD && (ePartSize == SIZE_2Nx2N))) //have motion estimation or merge check … … 2254 2169 if( bFirstTime == false && rpcTempCU->getSlice()->getVPS()->getUseAdvRP( iLayerId ) ) 2255 2170 { 2171 #if UPDATE_HM13 2172 rpcTempCU->initEstData( rpcTempCU->getDepth(0), rpcTempCU->getQP(0),bTransquantBypassFlag ); 2173 #else 2256 2174 rpcTempCU->initEstData( rpcTempCU->getDepth(0), rpcTempCU->getQP(0) ); 2175 #endif 2257 2176 } 2258 2177 #endif … … 2274 2193 rpcTempCU->setPartSizeSubParts ( ePartSize, 0, uhDepth ); 2275 2194 rpcTempCU->setPredModeSubParts ( MODE_INTER, 0, uhDepth ); 2276 rpcTempCU->setCUTransquantBypassSubParts ( m_pcEncCfg->getCUTransquantBypassFlagValue(), 0, uhDepth );2277 2278 2195 #if MTK_DDD_G0063 2279 2196 rpcTempCU->setUseDDD( false, 0, uhDepth ); … … 2328 2245 #endif 2329 2246 2330 #if RATE_CONTROL_LAMBDA_DOMAIN && (!M0036_RC_IMPROVEMENT || KWU_RC_MADPRED_E0227)2247 #if KWU_RC_MADPRED_E0227 2331 2248 if ( m_pcEncCfg->getUseRateCtrl() && m_pcEncCfg->getLCULevelRC() && ePartSize == SIZE_2Nx2N && uhDepth <= m_addSADDepth ) 2332 2249 { … … 2337 2254 } 2338 2255 #endif 2339 #if !RATE_CONTROL_LAMBDA_DOMAIN && KWU_RC_MADPRED_E02272340 if ( m_pcEncCfg->getUseRateCtrl() && ePartSize == SIZE_2Nx2N && uhDepth <= m_addSADDepth )2341 {2342 UInt SAD = m_pcRdCost->getSADPart( g_bitDepthY, m_ppcPredYuvTemp[uhDepth]->getLumaAddr(), m_ppcPredYuvTemp[uhDepth]->getStride(),2343 m_ppcOrigYuv[uhDepth]->getLumaAddr(), m_ppcOrigYuv[uhDepth]->getStride(),2344 rpcTempCU->getWidth(0), rpcTempCU->getHeight(0) );2345 m_temporalSAD = (Int)SAD;2346 }2347 #endif2348 2349 2256 m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcResiYuvBest[uhDepth], m_ppcRecoYuvTemp[uhDepth], false ); 2350 2351 2257 #if NTT_STORE_SPDV_VSP_G0148 // possible bug fix 2352 2258 if( rpcTempCU->getQtRootCbf(0)==0 ) … … 2361 2267 else 2362 2268 #endif 2269 2363 2270 rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); 2364 2271 #if H_3D_INTER_SDC … … 2380 2287 { 2381 2288 Int orgQP = rpcBestCU->getQP( 0 ); 2289 #if UPDATE_HM13 2290 rpcTempCU->initEstData( uhDepth, orgQP ,bTransquantBypassFlag ); 2291 #else 2382 2292 rpcTempCU->initEstData( uhDepth, orgQP ); 2293 #endif 2383 2294 rpcTempCU->copyPartFrom( rpcBestCU, 0, uhDepth ); 2384 2295 } … … 2657 2568 rpcTempCU->setPartSizeSubParts( eSize, 0, uiDepth ); 2658 2569 rpcTempCU->setPredModeSubParts( MODE_INTRA, 0, uiDepth ); 2659 rpcTempCU->setCUTransquantBypassSubParts( m_pcEncCfg->getCUTransquantBypassFlagValue(), 0, uiDepth );2660 2570 2661 2571 Bool bSeparateLumaChroma = true; // choose estimation mode … … 2693 2603 setdQPFlag( bCodeDQP ); 2694 2604 2695 if( m_bUseSBACRD )m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]);2605 m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]); 2696 2606 2697 2607 rpcTempCU->getTotalBits() = m_pcEntropyCoder->getNumberOfWrittenBits(); 2698 if(m_pcEncCfg->getUseSBACRD())2699 {2700 2608 rpcTempCU->getTotalBins() = ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); 2701 }2702 2703 2609 #if H_3D_VSO // M6 2704 2610 if( m_pcRdCost->getUseLambdaScaleVSO()) … … 2708 2614 rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); 2709 2615 2710 #if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT && KWU_RC_MADPRED_E02272711 UChar uhDepth = rpcTempCU->getDepth( 0 );2712 if ( m_pcEncCfg->getUseRateCtrl() && m_pcEncCfg->getLCULevelRC() && eSize == SIZE_2Nx2N && uhDepth <= m_addSADDepth )2713 {2714 UInt SAD = m_pcRdCost->getSADPart( g_bitDepthY, m_ppcPredYuvTemp[uhDepth]->getLumaAddr(), m_ppcPredYuvTemp[uhDepth]->getStride(),2715 m_ppcOrigYuv[uhDepth]->getLumaAddr(), m_ppcOrigYuv[uhDepth]->getStride(),2716 rpcTempCU->getWidth(0), rpcTempCU->getHeight(0) );2717 m_spatialSAD = (Int)SAD;2718 }2719 #endif2720 #if RATE_CONTROL_LAMBDA_DOMAIN && M0036_RC_IMPROVEMENT && KWU_RC_MADPRED_E02272721 UChar uhDepth = rpcTempCU->getDepth( 0 );2722 if ( m_pcEncCfg->getUseRateCtrl() && m_pcEncCfg->getLCULevelRC() && eSize == SIZE_2Nx2N && uhDepth <= m_addSADDepth )2723 {2724 UInt SAD = m_pcRdCost->getSADPart( g_bitDepthY, m_ppcPredYuvTemp[uhDepth]->getLumaAddr(), m_ppcPredYuvTemp[uhDepth]->getStride(),2725 m_ppcOrigYuv[uhDepth]->getLumaAddr(), m_ppcOrigYuv[uhDepth]->getStride(),2726 rpcTempCU->getWidth(0), rpcTempCU->getHeight(0) );2727 m_spatialSAD = (Int)SAD;2728 }2729 #endif2730 #if !RATE_CONTROL_LAMBDA_DOMAIN && KWU_RC_MADPRED_E02272731 UChar uhDepth = rpcTempCU->getDepth( 0 );2732 if ( m_pcEncCfg->getUseRateCtrl() && eSize == SIZE_2Nx2N && uhDepth <= m_addSADDepth )2733 {2734 UInt SAD = m_pcRdCost->getSADPart( g_bitDepthY, m_ppcPredYuvTemp[uhDepth]->getLumaAddr(), m_ppcPredYuvTemp[uhDepth]->getStride(),2735 m_ppcOrigYuv[uhDepth]->getLumaAddr(), m_ppcOrigYuv[uhDepth]->getStride(),2736 rpcTempCU->getWidth(0), rpcTempCU->getHeight(0) );2737 m_spatialSAD = (Int)SAD;2738 }2739 #endif2740 2616 xCheckDQP( rpcTempCU ); 2741 2617 xCheckBestMode(rpcBestCU, rpcTempCU, uiDepth); … … 2760 2636 rpcTempCU->setPredModeSubParts( MODE_INTRA, 0, uiDepth ); 2761 2637 rpcTempCU->setTrIdxSubParts ( 0, 0, uiDepth ); 2762 rpcTempCU->setCUTransquantBypassSubParts( m_pcEncCfg->getCUTransquantBypassFlagValue(), 0, uiDepth );2763 2638 2764 2639 m_pcPredSearch->IPCMSearch( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth]); 2765 2640 2766 if( m_bUseSBACRD )m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]);2641 m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]); 2767 2642 2768 2643 m_pcEntropyCoder->resetBits(); … … 2779 2654 m_pcEntropyCoder->encodeIPCMInfo ( rpcTempCU, 0, true ); 2780 2655 2781 if( m_bUseSBACRD )m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]);2656 m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]); 2782 2657 2783 2658 rpcTempCU->getTotalBits() = m_pcEntropyCoder->getNumberOfWrittenBits(); 2784 if(m_pcEncCfg->getUseSBACRD())2785 {2786 2659 rpcTempCU->getTotalBins() = ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); 2787 }2788 2660 #if H_3D_VSO // M44 2789 2661 if ( m_pcRdCost->getUseVSO() ) … … 2825 2697 pcCU = NULL; 2826 2698 2827 if( m_bUseSBACRD )// store temp best CI for next CU coding2699 // store temp best CI for next CU coding 2828 2700 m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]->store(m_pppcRDSbacCoder[uiDepth][CI_NEXT_BEST]); 2829 2701 } … … 2842 2714 m_pcEntropyCoder->encodeQP( pcCU, 0, false ); 2843 2715 pcCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // dQP bits 2844 if(m_pcEncCfg->getUseSBACRD())2845 {2846 2716 pcCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); 2847 }2848 2717 #if H_3D_VSO // M45 2849 2718 if ( m_pcRdCost->getUseVSO() ) -
branches/HTM-10.0-dev0/source/Lib/TLibEncoder/TEncCu.h
r833 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 104 104 TEncSbac*** m_pppcRDSbacCoder; 105 105 TEncSbac* m_pcRDGoOnSbacCoder; 106 Bool m_bUseSBACRD;107 106 TEncRateCtrl* m_pcRateCtrl; 108 #if RATE_CONTROL_LAMBDA_DOMAIN 109 #if !M0036_RC_IMPROVEMENT 110 UInt m_LCUPredictionSAD; 111 Int m_addSADDepth; 112 Int m_temporalSAD; 113 #endif 114 #if M0036_RC_IMPROVEMENT && KWU_RC_MADPRED_E0227 107 #if KWU_RC_MADPRED_E0227 115 108 UInt m_LCUPredictionSAD; 116 109 Int m_addSADDepth; … … 118 111 Int m_spatialSAD; 119 112 #endif 120 #endif121 #if !RATE_CONTROL_LAMBDA_DOMAIN && KWU_RC_MADPRED_E0227122 UInt m_LCUPredictionSAD;123 Int m_addSADDepth;124 Int m_temporalSAD;125 Int m_spatialSAD;126 #endif127 128 113 public: 129 114 /// copy parameters from encoder class … … 143 128 144 129 Void setBitCounter ( TComBitCounter* pcBitCounter ) { m_pcBitCounter = pcBitCounter; } 145 #if (RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT) ||KWU_RC_MADPRED_E0227130 #if KWU_RC_MADPRED_E0227 146 131 UInt getLCUPredictionSAD() { return m_LCUPredictionSAD; } 147 132 #endif 148 #if RATE_CONTROL_INTRA149 133 Int updateLCUDataISlice ( TComDataCU* pcCU, Int LCUIdx, Int width, Int height ); 150 #endif151 134 protected: 152 135 Void finishCU ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ); -
branches/HTM-10.0-dev0/source/Lib/TLibEncoder/TEncEntropy.cpp
r833 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 51 51 Void TEncEntropy::encodeSliceHeader ( TComSlice* pcSlice ) 52 52 { 53 if (pcSlice->getSPS()->getUseSAO())54 {55 SAOParam *saoParam = pcSlice->getPic()->getPicSym()->getSaoParam();56 pcSlice->setSaoEnabledFlag (saoParam->bSaoFlag[0]);57 {58 pcSlice->setSaoEnabledFlagChroma (saoParam->bSaoFlag[1]);59 }60 }61 62 53 m_pcEntropyCoderIf->codeSliceHeader( pcSlice ); 63 54 return; … … 787 778 } 788 779 789 /** Encode SAO Offset790 * \param saoLcuParam SAO LCU paramters791 */792 Void TEncEntropy::encodeSaoOffset(SaoLcuParam* saoLcuParam, UInt compIdx)793 {794 UInt uiSymbol;795 Int i;796 797 uiSymbol = saoLcuParam->typeIdx + 1;798 if (compIdx!=2)799 {800 m_pcEntropyCoderIf->codeSaoTypeIdx(uiSymbol);801 }802 if (uiSymbol)803 {804 if (saoLcuParam->typeIdx < 4 && compIdx != 2)805 {806 saoLcuParam->subTypeIdx = saoLcuParam->typeIdx;807 }808 Int bitDepth = compIdx ? g_bitDepthC : g_bitDepthY;809 Int offsetTh = 1 << min(bitDepth - 5,5);810 if( saoLcuParam->typeIdx == SAO_BO )811 {812 for( i=0; i< saoLcuParam->length; i++)813 {814 UInt absOffset = ( (saoLcuParam->offset[i] < 0) ? -saoLcuParam->offset[i] : saoLcuParam->offset[i]);815 m_pcEntropyCoderIf->codeSaoMaxUvlc(absOffset, offsetTh-1);816 }817 for( i=0; i< saoLcuParam->length; i++)818 {819 if (saoLcuParam->offset[i] != 0)820 {821 UInt sign = (saoLcuParam->offset[i] < 0) ? 1 : 0 ;822 m_pcEntropyCoderIf->codeSAOSign(sign);823 }824 }825 uiSymbol = (UInt) (saoLcuParam->subTypeIdx);826 m_pcEntropyCoderIf->codeSaoUflc(5, uiSymbol);827 }828 else if( saoLcuParam->typeIdx < 4 )829 {830 m_pcEntropyCoderIf->codeSaoMaxUvlc( saoLcuParam->offset[0], offsetTh-1);831 m_pcEntropyCoderIf->codeSaoMaxUvlc( saoLcuParam->offset[1], offsetTh-1);832 m_pcEntropyCoderIf->codeSaoMaxUvlc(-saoLcuParam->offset[2], offsetTh-1);833 m_pcEntropyCoderIf->codeSaoMaxUvlc(-saoLcuParam->offset[3], offsetTh-1);834 if (compIdx!=2)835 {836 uiSymbol = (UInt) (saoLcuParam->subTypeIdx);837 m_pcEntropyCoderIf->codeSaoUflc(2, uiSymbol);838 }839 }840 }841 }842 843 /** Encode SAO unit interleaving844 * \param rx845 * \param ry846 * \param pSaoParam847 * \param pcCU848 * \param iCUAddrInSlice849 * \param iCUAddrUpInSlice850 * \param bLFCrossSliceBoundaryFlag851 */852 Void TEncEntropy::encodeSaoUnitInterleaving(Int compIdx, Bool saoFlag, Int rx, Int ry, SaoLcuParam* saoLcuParam, Int cuAddrInSlice, Int cuAddrUpInSlice, Int allowMergeLeft, Int allowMergeUp)853 {854 if (saoFlag)855 {856 if (rx>0 && cuAddrInSlice!=0 && allowMergeLeft)857 {858 m_pcEntropyCoderIf->codeSaoMerge(saoLcuParam->mergeLeftFlag);859 }860 else861 {862 saoLcuParam->mergeLeftFlag = 0;863 }864 if (saoLcuParam->mergeLeftFlag == 0)865 {866 if ( (ry > 0) && (cuAddrUpInSlice>=0) && allowMergeUp )867 {868 m_pcEntropyCoderIf->codeSaoMerge(saoLcuParam->mergeUpFlag);869 }870 else871 {872 saoLcuParam->mergeUpFlag = 0;873 }874 if (!saoLcuParam->mergeUpFlag)875 {876 encodeSaoOffset(saoLcuParam, compIdx);877 }878 }879 }880 }881 882 780 Int TEncEntropy::countNonZeroCoeffs( TCoeff* pcCoef, UInt uiSize ) 883 781 { … … 996 894 } 997 895 #endif 998 999 896 //! \} -
branches/HTM-10.0-dev0/source/Lib/TLibEncoder/TEncEntropy.h
r833 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 127 127 virtual Void codeCoeffNxN ( TComDataCU* pcCU, TCoeff* pcCoef, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt uiDepth, TextType eTType ) = 0; 128 128 virtual Void codeTransformSkipFlags ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt width, UInt height, TextType eTType ) = 0; 129 virtual Void codeSAOSign ( UInt code ) = 0; 130 virtual Void codeSaoMaxUvlc ( UInt code, UInt maxSymbol ) = 0; 131 virtual Void codeSaoMerge ( UInt uiCode ) = 0; 132 virtual Void codeSaoTypeIdx ( UInt uiCode) = 0; 133 virtual Void codeSaoUflc ( UInt uiLength, UInt uiCode ) = 0; 129 virtual Void codeSAOBlkParam(SAOBlkParam& saoBlkParam, Bool* sliceEnabled, Bool leftMergeAvail, Bool aboveMergeAvail, Bool onlyEstMergeInfo = false) =0; 134 130 virtual Void estBit (estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, TextType eTType) = 0; 135 131 … … 232 228 233 229 Void estimateBit ( estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, TextType eTType); 234 Void encodeSaoOffset(SaoLcuParam* saoLcuParam, UInt compIdx); 235 Void encodeSaoUnitInterleaving(Int compIdx, Bool saoFlag, Int rx, Int ry, SaoLcuParam* saoLcuParam, Int cuAddrInSlice, Int cuAddrUpInSlice, Int allowMergeLeft, Int allowMergeUp); 230 Void encodeSAOBlkParam(SAOBlkParam& saoBlkParam, Bool* sliceEnabled, Bool leftMergeAvail, Bool aboveMergeAvail){m_pcEntropyCoderIf->codeSAOBlkParam(saoBlkParam, sliceEnabled, leftMergeAvail, aboveMergeAvail, false);} 236 231 static Int countNonZeroCoeffs( TCoeff* pcCoef, UInt uiSize ); 237 232 -
branches/HTM-10.0-dev0/source/Lib/TLibEncoder/TEncGOP.cpp
r773 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 49 49 #include <time.h> 50 50 #include <math.h> 51 52 51 using namespace std; 53 52 //! \ingroup TLibEncoder … … 104 103 m_isDepth = false; 105 104 #endif 105 #endif 106 #if FIX1172 107 m_associatedIRAPType = NAL_UNIT_CODED_SLICE_IDR_N_LP; 108 m_associatedIRAPPOC = 0; 106 109 #endif 107 110 return; … … 472 475 } 473 476 474 if( getNalUnitType(pocCurr, m_iLastIDR ) == NAL_UNIT_CODED_SLICE_IDR_W_RADL || getNalUnitType(pocCurr, m_iLastIDR) == NAL_UNIT_CODED_SLICE_IDR_N_LP )477 if( getNalUnitType(pocCurr, m_iLastIDR, isField) == NAL_UNIT_CODED_SLICE_IDR_W_RADL || getNalUnitType(pocCurr, m_iLastIDR, isField) == NAL_UNIT_CODED_SLICE_IDR_N_LP ) 475 478 { 476 479 m_iLastIDR = pocCurr; … … 551 554 #if H_MV 552 555 // Set the nal unit type 553 pcSlice->setNalUnitType(getNalUnitType(pocCurr, m_iLastIDR ));556 pcSlice->setNalUnitType(getNalUnitType(pocCurr, m_iLastIDR, isField)); 554 557 if( pcSlice->getSliceType() == B_SLICE ) 555 558 { … … 559 562 } 560 563 } 564 565 // To be checked! 566 if( pcSlice->getSliceType() == B_SLICE ) 567 { 568 if( m_pcCfg->getGOPEntry( ( pcSlice->getRapPicFlag() && getLayerId() > 0 ) ? MAX_GOP : iGOPid ).m_sliceType == 'I' ) 569 { 570 pcSlice->setSliceType( I_SLICE ); 571 } 572 } 561 573 #else 562 574 if(pcSlice->getSliceType()==B_SLICE&&m_pcCfg->getGOPEntry(iGOPid).m_sliceType=='P') … … 564 576 pcSlice->setSliceType(P_SLICE); 565 577 } 578 if(pcSlice->getSliceType()==B_SLICE&&m_pcCfg->getGOPEntry(iGOPid).m_sliceType=='I') 579 { 580 pcSlice->setSliceType(I_SLICE); 581 } 582 566 583 // Set the nal unit type 567 pcSlice->setNalUnitType(getNalUnitType(pocCurr, m_iLastIDR ));584 pcSlice->setNalUnitType(getNalUnitType(pocCurr, m_iLastIDR, isField)); 568 585 #endif 569 586 if(pcSlice->getTemporalLayerNonReferenceFlag()) … … 589 606 m_pcEncTop->selectReferencePictureSet(pcSlice, pocCurr, iGOPid); 590 607 pcSlice->getRPS()->setNumberOfLongtermPictures(0); 591 592 #if FIX1071 608 #if FIX1172 609 if ( pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP 610 || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL 611 || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP 612 || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL 613 || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP 614 || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA ) // IRAP picture 615 { 616 m_associatedIRAPType = pcSlice->getNalUnitType(); 617 m_associatedIRAPPOC = pocCurr; 618 } 619 pcSlice->setAssociatedIRAPType(m_associatedIRAPType); 620 pcSlice->setAssociatedIRAPPOC(m_associatedIRAPPOC); 621 #endif 622 593 623 if ((pcSlice->checkThatAllRefPicsAreAvailable(rcListPic, pcSlice->getRPS(), false) != 0) || (pcSlice->isIRAP())) 594 624 { 595 625 pcSlice->createExplicitReferencePictureSetFromReference(rcListPic, pcSlice->getRPS(), pcSlice->isIRAP()); 596 626 } 597 #else598 if(pcSlice->checkThatAllRefPicsAreAvailable(rcListPic, pcSlice->getRPS(), false) != 0)599 {600 pcSlice->createExplicitReferencePictureSetFromReference(rcListPic, pcSlice->getRPS());601 }602 #endif603 627 pcSlice->applyReferencePictureSet(rcListPic, pcSlice->getRPS()); 604 628 605 if(pcSlice->getTLayer() > 0) 629 if(pcSlice->getTLayer() > 0 630 && !( pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_N // Check if not a leading picture 631 || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_R 632 || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N 633 || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R ) 634 ) 606 635 { 607 636 if(pcSlice->isTemporalLayerSwitchingPoint(rcListPic) || pcSlice->getSPS()->getTemporalIdNestingFlag()) … … 613 642 else 614 643 { 615 pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_T LA_R);644 pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TSA_R); 616 645 } 617 646 } … … 907 936 pcPic->getSlice(pcSlice->getSliceIdx())->setMvdL1ZeroFlag(pcSlice->getMvdL1ZeroFlag()); 908 937 909 #if RATE_CONTROL_LAMBDA_DOMAIN910 938 Double lambda = 0.0; 911 939 Int actualHeadBits = 0; … … 944 972 else if ( frameLevel == 0 ) // intra case, but use the model 945 973 { 946 #if RATE_CONTROL_INTRA947 974 m_pcSliceEncoder->calCostSliceI(pcPic); 948 #endif949 975 if ( m_pcCfg->getIntraPeriod() != 1 ) // do not refine allocated bits for all intra case 950 976 { 951 977 Int bits = m_pcRateCtrl->getRCSeq()->getLeftAverageBits(); 952 #if RATE_CONTROL_INTRA953 978 bits = m_pcRateCtrl->getRCPic()->getRefineBitsForIntra( bits ); 954 #else955 bits = m_pcRateCtrl->getRCSeq()->getRefineBitsForIntra( bits );956 #endif957 979 if ( bits < 200 ) 958 980 { … … 963 985 964 986 list<TEncRCPic*> listPreviousPicture = m_pcRateCtrl->getPicList(); 965 #if RATE_CONTROL_INTRA966 987 m_pcRateCtrl->getRCPic()->getLCUInitTargetBits(); 967 988 lambda = m_pcRateCtrl->getRCPic()->estimatePicLambda( listPreviousPicture, pcSlice->getSliceType()); 968 #else969 lambda = m_pcRateCtrl->getRCPic()->estimatePicLambda( listPreviousPicture );970 #endif971 989 sliceQP = m_pcRateCtrl->getRCPic()->estimatePicQP( lambda, listPreviousPicture ); 972 990 } … … 984 1002 #endif 985 1003 list<TEncRCPic*> listPreviousPicture = m_pcRateCtrl->getPicList(); 986 #if RATE_CONTROL_INTRA987 1004 lambda = m_pcRateCtrl->getRCPic()->estimatePicLambda( listPreviousPicture, pcSlice->getSliceType()); 988 #else989 lambda = m_pcRateCtrl->getRCPic()->estimatePicLambda( listPreviousPicture );990 #endif991 1005 sliceQP = m_pcRateCtrl->getRCPic()->estimatePicQP( lambda, listPreviousPicture ); 992 1006 #if KWU_RC_MADPRED_E0227 … … 1000 1014 m_pcSliceEncoder->resetQP( pcPic, sliceQP, lambda ); 1001 1015 } 1002 #endif1003 1016 1004 1017 UInt uiNumSlices = 1; … … 1203 1216 1204 1217 // SAO parameter estimation using non-deblocked pixels for LCU bottom and right boundary areas 1205 if( m_pcCfg->getSaoLcuBasedOptimization() && m_pcCfg->getSaoLcuBoundary() ) 1206 { 1207 m_pcSAO->resetStats(); 1208 m_pcSAO->calcSaoStatsCu_BeforeDblk( pcPic ); 1218 if( pcSlice->getSPS()->getUseSAO() && m_pcCfg->getSaoLcuBoundary() ) 1219 { 1220 m_pcSAO->getPreDBFStatistics(pcPic); 1209 1221 } 1210 1222 … … 1218 1230 m_pcLoopFilter->loopFilterPic( pcPic ); 1219 1231 1220 pcSlice = pcPic->getSlice(0);1221 if(pcSlice->getSPS()->getUseSAO())1222 {1223 std::vector<Bool> LFCrossSliceBoundaryFlag;1224 for(Int s=0; s< uiNumSlices; s++)1225 {1226 LFCrossSliceBoundaryFlag.push_back( ((uiNumSlices==1)?true:pcPic->getSlice(s)->getLFCrossSliceBoundaryFlag()) );1227 }1228 m_storedStartCUAddrForEncodingSlice.resize(uiNumSlices+1);1229 pcPic->createNonDBFilterInfo(m_storedStartCUAddrForEncodingSlice, 0, &LFCrossSliceBoundaryFlag ,pcPic->getPicSym()->getNumTiles() ,bLFCrossTileBoundary);1230 }1231 1232 1233 pcSlice = pcPic->getSlice(0);1234 1235 if(pcSlice->getSPS()->getUseSAO())1236 {1237 m_pcSAO->createPicSaoInfo(pcPic);1238 }1239 1240 1232 /////////////////////////////////////////////////////////////////////////////////////////////////// File writing 1241 1233 // Set entropy coder … … 1254 1246 writeRBSPTrailingBits(nalu.m_Bitstream); 1255 1247 accessUnit.push_back(new NALUnitEBSP(nalu)); 1256 #if RATE_CONTROL_LAMBDA_DOMAIN1257 1248 actualTotalBits += UInt(accessUnit.back()->m_nalUnitData.str().size()) * 8; 1258 #endif1259 1249 1260 1250 #if H_MV … … 1296 1286 writeRBSPTrailingBits(nalu.m_Bitstream); 1297 1287 accessUnit.push_back(new NALUnitEBSP(nalu)); 1298 #if RATE_CONTROL_LAMBDA_DOMAIN1299 1288 actualTotalBits += UInt(accessUnit.back()->m_nalUnitData.str().size()) * 8; 1300 #endif1301 1289 1302 1290 #if H_MV … … 1313 1301 writeRBSPTrailingBits(nalu.m_Bitstream); 1314 1302 accessUnit.push_back(new NALUnitEBSP(nalu)); 1315 #if RATE_CONTROL_LAMBDA_DOMAIN1316 1303 actualTotalBits += UInt(accessUnit.back()->m_nalUnitData.str().size()) * 8; 1317 #endif 1304 1318 1305 #if PPS_FIX_DEPTH 1319 1306 } … … 1343 1330 { 1344 1331 SOPcurrPOC += deltaPOC; 1345 SOPDescriptionSEI.m_sopDescVclNaluType[i] = getNalUnitType(SOPcurrPOC, m_iLastIDR );1332 SOPDescriptionSEI.m_sopDescVclNaluType[i] = getNalUnitType(SOPcurrPOC, m_iLastIDR, isField); 1346 1333 SOPDescriptionSEI.m_sopDescTemporalId[i] = m_pcCfg->getGOPEntry(j).m_temporalId; 1347 1334 SOPDescriptionSEI.m_sopDescStRpsIdx[i] = m_pcEncTop->getReferencePictureSetIdxForSOP(pcSlice, SOPcurrPOC, j); … … 1621 1608 } 1622 1609 m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); 1623 #if RATE_CONTROL_LAMBDA_DOMAIN1624 1610 tmpBitsBeforeWriting = m_pcEntropyCoder->getNumberOfWrittenBits(); 1625 #endif1626 1611 m_pcEntropyCoder->encodeSliceHeader(pcSlice); 1627 #if RATE_CONTROL_LAMBDA_DOMAIN1628 1612 actualHeadBits += ( m_pcEntropyCoder->getNumberOfWrittenBits() - tmpBitsBeforeWriting ); 1629 #endif1630 1613 1631 1614 // is it needed? … … 1748 1731 xAttachSliceDataToNalUnit(nalu, pcBitstreamRedirect); 1749 1732 accessUnit.push_back(new NALUnitEBSP(nalu)); 1750 #if RATE_CONTROL_LAMBDA_DOMAIN1751 1733 actualTotalBits += UInt(accessUnit.back()->m_nalUnitData.str().size()) * 8; 1752 #endif1753 1734 bNALUAlignedWrittenToList = true; 1754 1735 uiOneBitstreamPerSliceLength += nalu.m_Bitstream.getNumberOfWrittenBits(); // length of bitstream after byte-alignment … … 1794 1775 m_pcEntropyCoder->resetEntropy(); 1795 1776 m_pcEntropyCoder->setBitstream( m_pcBitCounter ); 1796 m_pcSAO->startSaoEnc(pcPic, m_pcEntropyCoder, m_pcEncTop->getRDSbacCoder(), m_pcEncTop->getRDGoOnSbacCoder()); 1797 SAOParam& cSaoParam = *pcSlice->getPic()->getPicSym()->getSaoParam(); 1798 1799 #if SAO_CHROMA_LAMBDA 1800 #if SAO_ENCODING_CHOICE 1801 m_pcSAO->SAOProcess(&cSaoParam, pcPic->getSlice(0)->getLambdaLuma(), pcPic->getSlice(0)->getLambdaChroma(), pcPic->getSlice(0)->getDepth()); 1802 #else 1803 m_pcSAO->SAOProcess(&cSaoParam, pcPic->getSlice(0)->getLambdaLuma(), pcPic->getSlice(0)->getLambdaChroma()); 1804 #endif 1805 #else 1806 m_pcSAO->SAOProcess(&cSaoParam, pcPic->getSlice(0)->getLambda()); 1807 #endif 1808 m_pcSAO->endSaoEnc(); 1777 Bool sliceEnabled[NUM_SAO_COMPONENTS]; 1778 m_pcSAO->initRDOCabacCoder(m_pcEncTop->getRDGoOnSbacCoder(), pcSlice); 1779 m_pcSAO->SAOProcess(pcPic 1780 , sliceEnabled 1781 , pcPic->getSlice(0)->getLambdas() 1782 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 1783 , m_pcCfg->getSaoLcuBoundary() 1784 #endif 1785 ); 1809 1786 m_pcSAO->PCMLFDisableProcess(pcPic); 1810 } 1811 #if SAO_RDO 1812 m_pcEntropyCoder->setEntropyCoder ( m_pcCavlcCoder, pcSlice ); 1813 #endif 1814 processingState = ENCODE_SLICE; 1815 1787 1788 //assign SAO slice header 1816 1789 for(Int s=0; s< uiNumSlices; s++) 1817 1790 { 1818 if (pcSlice->getSPS()->getUseSAO())1819 {1820 pcPic->getSlice(s)->setSaoEnabledFlag((pcSlice->getPic()->getPicSym()->getSaoParam()->bSaoFlag[0]==1)?true:false);1791 pcPic->getSlice(s)->setSaoEnabledFlag(sliceEnabled[SAO_Y]); 1792 assert(sliceEnabled[SAO_Cb] == sliceEnabled[SAO_Cr]); 1793 pcPic->getSlice(s)->setSaoEnabledFlagChroma(sliceEnabled[SAO_Cb]); 1821 1794 } 1822 1795 } 1796 processingState = ENCODE_SLICE; 1823 1797 } 1824 1798 break; … … 1831 1805 } 1832 1806 } // end iteration over slices 1833 1834 if(pcSlice->getSPS()->getUseSAO())1835 {1836 if(pcSlice->getSPS()->getUseSAO())1837 {1838 m_pcSAO->destroyPicSaoInfo();1839 }1840 pcPic->destroyNonDBFilterInfo();1841 }1842 1807 #if H_3D 1843 1808 pcPic->compressMotion(2); … … 1919 1884 1920 1885 //In case of field coding, compute the interlaced PSNR for both fields 1921 if (isField && ((!pcPic->isTopField() && isTff) || (pcPic->isTopField() && !isTff)) )1886 if (isField && ((!pcPic->isTopField() && isTff) || (pcPic->isTopField() && !isTff)) && (pcPic->getPOC()%m_iGopSize != 1)) 1922 1887 { 1923 1888 //get complementary top field … … 1931 1896 xCalculateInterlacedAddPSNR(pcPicTop, pcPic, pcPicTop->getPicYuvRec(), pcPic->getPicYuvRec(), accessUnit, dEncTime ); 1932 1897 } 1898 else if (isField && pcPic->getPOC()!= 0 && (pcPic->getPOC()%m_iGopSize == 0)) 1899 { 1900 //get complementary bottom field 1901 TComPic* pcPicBottom; 1902 TComList<TComPic*>::iterator iterPic = rcListPic.begin(); 1903 while ((*iterPic)->getPOC() != pcPic->getPOC()+1) 1904 { 1905 iterPic ++; 1906 } 1907 pcPicBottom = *(iterPic); 1908 xCalculateInterlacedAddPSNR(pcPic, pcPicBottom, pcPic->getPicYuvRec(), pcPicBottom->getPicYuvRec(), accessUnit, dEncTime ); 1909 } 1933 1910 1934 1911 if (digestStr) … … 1947 1924 } 1948 1925 } 1949 #if RATE_CONTROL_LAMBDA_DOMAIN1950 1926 if ( m_pcCfg->getUseRateCtrl() ) 1951 1927 { 1952 #if !M0036_RC_IMPROVEMENT1953 Double effectivePercentage = m_pcRateCtrl->getRCPic()->getEffectivePercentage();1954 #endif1955 1928 Double avgQP = m_pcRateCtrl->getRCPic()->calAverageQP(); 1956 1929 Double avgLambda = m_pcRateCtrl->getRCPic()->calAverageLambda(); … … 1959 1932 avgLambda = lambda; 1960 1933 } 1961 #if M0036_RC_IMPROVEMENT1962 #if RATE_CONTROL_INTRA1963 1934 m_pcRateCtrl->getRCPic()->updateAfterPicture( actualHeadBits, actualTotalBits, avgQP, avgLambda, pcSlice->getSliceType()); 1964 #else1965 m_pcRateCtrl->getRCPic()->updateAfterPicture( actualHeadBits, actualTotalBits, avgQP, avgLambda );1966 #endif1967 #else1968 m_pcRateCtrl->getRCPic()->updateAfterPicture( actualHeadBits, actualTotalBits, avgQP, avgLambda, effectivePercentage );1969 #endif1970 1935 m_pcRateCtrl->getRCPic()->addToPictureLsit( m_pcRateCtrl->getPicList() ); 1971 1936 … … 1980 1945 } 1981 1946 } 1982 #else1983 if(m_pcCfg->getUseRateCtrl())1984 {1985 UInt frameBits = m_vRVM_RP[m_vRVM_RP.size()-1];1986 m_pcRateCtrl->updataRCFrameStatus((Int)frameBits, pcSlice->getSliceType());1987 }1988 #endif1989 1947 1990 1948 if( ( m_pcCfg->getPictureTimingSEIEnabled() || m_pcCfg->getDecodingUnitInfoSEIEnabled() ) && … … 2173 2131 delete[] pcSubstreamsOut; 2174 2132 } 2175 #if !KWU_FIX_URQ && !RATE_CONTROL_LAMBDA_DOMAIN2176 if(m_pcCfg->getUseRateCtrl())2177 {2178 m_pcRateCtrl->updateRCGOPStatus();2179 }2180 #endif2181 2133 delete pcBitstreamRedirect; 2182 2134 … … 2262 2214 m_pcEntropyCoder->resetEntropy (); 2263 2215 m_pcEntropyCoder->setBitstream ( m_pcBitCounter ); 2264 pcSlice = pcPic->getSlice(0);2265 if(pcSlice->getSPS()->getUseSAO())2266 {2267 std::vector<Bool> LFCrossSliceBoundaryFlag(1, true);2268 std::vector<Int> sliceStartAddress;2269 sliceStartAddress.push_back(0);2270 sliceStartAddress.push_back(pcPic->getNumCUsInFrame()* pcPic->getNumPartInCU());2271 pcPic->createNonDBFilterInfo(sliceStartAddress, 0, &LFCrossSliceBoundaryFlag);2272 }2273 2274 if( pcSlice->getSPS()->getUseSAO())2275 {2276 pcPic->destroyNonDBFilterInfo();2277 }2278 2279 2216 m_pcEntropyCoder->resetEntropy (); 2280 2217 ruiBits += m_pcEntropyCoder->getNumberOfWrittenBits(); … … 2454 2391 case NAL_UNIT_CODED_SLICE_TRAIL_R: return "TRAIL_R"; 2455 2392 case NAL_UNIT_CODED_SLICE_TRAIL_N: return "TRAIL_N"; 2456 case NAL_UNIT_CODED_SLICE_T LA_R: return "TLA_R";2393 case NAL_UNIT_CODED_SLICE_TSA_R: return "TSA_R"; 2457 2394 case NAL_UNIT_CODED_SLICE_TSA_N: return "TSA_N"; 2458 2395 case NAL_UNIT_CODED_SLICE_STSA_R: return "STSA_R"; … … 2702 2639 for (Int x = 0; x < width; x++) 2703 2640 { 2704 dst[x] = isTff ? (UChar) top[x] : (UChar)bottom[x];2705 dst[stride+x] = isTff ? (UChar) bottom[x] : (UChar)top[x];2641 dst[x] = isTff ? top[x] : bottom[x]; 2642 dst[stride+x] = isTff ? bottom[x] : top[x]; 2706 2643 } 2707 2644 top += stride; … … 2862 2799 * This function checks the configuration and returns the appropriate nal_unit_type for the picture. 2863 2800 */ 2864 NalUnitType TEncGOP::getNalUnitType(Int pocCurr, Int lastIDR )2801 NalUnitType TEncGOP::getNalUnitType(Int pocCurr, Int lastIDR, Bool isField) 2865 2802 { 2866 2803 if (pocCurr == 0) … … 2868 2805 return NAL_UNIT_CODED_SLICE_IDR_W_RADL; 2869 2806 } 2870 if ( pocCurr% m_pcCfg->getIntraPeriod() == 0)2807 if ((pocCurr - isField) % m_pcCfg->getIntraPeriod() == 0) 2871 2808 { 2872 2809 if (m_pcCfg->getDecodingRefreshType() == 1) -
branches/HTM-10.0-dev0/source/Lib/TLibEncoder/TEncGOP.h
r655 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 125 125 std::vector<Int> m_storedStartCUAddrForEncodingSlice; 126 126 std::vector<Int> m_storedStartCUAddrForEncodingSliceSegment; 127 #if FIX1172 128 NalUnitType m_associatedIRAPType; 129 Int m_associatedIRAPPOC; 130 #endif 127 131 128 132 std::vector<Int> m_vRVM_RP; … … 181 185 182 186 TEncSlice* getSliceEncoder() { return m_pcSliceEncoder; } 183 NalUnitType getNalUnitType( Int pocCurr, Int lastIdr );187 NalUnitType getNalUnitType( Int pocCurr, Int lastIdr, Bool isField ); 184 188 Void arrangeLongtermPicturesInRPS(TComSlice *, TComList<TComPic*>& ); 185 189 protected: … … 187 191 188 192 protected: 193 189 194 Void xInitGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, bool isField ); 190 191 195 Void xInitGOP ( Int iPOC, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut ); 192 196 Void xGetBuffer ( TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, Int iNumPicRcvd, Int iTimeOffset, TComPic*& rpcPic, TComPicYuv*& rpcPicYuvRecOut, Int pocCurr, bool isField ); -
branches/HTM-10.0-dev0/source/Lib/TLibEncoder/TEncPic.cpp
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/TLibEncoder/TEncPic.h
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/TLibEncoder/TEncPreanalyzer.cpp
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/TLibEncoder/TEncPreanalyzer.h
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/TLibEncoder/TEncRateCtrl.cpp
r655 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 42 42 using namespace std; 43 43 44 #if RATE_CONTROL_LAMBDA_DOMAIN45 46 44 //sequence level 47 45 TEncRCSeq::TEncRCSeq() … … 67 65 m_bitsLeft = 0; 68 66 m_useLCUSeparateModel = false; 69 #if M0036_RC_IMPROVEMENT70 67 m_adaptiveBit = 0; 71 68 m_lastLambda = 0.0; 72 #endif73 69 } 74 70 … … 78 74 } 79 75 80 #if M0036_RC_IMPROVEMENT81 76 Void TEncRCSeq::create( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Int numberOfLevel, Bool useLCUSeparateModel, Int adaptiveBit ) 82 #else83 Void TEncRCSeq::create( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Int numberOfLevel, Bool useLCUSeparateModel )84 #endif85 77 { 86 78 destroy(); … … 109 101 m_betaUpdate = 0.025; 110 102 } 111 #if M0036_RC_IMPROVEMENT112 103 else if ( m_seqTargetBpp < 0.2 ) 113 104 { … … 125 116 m_betaUpdate = 0.2; 126 117 } 127 #else128 else129 {130 m_alphaUpdate = 0.1;131 m_betaUpdate = 0.05;132 }133 #endif134 118 m_averageBits = (Int)(m_targetBits / totalFrames); 135 119 Int picWidthInBU = ( m_picWidth % m_LCUWidth ) == 0 ? m_picWidth / m_LCUWidth : m_picWidth / m_LCUWidth + 1; … … 172 156 m_framesLeft = m_totalFrames; 173 157 m_bitsLeft = m_targetBits; 174 #if M0036_RC_IMPROVEMENT175 158 m_adaptiveBit = adaptiveBit; 176 159 m_lastLambda = 0.0; 177 #endif178 160 } 179 161 … … 233 215 for ( Int i=0; i<m_numberOfLevel; i++ ) 234 216 { 235 #if RATE_CONTROL_INTRA236 217 if (i>0) 237 218 { … … 244 225 m_picPara[i].m_beta = BETA2; 245 226 } 246 #else247 m_picPara[i].m_alpha = 3.2003;248 m_picPara[i].m_beta = -1.367;249 #endif250 227 } 251 228 } … … 271 248 for ( Int j=0; j<m_numberOfLCU; j++) 272 249 { 273 #if RATE_CONTROL_INTRA274 250 m_LCUPara[i][j].m_alpha = m_picPara[i].m_alpha; 275 251 m_LCUPara[i][j].m_beta = m_picPara[i].m_beta; 276 #else277 m_LCUPara[i][j].m_alpha = 3.2003;278 m_LCUPara[i][j].m_beta = -1.367;279 #endif280 252 } 281 253 } … … 299 271 } 300 272 301 #if !RATE_CONTROL_INTRA302 Int TEncRCSeq::getRefineBitsForIntra( Int orgBits )303 {304 Double bpp = ( (Double)orgBits ) / m_picHeight / m_picHeight;305 if ( bpp > 0.2 )306 {307 return orgBits * 5;308 }309 if ( bpp > 0.1 )310 {311 return orgBits * 7;312 }313 return orgBits * 10;314 }315 #endif316 317 #if M0036_RC_IMPROVEMENT318 273 Void TEncRCSeq::setAllBitRatio( Double basicLambda, Double* equaCoeffA, Double* equaCoeffB ) 319 274 { … … 326 281 delete[] bitsRatio; 327 282 } 328 #endif329 283 330 284 //GOP level … … 349 303 Int targetBits = xEstGOPTargetBits( encRCSeq, numPic ); 350 304 351 #if M0036_RC_IMPROVEMENT352 305 if ( encRCSeq->getAdaptiveBits() > 0 && encRCSeq->getLastLambda() > 0.1 ) 353 306 { … … 409 362 delete []equaCoeffB; 410 363 } 411 #endif412 364 413 365 m_picTargetBitInGOP = new Int[numPic]; … … 422 374 { 423 375 currPicRatio = encRCSeq->getBitRatio( i ); 424 #if M0036_RC_IMPROVEMENT425 376 m_picTargetBitInGOP[i] = (Int)( ((Double)targetBits) * currPicRatio / totalPicRatio ); 426 #else427 m_picTargetBitInGOP[i] = targetBits * currPicRatio / totalPicRatio;428 #endif429 377 } 430 378 … … 436 384 } 437 385 438 #if M0036_RC_IMPROVEMENT439 386 Void TEncRCGOP::xCalEquaCoeff( TEncRCSeq* encRCSeq, Double* lambdaRatio, Double* equaCoeffA, Double* equaCoeffB, Int GOPSize ) 440 387 { … … 482 429 return solution; 483 430 } 484 #endif485 431 486 432 Void TEncRCGOP::destroy() … … 534 480 535 481 m_LCUs = NULL; 536 #if !M0036_RC_IMPROVEMENT537 m_lastPicture = NULL;538 #endif539 540 482 #if KWU_RC_MADPRED_E0227 541 483 m_lastIVPicture = NULL; … … 543 485 544 486 m_picActualHeaderBits = 0; 545 #if !M0036_RC_IMPROVEMENT546 m_totalMAD = 0.0;547 #endif548 487 m_picActualBits = 0; 549 488 m_picQP = 0; … … 574 513 } 575 514 576 #if M0036_RC_IMPROVEMENT577 515 targetBits = Int( ((Double)GOPbitsLeft) * currPicRatio / totalPicRatio ); 578 #else579 targetBits = Int( GOPbitsLeft * currPicRatio / totalPicRatio );580 #endif581 516 582 517 if ( targetBits < 100 ) … … 691 626 m_LCUs[LCUIdx].m_lambda = 0.0; 692 627 m_LCUs[LCUIdx].m_targetBits = 0; 693 #if M0036_RC_IMPROVEMENT694 628 m_LCUs[LCUIdx].m_bitWeight = 1.0; 695 #else696 m_LCUs[LCUIdx].m_MAD = 0.0;697 #endif698 629 Int currWidth = ( (i == picWidthInLCU -1) ? picWidth - LCUWidth *(picWidthInLCU -1) : LCUWidth ); 699 630 Int currHeight = ( (j == picHeightInLCU-1) ? picHeight - LCUHeight*(picHeightInLCU-1) : LCUHeight ); … … 708 639 } 709 640 m_picActualHeaderBits = 0; 710 #if !M0036_RC_IMPROVEMENT711 m_totalMAD = 0.0;712 #endif713 641 m_picActualBits = 0; 714 642 m_picQP = 0; … … 723 651 724 652 725 #if !M0036_RC_IMPROVEMENT726 m_lastPicture = NULL;727 list<TEncRCPic*>::reverse_iterator it;728 for ( it = listPreviousPictures.rbegin(); it != listPreviousPictures.rend(); it++ )729 {730 if ( (*it)->getFrameLevel() == m_frameLevel )731 {732 m_lastPicture = (*it);733 break;734 }735 }736 #endif737 738 653 #if KWU_RC_MADPRED_E0227 739 654 list<TEncRCPic*>::reverse_iterator it; … … 775 690 776 691 777 #if RATE_CONTROL_INTRA778 692 Double TEncRCPic::estimatePicLambda( list<TEncRCPic*>& listPreviousPictures, SliceType eSliceType) 779 #else780 Double TEncRCPic::estimatePicLambda( list<TEncRCPic*>& listPreviousPictures )781 #endif782 693 { 783 694 Double alpha = m_encRCSeq->getPicPara( m_frameLevel ).m_alpha; 784 695 Double beta = m_encRCSeq->getPicPara( m_frameLevel ).m_beta; 785 696 Double bpp = (Double)m_targetBits/(Double)m_numberOfPixel; 786 #if RATE_CONTROL_INTRA787 697 Double estLambda; 788 698 if (eSliceType == I_SLICE) … … 794 704 estLambda = alpha * pow( bpp, beta ); 795 705 } 796 #else797 Double estLambda = alpha * pow( bpp, beta );798 #endif799 706 800 707 Double lastLevelLambda = -1.0; … … 844 751 m_estPicLambda = estLambda; 845 752 846 #if M0036_RC_IMPROVEMENT847 753 Double totalWeight = 0.0; 848 754 // initial BU bit allocation weight 849 755 for ( Int i=0; i<m_numberOfLCU; i++ ) 850 756 { 851 #if RC_FIX852 757 Double alphaLCU, betaLCU; 853 758 if ( m_encRCSeq->getUseLCUSeparateModel() ) … … 861 766 betaLCU = m_encRCSeq->getPicPara( m_frameLevel ).m_beta; 862 767 } 863 #else864 Double alphaLCU = m_encRCSeq->getLCUPara( m_frameLevel, i ).m_alpha;865 Double betaLCU = m_encRCSeq->getLCUPara( m_frameLevel, i ).m_beta;866 #endif867 768 868 769 m_LCUs[i].m_bitWeight = m_LCUs[i].m_numberOfPixel * pow( estLambda/alphaLCU, 1.0/betaLCU ); … … 879 780 m_LCUs[i].m_bitWeight = BUTargetBits; 880 781 } 881 #endif882 782 883 783 return estLambda; … … 989 889 990 890 991 #if RATE_CONTROL_INTRA992 891 Double TEncRCPic::getLCUTargetBpp(SliceType eSliceType) 993 #else 994 Double TEncRCPic::getLCUTargetBpp() 995 #endif 892 { 893 Int LCUIdx = getLCUCoded(); 894 Double bpp = -1.0; 895 Int avgBits = 0; 896 897 if (eSliceType == I_SLICE) 898 { 899 Int noOfLCUsLeft = m_numberOfLCU - LCUIdx + 1; 900 Int bitrateWindow = min(4,noOfLCUsLeft); 901 Double MAD = getLCU(LCUIdx).m_costIntra; 902 903 if (m_remainingCostIntra > 0.1 ) 904 { 905 Double weightedBitsLeft = (m_bitsLeft*bitrateWindow+(m_bitsLeft-getLCU(LCUIdx).m_targetBitsLeft)*noOfLCUsLeft)/(Double)bitrateWindow; 906 avgBits = Int( MAD*weightedBitsLeft/m_remainingCostIntra ); 907 } 908 else 909 { 910 avgBits = Int( m_bitsLeft / m_LCULeft ); 911 } 912 m_remainingCostIntra -= MAD; 913 } 914 else 915 { 916 Double totalWeight = 0; 917 for ( Int i=LCUIdx; i<m_numberOfLCU; i++ ) 918 { 919 totalWeight += m_LCUs[i].m_bitWeight; 920 } 921 Int realInfluenceLCU = min( g_RCLCUSmoothWindowSize, getLCULeft() ); 922 avgBits = (Int)( m_LCUs[LCUIdx].m_bitWeight - ( totalWeight - m_bitsLeft ) / realInfluenceLCU + 0.5 ); 923 } 924 925 if ( avgBits < 1 ) 926 { 927 avgBits = 1; 928 } 929 930 bpp = ( Double )avgBits/( Double )m_LCUs[ LCUIdx ].m_numberOfPixel; 931 m_LCUs[ LCUIdx ].m_targetBits = avgBits; 932 933 return bpp; 934 } 935 936 937 #if KWU_RC_MADPRED_E0227 938 Double TEncRCPic::getLCUTargetBppforInterView( list<TEncRCPic*>& listPreviousPictures, TComDataCU* pcCU, Double basePos, Double curPos, Double focalLen, Double znear, Double zfar, Int direction, Int* disparity ) 996 939 { 997 940 Int LCUIdx = getLCUCoded(); … … 1003 946 #endif 1004 947 1005 #if RATE_CONTROL_INTRA1006 if (eSliceType == I_SLICE){1007 Int noOfLCUsLeft = m_numberOfLCU - LCUIdx + 1;1008 Int bitrateWindow = min(4,noOfLCUsLeft);1009 Double MAD = getLCU(LCUIdx).m_costIntra;1010 1011 if (m_remainingCostIntra > 0.1 )1012 {1013 Double weightedBitsLeft = (m_bitsLeft*bitrateWindow+(m_bitsLeft-getLCU(LCUIdx).m_targetBitsLeft)*noOfLCUsLeft)/(Double)bitrateWindow;1014 avgBits = Int( MAD*weightedBitsLeft/m_remainingCostIntra );1015 }1016 else1017 {1018 avgBits = Int( m_bitsLeft / m_LCULeft );1019 }1020 m_remainingCostIntra -= MAD;1021 }1022 else1023 {1024 #endif1025 #if M0036_RC_IMPROVEMENT1026 Double totalWeight = 0;1027 for ( Int i=LCUIdx; i<m_numberOfLCU; i++ )1028 {1029 totalWeight += m_LCUs[i].m_bitWeight;1030 }1031 Int realInfluenceLCU = min( g_RCLCUSmoothWindowSize, getLCULeft() );1032 avgBits = (Int)( m_LCUs[LCUIdx].m_bitWeight - ( totalWeight - m_bitsLeft ) / realInfluenceLCU + 0.5 );1033 #else1034 if ( m_lastPicture == NULL )1035 {1036 avgBits = Int( m_bitsLeft / m_LCULeft );1037 }1038 else1039 {1040 MAD = m_lastPicture->getLCU(LCUIdx).m_MAD;1041 totalMAD = m_lastPicture->getTotalMAD();1042 for ( Int i=0; i<LCUIdx; i++ )1043 {1044 totalMAD -= m_lastPicture->getLCU(i).m_MAD;1045 }1046 1047 if ( totalMAD > 0.1 )1048 {1049 avgBits = Int( m_bitsLeft * MAD / totalMAD );1050 }1051 else1052 {1053 avgBits = Int( m_bitsLeft / m_LCULeft );1054 }1055 }1056 #endif1057 #if RATE_CONTROL_INTRA1058 }1059 #endif1060 1061 if ( avgBits < 1 )1062 {1063 avgBits = 1;1064 }1065 1066 bpp = ( Double )avgBits/( Double )m_LCUs[ LCUIdx ].m_numberOfPixel;1067 m_LCUs[ LCUIdx ].m_targetBits = avgBits;1068 1069 return bpp;1070 }1071 1072 1073 #if KWU_RC_MADPRED_E02271074 Double TEncRCPic::getLCUTargetBppforInterView( list<TEncRCPic*>& listPreviousPictures, TComDataCU* pcCU, Double basePos, Double curPos, Double focalLen, Double znear, Double zfar, Int direction, Int* disparity )1075 {1076 Int LCUIdx = getLCUCoded();1077 Double bpp = -1.0;1078 Int avgBits = 0;1079 #if !M0036_RC_IMPROVEMENT1080 Double totalMAD = -1.0;1081 Double MAD = -1.0;1082 #endif1083 1084 948 Double totalMAD = -1.0; 1085 949 Double MAD = -1.0; … … 1300 1164 beta *= ( 1.0 - m_encRCSeq->getBetaUpdate() / 2.0 ); 1301 1165 1302 #if M0036_RC_IMPROVEMENT1303 1166 alpha = Clip3( g_RCAlphaMinValue, g_RCAlphaMaxValue, alpha ); 1304 1167 beta = Clip3( g_RCBetaMinValue, g_RCBetaMaxValue, beta ); 1305 #else1306 alpha = Clip3( 0.05, 20.0, alpha );1307 beta = Clip3( -3.0, -0.1, beta );1308 #endif1309 1168 1310 1169 TRCParameter rcPara; … … 1319 1178 alpha += m_encRCSeq->getAlphaUpdate() * ( log( inputLambda ) - log( calLambda ) ) * alpha; 1320 1179 double lnbpp = log( bpp ); 1321 #if M0036_RC_IMPROVEMENT1322 1180 lnbpp = Clip3( -5.0, -0.1, lnbpp ); 1323 #else1324 lnbpp = Clip3( -5.0, 1.0, lnbpp );1325 #endif1326 1181 beta += m_encRCSeq->getBetaUpdate() * ( log( inputLambda ) - log( calLambda ) ) * lnbpp; 1327 1182 1328 #if M0036_RC_IMPROVEMENT1329 1183 alpha = Clip3( g_RCAlphaMinValue, g_RCAlphaMaxValue, alpha ); 1330 1184 beta = Clip3( g_RCBetaMinValue, g_RCBetaMaxValue, beta ); 1331 #else1332 alpha = Clip3( 0.05, 20.0, alpha );1333 beta = Clip3( -3.0, -0.1, beta );1334 #endif1335 1185 TRCParameter rcPara; 1336 1186 rcPara.m_alpha = alpha; … … 1340 1190 } 1341 1191 1342 #if !M0036_RC_IMPROVEMENT1343 Double TEncRCPic::getEffectivePercentage()1344 {1345 Int effectivePiexels = 0;1346 Int totalPixels = 0;1347 1348 for ( Int i=0; i<m_numberOfLCU; i++ )1349 {1350 totalPixels += m_LCUs[i].m_numberOfPixel;1351 if ( m_LCUs[i].m_QP > 0 )1352 {1353 effectivePiexels += m_LCUs[i].m_numberOfPixel;1354 }1355 }1356 1357 Double effectivePixelPercentage = (Double)effectivePiexels/(Double)totalPixels;1358 return effectivePixelPercentage;1359 }1360 #endif1361 1362 1192 Double TEncRCPic::calAverageQP() 1363 1193 { … … 1414 1244 } 1415 1245 1416 #if M0036_RC_IMPROVEMENT1417 #if RATE_CONTROL_INTRA1418 1246 Void TEncRCPic::updateAfterPicture( Int actualHeaderBits, Int actualTotalBits, Double averageQP, Double averageLambda, SliceType eSliceType) 1419 #else1420 Void TEncRCPic::updateAfterPicture( Int actualHeaderBits, Int actualTotalBits, Double averageQP, Double averageLambda )1421 #endif1422 #else1423 Void TEncRCPic::updateAfterPicture( Int actualHeaderBits, Int actualTotalBits, Double averageQP, Double averageLambda, Double effectivePercentage )1424 #endif1425 1247 { 1426 1248 m_picActualHeaderBits = actualHeaderBits; … … 1435 1257 } 1436 1258 m_picLambda = averageLambda; 1437 #if !M0036_RC_IMPROVEMENT || KWU_RC_MADPRED_E02271438 1259 #if KWU_RC_MADPRED_E0227 1439 1260 m_totalMAD = 0; 1440 #endif1441 1261 for ( Int i=0; i<m_numberOfLCU; i++ ) 1442 1262 { … … 1447 1267 Double alpha = m_encRCSeq->getPicPara( m_frameLevel ).m_alpha; 1448 1268 Double beta = m_encRCSeq->getPicPara( m_frameLevel ).m_beta; 1449 #if RATE_CONTROL_INTRA1450 1269 if (eSliceType == I_SLICE) 1451 1270 { … … 1454 1273 else 1455 1274 { 1456 #endif1457 1275 // update parameters 1458 1276 Double picActualBits = ( Double )m_picActualBits; … … 1461 1279 Double inputLambda = m_picLambda; 1462 1280 1463 #if M0036_RC_IMPROVEMENT1464 1281 if ( inputLambda < 0.01 || calLambda < 0.01 || picActualBpp < 0.0001 ) 1465 #else1466 if ( inputLambda < 0.01 || calLambda < 0.01 || picActualBpp < 0.0001 || effectivePercentage < 0.05 )1467 #endif1468 1282 { 1469 1283 alpha *= ( 1.0 - m_encRCSeq->getAlphaUpdate() / 2.0 ); 1470 1284 beta *= ( 1.0 - m_encRCSeq->getBetaUpdate() / 2.0 ); 1471 1285 1472 #if M0036_RC_IMPROVEMENT1473 1286 alpha = Clip3( g_RCAlphaMinValue, g_RCAlphaMaxValue, alpha ); 1474 1287 beta = Clip3( g_RCBetaMinValue, g_RCBetaMaxValue, beta ); 1475 #else1476 alpha = Clip3( 0.05, 20.0, alpha );1477 beta = Clip3( -3.0, -0.1, beta );1478 #endif1479 1288 TRCParameter rcPara; 1480 1289 rcPara.m_alpha = alpha; … … 1488 1297 alpha += m_encRCSeq->getAlphaUpdate() * ( log( inputLambda ) - log( calLambda ) ) * alpha; 1489 1298 double lnbpp = log( picActualBpp ); 1490 #if M0036_RC_IMPROVEMENT1491 1299 lnbpp = Clip3( -5.0, -0.1, lnbpp ); 1492 #else1493 lnbpp = Clip3( -5.0, 1.0, lnbpp );1494 #endif1495 1300 beta += m_encRCSeq->getBetaUpdate() * ( log( inputLambda ) - log( calLambda ) ) * lnbpp; 1496 1301 1497 #if M0036_RC_IMPROVEMENT1498 1302 alpha = Clip3( g_RCAlphaMinValue, g_RCAlphaMaxValue, alpha ); 1499 1303 beta = Clip3( g_RCBetaMinValue, g_RCBetaMaxValue, beta ); 1500 #else 1501 alpha = Clip3( 0.05, 20.0, alpha ); 1502 beta = Clip3( -3.0, -0.1, beta ); 1503 #endif 1504 #if RATE_CONTROL_INTRA 1505 } 1506 #endif 1304 } 1507 1305 1508 1306 TRCParameter rcPara; … … 1512 1310 m_encRCSeq->setPicPara( m_frameLevel, rcPara ); 1513 1311 1514 #if M0036_RC_IMPROVEMENT1515 1312 if ( m_frameLevel == 1 ) 1516 1313 { … … 1519 1316 m_encRCSeq->setLastLambda( updateLastLambda ); 1520 1317 } 1521 #endif 1522 } 1523 1524 #if RATE_CONTROL_INTRA 1318 } 1319 1525 1320 Int TEncRCPic::getRefineBitsForIntra( Int orgBits ) 1526 1321 { … … 1611 1406 return estLambda; 1612 1407 } 1613 #endif1614 1408 1615 1409 TEncRateCtrl::TEncRateCtrl() … … 1645 1439 } 1646 1440 1647 #if M0036_RC_IMPROVEMENT1648 1441 #if KWU_RC_MADPRED_E0227 1649 1442 Void TEncRateCtrl::init( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Bool keepHierBits, Bool useLCUSeparateModel, GOPEntry GOPList[MAX_GOP], Int layerID ) … … 1651 1444 Void TEncRateCtrl::init( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Int keepHierBits, Bool useLCUSeparateModel, GOPEntry GOPList[MAX_GOP] ) 1652 1445 #endif 1653 #else1654 Void TEncRateCtrl::init( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Bool keepHierBits, Bool useLCUSeparateModel, GOPEntry GOPList[MAX_GOP] )1655 #endif1656 1446 { 1657 1447 destroy(); … … 1668 1458 1669 1459 Int numberOfLevel = 1; 1670 #if M0036_RC_IMPROVEMENT1671 1460 Int adaptiveBit = 0; 1672 1461 if ( keepHierBits > 0 ) 1673 #else1674 if ( keepHierBits )1675 #endif1676 1462 { 1677 1463 numberOfLevel = Int( log((Double)GOPSize)/log(2.0) + 0.5 ) + 1; … … 1696 1482 } 1697 1483 1698 #if M0036_RC_IMPROVEMENT1699 1484 if ( keepHierBits > 0 ) 1700 #else1701 if ( keepHierBits )1702 #endif1703 1485 { 1704 1486 Double bpp = (Double)( targetBitrate / (Double)( frameRate*picWidth*picHeight ) ); … … 1733 1515 bitsRatio[3] = 14; 1734 1516 } 1735 #if M0036_RC_IMPROVEMENT1736 1517 if ( keepHierBits == 2 ) 1737 1518 { 1738 1519 adaptiveBit = 1; 1739 1520 } 1740 #endif1741 1521 } 1742 1522 else if ( GOPSize == 8 && !isLowdelay ) … … 1786 1566 bitsRatio[7] = 1; 1787 1567 } 1788 #if M0036_RC_IMPROVEMENT1789 1568 if ( keepHierBits == 2 ) 1790 1569 { 1791 1570 adaptiveBit = 2; 1792 1571 } 1793 #endif1794 1572 } 1795 1573 else 1796 1574 { 1797 #if M0036_RC_IMPROVEMENT1798 1575 printf( "\n hierarchical bit allocation is not support for the specified coding structure currently.\n" ); 1799 #else1800 printf( "\n hierarchical bit allocation is not support for the specified coding structure currently." );1801 #endif1802 1576 } 1803 1577 } … … 1812 1586 } 1813 1587 } 1814 #if M0036_RC_IMPROVEMENT1815 1588 if ( keepHierBits > 0 ) 1816 #else1817 if ( keepHierBits )1818 #endif1819 1589 { 1820 1590 if ( GOPSize == 4 && isLowdelay ) … … 1851 1621 1852 1622 m_encRCSeq = new TEncRCSeq; 1853 #if M0036_RC_IMPROVEMENT1854 1623 m_encRCSeq->create( totalFrames, targetBitrate, frameRate, GOPSize, picWidth, picHeight, LCUWidth, LCUHeight, numberOfLevel, useLCUSeparateModel, adaptiveBit ); 1855 #else1856 m_encRCSeq->create( totalFrames, targetBitrate, frameRate, GOPSize, picWidth, picHeight, LCUWidth, LCUHeight, numberOfLevel, useLCUSeparateModel );1857 #endif1858 1624 m_encRCSeq->initBitsRatio( bitsRatio ); 1859 1625 m_encRCSeq->initGOPID2Level( GOPID2Level ); … … 1894 1660 } 1895 1661 1896 #else1897 1898 #define ADJUSTMENT_FACTOR 0.601899 #define HIGH_QSTEP_THRESHOLD 9.52381900 #define HIGH_QSTEP_ALPHA 4.93711901 #define HIGH_QSTEP_BETA 0.09221902 #define LOW_QSTEP_ALPHA 16.74291903 #define LOW_QSTEP_BETA -1.14941904 1905 #define MAD_PRED_Y1 1.01906 #define MAD_PRED_Y2 0.01907 1908 enum MAD_HISOTRY {1909 MAD_PPPrevious = 0,1910 MAD_PPrevious = 1,1911 MAD_Previous = 21912 };1913 1914 Void MADLinearModel::initMADLinearModel()1915 {1916 m_activeOn = false;1917 m_paramY1 = 1.0;1918 m_paramY2 = 0.0;1919 m_costMADs[0] = m_costMADs[1] = m_costMADs[2] = 0.0;1920 }1921 1922 Double MADLinearModel::getMAD()1923 {1924 Double costPredMAD = m_paramY1 * m_costMADs[MAD_Previous] + m_paramY2;1925 1926 if(costPredMAD < 0)1927 {1928 costPredMAD = m_costMADs[MAD_Previous];1929 m_paramY1 = MAD_PRED_Y1;1930 m_paramY2 = MAD_PRED_Y2;1931 }1932 return costPredMAD;1933 }1934 1935 Void MADLinearModel::updateMADLiearModel()1936 {1937 Double dNewY1 = ((m_costMADs[MAD_Previous] - m_costMADs[MAD_PPrevious]) / (m_costMADs[MAD_PPrevious] - m_costMADs[MAD_PPPrevious]));1938 Double dNewY2 = (m_costMADs[MAD_Previous] - (dNewY1*m_costMADs[MAD_PPrevious]));1939 1940 m_paramY1 = 0.70+0.20*m_paramY1+ 0.10*dNewY1;1941 m_paramY2 = 0.20*m_paramY2+ 0.10*dNewY2;1942 }1943 1944 Void MADLinearModel::updateMADHistory(Double dMAD)1945 {1946 m_costMADs[MAD_PPPrevious] = m_costMADs[MAD_PPrevious];1947 m_costMADs[MAD_PPrevious ] = m_costMADs[MAD_Previous ];1948 m_costMADs[MAD_Previous ] = dMAD;1949 m_activeOn = (m_costMADs[MAD_Previous ] && m_costMADs[MAD_PPrevious ] && m_costMADs[MAD_PPPrevious]);1950 }1951 1952 1953 Void PixelBaseURQQuadraticModel::initPixelBaseQuadraticModel()1954 {1955 m_paramHighX1 = HIGH_QSTEP_ALPHA;1956 m_paramHighX2 = HIGH_QSTEP_BETA;1957 m_paramLowX1 = LOW_QSTEP_ALPHA;1958 m_paramLowX2 = LOW_QSTEP_BETA;1959 }1960 1961 Int PixelBaseURQQuadraticModel::getQP(Int qp, Int targetBits, Int numberOfPixels, Double costPredMAD)1962 {1963 Double qStep;1964 Double bppPerMAD = (Double)(targetBits/(numberOfPixels*costPredMAD));1965 1966 if(xConvertQP2QStep(qp) >= HIGH_QSTEP_THRESHOLD)1967 {1968 qStep = 1/( sqrt((bppPerMAD/m_paramHighX1)+((m_paramHighX2*m_paramHighX2)/(4*m_paramHighX1*m_paramHighX1))) - (m_paramHighX2/(2*m_paramHighX1)));1969 }1970 else1971 {1972 qStep = 1/( sqrt((bppPerMAD/m_paramLowX1)+((m_paramLowX2*m_paramLowX2)/(4*m_paramLowX1*m_paramLowX1))) - (m_paramLowX2/(2*m_paramLowX1)));1973 }1974 1975 return xConvertQStep2QP(qStep);1976 }1977 1978 Void PixelBaseURQQuadraticModel::updatePixelBasedURQQuadraticModel (Int qp, Int bits, Int numberOfPixels, Double costMAD)1979 {1980 Double qStep = xConvertQP2QStep(qp);1981 Double invqStep = (1/qStep);1982 Double paramNewX1, paramNewX2;1983 1984 if(qStep >= HIGH_QSTEP_THRESHOLD)1985 {1986 paramNewX2 = (((bits/(numberOfPixels*costMAD))-(23.3772*invqStep*invqStep))/((1-200*invqStep)*invqStep));1987 paramNewX1 = (23.3772-200*paramNewX2);1988 m_paramHighX1 = 0.70*HIGH_QSTEP_ALPHA + 0.20 * m_paramHighX1 + 0.10 * paramNewX1;1989 m_paramHighX2 = 0.70*HIGH_QSTEP_BETA + 0.20 * m_paramHighX2 + 0.10 * paramNewX2;1990 }1991 else1992 {1993 paramNewX2 = (((bits/(numberOfPixels*costMAD))-(5.8091*invqStep*invqStep))/((1-9.5455*invqStep)*invqStep));1994 paramNewX1 = (5.8091-9.5455*paramNewX2);1995 m_paramLowX1 = 0.90*LOW_QSTEP_ALPHA + 0.09 * m_paramLowX1 + 0.01 * paramNewX1;1996 m_paramLowX2 = 0.90*LOW_QSTEP_BETA + 0.09 * m_paramLowX2 + 0.01 * paramNewX2;1997 }1998 }1999 2000 Bool PixelBaseURQQuadraticModel::checkUpdateAvailable(Int qpReference )2001 {2002 Double qStep = xConvertQP2QStep(qpReference);2003 2004 if (qStep > xConvertQP2QStep(MAX_QP)2005 ||qStep < xConvertQP2QStep(MIN_QP) )2006 {2007 return false;2008 }2009 2010 return true;2011 }2012 2013 Double PixelBaseURQQuadraticModel::xConvertQP2QStep(Int qp )2014 {2015 Int i;2016 Double qStep;2017 static const Double mapQP2QSTEP[6] = { 0.625, 0.703, 0.797, 0.891, 1.000, 1.125 };2018 2019 qStep = mapQP2QSTEP[qp % 6];2020 for( i=0; i<(qp/6); i++)2021 {2022 qStep *= 2;2023 }2024 2025 return qStep;2026 }2027 2028 Int PixelBaseURQQuadraticModel::xConvertQStep2QP(Double qStep )2029 {2030 Int per = 0, rem = 0;2031 2032 if( qStep < xConvertQP2QStep(MIN_QP))2033 {2034 return MIN_QP;2035 }2036 else if (qStep > xConvertQP2QStep(MAX_QP) )2037 {2038 return MAX_QP;2039 }2040 2041 while( qStep > xConvertQP2QStep(5) )2042 {2043 qStep /= 2.0;2044 per++;2045 }2046 2047 if (qStep <= 0.625)2048 {2049 rem = 0;2050 }2051 else if (qStep <= 0.703)2052 {2053 rem = 1;2054 }2055 else if (qStep <= 0.797)2056 {2057 rem = 2;2058 }2059 else if (qStep <= 0.891)2060 {2061 rem = 3;2062 }2063 else if (qStep <= 1.000)2064 {2065 rem = 4;2066 }2067 else2068 {2069 rem = 5;2070 }2071 return (per * 6 + rem);2072 }2073 2074 2075 Void TEncRateCtrl::create(Int sizeIntraPeriod, Int sizeGOP, Int frameRate, Int targetKbps, Int qp, Int numLCUInBasicUnit, Int sourceWidth, Int sourceHeight, Int maxCUWidth, Int maxCUHeight)2076 {2077 Int leftInHeight, leftInWidth;2078 2079 m_sourceWidthInLCU = (sourceWidth / maxCUWidth ) + (( sourceWidth % maxCUWidth ) ? 1 : 0);2080 m_sourceHeightInLCU = (sourceHeight / maxCUHeight) + (( sourceHeight % maxCUHeight) ? 1 : 0);2081 m_isLowdelay = (sizeIntraPeriod == -1) ? true : false;2082 2083 m_prevBitrate = ( targetKbps << 10 ); // in units of 1,024 bps2084 m_currBitrate = ( targetKbps << 10 );2085 2086 m_frameRate = frameRate;2087 m_refFrameNum = m_isLowdelay ? (sizeGOP) : (sizeGOP>>1);2088 m_nonRefFrameNum = sizeGOP-m_refFrameNum;2089 m_sizeGOP = sizeGOP;2090 m_numOfPixels = ((sourceWidth*sourceHeight*3)>>1);2091 m_indexGOP = 0;2092 m_indexFrame = 0;2093 m_indexLCU = 0;2094 m_indexUnit = 0;2095 m_indexRefFrame = 0;2096 m_indexNonRefFrame = 0;2097 m_occupancyVB = 0;2098 m_initialOVB = 0;2099 m_targetBufLevel = 0;2100 m_initialTBL = 0;2101 m_occupancyVBInFrame = 0;2102 m_remainingBitsInGOP = (m_currBitrate*sizeGOP/m_frameRate);2103 m_remainingBitsInFrame = 0;2104 m_numUnitInFrame = m_sourceWidthInLCU*m_sourceHeightInLCU;2105 m_cMADLinearModel. initMADLinearModel();2106 m_cPixelURQQuadraticModel.initPixelBaseQuadraticModel();2107 2108 m_costRefAvgWeighting = 0.0;2109 m_costNonRefAvgWeighting = 0.0;2110 m_costAvgbpp = 0.0;2111 m_activeUnitLevelOn = false;2112 2113 m_pcFrameData = new FrameData [sizeGOP+1]; initFrameData(qp);2114 m_pcLCUData = new LCUData [m_numUnitInFrame]; initUnitData (qp);2115 2116 for(Int i = 0, addressUnit = 0; i < m_sourceHeightInLCU*maxCUHeight; i += maxCUHeight)2117 {2118 leftInHeight = sourceHeight - i;2119 leftInHeight = min(leftInHeight, maxCUHeight);2120 for(Int j = 0; j < m_sourceWidthInLCU*maxCUWidth; j += maxCUWidth, addressUnit++)2121 {2122 leftInWidth = sourceWidth - j;2123 leftInWidth = min(leftInWidth, maxCUWidth);2124 m_pcLCUData[addressUnit].m_widthInPixel = leftInWidth;2125 m_pcLCUData[addressUnit].m_heightInPixel= leftInHeight;2126 m_pcLCUData[addressUnit].m_pixels = ((leftInHeight*leftInWidth*3)>>1);2127 }2128 }2129 }2130 2131 Void TEncRateCtrl::destroy()2132 {2133 if(m_pcFrameData)2134 {2135 delete [] m_pcFrameData;2136 m_pcFrameData = NULL;2137 }2138 if(m_pcLCUData)2139 {2140 delete [] m_pcLCUData;2141 m_pcLCUData = NULL;2142 }2143 }2144 2145 Void TEncRateCtrl::initFrameData (Int qp)2146 {2147 for(Int i = 0 ; i <= m_sizeGOP; i++)2148 {2149 m_pcFrameData[i].m_isReferenced = false;2150 m_pcFrameData[i].m_costMAD = 0.0;2151 m_pcFrameData[i].m_bits = 0;2152 m_pcFrameData[i].m_qp = qp;2153 }2154 }2155 2156 Void TEncRateCtrl::initUnitData (Int qp)2157 {2158 for(Int i = 1 ; i < m_numUnitInFrame; i++)2159 {2160 m_pcLCUData[i].m_qp = qp;2161 m_pcLCUData[i].m_bits = 0;2162 m_pcLCUData[i].m_pixels = 0;2163 m_pcLCUData[i].m_widthInPixel = 0;2164 m_pcLCUData[i].m_heightInPixel = 0;2165 m_pcLCUData[i].m_costMAD = 0.0;2166 }2167 }2168 2169 Int TEncRateCtrl::getFrameQP(Bool isReferenced, Int POC)2170 {2171 Int numofReferenced = 0;2172 Int finalQP = 0;2173 FrameData* pcFrameData;2174 2175 m_indexPOCInGOP = (POC%m_sizeGOP) == 0 ? m_sizeGOP : (POC%m_sizeGOP);2176 pcFrameData = &m_pcFrameData[m_indexPOCInGOP];2177 2178 if(m_indexFrame != 0)2179 {2180 if(isReferenced)2181 {2182 Double gamma = m_isLowdelay ? 0.5 : 0.25;2183 Double beta = m_isLowdelay ? 0.9 : 0.6;2184 Int numRemainingRefFrames = m_refFrameNum - m_indexRefFrame;2185 Int numRemainingNRefFrames = m_nonRefFrameNum - m_indexNonRefFrame;2186 2187 Double targetBitsOccupancy = (m_currBitrate/(Double)m_frameRate) + gamma*(m_targetBufLevel-m_occupancyVB - (m_initialOVB/(Double)m_frameRate));2188 Double targetBitsLeftBudget = ((m_costRefAvgWeighting*m_remainingBitsInGOP)/((m_costRefAvgWeighting*numRemainingRefFrames)+(m_costNonRefAvgWeighting*numRemainingNRefFrames)));2189 2190 m_targetBits = (Int)(beta * targetBitsLeftBudget + (1-beta) * targetBitsOccupancy);2191 2192 if(m_targetBits <= 0 || m_remainingBitsInGOP <= 0)2193 {2194 finalQP = m_pcFrameData[m_indexPrevPOCInGOP].m_qp + 2;2195 }2196 else2197 {2198 Double costPredMAD = m_cMADLinearModel.getMAD();2199 Int qpLowerBound = m_pcFrameData[m_indexPrevPOCInGOP].m_qp-2;2200 Int qpUpperBound = m_pcFrameData[m_indexPrevPOCInGOP].m_qp+2;2201 finalQP = m_cPixelURQQuadraticModel.getQP(m_pcFrameData[m_indexPrevPOCInGOP].m_qp, m_targetBits, m_numOfPixels, costPredMAD);2202 finalQP = max(qpLowerBound, min(qpUpperBound, finalQP));2203 m_activeUnitLevelOn = true;2204 m_remainingBitsInFrame = m_targetBits;2205 m_costAvgbpp = (m_targetBits/(Double)m_numOfPixels);2206 }2207 2208 m_indexRefFrame++;2209 }2210 else2211 {2212 Int bwdQP = m_pcFrameData[m_indexPOCInGOP-1].m_qp;2213 Int fwdQP = m_pcFrameData[m_indexPOCInGOP+1].m_qp;2214 2215 if( (fwdQP+bwdQP) == m_pcFrameData[m_indexPOCInGOP-1].m_qp2216 ||(fwdQP+bwdQP) == m_pcFrameData[m_indexPOCInGOP+1].m_qp)2217 {2218 finalQP = (fwdQP+bwdQP);2219 }2220 else if(bwdQP != fwdQP)2221 {2222 finalQP = ((bwdQP+fwdQP+2)>>1);2223 }2224 else2225 {2226 finalQP = bwdQP+2;2227 }2228 m_indexNonRefFrame++;2229 }2230 }2231 else2232 {2233 Int lastQPminus2 = m_pcFrameData[0].m_qp - 2;2234 Int lastQPplus2 = m_pcFrameData[0].m_qp + 2;2235 2236 for(Int idx = 1; idx <= m_sizeGOP; idx++)2237 {2238 if(m_pcFrameData[idx].m_isReferenced)2239 {2240 finalQP += m_pcFrameData[idx].m_qp;2241 numofReferenced++;2242 }2243 }2244 2245 finalQP = (numofReferenced == 0) ? m_pcFrameData[0].m_qp : ((finalQP + (1<<(numofReferenced>>1)))/numofReferenced);2246 finalQP = max( lastQPminus2, min( lastQPplus2, finalQP));2247 2248 Double costAvgFrameBits = m_remainingBitsInGOP/(Double)m_sizeGOP;2249 Int bufLevel = m_occupancyVB + m_initialOVB;2250 2251 if(abs(bufLevel) > costAvgFrameBits)2252 {2253 if(bufLevel < 0)2254 {2255 finalQP -= 2;2256 }2257 else2258 {2259 finalQP += 2;2260 }2261 }2262 m_indexRefFrame++;2263 }2264 finalQP = max(MIN_QP, min(MAX_QP, finalQP));2265 2266 for(Int indexLCU = 0 ; indexLCU < m_numUnitInFrame; indexLCU++)2267 {2268 m_pcLCUData[indexLCU].m_qp = finalQP;2269 }2270 2271 pcFrameData->m_isReferenced = isReferenced;2272 pcFrameData->m_qp = finalQP;2273 2274 return finalQP;2275 }2276 2277 Bool TEncRateCtrl::calculateUnitQP ()2278 {2279 if(!m_activeUnitLevelOn || m_indexLCU == 0)2280 {2281 return false;2282 }2283 Int upperQPBound, lowerQPBound, finalQP;2284 Int colQP = m_pcLCUData[m_indexLCU].m_qp;2285 Double colMAD = m_pcLCUData[m_indexLCU].m_costMAD;2286 Double budgetInUnit = m_pcLCUData[m_indexLCU].m_pixels*m_costAvgbpp;2287 2288 2289 Int targetBitsOccupancy = (Int)(budgetInUnit - (m_occupancyVBInFrame/(m_numUnitInFrame-m_indexUnit)));2290 Int targetBitsLeftBudget= (Int)((m_remainingBitsInFrame*m_pcLCUData[m_indexLCU].m_pixels)/(Double)(m_numOfPixels-m_codedPixels));2291 Int targetBits = (targetBitsLeftBudget>>1) + (targetBitsOccupancy>>1);2292 2293 2294 if( m_indexLCU >= m_sourceWidthInLCU)2295 {2296 upperQPBound = ( (m_pcLCUData[m_indexLCU-1].m_qp + m_pcLCUData[m_indexLCU - m_sourceWidthInLCU].m_qp)>>1) + MAX_DELTA_QP;2297 lowerQPBound = ( (m_pcLCUData[m_indexLCU-1].m_qp + m_pcLCUData[m_indexLCU - m_sourceWidthInLCU].m_qp)>>1) - MAX_DELTA_QP;2298 }2299 else2300 {2301 upperQPBound = m_pcLCUData[m_indexLCU-1].m_qp + MAX_DELTA_QP;2302 lowerQPBound = m_pcLCUData[m_indexLCU-1].m_qp - MAX_DELTA_QP;2303 }2304 2305 if(targetBits < 0)2306 {2307 finalQP = m_pcLCUData[m_indexLCU-1].m_qp + 1;2308 }2309 else2310 {2311 finalQP = m_cPixelURQQuadraticModel.getQP(colQP, targetBits, m_pcLCUData[m_indexLCU].m_pixels, colMAD);2312 }2313 2314 finalQP = max(lowerQPBound, min(upperQPBound, finalQP));2315 m_pcLCUData[m_indexLCU].m_qp = max(MIN_QP, min(MAX_QP, finalQP));2316 2317 return true;2318 }2319 2320 Void TEncRateCtrl::updateRCGOPStatus()2321 {2322 m_remainingBitsInGOP = ((m_currBitrate/m_frameRate)*m_sizeGOP) - m_occupancyVB;2323 2324 FrameData cFrameData = m_pcFrameData[m_sizeGOP];2325 initFrameData();2326 2327 m_pcFrameData[0] = cFrameData;2328 m_indexGOP++;2329 m_indexFrame = 0;2330 m_indexRefFrame = 0;2331 m_indexNonRefFrame = 0;2332 }2333 2334 Void TEncRateCtrl::updataRCFrameStatus(Int frameBits, SliceType eSliceType)2335 {2336 FrameData* pcFrameData = &m_pcFrameData[m_indexPOCInGOP];2337 Int occupancyBits;2338 Double adjustmentBits;2339 2340 m_remainingBitsInGOP = m_remainingBitsInGOP + ( ((m_currBitrate-m_prevBitrate)/m_frameRate)*(m_sizeGOP-m_indexFrame) ) - frameBits;2341 occupancyBits = (Int)((Double)frameBits - (m_currBitrate/(Double)m_frameRate));2342 2343 if( (occupancyBits < 0) && (m_initialOVB > 0) )2344 {2345 adjustmentBits = xAdjustmentBits(occupancyBits, m_initialOVB );2346 2347 if(m_initialOVB < 0)2348 {2349 adjustmentBits = m_initialOVB;2350 occupancyBits += (Int)adjustmentBits;2351 m_initialOVB = 0;2352 }2353 }2354 else if( (occupancyBits > 0) && (m_initialOVB < 0) )2355 {2356 adjustmentBits = xAdjustmentBits(m_initialOVB, occupancyBits );2357 2358 if(occupancyBits < 0)2359 {2360 adjustmentBits = occupancyBits;2361 m_initialOVB += (Int)adjustmentBits;2362 occupancyBits = 0;2363 }2364 }2365 2366 if(m_indexGOP == 0)2367 {2368 m_initialOVB = occupancyBits;2369 }2370 else2371 {2372 m_occupancyVB= m_occupancyVB + occupancyBits;2373 }2374 2375 if(pcFrameData->m_isReferenced)2376 {2377 m_costRefAvgWeighting = ((pcFrameData->m_bits*pcFrameData->m_qp)/8.0) + (7.0*(m_costRefAvgWeighting)/8.0);2378 2379 if(m_indexFrame == 0)2380 {2381 m_initialTBL = m_targetBufLevel = (frameBits - (m_currBitrate/m_frameRate));2382 }2383 else2384 {2385 Int distance = (m_costNonRefAvgWeighting == 0) ? 0 : 1;2386 m_targetBufLevel = m_targetBufLevel2387 - (m_initialTBL/(m_refFrameNum-1))2388 + (Int)((m_costRefAvgWeighting*(distance+1)*m_currBitrate)/(m_frameRate*(m_costRefAvgWeighting+(m_costNonRefAvgWeighting*distance))))2389 - (m_currBitrate/m_frameRate);2390 }2391 2392 if(m_cMADLinearModel.IsUpdateAvailable())2393 {2394 m_cMADLinearModel.updateMADLiearModel();2395 }2396 2397 if(eSliceType != I_SLICE &&2398 m_cPixelURQQuadraticModel.checkUpdateAvailable(pcFrameData->m_qp))2399 {2400 m_cPixelURQQuadraticModel.updatePixelBasedURQQuadraticModel(pcFrameData->m_qp, pcFrameData->m_bits, m_numOfPixels, pcFrameData->m_costMAD);2401 }2402 }2403 else2404 {2405 m_costNonRefAvgWeighting = ((pcFrameData->m_bits*pcFrameData->m_qp)/8.0) + (7.0*(m_costNonRefAvgWeighting)/8.0);2406 }2407 2408 m_indexFrame++;2409 m_indexLCU = 0;2410 m_indexUnit = 0;2411 m_occupancyVBInFrame = 0;2412 m_remainingBitsInFrame = 0;2413 m_codedPixels = 0;2414 m_activeUnitLevelOn = false;2415 m_costAvgbpp = 0.0;2416 }2417 Void TEncRateCtrl::updataRCUnitStatus ()2418 {2419 if(!m_activeUnitLevelOn || m_indexLCU == 0)2420 {2421 return;2422 }2423 2424 m_codedPixels += m_pcLCUData[m_indexLCU-1].m_pixels;2425 m_remainingBitsInFrame = m_remainingBitsInFrame - m_pcLCUData[m_indexLCU-1].m_bits;2426 m_occupancyVBInFrame = (Int)(m_occupancyVBInFrame + m_pcLCUData[m_indexLCU-1].m_bits - m_pcLCUData[m_indexLCU-1].m_pixels*m_costAvgbpp);2427 2428 if( m_cPixelURQQuadraticModel.checkUpdateAvailable(m_pcLCUData[m_indexLCU-1].m_qp) )2429 {2430 m_cPixelURQQuadraticModel.updatePixelBasedURQQuadraticModel(m_pcLCUData[m_indexLCU-1].m_qp, m_pcLCUData[m_indexLCU-1].m_bits, m_pcLCUData[m_indexLCU-1].m_pixels, m_pcLCUData[m_indexLCU-1].m_costMAD);2431 }2432 2433 m_indexUnit++;2434 }2435 2436 Void TEncRateCtrl::updateFrameData(UInt64 actualFrameBits)2437 {2438 Double costMAD = 0.0;2439 2440 for(Int i = 0; i < m_numUnitInFrame; i++)2441 {2442 costMAD += m_pcLCUData[i].m_costMAD;2443 }2444 2445 m_pcFrameData[m_indexPOCInGOP].m_costMAD = (costMAD/(Double)m_numUnitInFrame);2446 m_pcFrameData[m_indexPOCInGOP].m_bits = (Int)actualFrameBits;2447 2448 if(m_pcFrameData[m_indexPOCInGOP].m_isReferenced)2449 {2450 m_indexPrevPOCInGOP = m_indexPOCInGOP;2451 m_cMADLinearModel.updateMADHistory(m_pcFrameData[m_indexPOCInGOP].m_costMAD);2452 }2453 }2454 2455 Void TEncRateCtrl::updateLCUData(TComDataCU* pcCU, UInt64 actualLCUBits, Int qp)2456 {2457 Int x, y;2458 Double costMAD = 0.0;2459 2460 Pel* pOrg = pcCU->getPic()->getPicYuvOrg()->getLumaAddr(pcCU->getAddr(), 0);2461 Pel* pRec = pcCU->getPic()->getPicYuvRec()->getLumaAddr(pcCU->getAddr(), 0);2462 Int stride = pcCU->getPic()->getStride();2463 2464 Int width = m_pcLCUData[m_indexLCU].m_widthInPixel;2465 Int height = m_pcLCUData[m_indexLCU].m_heightInPixel;2466 2467 for( y = 0; y < height; y++ )2468 {2469 for( x = 0; x < width; x++ )2470 {2471 costMAD += abs( pOrg[x] - pRec[x] );2472 }2473 pOrg += stride;2474 pRec += stride;2475 }2476 m_pcLCUData[m_indexLCU ].m_qp = qp;2477 m_pcLCUData[m_indexLCU ].m_costMAD = (costMAD /(Double)(width*height));2478 m_pcLCUData[m_indexLCU++].m_bits = (Int)actualLCUBits;2479 }2480 2481 2482 #if KWU_RC_MADPRED_E02272483 Void TEncRateCtrl::updateLCUDataEnhancedView(TComDataCU* pcCU, UInt64 uiBits, Int qp, Double basePos, Double curPos, Double focalLen, Double znear, Double zfar, Int direction)2484 {2485 Int x, y;2486 Double dMAD = 0.0;2487 Int Sum = 0;2488 Double SAD = 0.0;2489 2490 Pel* pOrg = pcCU->getSlice()->getIvPic(false, 0)->getPicYuvOrg()->getLumaAddr(pcCU->getAddr(), 0);2491 Pel* pRec = pcCU->getSlice()->getIvPic(false, 0)->getPicYuvRec()->getLumaAddr(pcCU->getAddr(), 0);2492 Pel* pDep = pcCU->getSlice()->getIvPic(true, pcCU->getSlice()->getViewIndex())->getPicYuvOrg()->getLumaAddr(pcCU->getAddr(), 0);2493 Int iStride = pcCU->getSlice()->getIvPic(true, pcCU->getSlice()->getViewIndex())->getPicYuvOrg()->getStride();2494 2495 Int width = m_pcLCUData[m_indexLCU].m_widthInPixel;2496 Int height = m_pcLCUData[m_indexLCU].m_heightInPixel;2497 2498 for( y = 0 ; y < pcCU->getSlice()->getSPS()->getMaxCUHeight() ; y+=8)2499 {2500 for( x = 0 ; x < pcCU->getSlice()->getSPS()->getMaxCUWidth() ; x+=8)2501 {2502 Sum += pDep[x];2503 }2504 pDep += iStride;2505 }2506 2507 Double AvgDepth = (Double)Sum/((pcCU->getSlice()->getSPS()->getMaxCUHeight()/8)*(pcCU->getSlice()->getSPS()->getMaxCUWidth()/8));2508 Double fL = focalLen * abs( basePos - curPos );2509 Double z = abs( 1.0 / znear - 1.0 / zfar ) * ((Double)(AvgDepth) / (( 1 << g_bitDepthY ) - 1) ) + abs(1.0 / zfar);2510 Int disparity = (Int)(direction*fL * z);2511 Int shift = DISTORTION_PRECISION_ADJUSTMENT(g_bitDepthY-8);2512 Int disp = disparity;2513 2514 for( y = 0; y < height; y++ )2515 {2516 for( x = 0; x < width; x++ )2517 {2518 SAD += abs( pOrg[Clip3(0, (Int)(pcCU->getPic()->getPicYuvOrg()->getWidth() - pcCU->getSlice()->getSPS()->getMaxCUWidth()), x + disp)]2519 - pRec[Clip3(0, (Int)(pcCU->getPic()->getPicYuvOrg()->getWidth() - pcCU->getSlice()->getSPS()->getMaxCUWidth()), x + disp)] )>>shift;2520 }2521 pOrg += iStride;2522 pRec += iStride;2523 }2524 m_pcLCUData[m_indexLCU].m_qp = qp;2525 m_pcLCUData[m_indexLCU].m_costMAD = (SAD /(Double)(width*height));2526 m_pcLCUData[m_indexLCU].m_bits = (Int)uiBits;2527 }2528 #endif2529 2530 2531 Double TEncRateCtrl::xAdjustmentBits(Int& reductionBits, Int& compensationBits)2532 {2533 Double adjustment = ADJUSTMENT_FACTOR*reductionBits;2534 reductionBits -= (Int)adjustment;2535 compensationBits += (Int)adjustment;2536 2537 return adjustment;2538 }2539 2540 #endif2541 -
branches/HTM-10.0-dev0/source/Lib/TLibEncoder/TEncRateCtrl.h
r655 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 55 55 //! \{ 56 56 57 #if RATE_CONTROL_LAMBDA_DOMAIN58 57 #include "../TLibEncoder/TEncCfg.h" 59 58 #include <list> … … 65 64 const Double g_RCWeightPicTargetBitInGOP = 0.9; 66 65 const Double g_RCWeightPicRargetBitInBuffer = 1.0 - g_RCWeightPicTargetBitInGOP; 67 #if M0036_RC_IMPROVEMENT68 66 const Int g_RCIterationNum = 20; 69 67 const Double g_RCWeightHistoryLambda = 0.5; … … 74 72 const Double g_RCBetaMinValue = -3.0; 75 73 const Double g_RCBetaMaxValue = -0.1; 76 #endif 77 78 #if RATE_CONTROL_INTRA 74 79 75 #define ALPHA 6.7542; 80 76 #define BETA1 1.2517 81 77 #define BETA2 1.7860 82 #endif83 78 84 79 struct TRCLCU … … 88 83 Int m_targetBits; 89 84 Double m_lambda; 90 #if M0036_RC_IMPROVEMENT91 85 Double m_bitWeight; 92 #else93 Double m_MAD;94 #endif95 86 Int m_numberOfPixel; 96 #if RATE_CONTROL_INTRA97 87 Double m_costIntra; 98 88 Int m_targetBitsLeft; 99 #endif100 101 89 #if KWU_RC_MADPRED_E0227 102 90 Double m_MAD; 103 104 91 Int m_CUWidth; 105 92 Int m_CUHeight; … … 121 108 122 109 public: 123 #if M0036_RC_IMPROVEMENT124 110 Void create( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Int numberOfLevel, Bool useLCUSeparateModel, Int adaptiveBit ); 125 #else126 Void create( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Int numberOfLevel, Bool useLCUSeparateModel );127 #endif128 111 Void destroy(); 129 112 Void initBitsRatio( Int bitsRatio[] ); … … 132 115 Void initLCUPara( TRCParameter** LCUPara = NULL ); // NULL to initial with default value 133 116 Void updateAfterPic ( Int bits ); 134 #if !RATE_CONTROL_INTRA135 Int getRefineBitsForIntra( Int orgBits );136 #endif137 #if M0036_RC_IMPROVEMENT138 117 Void setAllBitRatio( Double basicLambda, Double* equaCoeffA, Double* equaCoeffB ); 139 #endif140 118 141 119 public: … … 175 153 Double getBetaUpdate() { return m_betaUpdate; } 176 154 177 #if M0036_RC_IMPROVEMENT178 155 Int getAdaptiveBits() { return m_adaptiveBit; } 179 156 Double getLastLambda() { return m_lastLambda; } 180 157 Void setLastLambda( Double lamdba ) { m_lastLambda = lamdba; } 181 #endif182 158 183 159 private: … … 208 184 Bool m_useLCUSeparateModel; 209 185 210 #if M0036_RC_IMPROVEMENT211 186 Int m_adaptiveBit; 212 187 Double m_lastLambda; 213 #endif214 188 }; 215 189 … … 227 201 private: 228 202 Int xEstGOPTargetBits( TEncRCSeq* encRCSeq, Int GOPSize ); 229 #if M0036_RC_IMPROVEMENT230 203 Void xCalEquaCoeff( TEncRCSeq* encRCSeq, Double* lambdaRatio, Double* equaCoeffA, Double* equaCoeffB, Int GOPSize ); 231 204 Double xSolveEqua( Double targetBpp, Double* equaCoeffA, Double* equaCoeffB, Int GOPSize ); 232 #endif233 205 234 206 public: … … 266 238 Double estimatePicLambdaIV( list<TEncRCPic*>& listPreviousPictures, Int curPOC ); 267 239 #endif 268 #if !RATE_CONTROL_INTRA269 Double estimatePicLambda( list<TEncRCPic*>& listPreviousPictures );270 #endif271 240 Int estimatePicQP ( Double lambda, list<TEncRCPic*>& listPreviousPictures ); 272 #if RATE_CONTROL_INTRA273 241 Int getRefineBitsForIntra(Int orgBits); 274 242 Double calculateLambdaIntra(double alpha, double beta, double MADPerPixel, double bitsPerPixel); … … 279 247 Double getLCUTargetBpp(SliceType eSliceType); 280 248 Double getLCUEstLambdaAndQP(Double bpp, Int clipPicQP, Int *estQP); 281 #else282 Double getLCUTargetBpp();283 #endif284 285 249 #if KWU_RC_MADPRED_E0227 286 250 Double getLCUTargetBppforInterView( list<TEncRCPic*>& listPreviousPictures, TComDataCU* pcCU, Double basePos, Double curPos, Double focalLen, Double znear, Double zfar, Int direction, Int* disparity ); 287 251 #endif 288 289 252 Double getLCUEstLambda( Double bpp ); 290 253 Int getLCUEstQP( Double lambda, Int clipPicQP ); 291 254 292 255 Void updateAfterLCU( Int LCUIdx, Int bits, Int QP, Double lambda, Bool updateLCUParameter = true ); 293 #if M0036_RC_IMPROVEMENT294 #if RATE_CONTROL_INTRA295 256 Void updateAfterPicture( Int actualHeaderBits, Int actualTotalBits, Double averageQP, Double averageLambda, SliceType eSliceType); 296 #else297 Void updateAfterPicture( Int actualHeaderBits, Int actualTotalBits, Double averageQP, Double averageLambda );298 #endif299 #else300 Void updateAfterPicture( Int actualHeaderBits, Int actualTotalBits, Double averageQP, Double averageLambda, Double effectivePercentage );301 #endif302 257 303 258 Void addToPictureLsit( list<TEncRCPic*>& listPreviousPictures ); 304 305 259 #if KWU_RC_MADPRED_E0227 306 260 Void addToPictureLsitIV( list<TEncRCPic*>& listPreviousPictures ); 307 261 Void setIVPic( TEncRCPic* baseRCPic ); 308 #endif309 310 #if !M0036_RC_IMPROVEMENT311 Double getEffectivePercentage();312 262 #endif 313 263 Double calAverageQP(); … … 326 276 Int getNumberOfLCU() { return m_numberOfLCU; } 327 277 Int getTargetBits() { return m_targetBits; } 328 #if !RATE_CONTROL_INTRA329 Void setTargetBits( Int bits ) { m_targetBits = bits; }330 #endif331 278 Int getEstHeaderBits() { return m_estHeaderBits; } 332 279 Int getLCULeft() { return m_LCULeft; } … … 338 285 TRCLCU& getLCU( Int LCUIdx ) { return m_LCUs[LCUIdx]; } 339 286 Int getPicActualHeaderBits() { return m_picActualHeaderBits; } 340 #if !M0036_RC_IMPROVEMENT341 Double getTotalMAD() { return m_totalMAD; }342 Void setTotalMAD( Double MAD ) { m_totalMAD = MAD; }343 #endif344 #if RATE_CONTROL_INTRA345 287 Void setTargetBits( Int bits ) { m_targetBits = bits; m_bitsLeft = bits;} 346 288 Void setTotalIntraCost(Double cost) { m_totalCostIntra = cost; } 347 289 Void getLCUInitTargetBits(); 348 #endif349 350 290 #if KWU_RC_MADPRED_E0227 351 291 Double getTotalMAD() { return m_totalMAD; } … … 368 308 Void setLayerID(Int layerid) { m_LayerID = layerid; } 369 309 #endif 370 371 310 private: 372 311 TEncRCSeq* m_encRCSeq; … … 387 326 TRCLCU* m_LCUs; 388 327 Int m_picActualHeaderBits; // only SH and potential APS 389 #if !M0036_RC_IMPROVEMENT390 Double m_totalMAD;391 #endif392 #if RATE_CONTROL_INTRA393 328 Double m_totalCostIntra; 394 329 Double m_remainingCostIntra; 395 #endif396 330 Int m_picActualBits; // the whole picture, including header 397 331 Int m_picQP; // in integer form 398 332 Double m_picLambda; 399 #if !M0036_RC_IMPROVEMENT400 TEncRCPic* m_lastPicture;401 #endif402 403 333 #if KWU_RC_MADPRED_E0227 404 334 Double m_totalMAD; … … 417 347 418 348 public: 419 #if M0036_RC_IMPROVEMENT420 349 #if KWU_RC_MADPRED_E0227 421 350 Void init( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Bool keepHierBits, Bool useLCUSeparateModel, GOPEntry GOPList[MAX_GOP], Int layerID ); 422 351 #else 423 352 Void init( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Int keepHierBits, Bool useLCUSeparateModel, GOPEntry GOPList[MAX_GOP] ); 424 #endif425 #else426 Void init( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Bool keepHierBits, Bool useLCUSeparateModel, GOPEntry GOPList[MAX_GOP] );427 353 #endif 428 354 Void destroy(); … … 443 369 Void setLayerID(Int layerid) { m_LayerID = layerid; } 444 370 #endif 445 446 371 private: 447 372 TEncRCSeq* m_encRCSeq; … … 450 375 list<TEncRCPic*> m_listRCPictures; 451 376 Int m_RCQP; 452 453 377 #if KWU_RC_MADPRED_E0227 454 378 Int m_LayerID; … … 456 380 }; 457 381 458 #else 459 460 // ==================================================================================================================== 461 // Class definition 462 // ==================================================================================================================== 463 #define MAX_DELTA_QP 2 464 #define MAX_CUDQP_DEPTH 0 465 466 typedef struct FrameData 467 { 468 Bool m_isReferenced; 469 Int m_qp; 470 Int m_bits; 471 Double m_costMAD; 472 }FrameData; 473 474 typedef struct LCUData 475 { 476 Int m_qp; ///< coded QP 477 Int m_bits; ///< actually generated bits 478 Int m_pixels; ///< number of pixels for a unit 479 Int m_widthInPixel; ///< number of pixels for width 480 Int m_heightInPixel; ///< number of pixels for height 481 Double m_costMAD; ///< texture complexity for a unit 482 }LCUData; 483 484 class MADLinearModel 485 { 486 private: 487 Bool m_activeOn; 488 Double m_paramY1; 489 Double m_paramY2; 490 Double m_costMADs[3]; 491 492 public: 493 MADLinearModel () {}; 494 ~MADLinearModel() {}; 495 496 Void initMADLinearModel (); 497 Double getMAD (); 498 Void updateMADLiearModel (); 499 Void updateMADHistory (Double costMAD); 500 Bool IsUpdateAvailable () { return m_activeOn; } 501 }; 502 503 class PixelBaseURQQuadraticModel 504 { 505 private: 506 Double m_paramHighX1; 507 Double m_paramHighX2; 508 Double m_paramLowX1; 509 Double m_paramLowX2; 510 public: 511 PixelBaseURQQuadraticModel () {}; 512 ~PixelBaseURQQuadraticModel() {}; 513 514 Void initPixelBaseQuadraticModel (); 515 Int getQP (Int qp, Int targetBits, Int numberOfPixels, Double costPredMAD); 516 Void updatePixelBasedURQQuadraticModel (Int qp, Int bits, Int numberOfPixels, Double costMAD); 517 Bool checkUpdateAvailable (Int qpReference ); 518 Double xConvertQP2QStep (Int qp ); 519 Int xConvertQStep2QP (Double qStep ); 520 }; 521 522 class TEncRateCtrl 523 { 524 private: 525 Bool m_isLowdelay; 526 Int m_prevBitrate; 527 Int m_currBitrate; 528 Int m_frameRate; 529 Int m_refFrameNum; 530 Int m_nonRefFrameNum; 531 Int m_numOfPixels; 532 Int m_sourceWidthInLCU; 533 Int m_sourceHeightInLCU; 534 Int m_sizeGOP; 535 Int m_indexGOP; 536 Int m_indexFrame; 537 Int m_indexLCU; 538 Int m_indexUnit; 539 Int m_indexRefFrame; 540 Int m_indexNonRefFrame; 541 Int m_indexPOCInGOP; 542 Int m_indexPrevPOCInGOP; 543 Int m_occupancyVB; 544 Int m_initialOVB; 545 Int m_targetBufLevel; 546 Int m_initialTBL; 547 Int m_remainingBitsInGOP; 548 Int m_remainingBitsInFrame; 549 Int m_occupancyVBInFrame; 550 Int m_targetBits; 551 Int m_numUnitInFrame; 552 Int m_codedPixels; 553 Bool m_activeUnitLevelOn; 554 Double m_costNonRefAvgWeighting; 555 Double m_costRefAvgWeighting; 556 Double m_costAvgbpp; 557 558 FrameData* m_pcFrameData; 559 LCUData* m_pcLCUData; 560 561 MADLinearModel m_cMADLinearModel; 562 PixelBaseURQQuadraticModel m_cPixelURQQuadraticModel; 563 564 public: 565 TEncRateCtrl () {}; 566 virtual ~TEncRateCtrl() {}; 567 568 Void create (Int sizeIntraPeriod, Int sizeGOP, Int frameRate, Int targetKbps, Int qp, Int numLCUInBasicUnit, Int sourceWidth, Int sourceHeight, Int maxCUWidth, Int maxCUHeight); 569 Void destroy (); 570 571 Void initFrameData (Int qp = 0); 572 Void initUnitData (Int qp = 0); 573 Int getFrameQP (Bool isReferenced, Int POC); 574 Bool calculateUnitQP (); 575 Int getUnitQP () { return m_pcLCUData[m_indexLCU].m_qp; } 576 Void updateRCGOPStatus (); 577 Void updataRCFrameStatus (Int frameBits, SliceType eSliceType); 578 Void updataRCUnitStatus (); 579 Void updateLCUData (TComDataCU* pcCU, UInt64 actualLCUBits, Int qp); 580 #if KWU_RC_MADPRED_E0227 581 Void updateLCUDataEnhancedView(TComDataCU* pcCU, UInt64 uiBits, Int qp, Double basePos, Double curPos, Double focalLen, Double znear, Double zfar, Int direction); 582 #endif 583 Void updateFrameData (UInt64 actualFrameBits); 584 Double xAdjustmentBits (Int& reductionBits, Int& compensationBits); 585 Int getGOPId () { return m_indexFrame; } 586 }; 587 #endif 588 589 #endif 590 591 382 #endif 383 384 -
branches/HTM-10.0-dev0/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.cpp
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-201 3, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 41 41 #include <stdio.h> 42 42 #include <math.h> 43 44 43 //! \ingroup TLibEncoder 45 44 //! \{ 46 45 47 TEncSampleAdaptiveOffset::TEncSampleAdaptiveOffset()48 {49 m_pcEntropyCoder = NULL;50 m_pppcRDSbacCoder = NULL;51 m_pcRDGoOnSbacCoder = NULL;52 m_pppcBinCoderCABAC = NULL;53 m_iCount = NULL;54 m_iOffset = NULL;55 m_iOffsetOrg = NULL;56 m_iRate = NULL;57 m_iDist = NULL;58 m_dCost = NULL;59 m_dCostPartBest = NULL;60 m_iDistOrg = NULL;61 m_iTypePartBest = NULL;62 #if SAO_ENCODING_CHOICE_CHROMA63 m_depthSaoRate[0][0] = 0;64 m_depthSaoRate[0][1] = 0;65 m_depthSaoRate[0][2] = 0;66 m_depthSaoRate[0][3] = 0;67 m_depthSaoRate[1][0] = 0;68 m_depthSaoRate[1][1] = 0;69 m_depthSaoRate[1][2] = 0;70 m_depthSaoRate[1][3] = 0;71 #endif72 }73 TEncSampleAdaptiveOffset::~TEncSampleAdaptiveOffset()74 {75 76 }77 // ====================================================================================================================78 // Constants79 // ====================================================================================================================80 81 82 // ====================================================================================================================83 // Tables84 // ====================================================================================================================85 86 inline Double xRoundIbdi2(Int bitDepth, Double x)87 {88 return ((x)>0) ? (Int)(((Int)(x)+(1<<(bitDepth-8-1)))/(1<<(bitDepth-8))) : ((Int)(((Int)(x)-(1<<(bitDepth-8-1)))/(1<<(bitDepth-8))));89 }90 46 91 47 /** rounding with IBDI 92 48 * \param x 93 49 */ 50 inline Double xRoundIbdi2(Int bitDepth, Double x) 51 { 52 return ((x)>0) ? (Int)(((Int)(x)+(1<<(bitDepth-8-1)))/(1<<(bitDepth-8))) : ((Int)(((Int)(x)-(1<<(bitDepth-8-1)))/(1<<(bitDepth-8)))); 53 } 54 94 55 inline Double xRoundIbdi(Int bitDepth, Double x) 95 56 { … … 98 59 99 60 100 101 /** process SAO for one partition 102 * \param *psQTPart, iPartIdx, dLambda 103 */ 104 Void TEncSampleAdaptiveOffset::rdoSaoOnePart(SAOQTPart *psQTPart, Int iPartIdx, Double dLambda, Int yCbCr) 105 { 106 Int iTypeIdx; 107 Int iNumTotalType = MAX_NUM_SAO_TYPE; 108 SAOQTPart* pOnePart = &(psQTPart[iPartIdx]); 109 110 Int64 iEstDist; 111 Int iClassIdx; 112 Int uiShift = 2 * DISTORTION_PRECISION_ADJUSTMENT((yCbCr == 0 ? g_bitDepthY : g_bitDepthC)-8); 113 UInt uiDepth = pOnePart->PartLevel; 114 115 m_iDistOrg [iPartIdx] = 0; 116 117 Double bestRDCostTableBo = MAX_DOUBLE; 118 Int bestClassTableBo = 0; 119 Int currentDistortionTableBo[MAX_NUM_SAO_CLASS]; 120 Double currentRdCostTableBo[MAX_NUM_SAO_CLASS]; 121 122 Int addr; 123 Int allowMergeLeft; 124 Int allowMergeUp; 125 Int frameWidthInCU = m_pcPic->getFrameWidthInCU(); 126 SaoLcuParam saoLcuParamRdo; 127 128 for (iTypeIdx=-1; iTypeIdx<iNumTotalType; iTypeIdx++) 129 { 130 if( m_bUseSBACRD ) 131 { 132 m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]); 133 m_pcRDGoOnSbacCoder->resetBits(); 134 } 135 else 136 { 137 m_pcEntropyCoder->resetEntropy(); 138 m_pcEntropyCoder->resetBits(); 139 } 140 141 iEstDist = 0; 142 143 if (iTypeIdx == -1) 144 { 145 for (Int ry = pOnePart->StartCUY; ry<= pOnePart->EndCUY; ry++) 146 { 147 for (Int rx = pOnePart->StartCUX; rx <= pOnePart->EndCUX; rx++) 148 { 149 addr = ry * frameWidthInCU + rx; 150 151 // get bits for iTypeIdx = -1 152 allowMergeLeft = 1; 153 allowMergeUp = 1; 154 if (rx != 0) 155 { 156 // check tile id and slice id 157 if ( (m_pcPic->getPicSym()->getTileIdxMap(addr-1) != m_pcPic->getPicSym()->getTileIdxMap(addr)) || (m_pcPic->getCU(addr-1)->getSlice()->getSliceIdx() != m_pcPic->getCU(addr)->getSlice()->getSliceIdx())) 158 { 159 allowMergeLeft = 0; 160 } 161 } 162 if (ry!=0) 163 { 164 if ( (m_pcPic->getPicSym()->getTileIdxMap(addr-m_iNumCuInWidth) != m_pcPic->getPicSym()->getTileIdxMap(addr)) || (m_pcPic->getCU(addr-m_iNumCuInWidth)->getSlice()->getSliceIdx() != m_pcPic->getCU(addr)->getSlice()->getSliceIdx())) 165 { 166 allowMergeUp = 0; 167 } 168 } 169 170 // reset 171 resetSaoUnit(&saoLcuParamRdo); 172 173 // set merge flag 174 saoLcuParamRdo.mergeUpFlag = 1; 175 saoLcuParamRdo.mergeLeftFlag = 1; 176 177 if (ry == pOnePart->StartCUY) 178 { 179 saoLcuParamRdo.mergeUpFlag = 0; 180 } 181 182 if (rx == pOnePart->StartCUX) 183 { 184 saoLcuParamRdo.mergeLeftFlag = 0; 185 } 186 187 m_pcEntropyCoder->encodeSaoUnitInterleaving(yCbCr, 1, rx, ry, &saoLcuParamRdo, 1, 1, allowMergeLeft, allowMergeUp); 188 189 } 190 } 191 } 192 193 if (iTypeIdx>=0) 194 { 195 iEstDist = estSaoTypeDist(iPartIdx, iTypeIdx, uiShift, dLambda, currentDistortionTableBo, currentRdCostTableBo); 196 if( iTypeIdx == SAO_BO ) 197 { 198 // Estimate Best Position 199 Double currentRDCost = 0.0; 200 201 for(Int i=0; i< SAO_MAX_BO_CLASSES -SAO_BO_LEN +1; i++) 202 { 203 currentRDCost = 0.0; 204 for(UInt uj = i; uj < i+SAO_BO_LEN; uj++) 205 { 206 currentRDCost += currentRdCostTableBo[uj]; 207 } 208 209 if( currentRDCost < bestRDCostTableBo) 210 { 211 bestRDCostTableBo = currentRDCost; 212 bestClassTableBo = i; 213 } 214 } 215 216 // Re code all Offsets 217 // Code Center 218 for(iClassIdx = bestClassTableBo; iClassIdx < bestClassTableBo+SAO_BO_LEN; iClassIdx++) 219 { 220 iEstDist += currentDistortionTableBo[iClassIdx]; 221 } 222 } 223 224 for (Int ry = pOnePart->StartCUY; ry<= pOnePart->EndCUY; ry++) 225 { 226 for (Int rx = pOnePart->StartCUX; rx <= pOnePart->EndCUX; rx++) 227 { 228 addr = ry * frameWidthInCU + rx; 229 230 // get bits for iTypeIdx = -1 231 allowMergeLeft = 1; 232 allowMergeUp = 1; 233 if (rx != 0) 234 { 235 // check tile id and slice id 236 if ( (m_pcPic->getPicSym()->getTileIdxMap(addr-1) != m_pcPic->getPicSym()->getTileIdxMap(addr)) || (m_pcPic->getCU(addr-1)->getSlice()->getSliceIdx() != m_pcPic->getCU(addr)->getSlice()->getSliceIdx())) 237 { 238 allowMergeLeft = 0; 239 } 240 } 241 if (ry!=0) 242 { 243 if ( (m_pcPic->getPicSym()->getTileIdxMap(addr-m_iNumCuInWidth) != m_pcPic->getPicSym()->getTileIdxMap(addr)) || (m_pcPic->getCU(addr-m_iNumCuInWidth)->getSlice()->getSliceIdx() != m_pcPic->getCU(addr)->getSlice()->getSliceIdx())) 244 { 245 allowMergeUp = 0; 246 } 247 } 248 249 // reset 250 resetSaoUnit(&saoLcuParamRdo); 251 252 // set merge flag 253 saoLcuParamRdo.mergeUpFlag = 1; 254 saoLcuParamRdo.mergeLeftFlag = 1; 255 256 if (ry == pOnePart->StartCUY) 257 { 258 saoLcuParamRdo.mergeUpFlag = 0; 259 } 260 261 if (rx == pOnePart->StartCUX) 262 { 263 saoLcuParamRdo.mergeLeftFlag = 0; 264 } 265 266 // set type and offsets 267 saoLcuParamRdo.typeIdx = iTypeIdx; 268 saoLcuParamRdo.subTypeIdx = (iTypeIdx==SAO_BO)?bestClassTableBo:0; 269 saoLcuParamRdo.length = m_iNumClass[iTypeIdx]; 270 for (iClassIdx = 0; iClassIdx < saoLcuParamRdo.length; iClassIdx++) 271 { 272 saoLcuParamRdo.offset[iClassIdx] = (Int)m_iOffset[iPartIdx][iTypeIdx][iClassIdx+saoLcuParamRdo.subTypeIdx+1]; 273 } 274 275 m_pcEntropyCoder->encodeSaoUnitInterleaving(yCbCr, 1, rx, ry, &saoLcuParamRdo, 1, 1, allowMergeLeft, allowMergeUp); 276 277 } 278 } 279 280 m_iDist[iPartIdx][iTypeIdx] = iEstDist; 281 m_iRate[iPartIdx][iTypeIdx] = m_pcEntropyCoder->getNumberOfWrittenBits(); 282 283 m_dCost[iPartIdx][iTypeIdx] = (Double)((Double)m_iDist[iPartIdx][iTypeIdx] + dLambda * (Double) m_iRate[iPartIdx][iTypeIdx]); 284 285 if(m_dCost[iPartIdx][iTypeIdx] < m_dCostPartBest[iPartIdx]) 286 { 287 m_iDistOrg [iPartIdx] = 0; 288 m_dCostPartBest[iPartIdx] = m_dCost[iPartIdx][iTypeIdx]; 289 m_iTypePartBest[iPartIdx] = iTypeIdx; 290 if( m_bUseSBACRD ) 291 m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[pOnePart->PartLevel][CI_TEMP_BEST] ); 292 } 293 } 294 else 295 { 296 if(m_iDistOrg[iPartIdx] < m_dCostPartBest[iPartIdx] ) 297 { 298 m_dCostPartBest[iPartIdx] = (Double) m_iDistOrg[iPartIdx] + m_pcEntropyCoder->getNumberOfWrittenBits()*dLambda ; 299 m_iTypePartBest[iPartIdx] = -1; 300 if( m_bUseSBACRD ) 301 { 302 m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[pOnePart->PartLevel][CI_TEMP_BEST] ); 303 } 304 } 305 } 306 } 307 308 pOnePart->bProcessed = true; 309 pOnePart->bSplit = false; 310 pOnePart->iMinDist = m_iTypePartBest[iPartIdx] >= 0 ? m_iDist[iPartIdx][m_iTypePartBest[iPartIdx]] : m_iDistOrg[iPartIdx]; 311 pOnePart->iMinRate = (Int) (m_iTypePartBest[iPartIdx] >= 0 ? m_iRate[iPartIdx][m_iTypePartBest[iPartIdx]] : 0); 312 pOnePart->dMinCost = pOnePart->iMinDist + dLambda * pOnePart->iMinRate; 313 pOnePart->iBestType = m_iTypePartBest[iPartIdx]; 314 if (pOnePart->iBestType != -1) 315 { 316 // pOnePart->bEnableFlag = 1; 317 pOnePart->iLength = m_iNumClass[pOnePart->iBestType]; 318 Int minIndex = 0; 319 if( pOnePart->iBestType == SAO_BO ) 320 { 321 pOnePart->subTypeIdx = bestClassTableBo; 322 minIndex = pOnePart->subTypeIdx; 323 } 324 for (Int i=0; i< pOnePart->iLength ; i++) 325 { 326 pOnePart->iOffset[i] = (Int) m_iOffset[iPartIdx][pOnePart->iBestType][minIndex+i+1]; 327 } 328 329 } 330 else 331 { 332 // pOnePart->bEnableFlag = 0; 333 pOnePart->iLength = 0; 334 } 335 } 336 337 /** Run partition tree disable 338 */ 339 Void TEncSampleAdaptiveOffset::disablePartTree(SAOQTPart *psQTPart, Int iPartIdx) 340 { 341 SAOQTPart* pOnePart= &(psQTPart[iPartIdx]); 342 pOnePart->bSplit = false; 343 pOnePart->iLength = 0; 344 pOnePart->iBestType = -1; 345 346 if (pOnePart->PartLevel < m_uiMaxSplitLevel) 347 { 348 for (Int i=0; i<NUM_DOWN_PART; i++) 349 { 350 disablePartTree(psQTPart, pOnePart->DownPartsIdx[i]); 351 } 352 } 353 } 354 355 /** Run quadtree decision function 356 * \param iPartIdx, pcPicOrg, pcPicDec, pcPicRest, &dCostFinal 357 */ 358 Void TEncSampleAdaptiveOffset::runQuadTreeDecision(SAOQTPart *psQTPart, Int iPartIdx, Double &dCostFinal, Int iMaxLevel, Double dLambda, Int yCbCr) 359 { 360 SAOQTPart* pOnePart = &(psQTPart[iPartIdx]); 361 362 UInt uiDepth = pOnePart->PartLevel; 363 UInt uhNextDepth = uiDepth+1; 364 365 if (iPartIdx == 0) 366 { 367 dCostFinal = 0; 368 } 369 370 //SAO for this part 371 if(!pOnePart->bProcessed) 372 { 373 rdoSaoOnePart (psQTPart, iPartIdx, dLambda, yCbCr); 374 } 375 376 //SAO for sub 4 parts 377 if (pOnePart->PartLevel < iMaxLevel) 378 { 379 Double dCostNotSplit = dLambda + pOnePart->dMinCost; 380 Double dCostSplit = dLambda; 381 382 for (Int i=0; i< NUM_DOWN_PART ;i++) 383 { 384 if( m_bUseSBACRD ) 385 { 386 if ( 0 == i) //initialize RD with previous depth buffer 387 { 388 m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]); 389 } 390 else 391 { 392 m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]); 393 } 394 } 395 runQuadTreeDecision(psQTPart, pOnePart->DownPartsIdx[i], dCostFinal, iMaxLevel, dLambda, yCbCr); 396 dCostSplit += dCostFinal; 397 if( m_bUseSBACRD ) 398 { 399 m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]->load(m_pppcRDSbacCoder[uhNextDepth][CI_TEMP_BEST]); 400 } 401 } 402 403 if(dCostSplit < dCostNotSplit) 404 { 405 dCostFinal = dCostSplit; 406 pOnePart->bSplit = true; 407 pOnePart->iLength = 0; 408 pOnePart->iBestType = -1; 409 if( m_bUseSBACRD ) 410 { 411 m_pppcRDSbacCoder[uiDepth][CI_NEXT_BEST]->load(m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]); 412 } 413 } 414 else 415 { 416 dCostFinal = dCostNotSplit; 417 pOnePart->bSplit = false; 418 for (Int i=0; i<NUM_DOWN_PART; i++) 419 { 420 disablePartTree(psQTPart, pOnePart->DownPartsIdx[i]); 421 } 422 if( m_bUseSBACRD ) 423 { 424 m_pppcRDSbacCoder[uiDepth][CI_NEXT_BEST]->load(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]); 425 } 426 } 427 } 428 else 429 { 430 dCostFinal = pOnePart->dMinCost; 431 } 432 } 433 434 /** delete allocated memory of TEncSampleAdaptiveOffset class. 435 */ 436 Void TEncSampleAdaptiveOffset::destroyEncBuffer() 437 { 438 for (Int i=0;i<m_iNumTotalParts;i++) 439 { 440 for (Int j=0;j<MAX_NUM_SAO_TYPE;j++) 441 { 442 if (m_iCount [i][j]) 443 { 444 delete [] m_iCount [i][j]; 445 } 446 if (m_iOffset[i][j]) 447 { 448 delete [] m_iOffset[i][j]; 449 } 450 if (m_iOffsetOrg[i][j]) 451 { 452 delete [] m_iOffsetOrg[i][j]; 453 } 454 } 455 if (m_iRate[i]) 456 { 457 delete [] m_iRate[i]; 458 } 459 if (m_iDist[i]) 460 { 461 delete [] m_iDist[i]; 462 } 463 if (m_dCost[i]) 464 { 465 delete [] m_dCost[i]; 466 } 467 if (m_iCount [i]) 468 { 469 delete [] m_iCount [i]; 470 } 471 if (m_iOffset[i]) 472 { 473 delete [] m_iOffset[i]; 474 } 475 if (m_iOffsetOrg[i]) 476 { 477 delete [] m_iOffsetOrg[i]; 478 } 479 480 } 481 if (m_iDistOrg) 482 { 483 delete [] m_iDistOrg ; m_iDistOrg = NULL; 484 } 485 if (m_dCostPartBest) 486 { 487 delete [] m_dCostPartBest ; m_dCostPartBest = NULL; 488 } 489 if (m_iTypePartBest) 490 { 491 delete [] m_iTypePartBest ; m_iTypePartBest = NULL; 492 } 493 if (m_iRate) 494 { 495 delete [] m_iRate ; m_iRate = NULL; 496 } 497 if (m_iDist) 498 { 499 delete [] m_iDist ; m_iDist = NULL; 500 } 501 if (m_dCost) 502 { 503 delete [] m_dCost ; m_dCost = NULL; 504 } 505 if (m_iCount) 506 { 507 delete [] m_iCount ; m_iCount = NULL; 508 } 509 if (m_iOffset) 510 { 511 delete [] m_iOffset ; m_iOffset = NULL; 512 } 513 if (m_iOffsetOrg) 514 { 515 delete [] m_iOffsetOrg ; m_iOffsetOrg = NULL; 516 } 517 Int numLcu = m_iNumCuInWidth * m_iNumCuInHeight; 518 519 for (Int i=0;i<numLcu;i++) 520 { 521 for (Int j=0;j<3;j++) 522 { 523 for (Int k=0;k<MAX_NUM_SAO_TYPE;k++) 524 { 525 if (m_count_PreDblk [i][j][k]) 526 { 527 delete [] m_count_PreDblk [i][j][k]; 528 } 529 if (m_offsetOrg_PreDblk[i][j][k]) 530 { 531 delete [] m_offsetOrg_PreDblk[i][j][k]; 532 } 533 } 534 if (m_count_PreDblk [i][j]) 535 { 536 delete [] m_count_PreDblk [i][j]; 537 } 538 if (m_offsetOrg_PreDblk[i][j]) 539 { 540 delete [] m_offsetOrg_PreDblk[i][j]; 541 } 542 } 543 if (m_count_PreDblk [i]) 544 { 545 delete [] m_count_PreDblk [i]; 546 } 547 if (m_offsetOrg_PreDblk[i]) 548 { 549 delete [] m_offsetOrg_PreDblk[i]; 550 } 551 } 552 if (m_count_PreDblk) 553 { 554 delete [] m_count_PreDblk ; m_count_PreDblk = NULL; 555 } 556 if (m_offsetOrg_PreDblk) 557 { 558 delete [] m_offsetOrg_PreDblk ; m_offsetOrg_PreDblk = NULL; 559 } 560 561 Int iMaxDepth = 4; 562 Int iDepth; 563 for ( iDepth = 0; iDepth < iMaxDepth+1; iDepth++ ) 564 { 565 for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ ) 566 { 567 delete m_pppcRDSbacCoder[iDepth][iCIIdx]; 568 delete m_pppcBinCoderCABAC[iDepth][iCIIdx]; 569 } 570 } 571 572 for ( iDepth = 0; iDepth < iMaxDepth+1; iDepth++ ) 573 { 574 delete [] m_pppcRDSbacCoder[iDepth]; 575 delete [] m_pppcBinCoderCABAC[iDepth]; 576 } 577 578 delete [] m_pppcRDSbacCoder; 579 delete [] m_pppcBinCoderCABAC; 580 } 581 582 /** create Encoder Buffer for SAO 583 * \param 584 */ 585 Void TEncSampleAdaptiveOffset::createEncBuffer() 586 { 587 m_iDistOrg = new Int64 [m_iNumTotalParts]; 588 m_dCostPartBest = new Double [m_iNumTotalParts]; 589 m_iTypePartBest = new Int [m_iNumTotalParts]; 590 591 m_iRate = new Int64* [m_iNumTotalParts]; 592 m_iDist = new Int64* [m_iNumTotalParts]; 593 m_dCost = new Double*[m_iNumTotalParts]; 594 595 m_iCount = new Int64 **[m_iNumTotalParts]; 596 m_iOffset = new Int64 **[m_iNumTotalParts]; 597 m_iOffsetOrg = new Int64 **[m_iNumTotalParts]; 598 599 for (Int i=0;i<m_iNumTotalParts;i++) 600 { 601 m_iRate[i] = new Int64 [MAX_NUM_SAO_TYPE]; 602 m_iDist[i] = new Int64 [MAX_NUM_SAO_TYPE]; 603 m_dCost[i] = new Double [MAX_NUM_SAO_TYPE]; 604 605 m_iCount [i] = new Int64 *[MAX_NUM_SAO_TYPE]; 606 m_iOffset[i] = new Int64 *[MAX_NUM_SAO_TYPE]; 607 m_iOffsetOrg[i] = new Int64 *[MAX_NUM_SAO_TYPE]; 608 609 for (Int j=0;j<MAX_NUM_SAO_TYPE;j++) 610 { 611 m_iCount [i][j] = new Int64 [MAX_NUM_SAO_CLASS]; 612 m_iOffset[i][j] = new Int64 [MAX_NUM_SAO_CLASS]; 613 m_iOffsetOrg[i][j]= new Int64 [MAX_NUM_SAO_CLASS]; 614 } 615 } 616 Int numLcu = m_iNumCuInWidth * m_iNumCuInHeight; 617 m_count_PreDblk = new Int64 ***[numLcu]; 618 m_offsetOrg_PreDblk = new Int64 ***[numLcu]; 619 for (Int i=0; i<numLcu; i++) 620 { 621 m_count_PreDblk[i] = new Int64 **[3]; 622 m_offsetOrg_PreDblk[i] = new Int64 **[3]; 623 624 for (Int j=0;j<3;j++) 625 { 626 m_count_PreDblk [i][j] = new Int64 *[MAX_NUM_SAO_TYPE]; 627 m_offsetOrg_PreDblk[i][j] = new Int64 *[MAX_NUM_SAO_TYPE]; 628 629 for (Int k=0;k<MAX_NUM_SAO_TYPE;k++) 630 { 631 m_count_PreDblk [i][j][k] = new Int64 [MAX_NUM_SAO_CLASS]; 632 m_offsetOrg_PreDblk[i][j][k]= new Int64 [MAX_NUM_SAO_CLASS]; 633 } 634 } 635 } 636 637 Int iMaxDepth = 4; 638 m_pppcRDSbacCoder = new TEncSbac** [iMaxDepth+1]; 639 #if FAST_BIT_EST 640 m_pppcBinCoderCABAC = new TEncBinCABACCounter** [iMaxDepth+1]; 641 #else 642 m_pppcBinCoderCABAC = new TEncBinCABAC** [iMaxDepth+1]; 643 #endif 644 645 for ( Int iDepth = 0; iDepth < iMaxDepth+1; iDepth++ ) 646 { 647 m_pppcRDSbacCoder[iDepth] = new TEncSbac* [CI_NUM]; 648 #if FAST_BIT_EST 649 m_pppcBinCoderCABAC[iDepth] = new TEncBinCABACCounter* [CI_NUM]; 650 #else 651 m_pppcBinCoderCABAC[iDepth] = new TEncBinCABAC* [CI_NUM]; 652 #endif 653 for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ ) 654 { 655 m_pppcRDSbacCoder[iDepth][iCIIdx] = new TEncSbac; 656 #if FAST_BIT_EST 657 m_pppcBinCoderCABAC [iDepth][iCIIdx] = new TEncBinCABACCounter; 658 #else 659 m_pppcBinCoderCABAC [iDepth][iCIIdx] = new TEncBinCABAC; 660 #endif 661 m_pppcRDSbacCoder [iDepth][iCIIdx]->init( m_pppcBinCoderCABAC [iDepth][iCIIdx] ); 662 } 663 } 664 } 665 666 /** Start SAO encoder 667 * \param pcPic, pcEntropyCoder, pppcRDSbacCoder, pcRDGoOnSbacCoder 668 */ 669 Void TEncSampleAdaptiveOffset::startSaoEnc( TComPic* pcPic, TEncEntropy* pcEntropyCoder, TEncSbac*** pppcRDSbacCoder, TEncSbac* pcRDGoOnSbacCoder) 670 { 671 m_bUseSBACRD = true; 672 m_pcPic = pcPic; 673 m_pcEntropyCoder = pcEntropyCoder; 674 61 TEncSampleAdaptiveOffset::TEncSampleAdaptiveOffset() 62 { 63 m_pppcRDSbacCoder = NULL; 64 m_pcRDGoOnSbacCoder = NULL; 65 m_pppcBinCoderCABAC = NULL; 66 m_statData = NULL; 67 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 68 m_preDBFstatData = NULL; 69 #endif 70 } 71 72 TEncSampleAdaptiveOffset::~TEncSampleAdaptiveOffset() 73 { 74 destroyEncData(); 75 } 76 77 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 78 Void TEncSampleAdaptiveOffset::createEncData(Bool isPreDBFSamplesUsed) 79 #else 80 Void TEncSampleAdaptiveOffset::createEncData() 81 #endif 82 { 83 84 //cabac coder for RDO 85 m_pppcRDSbacCoder = new TEncSbac* [NUM_SAO_CABACSTATE_LABELS]; 86 m_pppcBinCoderCABAC = new TEncBinCABACCounter* [NUM_SAO_CABACSTATE_LABELS]; 87 88 for(Int cs=0; cs < NUM_SAO_CABACSTATE_LABELS; cs++) 89 { 90 m_pppcRDSbacCoder[cs] = new TEncSbac; 91 m_pppcBinCoderCABAC[cs] = new TEncBinCABACCounter; 92 m_pppcRDSbacCoder [cs]->init( m_pppcBinCoderCABAC [cs] ); 93 } 94 95 96 //statistics 97 m_statData = new SAOStatData**[m_numCTUsPic]; 98 for(Int i=0; i< m_numCTUsPic; i++) 99 { 100 m_statData[i] = new SAOStatData*[NUM_SAO_COMPONENTS]; 101 for(Int compIdx=0; compIdx < NUM_SAO_COMPONENTS; compIdx++) 102 { 103 m_statData[i][compIdx] = new SAOStatData[NUM_SAO_NEW_TYPES]; 104 } 105 } 106 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 107 if(isPreDBFSamplesUsed) 108 { 109 m_preDBFstatData = new SAOStatData**[m_numCTUsPic]; 110 for(Int i=0; i< m_numCTUsPic; i++) 111 { 112 m_preDBFstatData[i] = new SAOStatData*[NUM_SAO_COMPONENTS]; 113 for(Int compIdx=0; compIdx < NUM_SAO_COMPONENTS; compIdx++) 114 { 115 m_preDBFstatData[i][compIdx] = new SAOStatData[NUM_SAO_NEW_TYPES]; 116 } 117 } 118 119 } 120 #endif 121 122 #if SAO_ENCODING_CHOICE 123 ::memset(m_saoDisabledRate, 0, sizeof(m_saoDisabledRate)); 124 #endif 125 126 for(Int typeIdc=0; typeIdc < NUM_SAO_NEW_TYPES; typeIdc++) 127 { 128 m_skipLinesR[SAO_Y ][typeIdc]= 5; 129 m_skipLinesR[SAO_Cb][typeIdc]= m_skipLinesR[SAO_Cr][typeIdc]= 3; 130 131 m_skipLinesB[SAO_Y ][typeIdc]= 4; 132 m_skipLinesB[SAO_Cb][typeIdc]= m_skipLinesB[SAO_Cr][typeIdc]= 2; 133 134 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 135 if(isPreDBFSamplesUsed) 136 { 137 switch(typeIdc) 138 { 139 case SAO_TYPE_EO_0: 140 { 141 m_skipLinesR[SAO_Y ][typeIdc]= 5; 142 m_skipLinesR[SAO_Cb][typeIdc]= m_skipLinesR[SAO_Cr][typeIdc]= 3; 143 144 m_skipLinesB[SAO_Y ][typeIdc]= 3; 145 m_skipLinesB[SAO_Cb][typeIdc]= m_skipLinesB[SAO_Cr][typeIdc]= 1; 146 } 147 break; 148 case SAO_TYPE_EO_90: 149 { 150 m_skipLinesR[SAO_Y ][typeIdc]= 4; 151 m_skipLinesR[SAO_Cb][typeIdc]= m_skipLinesR[SAO_Cr][typeIdc]= 2; 152 153 m_skipLinesB[SAO_Y ][typeIdc]= 4; 154 m_skipLinesB[SAO_Cb][typeIdc]= m_skipLinesB[SAO_Cr][typeIdc]= 2; 155 } 156 break; 157 case SAO_TYPE_EO_135: 158 case SAO_TYPE_EO_45: 159 { 160 m_skipLinesR[SAO_Y ][typeIdc]= 5; 161 m_skipLinesR[SAO_Cb][typeIdc]= m_skipLinesR[SAO_Cr][typeIdc]= 3; 162 163 m_skipLinesB[SAO_Y ][typeIdc]= 4; 164 m_skipLinesB[SAO_Cb][typeIdc]= m_skipLinesB[SAO_Cr][typeIdc]= 2; 165 } 166 break; 167 case SAO_TYPE_BO: 168 { 169 m_skipLinesR[SAO_Y ][typeIdc]= 4; 170 m_skipLinesR[SAO_Cb][typeIdc]= m_skipLinesR[SAO_Cr][typeIdc]= 2; 171 172 m_skipLinesB[SAO_Y ][typeIdc]= 3; 173 m_skipLinesB[SAO_Cb][typeIdc]= m_skipLinesB[SAO_Cr][typeIdc]= 1; 174 } 175 break; 176 default: 177 { 178 printf("Not a supported type"); 179 assert(0); 180 exit(-1); 181 } 182 } 183 } 184 #endif 185 } 186 187 } 188 189 Void TEncSampleAdaptiveOffset::destroyEncData() 190 { 191 if(m_pppcRDSbacCoder != NULL) 192 { 193 for (Int cs = 0; cs < NUM_SAO_CABACSTATE_LABELS; cs ++ ) 194 { 195 delete m_pppcRDSbacCoder[cs]; 196 } 197 delete[] m_pppcRDSbacCoder; m_pppcRDSbacCoder = NULL; 198 } 199 200 if(m_pppcBinCoderCABAC != NULL) 201 { 202 for (Int cs = 0; cs < NUM_SAO_CABACSTATE_LABELS; cs ++ ) 203 { 204 delete m_pppcBinCoderCABAC[cs]; 205 } 206 delete[] m_pppcBinCoderCABAC; m_pppcBinCoderCABAC = NULL; 207 } 208 209 if(m_statData != NULL) 210 { 211 for(Int i=0; i< m_numCTUsPic; i++) 212 { 213 for(Int compIdx=0; compIdx< NUM_SAO_COMPONENTS; compIdx++) 214 { 215 delete[] m_statData[i][compIdx]; 216 } 217 delete[] m_statData[i]; 218 } 219 delete[] m_statData; m_statData = NULL; 220 } 221 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 222 if(m_preDBFstatData != NULL) 223 { 224 for(Int i=0; i< m_numCTUsPic; i++) 225 { 226 for(Int compIdx=0; compIdx< NUM_SAO_COMPONENTS; compIdx++) 227 { 228 delete[] m_preDBFstatData[i][compIdx]; 229 } 230 delete[] m_preDBFstatData[i]; 231 } 232 delete[] m_preDBFstatData; m_preDBFstatData = NULL; 233 } 234 235 #endif 236 } 237 238 Void TEncSampleAdaptiveOffset::initRDOCabacCoder(TEncSbac* pcRDGoOnSbacCoder, TComSlice* pcSlice) 239 { 675 240 m_pcRDGoOnSbacCoder = pcRDGoOnSbacCoder; 676 m_pcEntropyCoder->setEntropyCoder(m_pcRDGoOnSbacCoder, pcPic->getSlice(0)); 677 m_pcEntropyCoder->resetEntropy(); 678 m_pcEntropyCoder->resetBits(); 679 680 if( m_bUseSBACRD ) 681 { 682 m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[0][CI_NEXT_BEST]); 683 m_pppcRDSbacCoder[0][CI_CURR_BEST]->load( m_pppcRDSbacCoder[0][CI_NEXT_BEST]); 684 } 685 } 686 687 /** End SAO encoder 688 */ 689 Void TEncSampleAdaptiveOffset::endSaoEnc() 690 { 691 m_pcPic = NULL; 692 m_pcEntropyCoder = NULL; 693 } 694 695 inline Int xSign(Int x) 696 { 697 return ((x >> 31) | ((Int)( (((UInt) -x)) >> 31))); 698 } 699 700 /** Calculate SAO statistics for non-cross-slice or non-cross-tile processing 701 * \param pRecStart to-be-filtered block buffer pointer 702 * \param pOrgStart original block buffer pointer 703 * \param stride picture buffer stride 704 * \param ppStat statistics buffer 705 * \param ppCount counter buffer 706 * \param width block width 707 * \param height block height 708 * \param pbBorderAvail availabilities of block border pixels 709 */ 710 Void TEncSampleAdaptiveOffset::calcSaoStatsBlock( Pel* pRecStart, Pel* pOrgStart, Int stride, Int64** ppStats, Int64** ppCount, UInt width, UInt height, Bool* pbBorderAvail, Int iYCbCr) 711 { 712 Int64 *stats, *count; 713 Int classIdx, posShift, startX, endX, startY, endY, signLeft,signRight,signDown,signDown1; 714 Pel *pOrg, *pRec; 715 UInt edgeType; 716 Int x, y; 717 Pel *pTableBo = (iYCbCr==0)?m_lumaTableBo:m_chromaTableBo; 718 719 //--------- Band offset-----------// 720 stats = ppStats[SAO_BO]; 721 count = ppCount[SAO_BO]; 722 pOrg = pOrgStart; 723 pRec = pRecStart; 724 for (y=0; y< height; y++) 725 { 726 for (x=0; x< width; x++) 727 { 728 classIdx = pTableBo[pRec[x]]; 729 if (classIdx) 730 { 731 stats[classIdx] += (pOrg[x] - pRec[x]); 732 count[classIdx] ++; 733 } 734 } 735 pOrg += stride; 736 pRec += stride; 737 } 738 //---------- Edge offset 0--------------// 739 stats = ppStats[SAO_EO_0]; 740 count = ppCount[SAO_EO_0]; 741 pOrg = pOrgStart; 742 pRec = pRecStart; 743 744 745 startX = (pbBorderAvail[SGU_L]) ? 0 : 1; 746 endX = (pbBorderAvail[SGU_R]) ? width : (width -1); 747 for (y=0; y< height; y++) 748 { 749 signLeft = xSign(pRec[startX] - pRec[startX-1]); 750 for (x=startX; x< endX; x++) 751 { 752 signRight = xSign(pRec[x] - pRec[x+1]); 753 edgeType = signRight + signLeft + 2; 754 signLeft = -signRight; 755 756 stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]); 757 count[m_auiEoTable[edgeType]] ++; 758 } 759 pRec += stride; 760 pOrg += stride; 761 } 762 763 //---------- Edge offset 1--------------// 764 stats = ppStats[SAO_EO_1]; 765 count = ppCount[SAO_EO_1]; 766 pOrg = pOrgStart; 767 pRec = pRecStart; 768 769 startY = (pbBorderAvail[SGU_T]) ? 0 : 1; 770 endY = (pbBorderAvail[SGU_B]) ? height : height-1; 771 if (!pbBorderAvail[SGU_T]) 772 { 773 pRec += stride; 774 pOrg += stride; 775 } 776 777 for (x=0; x< width; x++) 778 { 779 m_iUpBuff1[x] = xSign(pRec[x] - pRec[x-stride]); 780 } 781 for (y=startY; y<endY; y++) 782 { 783 for (x=0; x< width; x++) 784 { 785 signDown = xSign(pRec[x] - pRec[x+stride]); 786 edgeType = signDown + m_iUpBuff1[x] + 2; 787 m_iUpBuff1[x] = -signDown; 788 789 stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]); 790 count[m_auiEoTable[edgeType]] ++; 791 } 792 pOrg += stride; 793 pRec += stride; 794 } 795 //---------- Edge offset 2--------------// 796 stats = ppStats[SAO_EO_2]; 797 count = ppCount[SAO_EO_2]; 798 pOrg = pOrgStart; 799 pRec = pRecStart; 800 801 posShift= stride + 1; 802 803 startX = (pbBorderAvail[SGU_L]) ? 0 : 1 ; 804 endX = (pbBorderAvail[SGU_R]) ? width : (width-1); 805 806 //prepare 2nd line upper sign 807 pRec += stride; 808 for (x=startX; x< endX+1; x++) 809 { 810 m_iUpBuff1[x] = xSign(pRec[x] - pRec[x- posShift]); 811 } 812 813 //1st line 814 pRec -= stride; 815 if(pbBorderAvail[SGU_TL]) 816 { 817 x= 0; 818 edgeType = xSign(pRec[x] - pRec[x- posShift]) - m_iUpBuff1[x+1] + 2; 819 stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]); 820 count[m_auiEoTable[edgeType]] ++; 821 } 822 if(pbBorderAvail[SGU_T]) 823 { 824 for(x= 1; x< endX; x++) 825 { 826 edgeType = xSign(pRec[x] - pRec[x- posShift]) - m_iUpBuff1[x+1] + 2; 827 stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]); 828 count[m_auiEoTable[edgeType]] ++; 829 } 830 } 831 pRec += stride; 832 pOrg += stride; 833 834 //middle lines 835 for (y= 1; y< height-1; y++) 836 { 837 for (x=startX; x<endX; x++) 838 { 839 signDown1 = xSign(pRec[x] - pRec[x+ posShift]) ; 840 edgeType = signDown1 + m_iUpBuff1[x] + 2; 841 stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]); 842 count[m_auiEoTable[edgeType]] ++; 843 844 m_iUpBufft[x+1] = -signDown1; 845 } 846 m_iUpBufft[startX] = xSign(pRec[stride+startX] - pRec[startX-1]); 847 848 ipSwap = m_iUpBuff1; 849 m_iUpBuff1 = m_iUpBufft; 850 m_iUpBufft = ipSwap; 851 852 pRec += stride; 853 pOrg += stride; 854 } 855 856 //last line 857 if(pbBorderAvail[SGU_B]) 858 { 859 for(x= startX; x< width-1; x++) 860 { 861 edgeType = xSign(pRec[x] - pRec[x+ posShift]) + m_iUpBuff1[x] + 2; 862 stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]); 863 count[m_auiEoTable[edgeType]] ++; 864 } 865 } 866 if(pbBorderAvail[SGU_BR]) 867 { 868 x= width -1; 869 edgeType = xSign(pRec[x] - pRec[x+ posShift]) + m_iUpBuff1[x] + 2; 870 stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]); 871 count[m_auiEoTable[edgeType]] ++; 872 } 873 874 //---------- Edge offset 3--------------// 875 876 stats = ppStats[SAO_EO_3]; 877 count = ppCount[SAO_EO_3]; 878 pOrg = pOrgStart; 879 pRec = pRecStart; 880 881 posShift = stride - 1; 882 startX = (pbBorderAvail[SGU_L]) ? 0 : 1; 883 endX = (pbBorderAvail[SGU_R]) ? width : (width -1); 884 885 //prepare 2nd line upper sign 886 pRec += stride; 887 for (x=startX-1; x< endX; x++) 888 { 889 m_iUpBuff1[x] = xSign(pRec[x] - pRec[x- posShift]); 890 } 891 892 893 //first line 894 pRec -= stride; 895 if(pbBorderAvail[SGU_T]) 896 { 897 for(x= startX; x< width -1; x++) 898 { 899 edgeType = xSign(pRec[x] - pRec[x- posShift]) -m_iUpBuff1[x-1] + 2; 900 stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]); 901 count[m_auiEoTable[edgeType]] ++; 902 } 903 } 904 if(pbBorderAvail[SGU_TR]) 905 { 906 x= width-1; 907 edgeType = xSign(pRec[x] - pRec[x- posShift]) -m_iUpBuff1[x-1] + 2; 908 stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]); 909 count[m_auiEoTable[edgeType]] ++; 910 } 911 pRec += stride; 912 pOrg += stride; 913 914 //middle lines 915 for (y= 1; y< height-1; y++) 916 { 917 for(x= startX; x< endX; x++) 918 { 919 signDown1 = xSign(pRec[x] - pRec[x+ posShift]) ; 920 edgeType = signDown1 + m_iUpBuff1[x] + 2; 921 922 stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]); 923 count[m_auiEoTable[edgeType]] ++; 924 m_iUpBuff1[x-1] = -signDown1; 925 926 } 927 m_iUpBuff1[endX-1] = xSign(pRec[endX-1 + stride] - pRec[endX]); 928 929 pRec += stride; 930 pOrg += stride; 931 } 932 933 //last line 934 if(pbBorderAvail[SGU_BL]) 935 { 936 x= 0; 937 edgeType = xSign(pRec[x] - pRec[x+ posShift]) + m_iUpBuff1[x] + 2; 938 stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]); 939 count[m_auiEoTable[edgeType]] ++; 940 941 } 942 if(pbBorderAvail[SGU_B]) 943 { 944 for(x= 1; x< endX; x++) 945 { 946 edgeType = xSign(pRec[x] - pRec[x+ posShift]) + m_iUpBuff1[x] + 2; 947 stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]); 948 count[m_auiEoTable[edgeType]] ++; 949 } 950 } 951 } 952 953 /** Calculate SAO statistics for current LCU 954 * \param iAddr, iPartIdx, iYCbCr 955 */ 956 Void TEncSampleAdaptiveOffset::calcSaoStatsCu(Int iAddr, Int iPartIdx, Int iYCbCr) 957 { 958 if(!m_bUseNIF) 959 { 960 calcSaoStatsCuOrg( iAddr, iPartIdx, iYCbCr); 961 } 962 else 963 { 964 Int64** ppStats = m_iOffsetOrg[iPartIdx]; 965 Int64** ppCount = m_iCount [iPartIdx]; 966 967 //parameters 968 Int isChroma = (iYCbCr != 0)? 1:0; 969 Int stride = (iYCbCr != 0)?(m_pcPic->getCStride()):(m_pcPic->getStride()); 970 Pel* pPicOrg = getPicYuvAddr (m_pcPic->getPicYuvOrg(), iYCbCr); 971 Pel* pPicRec = getPicYuvAddr(m_pcYuvTmp, iYCbCr); 972 973 std::vector<NDBFBlockInfo>& vFilterBlocks = *(m_pcPic->getCU(iAddr)->getNDBFilterBlocks()); 974 975 //variables 976 UInt xPos, yPos, width, height; 977 Bool* pbBorderAvail; 978 UInt posOffset; 979 980 for(Int i=0; i< vFilterBlocks.size(); i++) 981 { 982 xPos = vFilterBlocks[i].posX >> isChroma; 983 yPos = vFilterBlocks[i].posY >> isChroma; 984 width = vFilterBlocks[i].width >> isChroma; 985 height = vFilterBlocks[i].height >> isChroma; 986 pbBorderAvail = vFilterBlocks[i].isBorderAvailable; 987 988 posOffset = (yPos* stride) + xPos; 989 990 calcSaoStatsBlock(pPicRec+ posOffset, pPicOrg+ posOffset, stride, ppStats, ppCount,width, height, pbBorderAvail, iYCbCr); 991 } 992 } 993 994 } 995 996 /** Calculate SAO statistics for current LCU without non-crossing slice 997 * \param iAddr, iPartIdx, iYCbCr 998 */ 999 Void TEncSampleAdaptiveOffset::calcSaoStatsCuOrg(Int iAddr, Int iPartIdx, Int iYCbCr) 1000 { 1001 Int x,y; 1002 TComDataCU *pTmpCu = m_pcPic->getCU(iAddr); 1003 TComSPS *pTmpSPS = m_pcPic->getSlice(0)->getSPS(); 1004 1005 Pel* pOrg; 1006 Pel* pRec; 1007 Int iStride; 1008 Int iLcuHeight = pTmpSPS->getMaxCUHeight(); 1009 Int iLcuWidth = pTmpSPS->getMaxCUWidth(); 1010 UInt uiLPelX = pTmpCu->getCUPelX(); 1011 UInt uiTPelY = pTmpCu->getCUPelY(); 1012 UInt uiRPelX; 1013 UInt uiBPelY; 1014 Int64* iStats; 1015 Int64* iCount; 1016 Int iClassIdx; 1017 Int iPicWidthTmp; 1018 Int iPicHeightTmp; 1019 Int iStartX; 1020 Int iStartY; 1021 Int iEndX; 1022 Int iEndY; 1023 Pel* pTableBo = (iYCbCr==0)?m_lumaTableBo:m_chromaTableBo; 1024 1025 Int iIsChroma = (iYCbCr!=0)? 1:0; 1026 Int numSkipLine = iIsChroma? 2:4; 1027 if (m_saoLcuBasedOptimization == 0) 1028 { 1029 numSkipLine = 0; 1030 } 1031 1032 Int numSkipLineRight = iIsChroma? 3:5; 1033 if (m_saoLcuBasedOptimization == 0) 1034 { 1035 numSkipLineRight = 0; 1036 } 1037 1038 iPicWidthTmp = m_iPicWidth >> iIsChroma; 1039 iPicHeightTmp = m_iPicHeight >> iIsChroma; 1040 iLcuWidth = iLcuWidth >> iIsChroma; 1041 iLcuHeight = iLcuHeight >> iIsChroma; 1042 uiLPelX = uiLPelX >> iIsChroma; 1043 uiTPelY = uiTPelY >> iIsChroma; 1044 uiRPelX = uiLPelX + iLcuWidth ; 1045 uiBPelY = uiTPelY + iLcuHeight ; 1046 uiRPelX = uiRPelX > iPicWidthTmp ? iPicWidthTmp : uiRPelX; 1047 uiBPelY = uiBPelY > iPicHeightTmp ? iPicHeightTmp : uiBPelY; 1048 iLcuWidth = uiRPelX - uiLPelX; 1049 iLcuHeight = uiBPelY - uiTPelY; 1050 1051 iStride = (iYCbCr == 0)? m_pcPic->getStride(): m_pcPic->getCStride(); 1052 1053 //if(iSaoType == BO_0 || iSaoType == BO_1) 1054 { 1055 if( m_saoLcuBasedOptimization && m_saoLcuBoundary ) 1056 { 1057 numSkipLine = iIsChroma? 1:3; 1058 numSkipLineRight = iIsChroma? 2:4; 1059 } 1060 iStats = m_iOffsetOrg[iPartIdx][SAO_BO]; 1061 iCount = m_iCount [iPartIdx][SAO_BO]; 1062 1063 pOrg = getPicYuvAddr(m_pcPic->getPicYuvOrg(), iYCbCr, iAddr); 1064 pRec = getPicYuvAddr(m_pcPic->getPicYuvRec(), iYCbCr, iAddr); 1065 1066 iEndX = (uiRPelX == iPicWidthTmp) ? iLcuWidth : iLcuWidth-numSkipLineRight; 1067 iEndY = (uiBPelY == iPicHeightTmp) ? iLcuHeight : iLcuHeight-numSkipLine; 1068 for (y=0; y<iEndY; y++) 1069 { 1070 for (x=0; x<iEndX; x++) 1071 { 1072 iClassIdx = pTableBo[pRec[x]]; 1073 if (iClassIdx) 1074 { 1075 iStats[iClassIdx] += (pOrg[x] - pRec[x]); 1076 iCount[iClassIdx] ++; 1077 } 1078 } 1079 pOrg += iStride; 1080 pRec += iStride; 1081 } 1082 1083 } 1084 Int iSignLeft; 1085 Int iSignRight; 1086 Int iSignDown; 1087 Int iSignDown1; 1088 Int iSignDown2; 1089 1090 UInt uiEdgeType; 1091 1092 //if (iSaoType == EO_0 || iSaoType == EO_1 || iSaoType == EO_2 || iSaoType == EO_3) 1093 { 1094 //if (iSaoType == EO_0) 1095 { 1096 if( m_saoLcuBasedOptimization && m_saoLcuBoundary ) 1097 { 1098 numSkipLine = iIsChroma? 1:3; 1099 numSkipLineRight = iIsChroma? 3:5; 1100 } 1101 iStats = m_iOffsetOrg[iPartIdx][SAO_EO_0]; 1102 iCount = m_iCount [iPartIdx][SAO_EO_0]; 1103 1104 pOrg = getPicYuvAddr(m_pcPic->getPicYuvOrg(), iYCbCr, iAddr); 1105 pRec = getPicYuvAddr(m_pcPic->getPicYuvRec(), iYCbCr, iAddr); 1106 1107 iStartX = (uiLPelX == 0) ? 1 : 0; 1108 iEndX = (uiRPelX == iPicWidthTmp) ? iLcuWidth-1 : iLcuWidth-numSkipLineRight; 1109 for (y=0; y<iLcuHeight-numSkipLine; y++) 1110 { 1111 iSignLeft = xSign(pRec[iStartX] - pRec[iStartX-1]); 1112 for (x=iStartX; x< iEndX; x++) 1113 { 1114 iSignRight = xSign(pRec[x] - pRec[x+1]); 1115 uiEdgeType = iSignRight + iSignLeft + 2; 1116 iSignLeft = -iSignRight; 1117 1118 iStats[m_auiEoTable[uiEdgeType]] += (pOrg[x] - pRec[x]); 1119 iCount[m_auiEoTable[uiEdgeType]] ++; 1120 } 1121 pOrg += iStride; 1122 pRec += iStride; 1123 } 1124 } 1125 1126 //if (iSaoType == EO_1) 1127 { 1128 if( m_saoLcuBasedOptimization && m_saoLcuBoundary ) 1129 { 1130 numSkipLine = iIsChroma? 2:4; 1131 numSkipLineRight = iIsChroma? 2:4; 1132 } 1133 iStats = m_iOffsetOrg[iPartIdx][SAO_EO_1]; 1134 iCount = m_iCount [iPartIdx][SAO_EO_1]; 1135 1136 pOrg = getPicYuvAddr(m_pcPic->getPicYuvOrg(), iYCbCr, iAddr); 1137 pRec = getPicYuvAddr(m_pcPic->getPicYuvRec(), iYCbCr, iAddr); 1138 1139 iStartY = (uiTPelY == 0) ? 1 : 0; 1140 iEndX = (uiRPelX == iPicWidthTmp) ? iLcuWidth : iLcuWidth-numSkipLineRight; 1141 iEndY = (uiBPelY == iPicHeightTmp) ? iLcuHeight-1 : iLcuHeight-numSkipLine; 1142 if (uiTPelY == 0) 1143 { 1144 pOrg += iStride; 1145 pRec += iStride; 1146 } 1147 1148 for (x=0; x< iLcuWidth; x++) 1149 { 1150 m_iUpBuff1[x] = xSign(pRec[x] - pRec[x-iStride]); 1151 } 1152 for (y=iStartY; y<iEndY; y++) 1153 { 1154 for (x=0; x<iEndX; x++) 1155 { 1156 iSignDown = xSign(pRec[x] - pRec[x+iStride]); 1157 uiEdgeType = iSignDown + m_iUpBuff1[x] + 2; 1158 m_iUpBuff1[x] = -iSignDown; 1159 1160 iStats[m_auiEoTable[uiEdgeType]] += (pOrg[x] - pRec[x]); 1161 iCount[m_auiEoTable[uiEdgeType]] ++; 1162 } 1163 pOrg += iStride; 1164 pRec += iStride; 1165 } 1166 } 1167 //if (iSaoType == EO_2) 1168 { 1169 if( m_saoLcuBasedOptimization && m_saoLcuBoundary ) 1170 { 1171 numSkipLine = iIsChroma? 2:4; 1172 numSkipLineRight = iIsChroma? 3:5; 1173 } 1174 iStats = m_iOffsetOrg[iPartIdx][SAO_EO_2]; 1175 iCount = m_iCount [iPartIdx][SAO_EO_2]; 1176 1177 pOrg = getPicYuvAddr(m_pcPic->getPicYuvOrg(), iYCbCr, iAddr); 1178 pRec = getPicYuvAddr(m_pcPic->getPicYuvRec(), iYCbCr, iAddr); 1179 1180 iStartX = (uiLPelX == 0) ? 1 : 0; 1181 iEndX = (uiRPelX == iPicWidthTmp) ? iLcuWidth-1 : iLcuWidth-numSkipLineRight; 1182 1183 iStartY = (uiTPelY == 0) ? 1 : 0; 1184 iEndY = (uiBPelY == iPicHeightTmp) ? iLcuHeight-1 : iLcuHeight-numSkipLine; 1185 if (uiTPelY == 0) 1186 { 1187 pOrg += iStride; 1188 pRec += iStride; 1189 } 1190 1191 for (x=iStartX; x<iEndX; x++) 1192 { 1193 m_iUpBuff1[x] = xSign(pRec[x] - pRec[x-iStride-1]); 1194 } 1195 for (y=iStartY; y<iEndY; y++) 1196 { 1197 iSignDown2 = xSign(pRec[iStride+iStartX] - pRec[iStartX-1]); 1198 for (x=iStartX; x<iEndX; x++) 1199 { 1200 iSignDown1 = xSign(pRec[x] - pRec[x+iStride+1]) ; 1201 uiEdgeType = iSignDown1 + m_iUpBuff1[x] + 2; 1202 m_iUpBufft[x+1] = -iSignDown1; 1203 iStats[m_auiEoTable[uiEdgeType]] += (pOrg[x] - pRec[x]); 1204 iCount[m_auiEoTable[uiEdgeType]] ++; 1205 } 1206 m_iUpBufft[iStartX] = iSignDown2; 1207 ipSwap = m_iUpBuff1; 1208 m_iUpBuff1 = m_iUpBufft; 1209 m_iUpBufft = ipSwap; 1210 1211 pRec += iStride; 1212 pOrg += iStride; 1213 } 1214 } 1215 //if (iSaoType == EO_3 ) 1216 { 1217 if( m_saoLcuBasedOptimization && m_saoLcuBoundary ) 1218 { 1219 numSkipLine = iIsChroma? 2:4; 1220 numSkipLineRight = iIsChroma? 3:5; 1221 } 1222 iStats = m_iOffsetOrg[iPartIdx][SAO_EO_3]; 1223 iCount = m_iCount [iPartIdx][SAO_EO_3]; 1224 1225 pOrg = getPicYuvAddr(m_pcPic->getPicYuvOrg(), iYCbCr, iAddr); 1226 pRec = getPicYuvAddr(m_pcPic->getPicYuvRec(), iYCbCr, iAddr); 1227 1228 iStartX = (uiLPelX == 0) ? 1 : 0; 1229 iEndX = (uiRPelX == iPicWidthTmp) ? iLcuWidth-1 : iLcuWidth-numSkipLineRight; 1230 1231 iStartY = (uiTPelY == 0) ? 1 : 0; 1232 iEndY = (uiBPelY == iPicHeightTmp) ? iLcuHeight-1 : iLcuHeight-numSkipLine; 1233 if (iStartY == 1) 1234 { 1235 pOrg += iStride; 1236 pRec += iStride; 1237 } 1238 1239 for (x=iStartX-1; x<iEndX; x++) 1240 { 1241 m_iUpBuff1[x] = xSign(pRec[x] - pRec[x-iStride+1]); 1242 } 1243 1244 for (y=iStartY; y<iEndY; y++) 1245 { 1246 for (x=iStartX; x<iEndX; x++) 1247 { 1248 iSignDown1 = xSign(pRec[x] - pRec[x+iStride-1]) ; 1249 uiEdgeType = iSignDown1 + m_iUpBuff1[x] + 2; 1250 m_iUpBuff1[x-1] = -iSignDown1; 1251 iStats[m_auiEoTable[uiEdgeType]] += (pOrg[x] - pRec[x]); 1252 iCount[m_auiEoTable[uiEdgeType]] ++; 1253 } 1254 m_iUpBuff1[iEndX-1] = xSign(pRec[iEndX-1 + iStride] - pRec[iEndX]); 1255 1256 pRec += iStride; 1257 pOrg += iStride; 1258 } 1259 } 1260 } 1261 } 1262 1263 1264 Void TEncSampleAdaptiveOffset::calcSaoStatsCu_BeforeDblk( TComPic* pcPic ) 1265 { 1266 Int addr, yCbCr; 1267 Int x,y; 1268 TComSPS *pTmpSPS = pcPic->getSlice(0)->getSPS(); 1269 1270 Pel* pOrg; 1271 Pel* pRec; 1272 Int stride; 1273 Int lcuHeight = pTmpSPS->getMaxCUHeight(); 1274 Int lcuWidth = pTmpSPS->getMaxCUWidth(); 1275 UInt rPelX; 1276 UInt bPelY; 1277 Int64* stats; 1278 Int64* count; 1279 Int classIdx; 1280 Int picWidthTmp = 0; 1281 Int picHeightTmp = 0; 1282 Int startX; 1283 Int startY; 1284 Int endX; 1285 Int endY; 1286 Int firstX, firstY; 1287 1288 Int idxY; 1289 Int idxX; 1290 Int frameHeightInCU = m_iNumCuInHeight; 1291 Int frameWidthInCU = m_iNumCuInWidth; 1292 Int j, k; 1293 1294 Int isChroma; 1295 Int numSkipLine, numSkipLineRight; 1296 1297 UInt lPelX, tPelY; 1298 TComDataCU *pTmpCu; 1299 Pel* pTableBo; 1300 1301 for (idxY = 0; idxY< frameHeightInCU; idxY++) 1302 { 1303 for (idxX = 0; idxX< frameWidthInCU; idxX++) 1304 { 1305 lcuHeight = pTmpSPS->getMaxCUHeight(); 1306 lcuWidth = pTmpSPS->getMaxCUWidth(); 1307 addr = idxX + frameWidthInCU*idxY; 1308 pTmpCu = pcPic->getCU(addr); 1309 lPelX = pTmpCu->getCUPelX(); 1310 tPelY = pTmpCu->getCUPelY(); 1311 for( yCbCr = 0; yCbCr < 3; yCbCr++ ) 1312 { 1313 isChroma = (yCbCr!=0)? 1:0; 1314 1315 for ( j=0;j<MAX_NUM_SAO_TYPE;j++) 1316 { 1317 for ( k=0;k< MAX_NUM_SAO_CLASS;k++) 1318 { 1319 m_count_PreDblk [addr][yCbCr][j][k] = 0; 1320 m_offsetOrg_PreDblk[addr][yCbCr][j][k] = 0; 1321 } 1322 } 1323 if( yCbCr == 0 ) 1324 { 1325 picWidthTmp = m_iPicWidth; 1326 picHeightTmp = m_iPicHeight; 1327 } 1328 else if( yCbCr == 1 ) 1329 { 1330 picWidthTmp = m_iPicWidth >> isChroma; 1331 picHeightTmp = m_iPicHeight >> isChroma; 1332 lcuWidth = lcuWidth >> isChroma; 1333 lcuHeight = lcuHeight >> isChroma; 1334 lPelX = lPelX >> isChroma; 1335 tPelY = tPelY >> isChroma; 1336 } 1337 rPelX = lPelX + lcuWidth ; 1338 bPelY = tPelY + lcuHeight ; 1339 rPelX = rPelX > picWidthTmp ? picWidthTmp : rPelX; 1340 bPelY = bPelY > picHeightTmp ? picHeightTmp : bPelY; 1341 lcuWidth = rPelX - lPelX; 1342 lcuHeight = bPelY - tPelY; 1343 1344 stride = (yCbCr == 0)? pcPic->getStride(): pcPic->getCStride(); 1345 pTableBo = (yCbCr==0)?m_lumaTableBo:m_chromaTableBo; 1346 1347 //if(iSaoType == BO) 1348 1349 numSkipLine = isChroma? 1:3; 1350 numSkipLineRight = isChroma? 2:4; 1351 1352 stats = m_offsetOrg_PreDblk[addr][yCbCr][SAO_BO]; 1353 count = m_count_PreDblk[addr][yCbCr][SAO_BO]; 1354 1355 pOrg = getPicYuvAddr(pcPic->getPicYuvOrg(), yCbCr, addr); 1356 pRec = getPicYuvAddr(pcPic->getPicYuvRec(), yCbCr, addr); 1357 1358 startX = (rPelX == picWidthTmp) ? lcuWidth : lcuWidth-numSkipLineRight; 1359 startY = (bPelY == picHeightTmp) ? lcuHeight : lcuHeight-numSkipLine; 1360 1361 for (y=0; y<lcuHeight; y++) 1362 { 1363 for (x=0; x<lcuWidth; x++) 1364 { 1365 if( x < startX && y < startY ) 1366 continue; 1367 1368 classIdx = pTableBo[pRec[x]]; 1369 if (classIdx) 1370 { 1371 stats[classIdx] += (pOrg[x] - pRec[x]); 1372 count[classIdx] ++; 1373 } 1374 } 1375 pOrg += stride; 1376 pRec += stride; 1377 } 1378 1379 Int signLeft; 1380 Int signRight; 1381 Int signDown; 1382 Int signDown1; 1383 Int signDown2; 1384 1385 UInt uiEdgeType; 1386 1387 //if (iSaoType == EO_0) 1388 1389 numSkipLine = isChroma? 1:3; 1390 numSkipLineRight = isChroma? 3:5; 1391 1392 stats = m_offsetOrg_PreDblk[addr][yCbCr][SAO_EO_0]; 1393 count = m_count_PreDblk[addr][yCbCr][SAO_EO_0]; 1394 1395 pOrg = getPicYuvAddr(pcPic->getPicYuvOrg(), yCbCr, addr); 1396 pRec = getPicYuvAddr(pcPic->getPicYuvRec(), yCbCr, addr); 1397 1398 startX = (rPelX == picWidthTmp) ? lcuWidth-1 : lcuWidth-numSkipLineRight; 1399 startY = (bPelY == picHeightTmp) ? lcuHeight : lcuHeight-numSkipLine; 1400 firstX = (lPelX == 0) ? 1 : 0; 1401 endX = (rPelX == picWidthTmp) ? lcuWidth-1 : lcuWidth; 1402 1403 for (y=0; y<lcuHeight; y++) 1404 { 1405 signLeft = xSign(pRec[firstX] - pRec[firstX-1]); 1406 for (x=firstX; x< endX; x++) 1407 { 1408 signRight = xSign(pRec[x] - pRec[x+1]); 1409 uiEdgeType = signRight + signLeft + 2; 1410 signLeft = -signRight; 1411 1412 if( x < startX && y < startY ) 1413 continue; 1414 1415 stats[m_auiEoTable[uiEdgeType]] += (pOrg[x] - pRec[x]); 1416 count[m_auiEoTable[uiEdgeType]] ++; 1417 } 1418 pOrg += stride; 1419 pRec += stride; 1420 } 1421 1422 //if (iSaoType == EO_1) 1423 1424 numSkipLine = isChroma? 2:4; 1425 numSkipLineRight = isChroma? 2:4; 1426 1427 stats = m_offsetOrg_PreDblk[addr][yCbCr][SAO_EO_1]; 1428 count = m_count_PreDblk[addr][yCbCr][SAO_EO_1]; 1429 1430 pOrg = getPicYuvAddr(pcPic->getPicYuvOrg(), yCbCr, addr); 1431 pRec = getPicYuvAddr(pcPic->getPicYuvRec(), yCbCr, addr); 1432 1433 startX = (rPelX == picWidthTmp) ? lcuWidth : lcuWidth-numSkipLineRight; 1434 startY = (bPelY == picHeightTmp) ? lcuHeight-1 : lcuHeight-numSkipLine; 1435 firstY = (tPelY == 0) ? 1 : 0; 1436 endY = (bPelY == picHeightTmp) ? lcuHeight-1 : lcuHeight; 1437 if (firstY == 1) 1438 { 1439 pOrg += stride; 1440 pRec += stride; 1441 } 1442 1443 for (x=0; x< lcuWidth; x++) 1444 { 1445 m_iUpBuff1[x] = xSign(pRec[x] - pRec[x-stride]); 1446 } 1447 for (y=firstY; y<endY; y++) 1448 { 1449 for (x=0; x<lcuWidth; x++) 1450 { 1451 signDown = xSign(pRec[x] - pRec[x+stride]); 1452 uiEdgeType = signDown + m_iUpBuff1[x] + 2; 1453 m_iUpBuff1[x] = -signDown; 1454 1455 if( x < startX && y < startY ) 1456 continue; 1457 1458 stats[m_auiEoTable[uiEdgeType]] += (pOrg[x] - pRec[x]); 1459 count[m_auiEoTable[uiEdgeType]] ++; 1460 } 1461 pOrg += stride; 1462 pRec += stride; 1463 } 1464 1465 //if (iSaoType == EO_2) 1466 1467 numSkipLine = isChroma? 2:4; 1468 numSkipLineRight = isChroma? 3:5; 1469 1470 stats = m_offsetOrg_PreDblk[addr][yCbCr][SAO_EO_2]; 1471 count = m_count_PreDblk[addr][yCbCr][SAO_EO_2]; 1472 1473 pOrg = getPicYuvAddr(pcPic->getPicYuvOrg(), yCbCr, addr); 1474 pRec = getPicYuvAddr(pcPic->getPicYuvRec(), yCbCr, addr); 1475 1476 startX = (rPelX == picWidthTmp) ? lcuWidth-1 : lcuWidth-numSkipLineRight; 1477 startY = (bPelY == picHeightTmp) ? lcuHeight-1 : lcuHeight-numSkipLine; 1478 firstX = (lPelX == 0) ? 1 : 0; 1479 firstY = (tPelY == 0) ? 1 : 0; 1480 endX = (rPelX == picWidthTmp) ? lcuWidth-1 : lcuWidth; 1481 endY = (bPelY == picHeightTmp) ? lcuHeight-1 : lcuHeight; 1482 if (firstY == 1) 1483 { 1484 pOrg += stride; 1485 pRec += stride; 1486 } 1487 1488 for (x=firstX; x<endX; x++) 1489 { 1490 m_iUpBuff1[x] = xSign(pRec[x] - pRec[x-stride-1]); 1491 } 1492 for (y=firstY; y<endY; y++) 1493 { 1494 signDown2 = xSign(pRec[stride+startX] - pRec[startX-1]); 1495 for (x=firstX; x<endX; x++) 1496 { 1497 signDown1 = xSign(pRec[x] - pRec[x+stride+1]) ; 1498 uiEdgeType = signDown1 + m_iUpBuff1[x] + 2; 1499 m_iUpBufft[x+1] = -signDown1; 1500 1501 if( x < startX && y < startY ) 1502 continue; 1503 1504 stats[m_auiEoTable[uiEdgeType]] += (pOrg[x] - pRec[x]); 1505 count[m_auiEoTable[uiEdgeType]] ++; 1506 } 1507 m_iUpBufft[firstX] = signDown2; 1508 ipSwap = m_iUpBuff1; 1509 m_iUpBuff1 = m_iUpBufft; 1510 m_iUpBufft = ipSwap; 1511 1512 pRec += stride; 1513 pOrg += stride; 1514 } 1515 1516 //if (iSaoType == EO_3) 1517 1518 numSkipLine = isChroma? 2:4; 1519 numSkipLineRight = isChroma? 3:5; 1520 1521 stats = m_offsetOrg_PreDblk[addr][yCbCr][SAO_EO_3]; 1522 count = m_count_PreDblk[addr][yCbCr][SAO_EO_3]; 1523 1524 pOrg = getPicYuvAddr(pcPic->getPicYuvOrg(), yCbCr, addr); 1525 pRec = getPicYuvAddr(pcPic->getPicYuvRec(), yCbCr, addr); 1526 1527 startX = (rPelX == picWidthTmp) ? lcuWidth-1 : lcuWidth-numSkipLineRight; 1528 startY = (bPelY == picHeightTmp) ? lcuHeight-1 : lcuHeight-numSkipLine; 1529 firstX = (lPelX == 0) ? 1 : 0; 1530 firstY = (tPelY == 0) ? 1 : 0; 1531 endX = (rPelX == picWidthTmp) ? lcuWidth-1 : lcuWidth; 1532 endY = (bPelY == picHeightTmp) ? lcuHeight-1 : lcuHeight; 1533 if (firstY == 1) 1534 { 1535 pOrg += stride; 1536 pRec += stride; 1537 } 1538 1539 for (x=firstX-1; x<endX; x++) 1540 { 1541 m_iUpBuff1[x] = xSign(pRec[x] - pRec[x-stride+1]); 1542 } 1543 1544 for (y=firstY; y<endY; y++) 1545 { 1546 for (x=firstX; x<endX; x++) 1547 { 1548 signDown1 = xSign(pRec[x] - pRec[x+stride-1]) ; 1549 uiEdgeType = signDown1 + m_iUpBuff1[x] + 2; 1550 m_iUpBuff1[x-1] = -signDown1; 1551 1552 if( x < startX && y < startY ) 1553 continue; 1554 1555 stats[m_auiEoTable[uiEdgeType]] += (pOrg[x] - pRec[x]); 1556 count[m_auiEoTable[uiEdgeType]] ++; 1557 } 1558 m_iUpBuff1[endX-1] = xSign(pRec[endX-1 + stride] - pRec[endX]); 1559 1560 pRec += stride; 1561 pOrg += stride; 1562 } 1563 } 1564 } 1565 } 1566 } 1567 1568 1569 /** get SAO statistics 1570 * \param *psQTPart, iYCbCr 1571 */ 1572 Void TEncSampleAdaptiveOffset::getSaoStats(SAOQTPart *psQTPart, Int iYCbCr) 1573 { 1574 Int iLevelIdx, iPartIdx, iTypeIdx, iClassIdx; 1575 Int i; 1576 Int iNumTotalType = MAX_NUM_SAO_TYPE; 1577 Int LcuIdxX; 1578 Int LcuIdxY; 1579 Int iAddr; 1580 Int iFrameWidthInCU = m_pcPic->getFrameWidthInCU(); 1581 Int iDownPartIdx; 1582 Int iPartStart; 1583 Int iPartEnd; 1584 SAOQTPart* pOnePart; 1585 1586 if (m_uiMaxSplitLevel == 0) 1587 { 1588 iPartIdx = 0; 1589 pOnePart = &(psQTPart[iPartIdx]); 1590 for (LcuIdxY = pOnePart->StartCUY; LcuIdxY<= pOnePart->EndCUY; LcuIdxY++) 1591 { 1592 for (LcuIdxX = pOnePart->StartCUX; LcuIdxX<= pOnePart->EndCUX; LcuIdxX++) 1593 { 1594 iAddr = LcuIdxY*iFrameWidthInCU + LcuIdxX; 1595 calcSaoStatsCu(iAddr, iPartIdx, iYCbCr); 1596 } 1597 } 1598 } 1599 else 1600 { 1601 for(iPartIdx=m_aiNumCulPartsLevel[m_uiMaxSplitLevel-1]; iPartIdx<m_aiNumCulPartsLevel[m_uiMaxSplitLevel]; iPartIdx++) 1602 { 1603 pOnePart = &(psQTPart[iPartIdx]); 1604 for (LcuIdxY = pOnePart->StartCUY; LcuIdxY<= pOnePart->EndCUY; LcuIdxY++) 1605 { 1606 for (LcuIdxX = pOnePart->StartCUX; LcuIdxX<= pOnePart->EndCUX; LcuIdxX++) 1607 { 1608 iAddr = LcuIdxY*iFrameWidthInCU + LcuIdxX; 1609 calcSaoStatsCu(iAddr, iPartIdx, iYCbCr); 1610 } 1611 } 1612 } 1613 for (iLevelIdx = m_uiMaxSplitLevel-1; iLevelIdx>=0; iLevelIdx-- ) 1614 { 1615 iPartStart = (iLevelIdx > 0) ? m_aiNumCulPartsLevel[iLevelIdx-1] : 0; 1616 iPartEnd = m_aiNumCulPartsLevel[iLevelIdx]; 1617 1618 for(iPartIdx = iPartStart; iPartIdx < iPartEnd; iPartIdx++) 1619 { 1620 pOnePart = &(psQTPart[iPartIdx]); 1621 for (i=0; i< NUM_DOWN_PART; i++) 1622 { 1623 iDownPartIdx = pOnePart->DownPartsIdx[i]; 1624 for (iTypeIdx=0; iTypeIdx<iNumTotalType; iTypeIdx++) 1625 { 1626 for (iClassIdx=0; iClassIdx< (iTypeIdx < SAO_BO ? m_iNumClass[iTypeIdx] : SAO_MAX_BO_CLASSES) +1; iClassIdx++) 1627 { 1628 m_iOffsetOrg[iPartIdx][iTypeIdx][iClassIdx] += m_iOffsetOrg[iDownPartIdx][iTypeIdx][iClassIdx]; 1629 m_iCount [iPartIdx][iTypeIdx][iClassIdx] += m_iCount [iDownPartIdx][iTypeIdx][iClassIdx]; 1630 } 1631 } 1632 } 1633 } 1634 } 1635 } 1636 } 1637 1638 /** reset offset statistics 1639 * \param 1640 */ 1641 Void TEncSampleAdaptiveOffset::resetStats() 1642 { 1643 for (Int i=0;i<m_iNumTotalParts;i++) 1644 { 1645 m_dCostPartBest[i] = MAX_DOUBLE; 1646 m_iTypePartBest[i] = -1; 1647 m_iDistOrg[i] = 0; 1648 for (Int j=0;j<MAX_NUM_SAO_TYPE;j++) 1649 { 1650 m_iDist[i][j] = 0; 1651 m_iRate[i][j] = 0; 1652 m_dCost[i][j] = 0; 1653 for (Int k=0;k<MAX_NUM_SAO_CLASS;k++) 1654 { 1655 m_iCount [i][j][k] = 0; 1656 m_iOffset[i][j][k] = 0; 1657 m_iOffsetOrg[i][j][k] = 0; 1658 } 1659 } 1660 } 1661 } 1662 1663 #if SAO_CHROMA_LAMBDA 1664 /** Sample adaptive offset process 1665 * \param pcSaoParam 1666 * \param dLambdaLuma 1667 * \param dLambdaChroma 1668 */ 1669 #if SAO_ENCODING_CHOICE 1670 Void TEncSampleAdaptiveOffset::SAOProcess(SAOParam *pcSaoParam, Double dLambdaLuma, Double dLambdaChroma, Int depth) 1671 #else 1672 Void TEncSampleAdaptiveOffset::SAOProcess(SAOParam *pcSaoParam, Double dLambdaLuma, Double dLambdaChroma) 1673 #endif 1674 #else 1675 /** Sample adaptive offset process 1676 * \param dLambda 1677 */ 1678 Void TEncSampleAdaptiveOffset::SAOProcess(SAOParam *pcSaoParam, Double dLambda) 1679 #endif 1680 { 1681 if(m_bUseNIF) 1682 { 1683 m_pcPic->getPicYuvRec()->copyToPic(m_pcYuvTmp); 1684 } 1685 1686 m_uiSaoBitIncreaseY = max(g_bitDepthY - 10, 0); 1687 m_uiSaoBitIncreaseC = max(g_bitDepthC - 10, 0); 1688 m_iOffsetThY = 1 << min(g_bitDepthY - 5, 5); 1689 m_iOffsetThC = 1 << min(g_bitDepthC - 5, 5); 1690 resetSAOParam(pcSaoParam); 1691 if( !m_saoLcuBasedOptimization || !m_saoLcuBoundary ) 1692 { 1693 resetStats(); 1694 } 1695 Double dCostFinal = 0; 1696 if ( m_saoLcuBasedOptimization) 1697 { 1698 #if SAO_ENCODING_CHOICE 1699 rdoSaoUnitAll(pcSaoParam, dLambdaLuma, dLambdaChroma, depth); 1700 #else 1701 rdoSaoUnitAll(pcSaoParam, dLambdaLuma, dLambdaChroma); 1702 #endif 1703 } 1704 else 1705 { 1706 pcSaoParam->bSaoFlag[0] = 1; 1707 pcSaoParam->bSaoFlag[1] = 0; 1708 dCostFinal = 0; 1709 Double lambdaRdo = dLambdaLuma; 1710 resetStats(); 1711 getSaoStats(pcSaoParam->psSaoPart[0], 0); 1712 runQuadTreeDecision(pcSaoParam->psSaoPart[0], 0, dCostFinal, m_uiMaxSplitLevel, lambdaRdo, 0); 1713 pcSaoParam->bSaoFlag[0] = dCostFinal < 0 ? 1:0; 1714 if(pcSaoParam->bSaoFlag[0]) 1715 { 1716 convertQT2SaoUnit(pcSaoParam, 0, 0); 1717 assignSaoUnitSyntax(pcSaoParam->saoLcuParam[0], pcSaoParam->psSaoPart[0], pcSaoParam->oneUnitFlag[0], 0); 1718 } 1719 } 1720 if (pcSaoParam->bSaoFlag[0]) 1721 { 1722 processSaoUnitAll( pcSaoParam->saoLcuParam[0], pcSaoParam->oneUnitFlag[0], 0); 1723 } 1724 if (pcSaoParam->bSaoFlag[1]) 1725 { 1726 processSaoUnitAll( pcSaoParam->saoLcuParam[1], pcSaoParam->oneUnitFlag[1], 1); 1727 processSaoUnitAll( pcSaoParam->saoLcuParam[2], pcSaoParam->oneUnitFlag[2], 2); 1728 } 1729 } 1730 /** Check merge SAO unit 1731 * \param saoUnitCurr current SAO unit 1732 * \param saoUnitCheck SAO unit tobe check 1733 * \param dir direction 1734 */ 1735 Void TEncSampleAdaptiveOffset::checkMerge(SaoLcuParam * saoUnitCurr, SaoLcuParam * saoUnitCheck, Int dir) 1736 { 1737 Int i ; 1738 Int countDiff = 0; 1739 if (saoUnitCurr->partIdx != saoUnitCheck->partIdx) 1740 { 1741 if (saoUnitCurr->typeIdx !=-1) 1742 { 1743 if (saoUnitCurr->typeIdx == saoUnitCheck->typeIdx) 1744 { 1745 for (i=0;i<saoUnitCurr->length;i++) 1746 { 1747 countDiff += (saoUnitCurr->offset[i] != saoUnitCheck->offset[i]); 1748 } 1749 countDiff += (saoUnitCurr->subTypeIdx != saoUnitCheck->subTypeIdx); 1750 if (countDiff ==0) 1751 { 1752 saoUnitCurr->partIdx = saoUnitCheck->partIdx; 1753 if (dir == 1) 1754 { 1755 saoUnitCurr->mergeUpFlag = 1; 1756 saoUnitCurr->mergeLeftFlag = 0; 1757 } 1758 else 1759 { 1760 saoUnitCurr->mergeUpFlag = 0; 1761 saoUnitCurr->mergeLeftFlag = 1; 1762 } 1763 } 1764 } 1765 } 1766 else 1767 { 1768 if (saoUnitCurr->typeIdx == saoUnitCheck->typeIdx) 1769 { 1770 saoUnitCurr->partIdx = saoUnitCheck->partIdx; 1771 if (dir == 1) 1772 { 1773 saoUnitCurr->mergeUpFlag = 1; 1774 saoUnitCurr->mergeLeftFlag = 0; 1775 } 1776 else 1777 { 1778 saoUnitCurr->mergeUpFlag = 0; 1779 saoUnitCurr->mergeLeftFlag = 1; 1780 } 1781 } 1782 } 1783 } 1784 } 1785 /** Assign SAO unit syntax from picture-based algorithm 1786 * \param saoLcuParam SAO LCU parameters 1787 * \param saoPart SAO part 1788 * \param oneUnitFlag SAO one unit flag 1789 * \param iYCbCr color component Index 1790 */ 1791 Void TEncSampleAdaptiveOffset::assignSaoUnitSyntax(SaoLcuParam* saoLcuParam, SAOQTPart* saoPart, Bool &oneUnitFlag, Int yCbCr) 1792 { 1793 if (saoPart->bSplit == 0) 1794 { 1795 oneUnitFlag = 1; 1796 } 1797 else 1798 { 1799 Int i,j, addr, addrUp, addrLeft, idx, idxUp, idxLeft, idxCount; 1800 1801 oneUnitFlag = 0; 1802 1803 idxCount = -1; 1804 saoLcuParam[0].mergeUpFlag = 0; 1805 saoLcuParam[0].mergeLeftFlag = 0; 1806 1807 for (j=0;j<m_iNumCuInHeight;j++) 1808 { 1809 for (i=0;i<m_iNumCuInWidth;i++) 1810 { 1811 addr = i + j*m_iNumCuInWidth; 1812 addrLeft = (addr%m_iNumCuInWidth == 0) ? -1 : addr - 1; 1813 addrUp = (addr<m_iNumCuInWidth) ? -1 : addr - m_iNumCuInWidth; 1814 idx = saoLcuParam[addr].partIdxTmp; 1815 idxLeft = (addrLeft == -1) ? -1 : saoLcuParam[addrLeft].partIdxTmp; 1816 idxUp = (addrUp == -1) ? -1 : saoLcuParam[addrUp].partIdxTmp; 1817 1818 if(idx!=idxLeft && idx!=idxUp) 1819 { 1820 saoLcuParam[addr].mergeUpFlag = 0; idxCount++; 1821 saoLcuParam[addr].mergeLeftFlag = 0; 1822 saoLcuParam[addr].partIdx = idxCount; 1823 } 1824 else if (idx==idxLeft) 1825 { 1826 saoLcuParam[addr].mergeUpFlag = 1; 1827 saoLcuParam[addr].mergeLeftFlag = 1; 1828 saoLcuParam[addr].partIdx = saoLcuParam[addrLeft].partIdx; 1829 } 1830 else if (idx==idxUp) 1831 { 1832 saoLcuParam[addr].mergeUpFlag = 1; 1833 saoLcuParam[addr].mergeLeftFlag = 0; 1834 saoLcuParam[addr].partIdx = saoLcuParam[addrUp].partIdx; 1835 } 1836 if (addrUp != -1) 1837 { 1838 checkMerge(&saoLcuParam[addr], &saoLcuParam[addrUp], 1); 1839 } 1840 if (addrLeft != -1) 1841 { 1842 checkMerge(&saoLcuParam[addr], &saoLcuParam[addrLeft], 0); 1843 } 1844 } 1845 } 1846 } 1847 } 1848 /** rate distortion optimization of all SAO units 1849 * \param saoParam SAO parameters 1850 * \param lambda 1851 * \param lambdaChroma 1852 */ 1853 #if SAO_ENCODING_CHOICE 1854 Void TEncSampleAdaptiveOffset::rdoSaoUnitAll(SAOParam *saoParam, Double lambda, Double lambdaChroma, Int depth) 1855 #else 1856 Void TEncSampleAdaptiveOffset::rdoSaoUnitAll(SAOParam *saoParam, Double lambda, Double lambdaChroma) 1857 #endif 1858 { 1859 1860 Int idxY; 1861 Int idxX; 1862 Int frameHeightInCU = saoParam->numCuInHeight; 1863 Int frameWidthInCU = saoParam->numCuInWidth; 1864 Int j, k; 1865 Int addr = 0; 1866 Int addrUp = -1; 1867 Int addrLeft = -1; 1868 Int compIdx = 0; 1869 SaoLcuParam mergeSaoParam[3][2]; 1870 Double compDistortion[3]; 1871 1872 saoParam->bSaoFlag[0] = true; 1873 saoParam->bSaoFlag[1] = true; 1874 saoParam->oneUnitFlag[0] = false; 1875 saoParam->oneUnitFlag[1] = false; 1876 saoParam->oneUnitFlag[2] = false; 241 m_pcRDGoOnSbacCoder->setSlice(pcSlice); 242 m_pcRDGoOnSbacCoder->resetEntropy(); 243 m_pcRDGoOnSbacCoder->resetBits(); 244 245 m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[SAO_CABACSTATE_PIC_INIT]); 246 } 247 248 249 250 Void TEncSampleAdaptiveOffset::SAOProcess(TComPic* pPic, Bool* sliceEnabled, const Double *lambdas 251 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 252 , Bool isPreDBFSamplesUsed 253 #endif 254 ) 255 { 256 TComPicYuv* orgYuv= pPic->getPicYuvOrg(); 257 TComPicYuv* resYuv= pPic->getPicYuvRec(); 258 m_lambda[SAO_Y]= lambdas[0]; m_lambda[SAO_Cb]= lambdas[1]; m_lambda[SAO_Cr]= lambdas[2]; 259 TComPicYuv* srcYuv = m_tempPicYuv; 260 resYuv->copyToPic(srcYuv); 261 srcYuv->setBorderExtension(false); 262 srcYuv->extendPicBorder(); 263 264 //collect statistics 265 getStatistics(m_statData, orgYuv, srcYuv, pPic); 266 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 267 if(isPreDBFSamplesUsed) 268 { 269 addPreDBFStatistics(m_statData); 270 } 271 #endif 272 //slice on/off 273 decidePicParams(sliceEnabled, pPic->getSlice(0)->getDepth()); 274 275 //block on/off 276 SAOBlkParam* reconParams = new SAOBlkParam[m_numCTUsPic]; //temporary parameter buffer for storing reconstructed SAO parameters 277 decideBlkParams(pPic, sliceEnabled, m_statData, srcYuv, resYuv, reconParams, pPic->getPicSym()->getSAOBlkParam()); 278 delete[] reconParams; 279 280 } 281 282 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 283 Void TEncSampleAdaptiveOffset::getPreDBFStatistics(TComPic* pPic) 284 { 285 getStatistics(m_preDBFstatData, pPic->getPicYuvOrg(), pPic->getPicYuvRec(), pPic, true); 286 } 287 288 Void TEncSampleAdaptiveOffset::addPreDBFStatistics(SAOStatData*** blkStats) 289 { 290 for(Int n=0; n< m_numCTUsPic; n++) 291 { 292 for(Int compIdx=0; compIdx < NUM_SAO_COMPONENTS; compIdx++) 293 { 294 for(Int typeIdc=0; typeIdc < NUM_SAO_NEW_TYPES; typeIdc++) 295 { 296 blkStats[n][compIdx][typeIdc] += m_preDBFstatData[n][compIdx][typeIdc]; 297 } 298 } 299 } 300 } 301 302 #endif 303 304 Void TEncSampleAdaptiveOffset::getStatistics(SAOStatData*** blkStats, TComPicYuv* orgYuv, TComPicYuv* srcYuv, TComPic* pPic 305 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 306 , Bool isCalculatePreDeblockSamples 307 #endif 308 ) 309 { 310 Bool isLeftAvail,isRightAvail,isAboveAvail,isBelowAvail,isAboveLeftAvail,isAboveRightAvail,isBelowLeftAvail,isBelowRightAvail; 311 312 for(Int ctu= 0; ctu < m_numCTUsPic; ctu++) 313 { 314 Int yPos = (ctu / m_numCTUInWidth)*m_maxCUHeight; 315 Int xPos = (ctu % m_numCTUInWidth)*m_maxCUWidth; 316 Int height = (yPos + m_maxCUHeight > m_picHeight)?(m_picHeight- yPos):m_maxCUHeight; 317 Int width = (xPos + m_maxCUWidth > m_picWidth )?(m_picWidth - xPos):m_maxCUWidth; 318 319 pPic->getPicSym()->deriveLoopFilterBoundaryAvailibility(ctu, isLeftAvail,isRightAvail,isAboveAvail,isBelowAvail,isAboveLeftAvail,isAboveRightAvail,isBelowLeftAvail,isBelowRightAvail); 320 321 //NOTE: The number of skipped lines during gathering CTU statistics depends on the slice boundary availabilities. 322 //For simplicity, here only picture boundaries are considered. 323 324 isRightAvail = (xPos + m_maxCUWidth < m_picWidth ); 325 isBelowAvail = (yPos + m_maxCUHeight < m_picHeight); 326 isBelowRightAvail = (isRightAvail && isBelowAvail); 327 isBelowLeftAvail = ((xPos > 0) && (isBelowAvail)); 328 isAboveRightAvail = ((yPos > 0) && (isRightAvail)); 329 330 for(Int compIdx=0; compIdx< NUM_SAO_COMPONENTS; compIdx++) 331 { 332 Bool isLuma = (compIdx == SAO_Y); 333 Int formatShift= isLuma?0:1; 334 335 Int srcStride = isLuma?srcYuv->getStride():srcYuv->getCStride(); 336 Pel* srcBlk = getPicBuf(srcYuv, compIdx)+ (yPos >> formatShift)*srcStride+ (xPos >> formatShift); 337 338 Int orgStride = isLuma?orgYuv->getStride():orgYuv->getCStride(); 339 Pel* orgBlk = getPicBuf(orgYuv, compIdx)+ (yPos >> formatShift)*orgStride+ (xPos >> formatShift); 340 341 getBlkStats(compIdx, blkStats[ctu][compIdx] 342 , srcBlk, orgBlk, srcStride, orgStride, (width >> formatShift), (height >> formatShift) 343 , isLeftAvail, isRightAvail, isAboveAvail, isBelowAvail, isAboveLeftAvail, isAboveRightAvail, isBelowLeftAvail, isBelowRightAvail 344 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 345 , isCalculatePreDeblockSamples 346 #endif 347 ); 348 349 } 350 } 351 } 352 353 Void TEncSampleAdaptiveOffset::decidePicParams(Bool* sliceEnabled, Int picTempLayer) 354 { 355 //decide sliceEnabled[compIdx] 356 for (Int compIdx=0; compIdx<NUM_SAO_COMPONENTS; compIdx++) 357 { 358 // reset flags & counters 359 sliceEnabled[compIdx] = true; 1877 360 1878 361 #if SAO_ENCODING_CHOICE 1879 362 #if SAO_ENCODING_CHOICE_CHROMA 1880 Int numNoSao[2]; 1881 numNoSao[0] = 0;// Luma 1882 numNoSao[1] = 0;// Chroma 1883 if( depth > 0 && m_depthSaoRate[0][depth-1] > SAO_ENCODING_RATE ) 1884 { 1885 saoParam->bSaoFlag[0] = false; 1886 } 1887 if( depth > 0 && m_depthSaoRate[1][depth-1] > SAO_ENCODING_RATE_CHROMA ) 1888 { 1889 saoParam->bSaoFlag[1] = false; 1890 } 1891 #else 1892 Int numNoSao = 0; 1893 1894 if( depth > 0 && m_depth0SaoRate > SAO_ENCODING_RATE ) 1895 { 1896 saoParam->bSaoFlag[0] = false; 1897 saoParam->bSaoFlag[1] = false; 1898 } 1899 #endif 1900 #endif 1901 1902 for (idxY = 0; idxY< frameHeightInCU; idxY++) 1903 { 1904 for (idxX = 0; idxX< frameWidthInCU; idxX++) 1905 { 1906 addr = idxX + frameWidthInCU*idxY; 1907 addrUp = addr < frameWidthInCU ? -1:idxX + frameWidthInCU*(idxY-1); 1908 addrLeft = idxX == 0 ? -1:idxX-1 + frameWidthInCU*idxY; 1909 Int allowMergeLeft = 1; 1910 Int allowMergeUp = 1; 1911 UInt rate; 1912 Double bestCost, mergeCost; 1913 if (idxX!=0) 1914 { 1915 // check tile id and slice id 1916 if ( (m_pcPic->getPicSym()->getTileIdxMap(addr-1) != m_pcPic->getPicSym()->getTileIdxMap(addr)) || (m_pcPic->getCU(addr-1)->getSlice()->getSliceIdx() != m_pcPic->getCU(addr)->getSlice()->getSliceIdx())) 1917 { 1918 allowMergeLeft = 0; 1919 } 1920 } 1921 else 1922 { 1923 allowMergeLeft = 0; 1924 } 1925 if (idxY!=0) 1926 { 1927 if ( (m_pcPic->getPicSym()->getTileIdxMap(addr-m_iNumCuInWidth) != m_pcPic->getPicSym()->getTileIdxMap(addr)) || (m_pcPic->getCU(addr-m_iNumCuInWidth)->getSlice()->getSliceIdx() != m_pcPic->getCU(addr)->getSlice()->getSliceIdx())) 1928 { 1929 allowMergeUp = 0; 1930 } 1931 } 1932 else 1933 { 1934 allowMergeUp = 0; 1935 } 1936 1937 compDistortion[0] = 0; 1938 compDistortion[1] = 0; 1939 compDistortion[2] = 0; 1940 m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[0][CI_CURR_BEST]); 1941 if (allowMergeLeft) 1942 { 1943 m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoMerge(0); 1944 } 1945 if (allowMergeUp) 1946 { 1947 m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoMerge(0); 1948 } 1949 m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[0][CI_TEMP_BEST] ); 1950 // reset stats Y, Cb, Cr 1951 for ( compIdx=0;compIdx<3;compIdx++) 1952 { 1953 for ( j=0;j<MAX_NUM_SAO_TYPE;j++) 1954 { 1955 for ( k=0;k< MAX_NUM_SAO_CLASS;k++) 1956 { 1957 m_iOffset [compIdx][j][k] = 0; 1958 if( m_saoLcuBasedOptimization && m_saoLcuBoundary ){ 1959 m_iCount [compIdx][j][k] = m_count_PreDblk [addr][compIdx][j][k]; 1960 m_iOffsetOrg[compIdx][j][k] = m_offsetOrg_PreDblk[addr][compIdx][j][k]; 1961 } 1962 else 1963 { 1964 m_iCount [compIdx][j][k] = 0; 1965 m_iOffsetOrg[compIdx][j][k] = 0; 1966 } 1967 } 1968 } 1969 saoParam->saoLcuParam[compIdx][addr].typeIdx = -1; 1970 saoParam->saoLcuParam[compIdx][addr].mergeUpFlag = 0; 1971 saoParam->saoLcuParam[compIdx][addr].mergeLeftFlag = 0; 1972 saoParam->saoLcuParam[compIdx][addr].subTypeIdx = 0; 1973 #if SAO_ENCODING_CHOICE 1974 if( (compIdx ==0 && saoParam->bSaoFlag[0])|| (compIdx >0 && saoParam->bSaoFlag[1]) ) 1975 #endif 1976 { 1977 calcSaoStatsCu(addr, compIdx, compIdx); 1978 1979 } 1980 } 1981 saoComponentParamDist(allowMergeLeft, allowMergeUp, saoParam, addr, addrUp, addrLeft, 0, lambda, &mergeSaoParam[0][0], &compDistortion[0]); 1982 sao2ChromaParamDist(allowMergeLeft, allowMergeUp, saoParam, addr, addrUp, addrLeft, lambdaChroma, &mergeSaoParam[1][0], &mergeSaoParam[2][0], &compDistortion[0]); 1983 if( saoParam->bSaoFlag[0] || saoParam->bSaoFlag[1] ) 1984 { 1985 // Cost of new SAO_params 1986 m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[0][CI_CURR_BEST]); 1987 m_pcRDGoOnSbacCoder->resetBits(); 1988 if (allowMergeLeft) 1989 { 1990 m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoMerge(0); 1991 } 1992 if (allowMergeUp) 1993 { 1994 m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoMerge(0); 1995 } 1996 for ( compIdx=0;compIdx<3;compIdx++) 1997 { 1998 if( (compIdx ==0 && saoParam->bSaoFlag[0]) || (compIdx >0 && saoParam->bSaoFlag[1])) 1999 { 2000 m_pcEntropyCoder->encodeSaoOffset(&saoParam->saoLcuParam[compIdx][addr], compIdx); 2001 } 2002 } 2003 2004 rate = m_pcEntropyCoder->getNumberOfWrittenBits(); 2005 bestCost = compDistortion[0] + (Double)rate; 2006 m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[0][CI_TEMP_BEST]); 2007 2008 // Cost of Merge 2009 for(Int mergeUp=0; mergeUp<2; ++mergeUp) 2010 { 2011 if ( (allowMergeLeft && (mergeUp==0)) || (allowMergeUp && (mergeUp==1)) ) 2012 { 2013 m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[0][CI_CURR_BEST]); 2014 m_pcRDGoOnSbacCoder->resetBits(); 2015 if (allowMergeLeft) 2016 { 2017 m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoMerge(1-mergeUp); 2018 } 2019 if ( allowMergeUp && (mergeUp==1) ) 2020 { 2021 m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoMerge(1); 2022 } 2023 2024 rate = m_pcEntropyCoder->getNumberOfWrittenBits(); 2025 mergeCost = compDistortion[mergeUp+1] + (Double)rate; 2026 if (mergeCost < bestCost) 2027 { 2028 bestCost = mergeCost; 2029 m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[0][CI_TEMP_BEST]); 2030 for ( compIdx=0;compIdx<3;compIdx++) 2031 { 2032 mergeSaoParam[compIdx][mergeUp].mergeLeftFlag = 1-mergeUp; 2033 mergeSaoParam[compIdx][mergeUp].mergeUpFlag = mergeUp; 2034 if( (compIdx==0 && saoParam->bSaoFlag[0]) || (compIdx>0 && saoParam->bSaoFlag[1])) 2035 { 2036 copySaoUnit(&saoParam->saoLcuParam[compIdx][addr], &mergeSaoParam[compIdx][mergeUp] ); 2037 } 2038 } 2039 } 2040 } 2041 } 2042 #if SAO_ENCODING_CHOICE 2043 #if SAO_ENCODING_CHOICE_CHROMA 2044 if( saoParam->saoLcuParam[0][addr].typeIdx == -1) 2045 { 2046 numNoSao[0]++; 2047 } 2048 if( saoParam->saoLcuParam[1][addr].typeIdx == -1) 2049 { 2050 numNoSao[1]+=2; 2051 } 2052 #else 2053 for ( compIdx=0;compIdx<3;compIdx++) 2054 { 2055 if( depth == 0 && saoParam->saoLcuParam[compIdx][addr].typeIdx == -1) 2056 { 2057 numNoSao++; 2058 } 2059 } 2060 #endif 2061 #endif 2062 m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[0][CI_TEMP_BEST]); 2063 m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[0][CI_CURR_BEST]); 2064 } 2065 } 2066 } 2067 #if SAO_ENCODING_CHOICE 2068 #if SAO_ENCODING_CHOICE_CHROMA 2069 if( !saoParam->bSaoFlag[0]) 2070 { 2071 m_depthSaoRate[0][depth] = 1.0; 2072 } 2073 else 2074 { 2075 m_depthSaoRate[0][depth] = numNoSao[0]/((Double) frameHeightInCU*frameWidthInCU); 2076 } 2077 if( !saoParam->bSaoFlag[1]) 2078 { 2079 m_depthSaoRate[1][depth] = 1.0; 2080 } 2081 else 2082 { 2083 m_depthSaoRate[1][depth] = numNoSao[1]/((Double) frameHeightInCU*frameWidthInCU*2); 2084 } 2085 #else 2086 if( depth == 0) 2087 { 2088 // update SAO Rate 2089 m_depth0SaoRate = numNoSao/((Double) frameHeightInCU*frameWidthInCU*3); 2090 } 2091 #endif 2092 #endif 2093 2094 } 2095 /** rate distortion optimization of SAO unit 2096 * \param saoParam SAO parameters 2097 * \param addr address 2098 * \param addrUp above address 2099 * \param addrLeft left address 2100 * \param yCbCr color component index 2101 * \param lambda 2102 */ 2103 inline Int64 TEncSampleAdaptiveOffset::estSaoTypeDist(Int compIdx, Int typeIdx, Int shift, Double lambda, Int *currentDistortionTableBo, Double *currentRdCostTableBo) 2104 { 2105 Int64 estDist = 0; 2106 Int classIdx; 2107 Int bitDepth = (compIdx==0) ? g_bitDepthY : g_bitDepthC; 2108 Int saoBitIncrease = (compIdx==0) ? m_uiSaoBitIncreaseY : m_uiSaoBitIncreaseC; 2109 Int saoOffsetTh = (compIdx==0) ? m_iOffsetThY : m_iOffsetThC; 2110 2111 for(classIdx=1; classIdx < ( (typeIdx < SAO_BO) ? m_iNumClass[typeIdx]+1 : SAO_MAX_BO_CLASSES+1); classIdx++) 2112 { 2113 if( typeIdx == SAO_BO) 2114 { 2115 currentDistortionTableBo[classIdx-1] = 0; 2116 currentRdCostTableBo[classIdx-1] = lambda; 2117 } 2118 if(m_iCount [compIdx][typeIdx][classIdx]) 2119 { 2120 m_iOffset[compIdx][typeIdx][classIdx] = (Int64) xRoundIbdi(bitDepth, (Double)(m_iOffsetOrg[compIdx][typeIdx][classIdx]<<(bitDepth-8)) / (Double)(m_iCount [compIdx][typeIdx][classIdx]<<saoBitIncrease)); 2121 m_iOffset[compIdx][typeIdx][classIdx] = Clip3(-saoOffsetTh+1, saoOffsetTh-1, (Int)m_iOffset[compIdx][typeIdx][classIdx]); 2122 if (typeIdx < 4) 2123 { 2124 if ( m_iOffset[compIdx][typeIdx][classIdx]<0 && classIdx<3 ) 2125 { 2126 m_iOffset[compIdx][typeIdx][classIdx] = 0; 2127 } 2128 if ( m_iOffset[compIdx][typeIdx][classIdx]>0 && classIdx>=3) 2129 { 2130 m_iOffset[compIdx][typeIdx][classIdx] = 0; 2131 } 2132 } 2133 m_iOffset[compIdx][typeIdx][classIdx] = estIterOffset( typeIdx, classIdx, lambda, m_iOffset[compIdx][typeIdx][classIdx], m_iCount [compIdx][typeIdx][classIdx], m_iOffsetOrg[compIdx][typeIdx][classIdx], shift, saoBitIncrease, currentDistortionTableBo, currentRdCostTableBo, saoOffsetTh ); 2134 } 2135 else 2136 { 2137 m_iOffsetOrg[compIdx][typeIdx][classIdx] = 0; 2138 m_iOffset[compIdx][typeIdx][classIdx] = 0; 2139 } 2140 if( typeIdx != SAO_BO ) 2141 { 2142 estDist += estSaoDist( m_iCount [compIdx][typeIdx][classIdx], m_iOffset[compIdx][typeIdx][classIdx] << saoBitIncrease, m_iOffsetOrg[compIdx][typeIdx][classIdx], shift); 2143 } 2144 2145 } 2146 return estDist; 2147 } 2148 2149 inline Int64 TEncSampleAdaptiveOffset::estSaoDist(Int64 count, Int64 offset, Int64 offsetOrg, Int shift) 2150 { 2151 return (( count*offset*offset-offsetOrg*offset*2 ) >> shift); 2152 } 2153 inline Int64 TEncSampleAdaptiveOffset::estIterOffset(Int typeIdx, Int classIdx, Double lambda, Int64 offsetInput, Int64 count, Int64 offsetOrg, Int shift, Int bitIncrease, Int *currentDistortionTableBo, Double *currentRdCostTableBo, Int offsetTh ) 2154 { 2155 //Clean up, best_q_offset. 2156 Int64 iterOffset, tempOffset; 363 // decide slice-level on/off based on previous results 364 if( (picTempLayer > 0) 365 && (m_saoDisabledRate[compIdx][picTempLayer-1] > ((compIdx==SAO_Y) ? SAO_ENCODING_RATE : SAO_ENCODING_RATE_CHROMA)) ) 366 { 367 sliceEnabled[compIdx] = false; 368 } 369 #else 370 // decide slice-level on/off based on previous results 371 if( (picTempLayer > 0) 372 && (m_saoDisabledRate[SAO_Y][0] > SAO_ENCODING_RATE) ) 373 { 374 sliceEnabled[compIdx] = false; 375 } 376 #endif 377 #endif 378 } 379 } 380 381 Int64 TEncSampleAdaptiveOffset::getDistortion(Int ctu, Int compIdx, Int typeIdc, Int typeAuxInfo, Int* invQuantOffset, SAOStatData& statData) 382 { 383 Int64 dist=0; 384 Int inputBitDepth = (compIdx == SAO_Y) ? g_bitDepthY : g_bitDepthC ; 385 Int shift = 2 * DISTORTION_PRECISION_ADJUSTMENT(inputBitDepth-8); 386 387 switch(typeIdc) 388 { 389 case SAO_TYPE_EO_0: 390 case SAO_TYPE_EO_90: 391 case SAO_TYPE_EO_135: 392 case SAO_TYPE_EO_45: 393 { 394 for (Int offsetIdx=0; offsetIdx<NUM_SAO_EO_CLASSES; offsetIdx++) 395 { 396 dist += estSaoDist( statData.count[offsetIdx], invQuantOffset[offsetIdx], statData.diff[offsetIdx], shift); 397 } 398 } 399 break; 400 case SAO_TYPE_BO: 401 { 402 for (Int offsetIdx=typeAuxInfo; offsetIdx<typeAuxInfo+4; offsetIdx++) 403 { 404 Int bandIdx = offsetIdx % NUM_SAO_BO_CLASSES ; 405 dist += estSaoDist( statData.count[bandIdx], invQuantOffset[bandIdx], statData.diff[bandIdx], shift); 406 } 407 } 408 break; 409 default: 410 { 411 printf("Not a supported type"); 412 assert(0); 413 exit(-1); 414 } 415 } 416 417 return dist; 418 } 419 420 inline Int64 TEncSampleAdaptiveOffset::estSaoDist(Int64 count, Int64 offset, Int64 diffSum, Int shift) 421 { 422 return (( count*offset*offset-diffSum*offset*2 ) >> shift); 423 } 424 425 426 inline Int TEncSampleAdaptiveOffset::estIterOffset(Int typeIdx, Int classIdx, Double lambda, Int offsetInput, Int64 count, Int64 diffSum, Int shift, Int bitIncrease, Int64& bestDist, Double& bestCost, Int offsetTh ) 427 { 428 Int iterOffset, tempOffset; 2157 429 Int64 tempDist, tempRate; 2158 430 Double tempCost, tempMinCost; 2159 Int 64offsetOutput = 0;431 Int offsetOutput = 0; 2160 432 iterOffset = offsetInput; 2161 433 // Assuming sending quantized value 0 results in zero offset and sending the value zero needs 1 bit. entropy coder can be used to measure the exact rate here. … … 2163 435 while (iterOffset != 0) 2164 436 { 2165 // Calculate the bits required for signal ling the offset2166 tempRate = (typeIdx == SAO_ BO) ? (abs((Int)iterOffset)+2) : (abs((Int)iterOffset)+1);2167 if (abs((Int)iterOffset)==offsetTh -1)437 // Calculate the bits required for signaling the offset 438 tempRate = (typeIdx == SAO_TYPE_BO) ? (abs((Int)iterOffset)+2) : (abs((Int)iterOffset)+1); 439 if (abs((Int)iterOffset)==offsetTh) //inclusive 2168 440 { 2169 441 tempRate --; 2170 442 } 2171 // Do the dequ ntization before distorion calculation443 // Do the dequantization before distortion calculation 2172 444 tempOffset = iterOffset << bitIncrease; 2173 tempDist = estSaoDist( count, tempOffset, offsetOrg, shift);445 tempDist = estSaoDist( count, tempOffset, diffSum, shift); 2174 446 tempCost = ((Double)tempDist + lambda * (Double) tempRate); 2175 447 if(tempCost < tempMinCost) … … 2177 449 tempMinCost = tempCost; 2178 450 offsetOutput = iterOffset; 2179 if(typeIdx == SAO_BO) 2180 { 2181 currentDistortionTableBo[classIdx-1] = (Int) tempDist; 2182 currentRdCostTableBo[classIdx-1] = tempCost; 2183 } 451 bestDist = tempDist; 452 bestCost = tempCost; 2184 453 } 2185 454 iterOffset = (iterOffset > 0) ? (iterOffset-1):(iterOffset+1); … … 2189 458 2190 459 2191 Void TEncSampleAdaptiveOffset::saoComponentParamDist(Int allowMergeLeft, Int allowMergeUp, SAOParam *saoParam, Int addr, Int addrUp, Int addrLeft, Int yCbCr, Double lambda, SaoLcuParam *compSaoParam, Double *compDistortion) 2192 { 2193 Int typeIdx; 2194 2195 Int64 estDist; 2196 Int classIdx; 2197 Int shift = 2 * DISTORTION_PRECISION_ADJUSTMENT(((yCbCr==0)?g_bitDepthY:g_bitDepthC)-8); 2198 Int64 bestDist; 2199 2200 SaoLcuParam* saoLcuParam = &(saoParam->saoLcuParam[yCbCr][addr]); 2201 SaoLcuParam* saoLcuParamNeighbor = NULL; 2202 2203 resetSaoUnit(saoLcuParam); 2204 resetSaoUnit(&compSaoParam[0]); 2205 resetSaoUnit(&compSaoParam[1]); 2206 2207 2208 Double dCostPartBest = MAX_DOUBLE; 2209 2210 Double bestRDCostTableBo = MAX_DOUBLE; 2211 Int bestClassTableBo = 0; 2212 Int currentDistortionTableBo[MAX_NUM_SAO_CLASS]; 2213 Double currentRdCostTableBo[MAX_NUM_SAO_CLASS]; 2214 2215 2216 SaoLcuParam saoLcuParamRdo; 2217 Double estRate = 0; 2218 2219 resetSaoUnit(&saoLcuParamRdo); 2220 2221 m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[0][CI_TEMP_BEST]); 460 Void TEncSampleAdaptiveOffset::deriveOffsets(Int ctu, Int compIdx, Int typeIdc, SAOStatData& statData, Int* quantOffsets, Int& typeAuxInfo) 461 { 462 Int bitDepth = (compIdx== SAO_Y) ? g_bitDepthY : g_bitDepthC; 463 Int shift = 2 * DISTORTION_PRECISION_ADJUSTMENT(bitDepth-8); 464 Int offsetTh = g_saoMaxOffsetQVal[compIdx]; //inclusive 465 466 ::memset(quantOffsets, 0, sizeof(Int)*MAX_NUM_SAO_CLASSES); 467 468 //derive initial offsets 469 Int numClasses = (typeIdc == SAO_TYPE_BO)?((Int)NUM_SAO_BO_CLASSES):((Int)NUM_SAO_EO_CLASSES); 470 for(Int classIdx=0; classIdx< numClasses; classIdx++) 471 { 472 if( (typeIdc != SAO_TYPE_BO) && (classIdx==SAO_CLASS_EO_PLAIN) ) 473 { 474 continue; //offset will be zero 475 } 476 477 if(statData.count[classIdx] == 0) 478 { 479 continue; //offset will be zero 480 } 481 482 quantOffsets[classIdx] = (Int) xRoundIbdi(bitDepth, (Double)( statData.diff[classIdx]<<(bitDepth-8)) 483 / 484 (Double)( statData.count[classIdx]<< m_offsetStepLog2[compIdx]) 485 ); 486 quantOffsets[classIdx] = Clip3(-offsetTh, offsetTh, quantOffsets[classIdx]); 487 } 488 489 // adjust offsets 490 switch(typeIdc) 491 { 492 case SAO_TYPE_EO_0: 493 case SAO_TYPE_EO_90: 494 case SAO_TYPE_EO_135: 495 case SAO_TYPE_EO_45: 496 { 497 Int64 classDist; 498 Double classCost; 499 for(Int classIdx=0; classIdx<NUM_SAO_EO_CLASSES; classIdx++) 500 { 501 if(classIdx==SAO_CLASS_EO_FULL_VALLEY && quantOffsets[classIdx] < 0) quantOffsets[classIdx] =0; 502 if(classIdx==SAO_CLASS_EO_HALF_VALLEY && quantOffsets[classIdx] < 0) quantOffsets[classIdx] =0; 503 if(classIdx==SAO_CLASS_EO_HALF_PEAK && quantOffsets[classIdx] > 0) quantOffsets[classIdx] =0; 504 if(classIdx==SAO_CLASS_EO_FULL_PEAK && quantOffsets[classIdx] > 0) quantOffsets[classIdx] =0; 505 506 if( quantOffsets[classIdx] != 0 ) //iterative adjustment only when derived offset is not zero 507 { 508 quantOffsets[classIdx] = estIterOffset( typeIdc, classIdx, m_lambda[compIdx], quantOffsets[classIdx], statData.count[classIdx], statData.diff[classIdx], shift, m_offsetStepLog2[compIdx], classDist , classCost , offsetTh ); 509 } 510 } 511 512 typeAuxInfo =0; 513 } 514 break; 515 case SAO_TYPE_BO: 516 { 517 Int64 distBOClasses[NUM_SAO_BO_CLASSES]; 518 Double costBOClasses[NUM_SAO_BO_CLASSES]; 519 ::memset(distBOClasses, 0, sizeof(Int64)*NUM_SAO_BO_CLASSES); 520 for(Int classIdx=0; classIdx< NUM_SAO_BO_CLASSES; classIdx++) 521 { 522 costBOClasses[classIdx]= m_lambda[compIdx]; 523 if( quantOffsets[classIdx] != 0 ) //iterative adjustment only when derived offset is not zero 524 { 525 quantOffsets[classIdx] = estIterOffset( typeIdc, classIdx, m_lambda[compIdx], quantOffsets[classIdx], statData.count[classIdx], statData.diff[classIdx], shift, m_offsetStepLog2[compIdx], distBOClasses[classIdx], costBOClasses[classIdx], offsetTh ); 526 } 527 } 528 529 //decide the starting band index 530 Double minCost = MAX_DOUBLE, cost; 531 for(Int band=0; band< NUM_SAO_BO_CLASSES- 4+ 1; band++) 532 { 533 cost = costBOClasses[band ]; 534 cost += costBOClasses[band+1]; 535 cost += costBOClasses[band+2]; 536 cost += costBOClasses[band+3]; 537 538 if(cost < minCost) 539 { 540 minCost = cost; 541 typeAuxInfo = band; 542 } 543 } 544 //clear those unused classes 545 Int clearQuantOffset[NUM_SAO_BO_CLASSES]; 546 ::memset(clearQuantOffset, 0, sizeof(Int)*NUM_SAO_BO_CLASSES); 547 for(Int i=0; i< 4; i++) 548 { 549 Int band = (typeAuxInfo+i)%NUM_SAO_BO_CLASSES; 550 clearQuantOffset[band] = quantOffsets[band]; 551 } 552 ::memcpy(quantOffsets, clearQuantOffset, sizeof(Int)*NUM_SAO_BO_CLASSES); 553 } 554 break; 555 default: 556 { 557 printf("Not a supported type"); 558 assert(0); 559 exit(-1); 560 } 561 562 } 563 564 565 } 566 567 568 Void TEncSampleAdaptiveOffset::deriveModeNewRDO(Int ctu, std::vector<SAOBlkParam*>& mergeList, Bool* sliceEnabled, SAOStatData*** blkStats, SAOBlkParam& modeParam, Double& modeNormCost, TEncSbac** cabacCoderRDO, Int inCabacLabel) 569 { 570 Double minCost, cost; 571 Int rate; 572 UInt previousWrittenBits; 573 Int64 dist[NUM_SAO_COMPONENTS], modeDist[NUM_SAO_COMPONENTS]; 574 SAOOffset testOffset[NUM_SAO_COMPONENTS]; 575 Int compIdx; 576 Int invQuantOffset[MAX_NUM_SAO_CLASSES]; 577 578 modeDist[SAO_Y]= modeDist[SAO_Cb] = modeDist[SAO_Cr] = 0; 579 580 //pre-encode merge flags 581 modeParam[SAO_Y ].modeIdc = SAO_MODE_OFF; 582 m_pcRDGoOnSbacCoder->load(cabacCoderRDO[inCabacLabel]); 583 m_pcRDGoOnSbacCoder->codeSAOBlkParam(modeParam, sliceEnabled, (mergeList[SAO_MERGE_LEFT]!= NULL), (mergeList[SAO_MERGE_ABOVE]!= NULL), true); 584 m_pcRDGoOnSbacCoder->store(cabacCoderRDO[SAO_CABACSTATE_BLK_MID]); 585 586 //------ luma --------// 587 compIdx = SAO_Y; 588 //"off" case as initial cost 589 modeParam[compIdx].modeIdc = SAO_MODE_OFF; 2222 590 m_pcRDGoOnSbacCoder->resetBits(); 2223 m_pcEntropyCoder->encodeSaoOffset(&saoLcuParamRdo, yCbCr); 2224 2225 dCostPartBest = m_pcEntropyCoder->getNumberOfWrittenBits()*lambda ; 2226 copySaoUnit(saoLcuParam, &saoLcuParamRdo ); 2227 bestDist = 0; 2228 2229 2230 2231 for (typeIdx=0; typeIdx<MAX_NUM_SAO_TYPE; typeIdx++) 2232 { 2233 estDist = estSaoTypeDist(yCbCr, typeIdx, shift, lambda, currentDistortionTableBo, currentRdCostTableBo); 2234 2235 if( typeIdx == SAO_BO ) 2236 { 2237 // Estimate Best Position 2238 Double currentRDCost = 0.0; 2239 2240 for(Int i=0; i< SAO_MAX_BO_CLASSES -SAO_BO_LEN +1; i++) 2241 { 2242 currentRDCost = 0.0; 2243 for(UInt uj = i; uj < i+SAO_BO_LEN; uj++) 2244 { 2245 currentRDCost += currentRdCostTableBo[uj]; 2246 } 2247 2248 if( currentRDCost < bestRDCostTableBo) 2249 { 2250 bestRDCostTableBo = currentRDCost; 2251 bestClassTableBo = i; 2252 } 2253 } 2254 2255 // Re code all Offsets 2256 // Code Center 2257 estDist = 0; 2258 for(classIdx = bestClassTableBo; classIdx < bestClassTableBo+SAO_BO_LEN; classIdx++) 2259 { 2260 estDist += currentDistortionTableBo[classIdx]; 2261 } 2262 } 2263 resetSaoUnit(&saoLcuParamRdo); 2264 saoLcuParamRdo.length = m_iNumClass[typeIdx]; 2265 saoLcuParamRdo.typeIdx = typeIdx; 2266 saoLcuParamRdo.mergeLeftFlag = 0; 2267 saoLcuParamRdo.mergeUpFlag = 0; 2268 saoLcuParamRdo.subTypeIdx = (typeIdx == SAO_BO) ? bestClassTableBo : 0; 2269 for (classIdx = 0; classIdx < saoLcuParamRdo.length; classIdx++) 2270 { 2271 saoLcuParamRdo.offset[classIdx] = (Int)m_iOffset[yCbCr][typeIdx][classIdx+saoLcuParamRdo.subTypeIdx+1]; 2272 } 2273 m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[0][CI_TEMP_BEST]); 591 m_pcRDGoOnSbacCoder->codeSAOOffsetParam(compIdx, modeParam[compIdx], sliceEnabled[compIdx]); 592 modeDist[compIdx] = 0; 593 minCost= m_lambda[compIdx]*((Double)m_pcRDGoOnSbacCoder->getNumberOfWrittenBits()); 594 m_pcRDGoOnSbacCoder->store(cabacCoderRDO[SAO_CABACSTATE_BLK_TEMP]); 595 if(sliceEnabled[compIdx]) 596 { 597 for(Int typeIdc=0; typeIdc< NUM_SAO_NEW_TYPES; typeIdc++) 598 { 599 testOffset[compIdx].modeIdc = SAO_MODE_NEW; 600 testOffset[compIdx].typeIdc = typeIdc; 601 602 //derive coded offset 603 deriveOffsets(ctu, compIdx, typeIdc, blkStats[ctu][compIdx][typeIdc], testOffset[compIdx].offset, testOffset[compIdx].typeAuxInfo); 604 605 //inversed quantized offsets 606 invertQuantOffsets(compIdx, typeIdc, testOffset[compIdx].typeAuxInfo, invQuantOffset, testOffset[compIdx].offset); 607 608 //get distortion 609 dist[compIdx] = getDistortion(ctu, compIdx, testOffset[compIdx].typeIdc, testOffset[compIdx].typeAuxInfo, invQuantOffset, blkStats[ctu][compIdx][typeIdc]); 610 611 //get rate 612 m_pcRDGoOnSbacCoder->load(cabacCoderRDO[SAO_CABACSTATE_BLK_MID]); 613 m_pcRDGoOnSbacCoder->resetBits(); 614 m_pcRDGoOnSbacCoder->codeSAOOffsetParam(compIdx, testOffset[compIdx], sliceEnabled[compIdx]); 615 rate = m_pcRDGoOnSbacCoder->getNumberOfWrittenBits(); 616 cost = (Double)dist[compIdx] + m_lambda[compIdx]*((Double)rate); 617 if(cost < minCost) 618 { 619 minCost = cost; 620 modeDist[compIdx] = dist[compIdx]; 621 modeParam[compIdx]= testOffset[compIdx]; 622 m_pcRDGoOnSbacCoder->store(cabacCoderRDO[SAO_CABACSTATE_BLK_TEMP]); 623 } 624 } 625 } 626 m_pcRDGoOnSbacCoder->load(cabacCoderRDO[SAO_CABACSTATE_BLK_TEMP]); 627 m_pcRDGoOnSbacCoder->store(cabacCoderRDO[SAO_CABACSTATE_BLK_MID]); 628 629 //------ chroma --------// 630 //"off" case as initial cost 631 cost = 0; 632 previousWrittenBits = 0; 633 m_pcRDGoOnSbacCoder->resetBits(); 634 for (Int component = SAO_Cb; component < NUM_SAO_COMPONENTS; component++) 635 { 636 modeParam[component].modeIdc = SAO_MODE_OFF; 637 modeDist [component] = 0; 638 639 m_pcRDGoOnSbacCoder->codeSAOOffsetParam(component, modeParam[component], sliceEnabled[component]); 640 641 const UInt currentWrittenBits = m_pcRDGoOnSbacCoder->getNumberOfWrittenBits(); 642 cost += m_lambda[component] * (currentWrittenBits - previousWrittenBits); 643 previousWrittenBits = currentWrittenBits; 644 } 645 646 minCost = cost; 647 648 //doesn't need to store cabac status here since the whole CTU parameters will be re-encoded at the end of this function 649 650 for(Int typeIdc=0; typeIdc< NUM_SAO_NEW_TYPES; typeIdc++) 651 { 652 m_pcRDGoOnSbacCoder->load(cabacCoderRDO[SAO_CABACSTATE_BLK_MID]); 2274 653 m_pcRDGoOnSbacCoder->resetBits(); 2275 m_pcEntropyCoder->encodeSaoOffset(&saoLcuParamRdo, yCbCr); 2276 2277 estRate = m_pcEntropyCoder->getNumberOfWrittenBits(); 2278 m_dCost[yCbCr][typeIdx] = (Double)((Double)estDist + lambda * (Double) estRate); 2279 2280 if(m_dCost[yCbCr][typeIdx] < dCostPartBest) 2281 { 2282 dCostPartBest = m_dCost[yCbCr][typeIdx]; 2283 copySaoUnit(saoLcuParam, &saoLcuParamRdo ); 2284 bestDist = estDist; 2285 } 2286 } 2287 compDistortion[0] += ((Double)bestDist/lambda); 2288 m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[0][CI_TEMP_BEST]); 2289 m_pcEntropyCoder->encodeSaoOffset(saoLcuParam, yCbCr); 2290 m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[0][CI_TEMP_BEST] ); 2291 2292 2293 // merge left or merge up 2294 2295 for (Int idxNeighbor=0;idxNeighbor<2;idxNeighbor++) 2296 { 2297 saoLcuParamNeighbor = NULL; 2298 if (allowMergeLeft && addrLeft>=0 && idxNeighbor ==0) 2299 { 2300 saoLcuParamNeighbor = &(saoParam->saoLcuParam[yCbCr][addrLeft]); 2301 } 2302 else if (allowMergeUp && addrUp>=0 && idxNeighbor ==1) 2303 { 2304 saoLcuParamNeighbor = &(saoParam->saoLcuParam[yCbCr][addrUp]); 2305 } 2306 if (saoLcuParamNeighbor!=NULL) 2307 { 2308 estDist = 0; 2309 typeIdx = saoLcuParamNeighbor->typeIdx; 2310 if (typeIdx>=0) 2311 { 2312 Int mergeBandPosition = (typeIdx == SAO_BO)?saoLcuParamNeighbor->subTypeIdx:0; 2313 Int merge_iOffset; 2314 for(classIdx = 0; classIdx < m_iNumClass[typeIdx]; classIdx++) 2315 { 2316 merge_iOffset = saoLcuParamNeighbor->offset[classIdx]; 2317 estDist += estSaoDist(m_iCount [yCbCr][typeIdx][classIdx+mergeBandPosition+1], merge_iOffset, m_iOffsetOrg[yCbCr][typeIdx][classIdx+mergeBandPosition+1], shift); 2318 } 2319 } 2320 else 2321 { 2322 estDist = 0; 2323 } 2324 2325 copySaoUnit(&compSaoParam[idxNeighbor], saoLcuParamNeighbor ); 2326 compSaoParam[idxNeighbor].mergeUpFlag = idxNeighbor; 2327 compSaoParam[idxNeighbor].mergeLeftFlag = !idxNeighbor; 2328 2329 compDistortion[idxNeighbor+1] += ((Double)estDist/lambda); 2330 } 2331 } 2332 } 2333 Void TEncSampleAdaptiveOffset::sao2ChromaParamDist(Int allowMergeLeft, Int allowMergeUp, SAOParam *saoParam, Int addr, Int addrUp, Int addrLeft, Double lambda, SaoLcuParam *crSaoParam, SaoLcuParam *cbSaoParam, Double *distortion) 2334 { 2335 Int typeIdx; 2336 2337 Int64 estDist[2]; 2338 Int classIdx; 2339 Int shift = 2 * DISTORTION_PRECISION_ADJUSTMENT(g_bitDepthC-8); 2340 Int64 bestDist = 0; 2341 2342 SaoLcuParam* saoLcuParam[2] = {&(saoParam->saoLcuParam[1][addr]), &(saoParam->saoLcuParam[2][addr])}; 2343 SaoLcuParam* saoLcuParamNeighbor[2] = {NULL, NULL}; 2344 SaoLcuParam* saoMergeParam[2][2]; 2345 saoMergeParam[0][0] = &crSaoParam[0]; 2346 saoMergeParam[0][1] = &crSaoParam[1]; 2347 saoMergeParam[1][0] = &cbSaoParam[0]; 2348 saoMergeParam[1][1] = &cbSaoParam[1]; 2349 2350 resetSaoUnit(saoLcuParam[0]); 2351 resetSaoUnit(saoLcuParam[1]); 2352 resetSaoUnit(saoMergeParam[0][0]); 2353 resetSaoUnit(saoMergeParam[0][1]); 2354 resetSaoUnit(saoMergeParam[1][0]); 2355 resetSaoUnit(saoMergeParam[1][1]); 2356 2357 2358 Double costPartBest = MAX_DOUBLE; 2359 2360 Double bestRDCostTableBo; 2361 Int bestClassTableBo[2] = {0, 0}; 2362 Int currentDistortionTableBo[MAX_NUM_SAO_CLASS]; 2363 Double currentRdCostTableBo[MAX_NUM_SAO_CLASS]; 2364 2365 SaoLcuParam saoLcuParamRdo[2]; 2366 Double estRate = 0; 2367 2368 resetSaoUnit(&saoLcuParamRdo[0]); 2369 resetSaoUnit(&saoLcuParamRdo[1]); 2370 2371 m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[0][CI_TEMP_BEST]); 654 previousWrittenBits = 0; 655 cost = 0; 656 657 for(compIdx= SAO_Cb; compIdx< NUM_SAO_COMPONENTS; compIdx++) 658 { 659 if(!sliceEnabled[compIdx]) 660 { 661 testOffset[compIdx].modeIdc = SAO_MODE_OFF; 662 dist[compIdx]= 0; 663 continue; 664 } 665 testOffset[compIdx].modeIdc = SAO_MODE_NEW; 666 testOffset[compIdx].typeIdc = typeIdc; 667 668 //derive offset & get distortion 669 deriveOffsets(ctu, compIdx, typeIdc, blkStats[ctu][compIdx][typeIdc], testOffset[compIdx].offset, testOffset[compIdx].typeAuxInfo); 670 invertQuantOffsets(compIdx, typeIdc, testOffset[compIdx].typeAuxInfo, invQuantOffset, testOffset[compIdx].offset); 671 dist[compIdx]= getDistortion(ctu, compIdx, typeIdc, testOffset[compIdx].typeAuxInfo, invQuantOffset, blkStats[ctu][compIdx][typeIdc]); 672 673 m_pcRDGoOnSbacCoder->codeSAOOffsetParam(compIdx, testOffset[compIdx], sliceEnabled[compIdx]); 674 675 const UInt currentWrittenBits = m_pcRDGoOnSbacCoder->getNumberOfWrittenBits(); 676 cost += dist[compIdx] + (m_lambda[compIdx] * (currentWrittenBits - previousWrittenBits)); 677 previousWrittenBits = currentWrittenBits; 678 } 679 680 if(cost < minCost) 681 { 682 minCost = cost; 683 for(compIdx= SAO_Cb; compIdx< NUM_SAO_COMPONENTS; compIdx++) 684 { 685 modeDist [compIdx] = dist [compIdx]; 686 modeParam[compIdx] = testOffset[compIdx]; 687 } 688 } 689 } 690 691 692 //----- re-gen rate & normalized cost----// 693 modeNormCost = 0; 694 for(UInt component = SAO_Y; component < NUM_SAO_COMPONENTS; component++) 695 { 696 modeNormCost += (Double)modeDist[component] / m_lambda[component]; 697 } 698 m_pcRDGoOnSbacCoder->load(cabacCoderRDO[inCabacLabel]); 2372 699 m_pcRDGoOnSbacCoder->resetBits(); 2373 m_pcEntropyCoder->encodeSaoOffset(&saoLcuParamRdo[0], 1); 2374 m_pcEntropyCoder->encodeSaoOffset(&saoLcuParamRdo[1], 2); 2375 2376 costPartBest = m_pcEntropyCoder->getNumberOfWrittenBits()*lambda ; 2377 copySaoUnit(saoLcuParam[0], &saoLcuParamRdo[0] ); 2378 copySaoUnit(saoLcuParam[1], &saoLcuParamRdo[1] ); 2379 2380 for (typeIdx=0; typeIdx<MAX_NUM_SAO_TYPE; typeIdx++) 2381 { 2382 if( typeIdx == SAO_BO ) 2383 { 2384 // Estimate Best Position 2385 for(Int compIdx = 0; compIdx < 2; compIdx++) 2386 { 2387 Double currentRDCost = 0.0; 2388 bestRDCostTableBo = MAX_DOUBLE; 2389 estDist[compIdx] = estSaoTypeDist(compIdx+1, typeIdx, shift, lambda, currentDistortionTableBo, currentRdCostTableBo); 2390 for(Int i=0; i< SAO_MAX_BO_CLASSES -SAO_BO_LEN +1; i++) 2391 { 2392 currentRDCost = 0.0; 2393 for(UInt uj = i; uj < i+SAO_BO_LEN; uj++) 700 m_pcRDGoOnSbacCoder->codeSAOBlkParam(modeParam, sliceEnabled, (mergeList[SAO_MERGE_LEFT]!= NULL), (mergeList[SAO_MERGE_ABOVE]!= NULL), false); 701 modeNormCost += (Double)m_pcRDGoOnSbacCoder->getNumberOfWrittenBits(); 702 703 } 704 705 Void TEncSampleAdaptiveOffset::deriveModeMergeRDO(Int ctu, std::vector<SAOBlkParam*>& mergeList, Bool* sliceEnabled, SAOStatData*** blkStats, SAOBlkParam& modeParam, Double& modeNormCost, TEncSbac** cabacCoderRDO, Int inCabacLabel) 706 { 707 Int mergeListSize = (Int)mergeList.size(); 708 modeNormCost = MAX_DOUBLE; 709 710 Double cost; 711 SAOBlkParam testBlkParam; 712 713 for(Int mergeType=0; mergeType< mergeListSize; mergeType++) 714 { 715 if(mergeList[mergeType] == NULL) 716 { 717 continue; 718 } 719 720 testBlkParam = *(mergeList[mergeType]); 721 //normalized distortion 722 Double normDist=0; 723 for(Int compIdx=0; compIdx< NUM_SAO_COMPONENTS; compIdx++) 724 { 725 testBlkParam[compIdx].modeIdc = SAO_MODE_MERGE; 726 testBlkParam[compIdx].typeIdc = mergeType; 727 728 SAOOffset& mergedOffsetParam = (*(mergeList[mergeType]))[compIdx]; 729 730 if( mergedOffsetParam.modeIdc != SAO_MODE_OFF) 731 { 732 //offsets have been reconstructed. Don't call inversed quantization function. 733 normDist += (((Double)getDistortion(ctu, compIdx, mergedOffsetParam.typeIdc, mergedOffsetParam.typeAuxInfo, mergedOffsetParam.offset, blkStats[ctu][compIdx][mergedOffsetParam.typeIdc])) 734 /m_lambda[compIdx] 735 ); 736 } 737 738 } 739 740 //rate 741 m_pcRDGoOnSbacCoder->load(cabacCoderRDO[inCabacLabel]); 742 m_pcRDGoOnSbacCoder->resetBits(); 743 m_pcRDGoOnSbacCoder->codeSAOBlkParam(testBlkParam, sliceEnabled, (mergeList[SAO_MERGE_LEFT]!= NULL), (mergeList[SAO_MERGE_ABOVE]!= NULL), false); 744 Int rate = m_pcRDGoOnSbacCoder->getNumberOfWrittenBits(); 745 746 cost = normDist+(Double)rate; 747 748 if(cost < modeNormCost) 749 { 750 modeNormCost = cost; 751 modeParam = testBlkParam; 752 m_pcRDGoOnSbacCoder->store(cabacCoderRDO[SAO_CABACSTATE_BLK_TEMP]); 753 } 754 } 755 756 m_pcRDGoOnSbacCoder->load(cabacCoderRDO[SAO_CABACSTATE_BLK_TEMP]); 757 758 759 } 760 761 Void TEncSampleAdaptiveOffset::decideBlkParams(TComPic* pic, Bool* sliceEnabled, SAOStatData*** blkStats, TComPicYuv* srcYuv, TComPicYuv* resYuv, SAOBlkParam* reconParams, SAOBlkParam* codedParams) 762 { 763 Bool isAllBlksDisabled = false; 764 if(!sliceEnabled[SAO_Y] && !sliceEnabled[SAO_Cb] && !sliceEnabled[SAO_Cr]) 765 { 766 isAllBlksDisabled = true; 767 } 768 769 m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[ SAO_CABACSTATE_PIC_INIT ]); 770 771 SAOBlkParam modeParam; 772 Double minCost, modeCost; 773 774 for(Int ctu=0; ctu< m_numCTUsPic; ctu++) 775 { 776 if(isAllBlksDisabled) 777 { 778 codedParams[ctu].reset(); 779 continue; 780 } 781 782 m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[ SAO_CABACSTATE_BLK_CUR ]); 783 784 //get merge list 785 std::vector<SAOBlkParam*> mergeList; 786 getMergeList(pic, ctu, reconParams, mergeList); 787 788 minCost = MAX_DOUBLE; 789 for(Int mode=0; mode < NUM_SAO_MODES; mode++) 790 { 791 switch(mode) 792 { 793 case SAO_MODE_OFF: 794 { 795 continue; //not necessary, since all-off case will be tested in SAO_MODE_NEW case. 796 } 797 break; 798 case SAO_MODE_NEW: 799 { 800 deriveModeNewRDO(ctu, mergeList, sliceEnabled, blkStats, modeParam, modeCost, m_pppcRDSbacCoder, SAO_CABACSTATE_BLK_CUR); 801 802 } 803 break; 804 case SAO_MODE_MERGE: 805 { 806 deriveModeMergeRDO(ctu, mergeList, sliceEnabled, blkStats , modeParam, modeCost, m_pppcRDSbacCoder, SAO_CABACSTATE_BLK_CUR); 807 } 808 break; 809 default: 810 { 811 printf("Not a supported SAO mode\n"); 812 assert(0); 813 exit(-1); 814 } 815 } 816 817 if(modeCost < minCost) 818 { 819 minCost = modeCost; 820 codedParams[ctu] = modeParam; 821 m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[ SAO_CABACSTATE_BLK_NEXT ]); 822 823 } 824 } //mode 825 m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[ SAO_CABACSTATE_BLK_NEXT ]); 826 827 //apply reconstructed offsets 828 reconParams[ctu] = codedParams[ctu]; 829 reconstructBlkSAOParam(reconParams[ctu], mergeList); 830 offsetCTU(ctu, srcYuv, resYuv, reconParams[ctu], pic); 831 } //ctu 832 833 #if SAO_ENCODING_CHOICE 834 Int picTempLayer = pic->getSlice(0)->getDepth(); 835 Int numLcusForSAOOff[NUM_SAO_COMPONENTS]; 836 numLcusForSAOOff[SAO_Y ] = numLcusForSAOOff[SAO_Cb]= numLcusForSAOOff[SAO_Cr]= 0; 837 838 for (Int compIdx=0; compIdx<NUM_SAO_COMPONENTS; compIdx++) 839 { 840 for(Int ctu=0; ctu< m_numCTUsPic; ctu++) 841 { 842 if( reconParams[ctu][compIdx].modeIdc == SAO_MODE_OFF) 843 { 844 numLcusForSAOOff[compIdx]++; 845 } 846 } 847 } 848 #if SAO_ENCODING_CHOICE_CHROMA 849 for (Int compIdx=0; compIdx<NUM_SAO_COMPONENTS; compIdx++) 850 { 851 m_saoDisabledRate[compIdx][picTempLayer] = (Double)numLcusForSAOOff[compIdx]/(Double)m_numCTUsPic; 852 } 853 #else 854 if (picTempLayer == 0) 855 { 856 m_saoDisabledRate[SAO_Y][0] = (Double)(numLcusForSAOOff[SAO_Y]+numLcusForSAOOff[SAO_Cb]+numLcusForSAOOff[SAO_Cr])/(Double)(m_numCTUsPic*3); 857 } 858 #endif 859 #endif 860 } 861 862 863 Void TEncSampleAdaptiveOffset::getBlkStats(Int compIdx, SAOStatData* statsDataTypes 864 , Pel* srcBlk, Pel* orgBlk, Int srcStride, Int orgStride, Int width, Int height 865 , Bool isLeftAvail, Bool isRightAvail, Bool isAboveAvail, Bool isBelowAvail, Bool isAboveLeftAvail, Bool isAboveRightAvail, Bool isBelowLeftAvail, Bool isBelowRightAvail 866 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 867 , Bool isCalculatePreDeblockSamples 868 #endif 869 ) 870 { 871 if(m_lineBufWidth != m_maxCUWidth) 872 { 873 m_lineBufWidth = m_maxCUWidth; 874 875 if (m_signLineBuf1) delete[] m_signLineBuf1; m_signLineBuf1 = NULL; 876 m_signLineBuf1 = new Char[m_lineBufWidth+1]; 877 878 if (m_signLineBuf2) delete[] m_signLineBuf2; m_signLineBuf2 = NULL; 879 m_signLineBuf2 = new Char[m_lineBufWidth+1]; 880 } 881 882 Int x,y, startX, startY, endX, endY, edgeType, firstLineStartX, firstLineEndX; 883 Char signLeft, signRight, signDown; 884 Int64 *diff, *count; 885 Pel *srcLine, *orgLine; 886 Int* skipLinesR = m_skipLinesR[compIdx]; 887 Int* skipLinesB = m_skipLinesB[compIdx]; 888 889 for(Int typeIdx=0; typeIdx< NUM_SAO_NEW_TYPES; typeIdx++) 890 { 891 SAOStatData& statsData= statsDataTypes[typeIdx]; 892 statsData.reset(); 893 894 srcLine = srcBlk; 895 orgLine = orgBlk; 896 diff = statsData.diff; 897 count = statsData.count; 898 switch(typeIdx) 899 { 900 case SAO_TYPE_EO_0: 901 { 902 diff +=2; 903 count+=2; 904 endY = (isBelowAvail) ? (height - skipLinesB[typeIdx]) : height; 905 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 906 startX = (!isCalculatePreDeblockSamples) ? (isLeftAvail ? 0 : 1) 907 : (isRightAvail ? (width - skipLinesR[typeIdx]) : (width - 1)) 908 ; 909 #else 910 startX = isLeftAvail ? 0 : 1; 911 #endif 912 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 913 endX = (!isCalculatePreDeblockSamples) ? (isRightAvail ? (width - skipLinesR[typeIdx]) : (width - 1)) 914 : (isRightAvail ? width : (width - 1)) 915 ; 916 #else 917 endX = isRightAvail ? (width - skipLinesR[typeIdx]): (width - 1); 918 #endif 919 for (y=0; y<endY; y++) 920 { 921 signLeft = (Char)m_sign[srcLine[startX] - srcLine[startX-1]]; 922 for (x=startX; x<endX; x++) 2394 923 { 2395 currentRDCost += currentRdCostTableBo[uj]; 924 signRight = (Char)m_sign[srcLine[x] - srcLine[x+1]]; 925 edgeType = signRight + signLeft; 926 signLeft = -signRight; 927 928 diff [edgeType] += (orgLine[x] - srcLine[x]); 929 count[edgeType] ++; 2396 930 } 2397 2398 if( currentRDCost < bestRDCostTableBo) 931 srcLine += srcStride; 932 orgLine += orgStride; 933 } 934 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 935 if(isCalculatePreDeblockSamples) 936 { 937 if(isBelowAvail) 2399 938 { 2400 bestRDCostTableBo = currentRDCost; 2401 bestClassTableBo[compIdx] = i; 939 startX = isLeftAvail ? 0 : 1; 940 endX = isRightAvail ? width : (width -1); 941 942 for(y=0; y<skipLinesB[typeIdx]; y++) 943 { 944 signLeft = (Char)m_sign[srcLine[startX] - srcLine[startX-1]]; 945 for (x=startX; x<endX; x++) 946 { 947 signRight = (Char)m_sign[srcLine[x] - srcLine[x+1]]; 948 edgeType = signRight + signLeft; 949 signLeft = -signRight; 950 951 diff [edgeType] += (orgLine[x] - srcLine[x]); 952 count[edgeType] ++; 953 } 954 srcLine += srcStride; 955 orgLine += orgStride; 956 } 2402 957 } 2403 958 } 2404 2405 // Re code all Offsets 2406 // Code Center 2407 estDist[compIdx] = 0; 2408 for(classIdx = bestClassTableBo[compIdx]; classIdx < bestClassTableBo[compIdx]+SAO_BO_LEN; classIdx++) 2409 { 2410 estDist[compIdx] += currentDistortionTableBo[classIdx]; 2411 } 2412 } 2413 } 2414 else 2415 { 2416 estDist[0] = estSaoTypeDist(1, typeIdx, shift, lambda, currentDistortionTableBo, currentRdCostTableBo); 2417 estDist[1] = estSaoTypeDist(2, typeIdx, shift, lambda, currentDistortionTableBo, currentRdCostTableBo); 2418 } 2419 2420 m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[0][CI_TEMP_BEST]); 2421 m_pcRDGoOnSbacCoder->resetBits(); 2422 2423 for(Int compIdx = 0; compIdx < 2; compIdx++) 2424 { 2425 resetSaoUnit(&saoLcuParamRdo[compIdx]); 2426 saoLcuParamRdo[compIdx].length = m_iNumClass[typeIdx]; 2427 saoLcuParamRdo[compIdx].typeIdx = typeIdx; 2428 saoLcuParamRdo[compIdx].mergeLeftFlag = 0; 2429 saoLcuParamRdo[compIdx].mergeUpFlag = 0; 2430 saoLcuParamRdo[compIdx].subTypeIdx = (typeIdx == SAO_BO) ? bestClassTableBo[compIdx] : 0; 2431 for (classIdx = 0; classIdx < saoLcuParamRdo[compIdx].length; classIdx++) 2432 { 2433 saoLcuParamRdo[compIdx].offset[classIdx] = (Int)m_iOffset[compIdx+1][typeIdx][classIdx+saoLcuParamRdo[compIdx].subTypeIdx+1]; 2434 } 2435 2436 m_pcEntropyCoder->encodeSaoOffset(&saoLcuParamRdo[compIdx], compIdx+1); 2437 } 2438 estRate = m_pcEntropyCoder->getNumberOfWrittenBits(); 2439 m_dCost[1][typeIdx] = (Double)((Double)(estDist[0] + estDist[1]) + lambda * (Double) estRate); 2440 2441 if(m_dCost[1][typeIdx] < costPartBest) 2442 { 2443 costPartBest = m_dCost[1][typeIdx]; 2444 copySaoUnit(saoLcuParam[0], &saoLcuParamRdo[0] ); 2445 copySaoUnit(saoLcuParam[1], &saoLcuParamRdo[1] ); 2446 bestDist = (estDist[0]+estDist[1]); 2447 } 2448 } 2449 2450 distortion[0] += ((Double)bestDist/lambda); 2451 m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[0][CI_TEMP_BEST]); 2452 m_pcEntropyCoder->encodeSaoOffset(saoLcuParam[0], 1); 2453 m_pcEntropyCoder->encodeSaoOffset(saoLcuParam[1], 2); 2454 m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[0][CI_TEMP_BEST] ); 2455 2456 // merge left or merge up 2457 2458 for (Int idxNeighbor=0;idxNeighbor<2;idxNeighbor++) 2459 { 2460 for(Int compIdx = 0; compIdx < 2; compIdx++) 2461 { 2462 saoLcuParamNeighbor[compIdx] = NULL; 2463 if (allowMergeLeft && addrLeft>=0 && idxNeighbor ==0) 2464 { 2465 saoLcuParamNeighbor[compIdx] = &(saoParam->saoLcuParam[compIdx+1][addrLeft]); 2466 } 2467 else if (allowMergeUp && addrUp>=0 && idxNeighbor ==1) 2468 { 2469 saoLcuParamNeighbor[compIdx] = &(saoParam->saoLcuParam[compIdx+1][addrUp]); 2470 } 2471 if (saoLcuParamNeighbor[compIdx]!=NULL) 2472 { 2473 estDist[compIdx] = 0; 2474 typeIdx = saoLcuParamNeighbor[compIdx]->typeIdx; 2475 if (typeIdx>=0) 2476 { 2477 Int mergeBandPosition = (typeIdx == SAO_BO)?saoLcuParamNeighbor[compIdx]->subTypeIdx:0; 2478 Int merge_iOffset; 2479 for(classIdx = 0; classIdx < m_iNumClass[typeIdx]; classIdx++) 959 #endif 960 } 961 break; 962 case SAO_TYPE_EO_90: 963 { 964 diff +=2; 965 count+=2; 966 Char *signUpLine = m_signLineBuf1; 967 968 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 969 startX = (!isCalculatePreDeblockSamples) ? 0 970 : (isRightAvail ? (width - skipLinesR[typeIdx]) : width) 971 ; 972 #endif 973 startY = isAboveAvail ? 0 : 1; 974 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 975 endX = (!isCalculatePreDeblockSamples) ? (isRightAvail ? (width - skipLinesR[typeIdx]) : width) 976 : width 977 ; 978 #else 979 endX = isRightAvail ? (width - skipLinesR[typeIdx]) : width ; 980 #endif 981 endY = isBelowAvail ? (height - skipLinesB[typeIdx]) : (height - 1); 982 if (!isAboveAvail) 983 { 984 srcLine += srcStride; 985 orgLine += orgStride; 986 } 987 988 Pel* srcLineAbove = srcLine - srcStride; 989 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 990 for (x=startX; x<endX; x++) 991 #else 992 for (x=0; x< endX; x++) 993 #endif 994 { 995 signUpLine[x] = (Char)m_sign[srcLine[x] - srcLineAbove[x]]; 996 } 997 998 Pel* srcLineBelow; 999 for (y=startY; y<endY; y++) 1000 { 1001 srcLineBelow = srcLine + srcStride; 1002 1003 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 1004 for (x=startX; x<endX; x++) 1005 #else 1006 for (x=0; x<endX; x++) 1007 #endif 2480 1008 { 2481 merge_iOffset = saoLcuParamNeighbor[compIdx]->offset[classIdx]; 2482 estDist[compIdx] += estSaoDist(m_iCount [compIdx+1][typeIdx][classIdx+mergeBandPosition+1], merge_iOffset, m_iOffsetOrg[compIdx+1][typeIdx][classIdx+mergeBandPosition+1], shift); 1009 signDown = (Char)m_sign[srcLine[x] - srcLineBelow[x]]; 1010 edgeType = signDown + signUpLine[x]; 1011 signUpLine[x]= -signDown; 1012 1013 diff [edgeType] += (orgLine[x] - srcLine[x]); 1014 count[edgeType] ++; 2483 1015 } 2484 } 2485 else 2486 { 2487 estDist[compIdx] = 0; 2488 } 2489 2490 copySaoUnit(saoMergeParam[compIdx][idxNeighbor], saoLcuParamNeighbor[compIdx] ); 2491 saoMergeParam[compIdx][idxNeighbor]->mergeUpFlag = idxNeighbor; 2492 saoMergeParam[compIdx][idxNeighbor]->mergeLeftFlag = !idxNeighbor; 2493 distortion[idxNeighbor+1] += ((Double)estDist[compIdx]/lambda); 2494 } 2495 } 2496 } 1016 srcLine += srcStride; 1017 orgLine += orgStride; 1018 } 1019 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 1020 if(isCalculatePreDeblockSamples) 1021 { 1022 if(isBelowAvail) 1023 { 1024 startX = 0; 1025 endX = width; 1026 1027 for(y=0; y<skipLinesB[typeIdx]; y++) 1028 { 1029 srcLineBelow = srcLine + srcStride; 1030 srcLineAbove = srcLine - srcStride; 1031 1032 for (x=startX; x<endX; x++) 1033 { 1034 edgeType = m_sign[srcLine[x] - srcLineBelow[x]] + m_sign[srcLine[x] - srcLineAbove[x]]; 1035 diff [edgeType] += (orgLine[x] - srcLine[x]); 1036 count[edgeType] ++; 1037 } 1038 srcLine += srcStride; 1039 orgLine += orgStride; 1040 } 1041 } 1042 } 1043 #endif 1044 1045 } 1046 break; 1047 case SAO_TYPE_EO_135: 1048 { 1049 diff +=2; 1050 count+=2; 1051 Char *signUpLine, *signDownLine, *signTmpLine; 1052 1053 signUpLine = m_signLineBuf1; 1054 signDownLine= m_signLineBuf2; 1055 1056 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 1057 startX = (!isCalculatePreDeblockSamples) ? (isLeftAvail ? 0 : 1) 1058 : (isRightAvail ? (width - skipLinesR[typeIdx]) : (width - 1)) 1059 ; 1060 #else 1061 startX = isLeftAvail ? 0 : 1 ; 1062 #endif 1063 1064 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 1065 endX = (!isCalculatePreDeblockSamples) ? (isRightAvail ? (width - skipLinesR[typeIdx]): (width - 1)) 1066 : (isRightAvail ? width : (width - 1)) 1067 ; 1068 #else 1069 endX = isRightAvail ? (width - skipLinesR[typeIdx]): (width - 1); 1070 #endif 1071 endY = isBelowAvail ? (height - skipLinesB[typeIdx]) : (height - 1); 1072 1073 //prepare 2nd line's upper sign 1074 Pel* srcLineBelow = srcLine + srcStride; 1075 for (x=startX; x<endX+1; x++) 1076 { 1077 signUpLine[x] = (Char)m_sign[srcLineBelow[x] - srcLine[x-1]]; 1078 } 1079 1080 //1st line 1081 Pel* srcLineAbove = srcLine - srcStride; 1082 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 1083 firstLineStartX = (!isCalculatePreDeblockSamples) ? (isAboveLeftAvail ? 0 : 1) : startX; 1084 firstLineEndX = (!isCalculatePreDeblockSamples) ? (isAboveAvail ? endX : 1) : endX; 1085 #else 1086 firstLineStartX = isAboveLeftAvail ? 0 : 1; 1087 firstLineEndX = isAboveAvail ? endX : 1; 1088 #endif 1089 for(x=firstLineStartX; x<firstLineEndX; x++) 1090 { 1091 edgeType = m_sign[srcLine[x] - srcLineAbove[x-1]] - signUpLine[x+1]; 1092 diff [edgeType] += (orgLine[x] - srcLine[x]); 1093 count[edgeType] ++; 1094 } 1095 srcLine += srcStride; 1096 orgLine += orgStride; 1097 1098 1099 //middle lines 1100 for (y=1; y<endY; y++) 1101 { 1102 srcLineBelow = srcLine + srcStride; 1103 1104 for (x=startX; x<endX; x++) 1105 { 1106 signDown = (Char)m_sign[srcLine[x] - srcLineBelow[x+1]] ; 1107 edgeType = signDown + signUpLine[x]; 1108 diff [edgeType] += (orgLine[x] - srcLine[x]); 1109 count[edgeType] ++; 1110 1111 signDownLine[x+1] = -signDown; 1112 } 1113 signDownLine[startX] = (Char)m_sign[srcLineBelow[startX] - srcLine[startX-1]]; 1114 1115 signTmpLine = signUpLine; 1116 signUpLine = signDownLine; 1117 signDownLine = signTmpLine; 1118 1119 srcLine += srcStride; 1120 orgLine += orgStride; 1121 } 1122 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 1123 if(isCalculatePreDeblockSamples) 1124 { 1125 if(isBelowAvail) 1126 { 1127 startX = isLeftAvail ? 0 : 1 ; 1128 endX = isRightAvail ? width : (width -1); 1129 1130 for(y=0; y<skipLinesB[typeIdx]; y++) 1131 { 1132 srcLineBelow = srcLine + srcStride; 1133 srcLineAbove = srcLine - srcStride; 1134 1135 for (x=startX; x< endX; x++) 1136 { 1137 edgeType = m_sign[srcLine[x] - srcLineBelow[x+1]] + m_sign[srcLine[x] - srcLineAbove[x-1]]; 1138 diff [edgeType] += (orgLine[x] - srcLine[x]); 1139 count[edgeType] ++; 1140 } 1141 srcLine += srcStride; 1142 orgLine += orgStride; 1143 } 1144 } 1145 } 1146 #endif 1147 } 1148 break; 1149 case SAO_TYPE_EO_45: 1150 { 1151 diff +=2; 1152 count+=2; 1153 Char *signUpLine = m_signLineBuf1+1; 1154 1155 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 1156 startX = (!isCalculatePreDeblockSamples) ? (isLeftAvail ? 0 : 1) 1157 : (isRightAvail ? (width - skipLinesR[typeIdx]) : (width - 1)) 1158 ; 1159 #else 1160 startX = isLeftAvail ? 0 : 1; 1161 #endif 1162 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 1163 endX = (!isCalculatePreDeblockSamples) ? (isRightAvail ? (width - skipLinesR[typeIdx]) : (width - 1)) 1164 : (isRightAvail ? width : (width - 1)) 1165 ; 1166 #else 1167 endX = isRightAvail ? (width - skipLinesR[typeIdx]) : (width - 1); 1168 #endif 1169 endY = isBelowAvail ? (height - skipLinesB[typeIdx]) : (height - 1); 1170 1171 //prepare 2nd line upper sign 1172 Pel* srcLineBelow = srcLine + srcStride; 1173 for (x=startX-1; x<endX; x++) 1174 { 1175 signUpLine[x] = (Char)m_sign[srcLineBelow[x] - srcLine[x+1]]; 1176 } 1177 1178 1179 //first line 1180 Pel* srcLineAbove = srcLine - srcStride; 1181 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 1182 firstLineStartX = (!isCalculatePreDeblockSamples) ? (isAboveAvail ? startX : endX) 1183 : startX 1184 ; 1185 firstLineEndX = (!isCalculatePreDeblockSamples) ? ((!isRightAvail && isAboveRightAvail) ? width : endX) 1186 : endX 1187 ; 1188 #else 1189 firstLineStartX = isAboveAvail ? startX : endX; 1190 firstLineEndX = (!isRightAvail && isAboveRightAvail) ? width : endX; 1191 #endif 1192 for(x=firstLineStartX; x<firstLineEndX; x++) 1193 { 1194 edgeType = m_sign[srcLine[x] - srcLineAbove[x+1]] - signUpLine[x-1]; 1195 diff [edgeType] += (orgLine[x] - srcLine[x]); 1196 count[edgeType] ++; 1197 } 1198 1199 srcLine += srcStride; 1200 orgLine += orgStride; 1201 1202 //middle lines 1203 for (y=1; y<endY; y++) 1204 { 1205 srcLineBelow = srcLine + srcStride; 1206 1207 for(x=startX; x<endX; x++) 1208 { 1209 signDown = (Char)m_sign[srcLine[x] - srcLineBelow[x-1]] ; 1210 edgeType = signDown + signUpLine[x]; 1211 1212 diff [edgeType] += (orgLine[x] - srcLine[x]); 1213 count[edgeType] ++; 1214 1215 signUpLine[x-1] = -signDown; 1216 } 1217 signUpLine[endX-1] = (Char)m_sign[srcLineBelow[endX-1] - srcLine[endX]]; 1218 srcLine += srcStride; 1219 orgLine += orgStride; 1220 } 1221 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 1222 if(isCalculatePreDeblockSamples) 1223 { 1224 if(isBelowAvail) 1225 { 1226 startX = isLeftAvail ? 0 : 1 ; 1227 endX = isRightAvail ? width : (width -1); 1228 1229 for(y=0; y<skipLinesB[typeIdx]; y++) 1230 { 1231 srcLineBelow = srcLine + srcStride; 1232 srcLineAbove = srcLine - srcStride; 1233 1234 for (x=startX; x<endX; x++) 1235 { 1236 edgeType = m_sign[srcLine[x] - srcLineBelow[x-1]] + m_sign[srcLine[x] - srcLineAbove[x+1]]; 1237 diff [edgeType] += (orgLine[x] - srcLine[x]); 1238 count[edgeType] ++; 1239 } 1240 srcLine += srcStride; 1241 orgLine += orgStride; 1242 } 1243 } 1244 } 1245 #endif 1246 } 1247 break; 1248 case SAO_TYPE_BO: 1249 { 1250 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 1251 startX = (!isCalculatePreDeblockSamples)?0 1252 :( isRightAvail?(width- skipLinesR[typeIdx]):width) 1253 ; 1254 endX = (!isCalculatePreDeblockSamples)?(isRightAvail ? (width - skipLinesR[typeIdx]) : width ) 1255 :width 1256 ; 1257 #else 1258 endX = isRightAvail ? (width- skipLinesR[typeIdx]) : width; 1259 #endif 1260 endY = isBelowAvail ? (height- skipLinesB[typeIdx]) : height; 1261 Int shiftBits = ((compIdx == SAO_Y)?g_bitDepthY:g_bitDepthC)- NUM_SAO_BO_CLASSES_LOG2; 1262 for (y=0; y< endY; y++) 1263 { 1264 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 1265 for (x=startX; x< endX; x++) 1266 #else 1267 for (x=0; x< endX; x++) 1268 #endif 1269 { 1270 1271 Int bandIdx= srcLine[x] >> shiftBits; 1272 diff [bandIdx] += (orgLine[x] - srcLine[x]); 1273 count[bandIdx] ++; 1274 } 1275 srcLine += srcStride; 1276 orgLine += orgStride; 1277 } 1278 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 1279 if(isCalculatePreDeblockSamples) 1280 { 1281 if(isBelowAvail) 1282 { 1283 startX = 0; 1284 endX = width; 1285 1286 for(y= 0; y< skipLinesB[typeIdx]; y++) 1287 { 1288 for (x=startX; x< endX; x++) 1289 { 1290 Int bandIdx= srcLine[x] >> shiftBits; 1291 diff [bandIdx] += (orgLine[x] - srcLine[x]); 1292 count[bandIdx] ++; 1293 } 1294 srcLine += srcStride; 1295 orgLine += orgStride; 1296 1297 } 1298 1299 } 1300 } 1301 #endif 1302 } 1303 break; 1304 default: 1305 { 1306 printf("Not a supported SAO types\n"); 1307 assert(0); 1308 exit(-1); 1309 } 1310 } 1311 } 2497 1312 } 2498 1313 -
branches/HTM-10.0-dev0/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.h
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-201 3, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 54 54 // ==================================================================================================================== 55 55 56 enum SAOCabacStateLablesRDO //CABAC state labels 57 { 58 SAO_CABACSTATE_PIC_INIT =0, 59 SAO_CABACSTATE_BLK_CUR, 60 SAO_CABACSTATE_BLK_NEXT, 61 SAO_CABACSTATE_BLK_MID, 62 SAO_CABACSTATE_BLK_TEMP, 63 NUM_SAO_CABACSTATE_LABELS 64 }; 65 66 struct SAOStatData //data structure for SAO statistics 67 { 68 Int64 diff[MAX_NUM_SAO_CLASSES]; 69 Int64 count[MAX_NUM_SAO_CLASSES]; 70 71 SAOStatData(){} 72 ~SAOStatData(){} 73 Void reset() 74 { 75 ::memset(diff, 0, sizeof(Int64)*MAX_NUM_SAO_CLASSES); 76 ::memset(count, 0, sizeof(Int64)*MAX_NUM_SAO_CLASSES); 77 } 78 const SAOStatData& operator=(const SAOStatData& src) 79 { 80 ::memcpy(diff, src.diff, sizeof(Int64)*MAX_NUM_SAO_CLASSES); 81 ::memcpy(count, src.count, sizeof(Int64)*MAX_NUM_SAO_CLASSES); 82 return *this; 83 } 84 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 85 const SAOStatData& operator+= (const SAOStatData& src) 86 { 87 for(Int i=0; i< MAX_NUM_SAO_CLASSES; i++) 88 { 89 diff[i] += src.diff[i]; 90 count[i] += src.count[i]; 91 } 92 return *this; 93 } 94 #endif 95 }; 96 56 97 class TEncSampleAdaptiveOffset : public TComSampleAdaptiveOffset 57 98 { 58 private:59 TEncEntropy* m_pcEntropyCoder;60 TEncSbac*** m_pppcRDSbacCoder; ///< for CABAC61 TEncSbac* m_pcRDGoOnSbacCoder;62 #if FAST_BIT_EST63 TEncBinCABACCounter*** m_pppcBinCoderCABAC; ///< temporal CABAC state storage for RD computation64 #else65 TEncBinCABAC*** m_pppcBinCoderCABAC; ///< temporal CABAC state storage for RD computation66 #endif67 68 Int64 ***m_iCount; //[MAX_NUM_SAO_PART][MAX_NUM_SAO_TYPE][MAX_NUM_SAO_CLASS];69 Int64 ***m_iOffset; //[MAX_NUM_SAO_PART][MAX_NUM_SAO_TYPE][MAX_NUM_SAO_CLASS];70 Int64 ***m_iOffsetOrg; //[MAX_NUM_SAO_PART][MAX_NUM_SAO_TYPE];71 Int64 ****m_count_PreDblk; //[LCU][YCbCr][MAX_NUM_SAO_TYPE][MAX_NUM_SAO_CLASS];72 Int64 ****m_offsetOrg_PreDblk; //[LCU][YCbCr][MAX_NUM_SAO_TYPE][MAX_NUM_SAO_CLASS];73 Int64 **m_iRate; //[MAX_NUM_SAO_PART][MAX_NUM_SAO_TYPE];74 Int64 **m_iDist; //[MAX_NUM_SAO_PART][MAX_NUM_SAO_TYPE];75 Double **m_dCost; //[MAX_NUM_SAO_PART][MAX_NUM_SAO_TYPE];76 Double *m_dCostPartBest; //[MAX_NUM_SAO_PART];77 Int64 *m_iDistOrg; //[MAX_NUM_SAO_PART];78 Int *m_iTypePartBest; //[MAX_NUM_SAO_PART];79 Int m_iOffsetThY;80 Int m_iOffsetThC;81 Bool m_bUseSBACRD;82 #if SAO_ENCODING_CHOICE83 #if SAO_ENCODING_CHOICE_CHROMA84 Double m_depthSaoRate[2][4];85 #else86 Double m_depth0SaoRate;87 #endif88 #endif89 90 99 public: 91 TEncSampleAdaptiveOffset 100 TEncSampleAdaptiveOffset(); 92 101 virtual ~TEncSampleAdaptiveOffset(); 93 102 94 Void startSaoEnc( TComPic* pcPic, TEncEntropy* pcEntropyCoder, TEncSbac*** pppcRDSbacCoder, TEncSbac* pcRDGoOnSbacCoder); 95 Void endSaoEnc(); 96 Void resetStats(); 97 #if SAO_CHROMA_LAMBDA 103 //interface 104 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 105 Void createEncData(Bool isPreDBFSamplesUsed); 106 #else 107 Void createEncData(); 108 #endif 109 Void destroyEncData(); 110 Void initRDOCabacCoder(TEncSbac* pcRDGoOnSbacCoder, TComSlice* pcSlice) ; 111 Void SAOProcess(TComPic* pPic, Bool* sliceEnabled, const Double *lambdas 112 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 113 , Bool isPreDBFSamplesUsed 114 #endif 115 ); 116 public: //methods 117 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 118 Void getPreDBFStatistics(TComPic* pPic); 119 #endif 120 private: //methods 121 Void getStatistics(SAOStatData*** blkStats, TComPicYuv* orgYuv, TComPicYuv* srcYuv,TComPic* pPic 122 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 123 , Bool isCalculatePreDeblockSamples = false 124 #endif 125 ); 126 Void decidePicParams(Bool* sliceEnabled, Int picTempLayer); 127 Void decideBlkParams(TComPic* pic, Bool* sliceEnabled, SAOStatData*** blkStats, TComPicYuv* srcYuv, TComPicYuv* resYuv, SAOBlkParam* reconParams, SAOBlkParam* codedParams); 128 Void getBlkStats(Int compIdx, SAOStatData* statsDataTypes, Pel* srcBlk, Pel* orgBlk, Int srcStride, Int orgStride, Int width, Int height, Bool isLeftAvail, Bool isRightAvail, Bool isAboveAvail, Bool isBelowAvail, Bool isAboveLeftAvail, Bool isAboveRightAvail, Bool isBelowLeftAvail, Bool isBelowRightAvail 129 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 130 , Bool isCalculatePreDeblockSamples 131 #endif 132 ); 133 Void deriveModeNewRDO(Int ctu, std::vector<SAOBlkParam*>& mergeList, Bool* sliceEnabled, SAOStatData*** blkStats, SAOBlkParam& modeParam, Double& modeNormCost, TEncSbac** cabacCoderRDO, Int inCabacLabel); 134 Void deriveModeMergeRDO(Int ctu, std::vector<SAOBlkParam*>& mergeList, Bool* sliceEnabled, SAOStatData*** blkStats, SAOBlkParam& modeParam, Double& modeNormCost, TEncSbac** cabacCoderRDO, Int inCabacLabel); 135 Int64 getDistortion(Int ctu, Int compIdx, Int typeIdc, Int typeAuxInfo, Int* offsetVal, SAOStatData& statData); 136 Void deriveOffsets(Int ctu, Int compIdx, Int typeIdc, SAOStatData& statData, Int* quantOffsets, Int& typeAuxInfo); 137 inline Int64 estSaoDist(Int64 count, Int64 offset, Int64 diffSum, Int shift); 138 inline Int estIterOffset(Int typeIdx, Int classIdx, Double lambda, Int offsetInput, Int64 count, Int64 diffSum, Int shift, Int bitIncrease, Int64& bestDist, Double& bestCost, Int offsetTh ); 139 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 140 Void addPreDBFStatistics(SAOStatData*** blkStats); 141 #endif 142 private: //members 143 //for RDO 144 TEncSbac** m_pppcRDSbacCoder; 145 TEncSbac* m_pcRDGoOnSbacCoder; 146 TEncBinCABACCounter** m_pppcBinCoderCABAC; 147 Double m_lambda[NUM_SAO_COMPONENTS]; 148 149 //statistics 150 SAOStatData*** m_statData; //[ctu][comp][classes] 151 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 152 SAOStatData*** m_preDBFstatData; 153 #endif 98 154 #if SAO_ENCODING_CHOICE 99 Void SAOProcess(SAOParam *pcSaoParam, Double dLambda, Double dLambdaChroma, Int depth); 100 #else 101 Void SAOProcess(SAOParam *pcSaoParam, Double dLambda, Double dLambdaChroma); 155 Double m_saoDisabledRate[NUM_SAO_COMPONENTS][MAX_TLAYER]; 102 156 #endif 103 #else 104 Void SAOProcess(SAOParam *pcSaoParam, Double dLambda); 105 #endif 106 107 Void runQuadTreeDecision(SAOQTPart *psQTPart, Int iPartIdx, Double &dCostFinal, Int iMaxLevel, Double dLambda, Int yCbCr); 108 Void rdoSaoOnePart(SAOQTPart *psQTPart, Int iPartIdx, Double dLambda, Int yCbCr); 109 110 Void disablePartTree(SAOQTPart *psQTPart, Int iPartIdx); 111 Void getSaoStats(SAOQTPart *psQTPart, Int iYCbCr); 112 Void calcSaoStatsCu(Int iAddr, Int iPartIdx, Int iYCbCr); 113 Void calcSaoStatsBlock( Pel* pRecStart, Pel* pOrgStart, Int stride, Int64** ppStats, Int64** ppCount, UInt width, UInt height, Bool* pbBorderAvail, Int iYCbCr); 114 Void calcSaoStatsCuOrg(Int iAddr, Int iPartIdx, Int iYCbCr); 115 Void calcSaoStatsCu_BeforeDblk( TComPic* pcPic ); 116 Void destroyEncBuffer(); 117 Void createEncBuffer(); 118 Void assignSaoUnitSyntax(SaoLcuParam* saoLcuParam, SAOQTPart* saoPart, Bool &oneUnitFlag, Int yCbCr); 119 Void checkMerge(SaoLcuParam * lcuParamCurr,SaoLcuParam * lcuParamCheck, Int dir); 120 #if SAO_ENCODING_CHOICE 121 Void rdoSaoUnitAll(SAOParam *saoParam, Double lambda, Double lambdaChroma, Int depth); 122 #else 123 Void rdoSaoUnitAll(SAOParam *saoParam, Double lambda, Double lambdaChroma); 124 #endif 125 Void saoComponentParamDist(Int allowMergeLeft, Int allowMergeUp, SAOParam *saoParam, Int addr, Int addrUp, Int addrLeft, Int yCbCr, Double lambda, SaoLcuParam *compSaoParam, Double *distortion); 126 Void sao2ChromaParamDist(Int allowMergeLeft, Int allowMergeUp, SAOParam *saoParam, Int addr, Int addrUp, Int addrLeft, Double lambda, SaoLcuParam *crSaoParam, SaoLcuParam *cbSaoParam, Double *distortion); 127 inline Int64 estSaoDist(Int64 count, Int64 offset, Int64 offsetOrg, Int shift); 128 inline Int64 estIterOffset(Int typeIdx, Int classIdx, Double lambda, Int64 offsetInput, Int64 count, Int64 offsetOrg, Int shift, Int bitIncrease, Int *currentDistortionTableBo, Double *currentRdCostTableBo, Int offsetTh ); 129 inline Int64 estSaoTypeDist(Int compIdx, Int typeIdx, Int shift, Double lambda, Int *currentDistortionTableBo, Double *currentRdCostTableBo); 130 Void setMaxNumOffsetsPerPic(Int iVal) {m_maxNumOffsetsPerPic = iVal; } 131 Int getMaxNumOffsetsPerPic() {return m_maxNumOffsetsPerPic; } 157 Int m_skipLinesR[NUM_SAO_COMPONENTS][NUM_SAO_NEW_TYPES]; 158 Int m_skipLinesB[NUM_SAO_COMPONENTS][NUM_SAO_NEW_TYPES]; 132 159 }; 133 134 160 //! \} 135 161 -
branches/HTM-10.0-dev0/source/Lib/TLibEncoder/TEncSbac.cpp
r833 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 84 84 , m_cCUAbsSCModel ( 1, 1, NUM_ABS_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) 85 85 , m_cMVPIdxSCModel ( 1, 1, NUM_MVP_IDX_CTX , m_contextModels + m_numContextModels, m_numContextModels) 86 , m_cCUAMPSCModel ( 1, 1, NUM_CU_AMP_CTX , m_contextModels + m_numContextModels, m_numContextModels)87 86 , m_cSaoMergeSCModel ( 1, 1, NUM_SAO_MERGE_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) 88 87 , m_cSaoTypeIdxSCModel ( 1, 1, NUM_SAO_TYPE_IDX_CTX , m_contextModels + m_numContextModels, m_numContextModels) … … 153 152 #endif 154 153 m_cCUPartSizeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_PART_SIZE ); 155 m_cCUAMPSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CU_AMP_POS );156 154 m_cCUPredModeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_PRED_MODE ); 157 155 m_cCUIntraPredSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_INTRA_PRED_MODE ); … … 254 252 #endif 255 253 curCost += m_cCUPartSizeSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_PART_SIZE ); 256 curCost += m_cCUAMPSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_CU_AMP_POS );257 254 curCost += m_cCUPredModeSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_PRED_MODE ); 258 255 curCost += m_cCUIntraPredSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_INTRA_PRED_MODE ); … … 326 323 #endif 327 324 m_cCUPartSizeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_PART_SIZE ); 328 m_cCUAMPSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CU_AMP_POS );329 325 m_cCUPredModeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_PRED_MODE ); 330 326 m_cCUIntraPredSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_INTRA_PRED_MODE ); … … 348 344 m_cTransformSkipSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANSFORMSKIP_FLAG ); 349 345 m_CUTransquantBypassFlagSCModel.initBuffer( eSliceType, iQp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG ); 350 351 346 #if H_3D_DIM 352 347 m_cDepthIntraModeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DEPTH_INTRA_MODE ); … … 794 789 if (eSize == SIZE_2NxN) 795 790 { 796 m_pcBinIf->encodeBin(1, m_cCU AMPSCModel.get( 0, 0, 0));791 m_pcBinIf->encodeBin(1, m_cCUPartSizeSCModel.get( 0, 0, 3 )); 797 792 } 798 793 else 799 794 { 800 m_pcBinIf->encodeBin(0, m_cCU AMPSCModel.get( 0, 0, 0 ));795 m_pcBinIf->encodeBin(0, m_cCUPartSizeSCModel.get( 0, 0, 3 )); 801 796 m_pcBinIf->encodeBinEP((eSize == SIZE_2NxnU? 0: 1)); 802 797 } … … 818 813 if (eSize == SIZE_Nx2N) 819 814 { 820 m_pcBinIf->encodeBin(1, m_cCU AMPSCModel.get( 0, 0, 0));815 m_pcBinIf->encodeBin(1, m_cCUPartSizeSCModel.get( 0, 0, 3 )); 821 816 } 822 817 else 823 818 { 824 m_pcBinIf->encodeBin(0, m_cCU AMPSCModel.get( 0, 0, 0));819 m_pcBinIf->encodeBin(0, m_cCUPartSizeSCModel.get( 0, 0, 3 )); 825 820 m_pcBinIf->encodeBinEP((eSize == SIZE_nLx2N? 0: 1)); 826 821 } … … 2134 2129 { 2135 2130 m_pcBinIf->encodeBin( 1, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) ); 2136 m_pcBinIf->encodeBinEP( uiCode <= 4 ? 1 : 0);2131 m_pcBinIf->encodeBinEP( uiCode == 1 ? 0 : 1 ); 2137 2132 } 2138 2133 } … … 2337 2332 } 2338 2333 2334 Void TEncSbac::codeSAOOffsetParam(Int compIdx, SAOOffset& ctbParam, Bool sliceEnabled) 2335 { 2336 UInt uiSymbol; 2337 if(!sliceEnabled) 2338 { 2339 assert(ctbParam.modeIdc == SAO_MODE_OFF); 2340 return; 2341 } 2342 2343 //type 2344 if(compIdx == SAO_Y || compIdx == SAO_Cb) 2345 { 2346 //sao_type_idx_luma or sao_type_idx_chroma 2347 if(ctbParam.modeIdc == SAO_MODE_OFF) 2348 { 2349 uiSymbol =0; 2350 } 2351 else if(ctbParam.typeIdc == SAO_TYPE_BO) //BO 2352 { 2353 uiSymbol = 1; 2354 } 2355 else 2356 { 2357 assert(ctbParam.typeIdc < SAO_TYPE_START_BO); //EO 2358 uiSymbol = 2; 2359 } 2360 codeSaoTypeIdx(uiSymbol); 2361 } 2362 2363 if(ctbParam.modeIdc == SAO_MODE_NEW) 2364 { 2365 Int numClasses = (ctbParam.typeIdc == SAO_TYPE_BO)?4:NUM_SAO_EO_CLASSES; 2366 Int offset[4]; 2367 Int k=0; 2368 for(Int i=0; i< numClasses; i++) 2369 { 2370 if(ctbParam.typeIdc != SAO_TYPE_BO && i == SAO_CLASS_EO_PLAIN) 2371 { 2372 continue; 2373 } 2374 Int classIdx = (ctbParam.typeIdc == SAO_TYPE_BO)?( (ctbParam.typeAuxInfo+i)% NUM_SAO_BO_CLASSES ):i; 2375 offset[k] = ctbParam.offset[classIdx]; 2376 k++; 2377 } 2378 2379 for(Int i=0; i< 4; i++) 2380 { 2381 codeSaoMaxUvlc((offset[i]<0)?(-offset[i]):(offset[i]), g_saoMaxOffsetQVal[compIdx] ); //sao_offset_abs 2382 } 2383 2384 2385 if(ctbParam.typeIdc == SAO_TYPE_BO) 2386 { 2387 for(Int i=0; i< 4; i++) 2388 { 2389 if(offset[i] != 0) 2390 { 2391 codeSAOSign((offset[i]< 0)?1:0); 2392 } 2393 } 2394 2395 codeSaoUflc(NUM_SAO_BO_CLASSES_LOG2, ctbParam.typeAuxInfo ); //sao_band_position 2396 } 2397 else //EO 2398 { 2399 if(compIdx == SAO_Y || compIdx == SAO_Cb) 2400 { 2401 assert(ctbParam.typeIdc - SAO_TYPE_START_EO >=0); 2402 codeSaoUflc(NUM_SAO_EO_TYPES_LOG2, ctbParam.typeIdc - SAO_TYPE_START_EO ); //sao_eo_class_luma or sao_eo_class_chroma 2403 } 2404 } 2405 2406 } 2407 } 2408 2409 2410 Void TEncSbac::codeSAOBlkParam(SAOBlkParam& saoBlkParam 2411 , Bool* sliceEnabled 2412 , Bool leftMergeAvail 2413 , Bool aboveMergeAvail 2414 , Bool onlyEstMergeInfo // = false 2415 ) 2416 { 2417 2418 Bool isLeftMerge = false; 2419 Bool isAboveMerge= false; 2420 2421 if(leftMergeAvail) 2422 { 2423 isLeftMerge = ((saoBlkParam[SAO_Y].modeIdc == SAO_MODE_MERGE) && (saoBlkParam[SAO_Y].typeIdc == SAO_MERGE_LEFT)); 2424 codeSaoMerge( isLeftMerge?1:0 ); //sao_merge_left_flag 2425 } 2426 2427 if( aboveMergeAvail && !isLeftMerge) 2428 { 2429 isAboveMerge = ((saoBlkParam[SAO_Y].modeIdc == SAO_MODE_MERGE) && (saoBlkParam[SAO_Y].typeIdc == SAO_MERGE_ABOVE)); 2430 codeSaoMerge( isAboveMerge?1:0 ); //sao_merge_left_flag 2431 } 2432 2433 if(onlyEstMergeInfo) 2434 { 2435 return; //only for RDO 2436 } 2437 2438 if(!isLeftMerge && !isAboveMerge) //not merge mode 2439 { 2440 for(Int compIdx=0; compIdx < NUM_SAO_COMPONENTS; compIdx++) 2441 { 2442 codeSAOOffsetParam(compIdx, saoBlkParam[compIdx], sliceEnabled[compIdx]); 2443 } 2444 } 2445 } 2446 2339 2447 #if H_3D_INTER_SDC 2340 2448 #if QC_SDC_UNIFY_G0130 -
branches/HTM-10.0-dev0/source/Lib/TLibEncoder/TEncSbac.h
r833 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 111 111 Void codeScalingList ( TComScalingList* /*scalingList*/ ){ assert (0); return;}; 112 112 113 Void codeSAOOffsetParam(Int compIdx, SAOOffset& ctbParam, Bool sliceEnabled); 114 Void codeSAOBlkParam(SAOBlkParam& saoBlkParam 115 , Bool* sliceEnabled 116 , Bool leftMergeAvail 117 , Bool aboveMergeAvail 118 , Bool onlyEstMergeInfo = false 119 ); 120 113 121 private: 114 122 Void xWriteUnarySymbol ( UInt uiSymbol, ContextModel* pcSCModel, Int iOffset ); … … 245 253 ContextModel3DBuffer m_cMVPIdxSCModel; 246 254 247 ContextModel3DBuffer m_cCUAMPSCModel;248 255 ContextModel3DBuffer m_cSaoMergeSCModel; 249 256 ContextModel3DBuffer m_cSaoTypeIdxSCModel; -
branches/HTM-10.0-dev0/source/Lib/TLibEncoder/TEncSearch.cpp
r833 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 202 202 m_pppcRDSbacCoder = pppcRDSbacCoder; 203 203 m_pcRDGoOnSbacCoder = pcRDGoOnSbacCoder; 204 205 m_bUseSBACRD = pppcRDSbacCoder ? true : false;206 204 207 205 for (Int iDir = 0; iDir < 2; iDir++) … … 728 726 Pel* piRefPos; 729 727 Int iRefStride = m_filteredBlock[0][0].getStride(); 730 #if NS_HAD731 m_pcRdCost->setDistParam( pcPatternKey, m_filteredBlock[0][0].getLumaAddr(), iRefStride, 1, m_cDistParam, m_pcEncCfg->getUseHADME(), m_pcEncCfg->getUseNSQT() );732 #else733 728 m_pcRdCost->setDistParam( pcPatternKey, m_filteredBlock[0][0].getLumaAddr(), iRefStride, 1, m_cDistParam, m_pcEncCfg->getUseHADME() ); 734 #endif735 729 736 730 const TComMv* pcMvRefine = (iFrac == 2 ? s_acMvRefineH : s_acMvRefineQ); … … 745 739 piRefPos = m_filteredBlock[ verVal & 3 ][ horVal & 3 ].getLumaAddr(); 746 740 if ( horVal == 2 && ( verVal & 1 ) == 0 ) 741 { 747 742 piRefPos += 1; 743 } 748 744 if ( ( horVal & 1 ) == 0 && verVal == 2 ) 745 { 749 746 piRefPos += iRefStride; 747 } 750 748 cMvTest = pcMvRefine[i]; 751 749 cMvTest += rcMvFrac; … … 787 785 UInt uiLog2TrafoSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()] + 2 - uiFullDepth; 788 786 789 {790 787 if( pcCU->getPredictionMode(0) == MODE_INTRA && pcCU->getPartitionSize(0) == SIZE_NxN && uiTrDepth == 0 ) 791 788 { … … 812 809 } 813 810 } 814 }815 811 816 812 if ( bChroma ) … … 819 815 { 820 816 if( uiTrDepth==0 || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth-1 ) ) 817 { 821 818 m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth ); 819 } 822 820 if( uiTrDepth==0 || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth-1 ) ) 821 { 823 822 m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth ); 824 823 } 824 } 825 825 } 826 826 … … 835 835 } 836 836 837 {838 837 //===== Cbfs ===== 839 838 if( bLuma ) … … 842 841 } 843 842 } 844 }845 843 846 844 Void … … 1212 1210 { 1213 1211 Int scalingListType = 0 + g_eTTable[(Int)TEXT_LUMA]; 1214 assert(scalingListType < 6);1212 assert(scalingListType < SCALING_LIST_NUM); 1215 1213 m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), TEXT_LUMA,pcCU->getLumaIntraDir( uiAbsPartIdx ), piResi, uiStride, pcCoeff, uiWidth, uiHeight, scalingListType, useTransformSkip ); 1216 1214 } … … 1412 1410 1413 1411 #if RDOQ_CHROMA_LAMBDA 1414 m_pcTrQuant->selectLambda (TEXT_CHROMA);1412 m_pcTrQuant->selectLambda(eText); 1415 1413 #endif 1416 1414 m_pcTrQuant->transformNxN ( pcCU, piResi, uiStride, pcCoeff, … … 1425 1423 { 1426 1424 Int scalingListType = 0 + g_eTTable[(Int)eText]; 1427 assert(scalingListType < 6);1425 assert(scalingListType < SCALING_LIST_NUM); 1428 1426 m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), TEXT_CHROMA, REG_DCT, piResi, uiStride, pcCoeff, uiWidth, uiHeight, scalingListType, useTransformSkipChroma ); 1429 1427 } … … 1464 1462 1465 1463 //===== update distortion ===== 1466 #if WEIGHTED_CHROMA_DISTORTION1467 1464 ruiDist += m_pcRdCost->getDistPart(g_bitDepthC, piReco, uiStride, piOrg, uiStride, uiWidth, uiHeight, eText ); 1468 #else1469 ruiDist += m_pcRdCost->getDistPart(g_bitDepthC, piReco, uiStride, piOrg, uiStride, uiWidth, uiHeight );1470 #endif1471 1465 } 1472 1466 … … 1553 1547 checkTransformSkip &= (widthTransformSkip == 4 && heightTransformSkip == 4); 1554 1548 checkTransformSkip &= (!pcCU->getCUTransquantBypass(0)); 1555 checkTransformSkip &= (!((pcCU->getQP( 0 ) == 0) && (pcCU->getSlice()->getSPS()->getUseLossless())));1556 1549 if ( m_pcEncCfg->getUseTransformSkipFast() ) 1557 1550 { … … 1563 1556 { 1564 1557 //----- store original entropy coding status ----- 1565 if( m_bUseSBACRD)1566 {1567 1558 m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[ uiFullDepth ][ CI_QT_TRAFO_ROOT ] ); 1568 }1569 1559 #if H_3D_VSO 1570 1560 Dist singleDistYTmp = 0; … … 1641 1631 { 1642 1632 xStoreIntraResultQT(pcCU, uiTrDepth, uiAbsPartIdx,bLumaOnly ); 1643 if( m_bUseSBACRD)1644 {1645 1633 m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[ uiFullDepth ][ CI_TEMP_BEST ] ); 1646 1634 } 1647 1635 } 1648 }1649 1636 if(modeId == firstCheckId) 1650 1637 { … … 1667 1654 } 1668 1655 } 1669 if(m_bUseSBACRD)1670 {1671 1656 m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ uiFullDepth ][ CI_TEMP_BEST ] ); 1672 1657 } 1673 }1674 1658 1675 1659 if( !bLumaOnly ) … … 1696 1680 pcCU ->setTransformSkipSubParts ( 0, TEXT_LUMA, uiAbsPartIdx, uiFullDepth ); 1697 1681 //----- store original entropy coding status ----- 1698 if( m_bUseSBACRD &&bCheckSplit )1682 if( bCheckSplit ) 1699 1683 { 1700 1684 m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[ uiFullDepth ][ CI_QT_TRAFO_ROOT ] ); … … 1742 1726 { 1743 1727 //----- store full entropy coding status, load original entropy coding status ----- 1744 if( m_bUseSBACRD )1745 {1746 1728 if( bCheckFull ) 1747 1729 { … … 1753 1735 m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[ uiFullDepth ][ CI_QT_TRAFO_ROOT ] ); 1754 1736 } 1755 } 1737 1756 1738 //----- code splitted block ----- 1757 1739 Double dSplitCost = 0.0; … … 1798 1780 } 1799 1781 //----- restore context states ----- 1800 if( m_bUseSBACRD )1801 {1802 1782 m_pcRDGoOnSbacCoder->load ( m_pppcRDSbacCoder[ uiFullDepth ][ CI_QT_TRAFO_ROOT ] ); 1803 } 1783 1804 1784 //----- determine rate and r-d cost ----- 1805 1785 UInt uiSplitBits = xGetIntraBitsQT( pcCU, uiTrDepth, uiAbsPartIdx, true, !bLumaOnly, false ); … … 1821 1801 } 1822 1802 //----- set entropy coding status ----- 1823 if( m_bUseSBACRD )1824 {1825 1803 m_pcRDGoOnSbacCoder->load ( m_pppcRDSbacCoder[ uiFullDepth ][ CI_QT_TRAFO_TEST ] ); 1826 }1827 1804 1828 1805 //--- set transform index and Cbf values --- … … 2718 2695 { 2719 2696 //use RDO to decide whether Cr/Cb takes TS 2720 if( m_bUseSBACRD )2721 {2722 2697 m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[uiFullDepth][CI_QT_TRAFO_ROOT] ); 2723 }2724 2698 2725 2699 for(Int chromaId = 0; chromaId < 2; chromaId ++) … … 2772 2746 { 2773 2747 xStoreIntraResultChromaQT(pcCU, uiTrDepth, uiAbsPartIdx,chromaId); 2774 if( m_bUseSBACRD)2775 {2776 2748 m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[ uiFullDepth ][ CI_TEMP_BEST ] ); 2777 2749 } 2778 2750 } 2779 }2780 2751 if(chromaModeId == firstCheckId) 2781 2752 { … … 2788 2759 xLoadIntraResultChromaQT(pcCU, uiTrDepth, uiAbsPartIdx,chromaId); 2789 2760 pcCU->setCbfSubParts ( singleCbfC << uiTrDepth, (TextType)(chromaId + 2), uiAbsPartIdx, pcCU->getDepth(0) + actualTrDepth ); 2790 if(m_bUseSBACRD)2791 {2792 2761 m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ uiFullDepth ][ CI_TEMP_BEST ] ); 2793 2762 } 2794 }2795 2763 pcCU ->setTransformSkipSubParts( bestModeId, (TextType)(chromaId + 2), uiAbsPartIdx, pcCU->getDepth( 0 ) + actualTrDepth ); 2796 2764 ruiDist += singleDistC; … … 2798 2766 if(chromaId == 0) 2799 2767 { 2800 if( m_bUseSBACRD )2801 {2802 2768 m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[uiFullDepth][CI_QT_TRAFO_ROOT] ); 2803 2769 } 2804 2770 } 2805 2771 } 2806 }2807 2772 else 2808 2773 { … … 3216 3181 { 3217 3182 #endif 3218 // set context models 3219 if( m_bUseSBACRD ) 3220 { 3183 // set context models 3221 3184 m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST] ); 3222 } 3223 3224 // determine residual for partition 3185 3186 // determine residual for partition 3225 3187 #if H_3D_VSO 3226 Dist uiPUDistY = 0;3188 Dist uiPUDistY = 0; 3227 3189 #else 3228 UInt uiPUDistY = 0;3229 #endif 3230 UInt uiPUDistC = 0;3231 Double dPUCost = 0.0;3190 UInt uiPUDistY = 0; 3191 #endif 3192 UInt uiPUDistC = 0; 3193 Double dPUCost = 0.0; 3232 3194 #if H_3D_VSO // M36 3233 if( m_pcRdCost->getUseRenModel() )3234 {3235 m_pcRdCost->setRenModelData( pcCU, uiPartOffset, piOrg, uiStride, uiWidth, uiHeight );3236 }3195 if( m_pcRdCost->getUseRenModel() ) 3196 { 3197 m_pcRdCost->setRenModelData( pcCU, uiPartOffset, piOrg, uiStride, uiWidth, uiHeight ); 3198 } 3237 3199 #endif 3238 3200 #if H_3D_DIM_SDC 3239 3240 3241 3242 3243 3244 3201 if( pcCU->getSDCFlag(uiPartOffset) ) 3202 { 3203 pcCU->setTrIdxSubParts(0, uiPartOffset, uiDepth + uiInitTrDepth); 3204 pcCU->setCbfSubParts(1, 1, 1, uiPartOffset, uiDepth + uiInitTrDepth); 3205 3206 // start encoding with SDC 3245 3207 #if QC_GENERIC_SDC_G0122 3246 3208 xIntraCodingSDC(pcCU, uiPartOffset, pcOrgYuv, pcPredYuv, uiPUDistY, dPUCost, ( testZeroResi != 0 ), iSDCDeltaResi ); 3247 3209 #else 3248 3249 #endif 3250 3251 3252 3210 xIntraCodingSDC(pcCU, uiPartOffset, pcOrgYuv, pcPredYuv, uiPUDistY, dPUCost, (testZeroResi!=0)); 3211 #endif 3212 } 3213 else 3214 { 3253 3215 #endif 3254 3216 #if HHI_RQT_INTRA_SPEEDUP 3255 3217 #if H_3D_DIM_ENC 3256 xRecurIntraCodingQT( pcCU, uiInitTrDepth, uiPartOffset, bLumaOnly, pcOrgYuv, pcPredYuv, pcResiYuv, uiPUDistY, uiPUDistC, true, dPUCost, (testZeroResi != 0) );3218 xRecurIntraCodingQT( pcCU, uiInitTrDepth, uiPartOffset, bLumaOnly, pcOrgYuv, pcPredYuv, pcResiYuv, uiPUDistY, uiPUDistC, true, dPUCost, (testZeroResi != 0) ); 3257 3219 #else 3258 xRecurIntraCodingQT( pcCU, uiInitTrDepth, uiPartOffset, bLumaOnly, pcOrgYuv, pcPredYuv, pcResiYuv, uiPUDistY, uiPUDistC, true, dPUCost );3220 xRecurIntraCodingQT( pcCU, uiInitTrDepth, uiPartOffset, bLumaOnly, pcOrgYuv, pcPredYuv, pcResiYuv, uiPUDistY, uiPUDistC, true, dPUCost ); 3259 3221 #endif 3260 3222 #else 3261 3223 #if H_3D_DIM_ENC 3262 xRecurIntraCodingQT( pcCU, uiInitTrDepth, uiPartOffset, bLumaOnly, pcOrgYuv, pcPredYuv, pcResiYuv, uiPUDistY, uiPUDistC, dPUCost, (testZeroResi != 0) );3224 xRecurIntraCodingQT( pcCU, uiInitTrDepth, uiPartOffset, bLumaOnly, pcOrgYuv, pcPredYuv, pcResiYuv, uiPUDistY, uiPUDistC, dPUCost, (testZeroResi != 0) ); 3263 3225 #else 3264 xRecurIntraCodingQT( pcCU, uiInitTrDepth, uiPartOffset, bLumaOnly, pcOrgYuv, pcPredYuv, pcResiYuv, uiPUDistY, uiPUDistC, dPUCost );3226 xRecurIntraCodingQT( pcCU, uiInitTrDepth, uiPartOffset, bLumaOnly, pcOrgYuv, pcPredYuv, pcResiYuv, uiPUDistY, uiPUDistC, dPUCost ); 3265 3227 #endif 3266 3228 #endif 3267 3229 #if H_3D_DIM_SDC 3268 3269 #endif 3270 3271 // check r-d cost3272 if( dPUCost < dBestPUCost )3273 {3230 } 3231 #endif 3232 3233 // check r-d cost 3234 if( dPUCost < dBestPUCost ) 3235 { 3274 3236 #if HHI_RQT_INTRA_SPEEDUP_MOD 3275 uiSecondBestMode = uiBestPUMode;3276 dSecondBestPUCost = dBestPUCost;3277 #endif 3278 uiBestPUMode = uiOrgMode;3279 uiBestPUDistY = uiPUDistY;3280 uiBestPUDistC = uiPUDistC;3281 dBestPUCost = dPUCost;3282 3237 uiSecondBestMode = uiBestPUMode; 3238 dSecondBestPUCost = dBestPUCost; 3239 #endif 3240 uiBestPUMode = uiOrgMode; 3241 uiBestPUDistY = uiPUDistY; 3242 uiBestPUDistC = uiPUDistC; 3243 dBestPUCost = dPUCost; 3244 3283 3245 #if H_3D_DIM_SDC 3284 if( pcCU->getSDCFlag(uiPartOffset) )3285 {3286 bBestUseSDC = true;3287 3288 // copy reconstruction3289 pcPredYuv->copyPartToPartYuv(pcRecoYuv, uiPartOffset, uiWidth, uiHeight);3290 3291 // copy DC values3292 apBestDCOffsets[0] = pcCU->getSDCSegmentDCOffset(0, uiPartOffset);3293 apBestDCOffsets[1] = pcCU->getSDCSegmentDCOffset(1, uiPartOffset);3294 }3295 else3296 {3297 bBestUseSDC = false;3298 #endif 3299 xSetIntraResultQT( pcCU, uiInitTrDepth, uiPartOffset, bLumaOnly, pcRecoYuv );3300 3301 UInt uiQPartNum = pcCU->getPic()->getNumPartInCU() >> ( ( pcCU->getDepth(0) + uiInitTrDepth ) << 1 );3302 ::memcpy( m_puhQTTempTrIdx, pcCU->getTransformIdx() + uiPartOffset, uiQPartNum * sizeof( UChar ) );3303 ::memcpy( m_puhQTTempCbf[0], pcCU->getCbf( TEXT_LUMA ) + uiPartOffset, uiQPartNum * sizeof( UChar ) );3304 ::memcpy( m_puhQTTempCbf[1], pcCU->getCbf( TEXT_CHROMA_U ) + uiPartOffset, uiQPartNum * sizeof( UChar ) );3305 ::memcpy( m_puhQTTempCbf[2], pcCU->getCbf( TEXT_CHROMA_V ) + uiPartOffset, uiQPartNum * sizeof( UChar ) );3306 ::memcpy( m_puhQTTempTransformSkipFlag[0], pcCU->getTransformSkip(TEXT_LUMA) + uiPartOffset, uiQPartNum * sizeof( UChar ) );3307 ::memcpy( m_puhQTTempTransformSkipFlag[1], pcCU->getTransformSkip(TEXT_CHROMA_U) + uiPartOffset, uiQPartNum * sizeof( UChar ) );3308 ::memcpy( m_puhQTTempTransformSkipFlag[2], pcCU->getTransformSkip(TEXT_CHROMA_V) + uiPartOffset, uiQPartNum * sizeof( UChar ) );3246 if( pcCU->getSDCFlag(uiPartOffset) ) 3247 { 3248 bBestUseSDC = true; 3249 3250 // copy reconstruction 3251 pcPredYuv->copyPartToPartYuv(pcRecoYuv, uiPartOffset, uiWidth, uiHeight); 3252 3253 // copy DC values 3254 apBestDCOffsets[0] = pcCU->getSDCSegmentDCOffset(0, uiPartOffset); 3255 apBestDCOffsets[1] = pcCU->getSDCSegmentDCOffset(1, uiPartOffset); 3256 } 3257 else 3258 { 3259 bBestUseSDC = false; 3260 #endif 3261 xSetIntraResultQT( pcCU, uiInitTrDepth, uiPartOffset, bLumaOnly, pcRecoYuv ); 3262 3263 UInt uiQPartNum = pcCU->getPic()->getNumPartInCU() >> ( ( pcCU->getDepth(0) + uiInitTrDepth ) << 1 ); 3264 ::memcpy( m_puhQTTempTrIdx, pcCU->getTransformIdx() + uiPartOffset, uiQPartNum * sizeof( UChar ) ); 3265 ::memcpy( m_puhQTTempCbf[0], pcCU->getCbf( TEXT_LUMA ) + uiPartOffset, uiQPartNum * sizeof( UChar ) ); 3266 ::memcpy( m_puhQTTempCbf[1], pcCU->getCbf( TEXT_CHROMA_U ) + uiPartOffset, uiQPartNum * sizeof( UChar ) ); 3267 ::memcpy( m_puhQTTempCbf[2], pcCU->getCbf( TEXT_CHROMA_V ) + uiPartOffset, uiQPartNum * sizeof( UChar ) ); 3268 ::memcpy( m_puhQTTempTransformSkipFlag[0], pcCU->getTransformSkip(TEXT_LUMA) + uiPartOffset, uiQPartNum * sizeof( UChar ) ); 3269 ::memcpy( m_puhQTTempTransformSkipFlag[1], pcCU->getTransformSkip(TEXT_CHROMA_U) + uiPartOffset, uiQPartNum * sizeof( UChar ) ); 3270 ::memcpy( m_puhQTTempTransformSkipFlag[2], pcCU->getTransformSkip(TEXT_CHROMA_V) + uiPartOffset, uiQPartNum * sizeof( UChar ) ); 3309 3271 #if H_3D_DIM_SDC 3310 }3311 #endif 3312 }3272 } 3273 #endif 3274 } 3313 3275 #if HHI_RQT_INTRA_SPEEDUP_MOD 3314 else if( dPUCost < dSecondBestPUCost )3315 {3316 uiSecondBestMode = uiOrgMode;3317 dSecondBestPUCost = dPUCost;3318 }3276 else if( dPUCost < dSecondBestPUCost ) 3277 { 3278 uiSecondBestMode = uiOrgMode; 3279 dSecondBestPUCost = dPUCost; 3280 } 3319 3281 #endif 3320 3282 #if H_3D_DIM_ENC || H_3D_DIM_SDC … … 3350 3312 3351 3313 // set context models 3352 if( m_bUseSBACRD )3353 {3354 3314 m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST] ); 3355 }3356 3315 3357 3316 // determine residual for partition … … 3521 3480 3522 3481 //===== reset context models ===== 3523 if(m_bUseSBACRD)3524 {3525 3482 m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]); 3526 }3527 3483 3528 3484 //===== set distortion (rate and r-d costs are determined later) ===== … … 3556 3512 { 3557 3513 //----- restore context models ----- 3558 if( m_bUseSBACRD )3559 {3560 3514 m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST] ); 3561 }3562 3515 3563 3516 //----- chroma coding ----- … … 3565 3518 pcCU->setChromIntraDirSubParts ( uiModeList[uiMode], 0, uiDepth ); 3566 3519 xRecurIntraChromaCodingQT ( pcCU, 0, 0, pcOrgYuv, pcPredYuv, pcResiYuv, uiDist ); 3567 if( m_bUseSBACRD &&pcCU->getSlice()->getPPS()->getUseTransformSkip() )3520 if( pcCU->getSlice()->getPPS()->getUseTransformSkip() ) 3568 3521 { 3569 3522 m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST] ); … … 3597 3550 3598 3551 //----- restore context models ----- 3599 if( m_bUseSBACRD )3600 {3601 3552 m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST] ); 3602 3553 } 3603 }3604 3554 3605 3555 /** Function for encoding and reconstructing luma/chroma samples of a PCM mode CU. … … 3761 3711 dCost = m_pcRdCost->calcRdCost( uiBits, uiDistortion ); 3762 3712 3763 if(m_bUseSBACRD)3764 {3765 3713 m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]); 3766 }3767 3714 3768 3715 pcCU->getTotalBits() = uiBits; … … 3789 3736 pcYuvOrg->getLumaAddr( uiAbsPartIdx ), pcYuvOrg->getStride(), 3790 3737 m_tmpYuvPred .getLumaAddr( uiAbsPartIdx ), m_tmpYuvPred .getStride(), 3791 #if NS_HAD3792 iWidth, iHeight, m_pcEncCfg->getUseHADME(), m_pcEncCfg->getUseNSQT() );3793 #else3794 3738 iWidth, iHeight, m_pcEncCfg->getUseHADME() ); 3795 #endif3796 3739 #if H_3D_IC 3797 3740 cDistParam.bUseIC = false; … … 3942 3885 for( UInt uiMergeCand = 0; uiMergeCand < numValidMergeCand; ++uiMergeCand ) 3943 3886 { 3944 {3945 3887 UInt uiCostCand = MAX_UINT; 3946 3888 UInt uiBitsCand = 0; … … 4004 3946 } 4005 3947 else 4006 #endif 4007 { 3948 { 3949 #endif 4008 3950 pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvField( cMvFieldNeighbours[0 + 2*uiMergeCand], ePartSize, uiAbsPartIdx, 0, iPUIdx ); 4009 3951 pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvField( cMvFieldNeighbours[1 + 2*uiMergeCand], ePartSize, uiAbsPartIdx, 0, iPUIdx ); 4010 } 4011 3952 #if NTT_STORE_SPDV_VSP_G0148 3953 } 3954 #endif 4012 3955 #if H_3D_VSP && !NTT_STORE_SPDV_VSP_G0148 4013 3956 pcCU->setVSPFlagSubParts( vspFlag[uiMergeCand], uiAbsPartIdx, iPUIdx, pcCU->getDepth( uiAbsPartIdx ) ); … … 4044 3987 } 4045 3988 } 4046 }4047 3989 4048 3990 /** convert bi-pred merge candidates to uni-pred … … 4100 4042 m_cYuvPredTemp.clear(); 4101 4043 rpcPredYuv->clear(); 4102 4044 4103 4045 if ( !bUseRes ) 4104 4046 { 4105 4047 rpcResiYuv->clear(); 4106 4048 } 4107 4049 4108 4050 rpcRecoYuv->clear(); 4109 4051 4110 4052 TComMv cMvSrchRngLT; 4111 4053 TComMv cMvSrchRngRB; 4112 4054 4113 4055 TComMv cMvZero; 4114 4056 TComMv TempMv; //kolya 4115 4057 4116 4058 TComMv cMv[2]; 4117 4059 TComMv cMvBi[2]; 4118 4060 TComMv cMvTemp[2][33]; 4119 4061 4120 4062 Int iNumPart = pcCU->getNumPartInter(); 4121 4063 Int iNumPredDir = pcCU->getSlice()->isInterP() ? 1 : 2; 4122 4064 4123 4065 TComMv cMvPred[2][33]; 4124 4066 4125 4067 TComMv cMvPredBi[2][33]; 4126 4068 Int aaiMvpIdxBi[2][33]; 4127 4069 4128 4070 Int aaiMvpIdx[2][33]; 4129 4071 Int aaiMvpNum[2][33]; 4130 4072 4131 4073 AMVPInfo aacAMVPInfo[2][33]; 4132 4074 4133 4075 Int iRefIdx[2]={0,0}; //If un-initialized, may cause SEGV in bi-directional prediction iterative stage. 4134 4076 Int iRefIdxBi[2]; 4135 4077 4136 4078 UInt uiPartAddr; 4137 4079 Int iRoiWidth, iRoiHeight; 4138 4080 4139 4081 UInt uiMbBits[3] = {1, 1, 0}; 4140 4082 4141 4083 UInt uiLastMode = 0; 4142 4084 Int iRefStart, iRefEnd; 4143 4085 4144 4086 PartSize ePartSize = pcCU->getPartitionSize( 0 ); 4145 4087 … … 4168 4110 UInt uiCostBi = MAX_UINT; 4169 4111 UInt uiCostTemp; 4170 4112 4171 4113 UInt uiBits[3]; 4172 4114 UInt uiBitsTemp; … … 4181 4123 4182 4124 UInt uiCostTempL0[MAX_NUM_REF]; 4183 for (Int iNumRef=0; iNumRef < MAX_NUM_REF; iNumRef++) uiCostTempL0[iNumRef] = MAX_UINT; 4125 for (Int iNumRef=0; iNumRef < MAX_NUM_REF; iNumRef++) 4126 { 4127 uiCostTempL0[iNumRef] = MAX_UINT; 4128 } 4184 4129 UInt uiBitsTempL0[MAX_NUM_REF]; 4185 4130 … … 4190 4135 4191 4136 xGetBlkBits( ePartSize, pcCU->getSlice()->isInterP(), iPartIdx, uiLastMode, uiMbBits); 4192 4137 4193 4138 pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iRoiWidth, iRoiHeight ); 4194 4139 … … 4196 4141 pcCU->setVSPFlagSubParts( 0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr) ); 4197 4142 #endif 4198 4143 4199 4144 #if AMP_MRG 4200 4145 Bool bTestNormalMC = true; … … 4207 4152 bTestNormalMC = false; 4208 4153 } 4209 4154 4210 4155 if (bTestNormalMC) 4211 4156 { 4212 4157 #endif 4213 4158 4214 // Uni-directional prediction4215 for ( Int iRefList = 0; iRefList < iNumPredDir; iRefList++ )4216 {4217 RefPicList eRefPicList = ( iRefList ? REF_PIC_LIST_1 : REF_PIC_LIST_0 );4218 4219 for ( Int iRefIdxTemp = 0; iRefIdxTemp < pcCU->getSlice()->getNumRefIdx(eRefPicList); iRefIdxTemp++ )4220 {4221 uiBitsTemp = uiMbBits[iRefList];4222 if ( pcCU->getSlice()->getNumRefIdx(eRefPicList) > 1 )4223 {4224 uiBitsTemp += iRefIdxTemp+1;4225 if ( iRefIdxTemp == pcCU->getSlice()->getNumRefIdx(eRefPicList)-1 ) uiBitsTemp--;4226 }4159 // Uni-directional prediction 4160 for ( Int iRefList = 0; iRefList < iNumPredDir; iRefList++ ) 4161 { 4162 RefPicList eRefPicList = ( iRefList ? REF_PIC_LIST_1 : REF_PIC_LIST_0 ); 4163 4164 for ( Int iRefIdxTemp = 0; iRefIdxTemp < pcCU->getSlice()->getNumRefIdx(eRefPicList); iRefIdxTemp++ ) 4165 { 4166 uiBitsTemp = uiMbBits[iRefList]; 4167 if ( pcCU->getSlice()->getNumRefIdx(eRefPicList) > 1 ) 4168 { 4169 uiBitsTemp += iRefIdxTemp+1; 4170 if ( iRefIdxTemp == pcCU->getSlice()->getNumRefIdx(eRefPicList)-1 ) uiBitsTemp--; 4171 } 4227 4172 #if ZERO_MVD_EST 4228 xEstimateMvPredAMVP( pcCU, pcOrgYuv, iPartIdx, eRefPicList, iRefIdxTemp, cMvPred[iRefList][iRefIdxTemp], false, &biPDistTemp, &uiZeroMvdDistTemp);4173 xEstimateMvPredAMVP( pcCU, pcOrgYuv, iPartIdx, eRefPicList, iRefIdxTemp, cMvPred[iRefList][iRefIdxTemp], false, &biPDistTemp, &uiZeroMvdDistTemp); 4229 4174 #else 4230 xEstimateMvPredAMVP( pcCU, pcOrgYuv, iPartIdx, eRefPicList, iRefIdxTemp, cMvPred[iRefList][iRefIdxTemp], false, &biPDistTemp);4231 #endif 4232 aaiMvpIdx[iRefList][iRefIdxTemp] = pcCU->getMVPIdx(eRefPicList, uiPartAddr);4233 aaiMvpNum[iRefList][iRefIdxTemp] = pcCU->getMVPNum(eRefPicList, uiPartAddr);4234 4235 if(pcCU->getSlice()->getMvdL1ZeroFlag() && iRefList==1 && biPDistTemp < bestBiPDist)4236 {4237 bestBiPDist = biPDistTemp;4238 bestBiPMvpL1 = aaiMvpIdx[iRefList][iRefIdxTemp];4239 bestBiPRefIdxL1 = iRefIdxTemp;4240 }4241 4242 uiBitsTemp += m_auiMVPIdxCost[aaiMvpIdx[iRefList][iRefIdxTemp]][AMVP_MAX_NUM_CANDS];4175 xEstimateMvPredAMVP( pcCU, pcOrgYuv, iPartIdx, eRefPicList, iRefIdxTemp, cMvPred[iRefList][iRefIdxTemp], false, &biPDistTemp); 4176 #endif 4177 aaiMvpIdx[iRefList][iRefIdxTemp] = pcCU->getMVPIdx(eRefPicList, uiPartAddr); 4178 aaiMvpNum[iRefList][iRefIdxTemp] = pcCU->getMVPNum(eRefPicList, uiPartAddr); 4179 4180 if(pcCU->getSlice()->getMvdL1ZeroFlag() && iRefList==1 && biPDistTemp < bestBiPDist) 4181 { 4182 bestBiPDist = biPDistTemp; 4183 bestBiPMvpL1 = aaiMvpIdx[iRefList][iRefIdxTemp]; 4184 bestBiPRefIdxL1 = iRefIdxTemp; 4185 } 4186 4187 uiBitsTemp += m_auiMVPIdxCost[aaiMvpIdx[iRefList][iRefIdxTemp]][AMVP_MAX_NUM_CANDS]; 4243 4188 #if ZERO_MVD_EST 4244 if ( iRefList == 0 || pcCU->getSlice()->getList1IdxToList0Idx( iRefIdxTemp ) < 0 ) 4245 { 4246 uiZeroMvdBitsTemp = uiBitsTemp; 4247 uiZeroMvdBitsTemp += 2; //zero mvd bits 4248 4249 m_pcRdCost->getMotionCost( 1, 0 ); 4250 uiZeroMvdCostTemp = uiZeroMvdDistTemp + m_pcRdCost->getCost(uiZeroMvdBitsTemp); 4251 4252 if (uiZeroMvdCostTemp < uiZeroMvdCost) 4189 if ( iRefList == 0 || pcCU->getSlice()->getList1IdxToList0Idx( iRefIdxTemp ) < 0 ) 4253 4190 { 4254 uiZeroMvdCost = uiZeroMvdCostTemp; 4255 iZeroMvdDir = iRefList + 1; 4256 aiZeroMvdRefIdx[iRefList] = iRefIdxTemp; 4257 aiZeroMvdMvpIdx[iRefList] = aaiMvpIdx[iRefList][iRefIdxTemp]; 4258 auiZeroMvdBits[iRefList] = uiZeroMvdBitsTemp; 4259 } 4260 } 4261 #endif 4262 4191 uiZeroMvdBitsTemp = uiBitsTemp; 4192 uiZeroMvdBitsTemp += 2; //zero mvd bits 4193 4194 m_pcRdCost->getMotionCost( 1, 0 ); 4195 uiZeroMvdCostTemp = uiZeroMvdDistTemp + m_pcRdCost->getCost(uiZeroMvdBitsTemp); 4196 4197 if (uiZeroMvdCostTemp < uiZeroMvdCost) 4198 { 4199 uiZeroMvdCost = uiZeroMvdCostTemp; 4200 iZeroMvdDir = iRefList + 1; 4201 aiZeroMvdRefIdx[iRefList] = iRefIdxTemp; 4202 aiZeroMvdMvpIdx[iRefList] = aaiMvpIdx[iRefList][iRefIdxTemp]; 4203 auiZeroMvdBits[iRefList] = uiZeroMvdBitsTemp; 4204 } 4205 } 4206 #endif 4207 4263 4208 #if GPB_SIMPLE_UNI 4264 if ( iRefList == 1 ) // list 1 4265 { 4266 if ( pcCU->getSlice()->getList1IdxToList0Idx( iRefIdxTemp ) >= 0 ) 4209 if ( iRefList == 1 ) // list 1 4267 4210 { 4268 cMvTemp[1][iRefIdxTemp] = cMvTemp[0][pcCU->getSlice()->getList1IdxToList0Idx( iRefIdxTemp )]; 4269 uiCostTemp = uiCostTempL0[pcCU->getSlice()->getList1IdxToList0Idx( iRefIdxTemp )]; 4270 /*first subtract the bit-rate part of the cost of the other list*/ 4271 uiCostTemp -= m_pcRdCost->getCost( uiBitsTempL0[pcCU->getSlice()->getList1IdxToList0Idx( iRefIdxTemp )] ); 4272 /*correct the bit-rate part of the current ref*/ 4273 m_pcRdCost->setPredictor ( cMvPred[iRefList][iRefIdxTemp] ); 4274 uiBitsTemp += m_pcRdCost->getBits( cMvTemp[1][iRefIdxTemp].getHor(), cMvTemp[1][iRefIdxTemp].getVer() ); 4275 /*calculate the correct cost*/ 4276 uiCostTemp += m_pcRdCost->getCost( uiBitsTemp ); 4211 if ( pcCU->getSlice()->getList1IdxToList0Idx( iRefIdxTemp ) >= 0 ) 4212 { 4213 cMvTemp[1][iRefIdxTemp] = cMvTemp[0][pcCU->getSlice()->getList1IdxToList0Idx( iRefIdxTemp )]; 4214 uiCostTemp = uiCostTempL0[pcCU->getSlice()->getList1IdxToList0Idx( iRefIdxTemp )]; 4215 /*first subtract the bit-rate part of the cost of the other list*/ 4216 uiCostTemp -= m_pcRdCost->getCost( uiBitsTempL0[pcCU->getSlice()->getList1IdxToList0Idx( iRefIdxTemp )] ); 4217 /*correct the bit-rate part of the current ref*/ 4218 m_pcRdCost->setPredictor ( cMvPred[iRefList][iRefIdxTemp] ); 4219 uiBitsTemp += m_pcRdCost->getBits( cMvTemp[1][iRefIdxTemp].getHor(), cMvTemp[1][iRefIdxTemp].getVer() ); 4220 /*calculate the correct cost*/ 4221 uiCostTemp += m_pcRdCost->getCost( uiBitsTemp ); 4222 } 4223 else 4224 { 4225 xMotionEstimation ( pcCU, pcOrgYuv, iPartIdx, eRefPicList, &cMvPred[iRefList][iRefIdxTemp], iRefIdxTemp, cMvTemp[iRefList][iRefIdxTemp], uiBitsTemp, uiCostTemp ); 4226 } 4277 4227 } 4278 4228 else … … 4280 4230 xMotionEstimation ( pcCU, pcOrgYuv, iPartIdx, eRefPicList, &cMvPred[iRefList][iRefIdxTemp], iRefIdxTemp, cMvTemp[iRefList][iRefIdxTemp], uiBitsTemp, uiCostTemp ); 4281 4231 } 4232 #else 4233 xMotionEstimation ( pcCU, pcOrgYuv, iPartIdx, eRefPicList, &cMvPred[iRefList][iRefIdxTemp], iRefIdxTemp, cMvTemp[iRefList][iRefIdxTemp], uiBitsTemp, uiCostTemp ); 4234 #endif 4235 xCopyAMVPInfo(pcCU->getCUMvField(eRefPicList)->getAMVPInfo(), &aacAMVPInfo[iRefList][iRefIdxTemp]); // must always be done ( also when AMVP_MODE = AM_NONE ) 4236 xCheckBestMVP(pcCU, eRefPicList, cMvTemp[iRefList][iRefIdxTemp], cMvPred[iRefList][iRefIdxTemp], aaiMvpIdx[iRefList][iRefIdxTemp], uiBitsTemp, uiCostTemp); 4237 4238 if ( iRefList == 0 ) 4239 { 4240 uiCostTempL0[iRefIdxTemp] = uiCostTemp; 4241 uiBitsTempL0[iRefIdxTemp] = uiBitsTemp; 4242 } 4243 if ( uiCostTemp < uiCost[iRefList] ) 4244 { 4245 uiCost[iRefList] = uiCostTemp; 4246 uiBits[iRefList] = uiBitsTemp; // storing for bi-prediction 4247 4248 // set motion 4249 cMv[iRefList] = cMvTemp[iRefList][iRefIdxTemp]; 4250 iRefIdx[iRefList] = iRefIdxTemp; 4251 } 4252 4253 if ( iRefList == 1 && uiCostTemp < costValidList1 && pcCU->getSlice()->getList1IdxToList0Idx( iRefIdxTemp ) < 0 ) 4254 { 4255 costValidList1 = uiCostTemp; 4256 bitsValidList1 = uiBitsTemp; 4257 4258 // set motion 4259 mvValidList1 = cMvTemp[iRefList][iRefIdxTemp]; 4260 refIdxValidList1 = iRefIdxTemp; 4261 } 4262 } 4263 } 4264 // Bi-directional prediction 4265 if ( (pcCU->getSlice()->isInterB()) && (pcCU->isBipredRestriction(iPartIdx) == false) ) 4266 { 4267 4268 cMvBi[0] = cMv[0]; cMvBi[1] = cMv[1]; 4269 iRefIdxBi[0] = iRefIdx[0]; iRefIdxBi[1] = iRefIdx[1]; 4270 4271 ::memcpy(cMvPredBi, cMvPred, sizeof(cMvPred)); 4272 ::memcpy(aaiMvpIdxBi, aaiMvpIdx, sizeof(aaiMvpIdx)); 4273 4274 UInt uiMotBits[2]; 4275 4276 if(pcCU->getSlice()->getMvdL1ZeroFlag()) 4277 { 4278 xCopyAMVPInfo(&aacAMVPInfo[1][bestBiPRefIdxL1], pcCU->getCUMvField(REF_PIC_LIST_1)->getAMVPInfo()); 4279 pcCU->setMVPIdxSubParts( bestBiPMvpL1, REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); 4280 aaiMvpIdxBi[1][bestBiPRefIdxL1] = bestBiPMvpL1; 4281 cMvPredBi[1][bestBiPRefIdxL1] = pcCU->getCUMvField(REF_PIC_LIST_1)->getAMVPInfo()->m_acMvCand[bestBiPMvpL1]; 4282 4283 cMvBi[1] = cMvPredBi[1][bestBiPRefIdxL1]; 4284 iRefIdxBi[1] = bestBiPRefIdxL1; 4285 pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMv( cMvBi[1], ePartSize, uiPartAddr, 0, iPartIdx ); 4286 pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllRefIdx( iRefIdxBi[1], ePartSize, uiPartAddr, 0, iPartIdx ); 4287 TComYuv* pcYuvPred = &m_acYuvPred[1]; 4288 motionCompensation( pcCU, pcYuvPred, REF_PIC_LIST_1, iPartIdx ); 4289 4290 uiMotBits[0] = uiBits[0] - uiMbBits[0]; 4291 uiMotBits[1] = uiMbBits[1]; 4292 4293 if ( pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_1) > 1 ) 4294 { 4295 uiMotBits[1] += bestBiPRefIdxL1+1; 4296 if ( bestBiPRefIdxL1 == pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_1)-1 ) uiMotBits[1]--; 4297 } 4298 4299 uiMotBits[1] += m_auiMVPIdxCost[aaiMvpIdxBi[1][bestBiPRefIdxL1]][AMVP_MAX_NUM_CANDS]; 4300 4301 uiBits[2] = uiMbBits[2] + uiMotBits[0] + uiMotBits[1]; 4302 4303 cMvTemp[1][bestBiPRefIdxL1] = cMvBi[1]; 4282 4304 } 4283 4305 else 4284 4306 { 4285 xMotionEstimation ( pcCU, pcOrgYuv, iPartIdx, eRefPicList, &cMvPred[iRefList][iRefIdxTemp], iRefIdxTemp, cMvTemp[iRefList][iRefIdxTemp], uiBitsTemp, uiCostTemp ); 4286 } 4287 #else 4288 xMotionEstimation ( pcCU, pcOrgYuv, iPartIdx, eRefPicList, &cMvPred[iRefList][iRefIdxTemp], iRefIdxTemp, cMvTemp[iRefList][iRefIdxTemp], uiBitsTemp, uiCostTemp ); 4289 #endif 4290 xCopyAMVPInfo(pcCU->getCUMvField(eRefPicList)->getAMVPInfo(), &aacAMVPInfo[iRefList][iRefIdxTemp]); // must always be done ( also when AMVP_MODE = AM_NONE ) 4291 xCheckBestMVP(pcCU, eRefPicList, cMvTemp[iRefList][iRefIdxTemp], cMvPred[iRefList][iRefIdxTemp], aaiMvpIdx[iRefList][iRefIdxTemp], uiBitsTemp, uiCostTemp); 4292 4293 if ( iRefList == 0 ) 4294 { 4295 uiCostTempL0[iRefIdxTemp] = uiCostTemp; 4296 uiBitsTempL0[iRefIdxTemp] = uiBitsTemp; 4297 } 4298 if ( uiCostTemp < uiCost[iRefList] ) 4299 { 4300 uiCost[iRefList] = uiCostTemp; 4301 uiBits[iRefList] = uiBitsTemp; // storing for bi-prediction 4302 4303 // set motion 4304 cMv[iRefList] = cMvTemp[iRefList][iRefIdxTemp]; 4305 iRefIdx[iRefList] = iRefIdxTemp; 4306 } 4307 4308 if ( iRefList == 1 && uiCostTemp < costValidList1 && pcCU->getSlice()->getList1IdxToList0Idx( iRefIdxTemp ) < 0 ) 4309 { 4310 costValidList1 = uiCostTemp; 4311 bitsValidList1 = uiBitsTemp; 4312 4313 // set motion 4314 mvValidList1 = cMvTemp[iRefList][iRefIdxTemp]; 4315 refIdxValidList1 = iRefIdxTemp; 4316 } 4317 } 4318 } 4319 // Bi-directional prediction 4320 if ( (pcCU->getSlice()->isInterB()) && (pcCU->isBipredRestriction(iPartIdx) == false) ) 4321 { 4322 4323 cMvBi[0] = cMv[0]; cMvBi[1] = cMv[1]; 4324 iRefIdxBi[0] = iRefIdx[0]; iRefIdxBi[1] = iRefIdx[1]; 4325 4326 ::memcpy(cMvPredBi, cMvPred, sizeof(cMvPred)); 4327 ::memcpy(aaiMvpIdxBi, aaiMvpIdx, sizeof(aaiMvpIdx)); 4328 4329 UInt uiMotBits[2]; 4330 4331 if(pcCU->getSlice()->getMvdL1ZeroFlag()) 4332 { 4333 xCopyAMVPInfo(&aacAMVPInfo[1][bestBiPRefIdxL1], pcCU->getCUMvField(REF_PIC_LIST_1)->getAMVPInfo()); 4334 pcCU->setMVPIdxSubParts( bestBiPMvpL1, REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); 4335 aaiMvpIdxBi[1][bestBiPRefIdxL1] = bestBiPMvpL1; 4336 cMvPredBi[1][bestBiPRefIdxL1] = pcCU->getCUMvField(REF_PIC_LIST_1)->getAMVPInfo()->m_acMvCand[bestBiPMvpL1]; 4337 4338 cMvBi[1] = cMvPredBi[1][bestBiPRefIdxL1]; 4339 iRefIdxBi[1] = bestBiPRefIdxL1; 4340 pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMv( cMvBi[1], ePartSize, uiPartAddr, 0, iPartIdx ); 4341 pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllRefIdx( iRefIdxBi[1], ePartSize, uiPartAddr, 0, iPartIdx ); 4342 TComYuv* pcYuvPred = &m_acYuvPred[1]; 4343 motionCompensation( pcCU, pcYuvPred, REF_PIC_LIST_1, iPartIdx ); 4344 4345 uiMotBits[0] = uiBits[0] - uiMbBits[0]; 4346 uiMotBits[1] = uiMbBits[1]; 4347 4348 if ( pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_1) > 1 ) 4349 { 4350 uiMotBits[1] += bestBiPRefIdxL1+1; 4351 if ( bestBiPRefIdxL1 == pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_1)-1 ) uiMotBits[1]--; 4352 } 4353 4354 uiMotBits[1] += m_auiMVPIdxCost[aaiMvpIdxBi[1][bestBiPRefIdxL1]][AMVP_MAX_NUM_CANDS]; 4355 4356 uiBits[2] = uiMbBits[2] + uiMotBits[0] + uiMotBits[1]; 4357 4358 cMvTemp[1][bestBiPRefIdxL1] = cMvBi[1]; 4359 } 4360 else 4361 { 4362 uiMotBits[0] = uiBits[0] - uiMbBits[0]; 4363 uiMotBits[1] = uiBits[1] - uiMbBits[1]; 4364 uiBits[2] = uiMbBits[2] + uiMotBits[0] + uiMotBits[1]; 4365 } 4366 4367 // 4-times iteration (default) 4368 Int iNumIter = 4; 4369 4370 // fast encoder setting: only one iteration 4371 if ( m_pcEncCfg->getUseFastEnc() || pcCU->getSlice()->getMvdL1ZeroFlag()) 4372 { 4373 iNumIter = 1; 4374 } 4375 4376 for ( Int iIter = 0; iIter < iNumIter; iIter++ ) 4377 { 4378 4379 Int iRefList = iIter % 2; 4380 if ( m_pcEncCfg->getUseFastEnc() ) 4381 { 4382 if( uiCost[0] <= uiCost[1] ) 4307 uiMotBits[0] = uiBits[0] - uiMbBits[0]; 4308 uiMotBits[1] = uiBits[1] - uiMbBits[1]; 4309 uiBits[2] = uiMbBits[2] + uiMotBits[0] + uiMotBits[1]; 4310 } 4311 4312 // 4-times iteration (default) 4313 Int iNumIter = 4; 4314 4315 // fast encoder setting: only one iteration 4316 if ( m_pcEncCfg->getUseFastEnc() || pcCU->getSlice()->getMvdL1ZeroFlag()) 4317 { 4318 iNumIter = 1; 4319 } 4320 4321 for ( Int iIter = 0; iIter < iNumIter; iIter++ ) 4322 { 4323 4324 Int iRefList = iIter % 2; 4325 if ( m_pcEncCfg->getUseFastEnc() ) 4383 4326 { 4384 iRefList = 1; 4327 if( uiCost[0] <= uiCost[1] ) 4328 { 4329 iRefList = 1; 4330 } 4331 else 4332 { 4333 iRefList = 0; 4334 } 4385 4335 } 4386 else 4336 else if ( iIter == 0 ) 4387 4337 { 4388 4338 iRefList = 0; 4389 4339 } 4390 } 4391 else if ( iIter == 0 ) 4392 { 4393 iRefList = 0; 4394 } 4395 if ( iIter == 0 && !pcCU->getSlice()->getMvdL1ZeroFlag()) 4396 { 4397 pcCU->getCUMvField(RefPicList(1-iRefList))->setAllMv( cMv[1-iRefList], ePartSize, uiPartAddr, 0, iPartIdx ); 4398 pcCU->getCUMvField(RefPicList(1-iRefList))->setAllRefIdx( iRefIdx[1-iRefList], ePartSize, uiPartAddr, 0, iPartIdx ); 4399 TComYuv* pcYuvPred = &m_acYuvPred[1-iRefList]; 4400 motionCompensation ( pcCU, pcYuvPred, RefPicList(1-iRefList), iPartIdx ); 4401 } 4402 RefPicList eRefPicList = ( iRefList ? REF_PIC_LIST_1 : REF_PIC_LIST_0 ); 4403 4404 if(pcCU->getSlice()->getMvdL1ZeroFlag()) 4405 { 4406 iRefList = 0; 4407 eRefPicList = REF_PIC_LIST_0; 4408 } 4409 4410 Bool bChanged = false; 4411 4412 iRefStart = 0; 4413 iRefEnd = pcCU->getSlice()->getNumRefIdx(eRefPicList)-1; 4414 4415 for ( Int iRefIdxTemp = iRefStart; iRefIdxTemp <= iRefEnd; iRefIdxTemp++ ) 4416 { 4417 uiBitsTemp = uiMbBits[2] + uiMotBits[1-iRefList]; 4418 if ( pcCU->getSlice()->getNumRefIdx(eRefPicList) > 1 ) 4340 if ( iIter == 0 && !pcCU->getSlice()->getMvdL1ZeroFlag()) 4419 4341 { 4420 uiBitsTemp += iRefIdxTemp+1; 4421 if ( iRefIdxTemp == pcCU->getSlice()->getNumRefIdx(eRefPicList)-1 ) uiBitsTemp--; 4342 pcCU->getCUMvField(RefPicList(1-iRefList))->setAllMv( cMv[1-iRefList], ePartSize, uiPartAddr, 0, iPartIdx ); 4343 pcCU->getCUMvField(RefPicList(1-iRefList))->setAllRefIdx( iRefIdx[1-iRefList], ePartSize, uiPartAddr, 0, iPartIdx ); 4344 TComYuv* pcYuvPred = &m_acYuvPred[1-iRefList]; 4345 motionCompensation ( pcCU, pcYuvPred, RefPicList(1-iRefList), iPartIdx ); 4422 4346 } 4423 uiBitsTemp += m_auiMVPIdxCost[aaiMvpIdxBi[iRefList][iRefIdxTemp]][AMVP_MAX_NUM_CANDS]; 4424 // call ME 4425 xMotionEstimation ( pcCU, pcOrgYuv, iPartIdx, eRefPicList, &cMvPredBi[iRefList][iRefIdxTemp], iRefIdxTemp, cMvTemp[iRefList][iRefIdxTemp], uiBitsTemp, uiCostTemp, true ); 4426 xCopyAMVPInfo(&aacAMVPInfo[iRefList][iRefIdxTemp], pcCU->getCUMvField(eRefPicList)->getAMVPInfo()); 4427 xCheckBestMVP(pcCU, eRefPicList, cMvTemp[iRefList][iRefIdxTemp], cMvPredBi[iRefList][iRefIdxTemp], aaiMvpIdxBi[iRefList][iRefIdxTemp], uiBitsTemp, uiCostTemp); 4428 4429 if ( uiCostTemp < uiCostBi ) 4347 RefPicList eRefPicList = ( iRefList ? REF_PIC_LIST_1 : REF_PIC_LIST_0 ); 4348 4349 if(pcCU->getSlice()->getMvdL1ZeroFlag()) 4430 4350 { 4431 bChanged = true; 4432 4433 cMvBi[iRefList] = cMvTemp[iRefList][iRefIdxTemp]; 4434 iRefIdxBi[iRefList] = iRefIdxTemp; 4435 4436 uiCostBi = uiCostTemp; 4437 uiMotBits[iRefList] = uiBitsTemp - uiMbBits[2] - uiMotBits[1-iRefList]; 4438 uiBits[2] = uiBitsTemp; 4439 4440 if(iNumIter!=1) 4351 iRefList = 0; 4352 eRefPicList = REF_PIC_LIST_0; 4353 } 4354 4355 Bool bChanged = false; 4356 4357 iRefStart = 0; 4358 iRefEnd = pcCU->getSlice()->getNumRefIdx(eRefPicList)-1; 4359 4360 for ( Int iRefIdxTemp = iRefStart; iRefIdxTemp <= iRefEnd; iRefIdxTemp++ ) 4361 { 4362 uiBitsTemp = uiMbBits[2] + uiMotBits[1-iRefList]; 4363 if ( pcCU->getSlice()->getNumRefIdx(eRefPicList) > 1 ) 4441 4364 { 4442 // Set motion 4443 pcCU->getCUMvField( eRefPicList )->setAllMv( cMvBi[iRefList], ePartSize, uiPartAddr, 0, iPartIdx ); 4444 pcCU->getCUMvField( eRefPicList )->setAllRefIdx( iRefIdxBi[iRefList], ePartSize, uiPartAddr, 0, iPartIdx ); 4445 4446 TComYuv* pcYuvPred = &m_acYuvPred[iRefList]; 4447 motionCompensation( pcCU, pcYuvPred, eRefPicList, iPartIdx ); 4365 uiBitsTemp += iRefIdxTemp+1; 4366 if ( iRefIdxTemp == pcCU->getSlice()->getNumRefIdx(eRefPicList)-1 ) uiBitsTemp--; 4367 } 4368 uiBitsTemp += m_auiMVPIdxCost[aaiMvpIdxBi[iRefList][iRefIdxTemp]][AMVP_MAX_NUM_CANDS]; 4369 // call ME 4370 xMotionEstimation ( pcCU, pcOrgYuv, iPartIdx, eRefPicList, &cMvPredBi[iRefList][iRefIdxTemp], iRefIdxTemp, cMvTemp[iRefList][iRefIdxTemp], uiBitsTemp, uiCostTemp, true ); 4371 xCopyAMVPInfo(&aacAMVPInfo[iRefList][iRefIdxTemp], pcCU->getCUMvField(eRefPicList)->getAMVPInfo()); 4372 xCheckBestMVP(pcCU, eRefPicList, cMvTemp[iRefList][iRefIdxTemp], cMvPredBi[iRefList][iRefIdxTemp], aaiMvpIdxBi[iRefList][iRefIdxTemp], uiBitsTemp, uiCostTemp); 4373 4374 if ( uiCostTemp < uiCostBi ) 4375 { 4376 bChanged = true; 4377 4378 cMvBi[iRefList] = cMvTemp[iRefList][iRefIdxTemp]; 4379 iRefIdxBi[iRefList] = iRefIdxTemp; 4380 4381 uiCostBi = uiCostTemp; 4382 uiMotBits[iRefList] = uiBitsTemp - uiMbBits[2] - uiMotBits[1-iRefList]; 4383 uiBits[2] = uiBitsTemp; 4384 4385 if(iNumIter!=1) 4386 { 4387 // Set motion 4388 pcCU->getCUMvField( eRefPicList )->setAllMv( cMvBi[iRefList], ePartSize, uiPartAddr, 0, iPartIdx ); 4389 pcCU->getCUMvField( eRefPicList )->setAllRefIdx( iRefIdxBi[iRefList], ePartSize, uiPartAddr, 0, iPartIdx ); 4390 4391 TComYuv* pcYuvPred = &m_acYuvPred[iRefList]; 4392 motionCompensation( pcCU, pcYuvPred, eRefPicList, iPartIdx ); 4393 } 4394 } 4395 } // for loop-iRefIdxTemp 4396 4397 if ( !bChanged ) 4398 { 4399 if ( uiCostBi <= uiCost[0] && uiCostBi <= uiCost[1] ) 4400 { 4401 xCopyAMVPInfo(&aacAMVPInfo[0][iRefIdxBi[0]], pcCU->getCUMvField(REF_PIC_LIST_0)->getAMVPInfo()); 4402 xCheckBestMVP(pcCU, REF_PIC_LIST_0, cMvBi[0], cMvPredBi[0][iRefIdxBi[0]], aaiMvpIdxBi[0][iRefIdxBi[0]], uiBits[2], uiCostBi); 4403 if(!pcCU->getSlice()->getMvdL1ZeroFlag()) 4404 { 4405 xCopyAMVPInfo(&aacAMVPInfo[1][iRefIdxBi[1]], pcCU->getCUMvField(REF_PIC_LIST_1)->getAMVPInfo()); 4406 xCheckBestMVP(pcCU, REF_PIC_LIST_1, cMvBi[1], cMvPredBi[1][iRefIdxBi[1]], aaiMvpIdxBi[1][iRefIdxBi[1]], uiBits[2], uiCostBi); 4407 } 4408 } 4409 break; 4410 } 4411 } // for loop-iter 4412 } // if (B_SLICE) 4413 #if ZERO_MVD_EST 4414 if ( (pcCU->getSlice()->isInterB()) && (pcCU->isBipredRestriction(iPartIdx) == false) ) 4415 { 4416 m_pcRdCost->getMotionCost( 1, 0 ); 4417 4418 for ( Int iL0RefIdxTemp = 0; iL0RefIdxTemp <= pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_0)-1; iL0RefIdxTemp++ ) 4419 for ( Int iL1RefIdxTemp = 0; iL1RefIdxTemp <= pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_1)-1; iL1RefIdxTemp++ ) 4420 { 4421 UInt uiRefIdxBitsTemp = 0; 4422 if ( pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_0) > 1 ) 4423 { 4424 uiRefIdxBitsTemp += iL0RefIdxTemp+1; 4425 if ( iL0RefIdxTemp == pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_0)-1 ) uiRefIdxBitsTemp--; 4426 } 4427 if ( pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_1) > 1 ) 4428 { 4429 uiRefIdxBitsTemp += iL1RefIdxTemp+1; 4430 if ( iL1RefIdxTemp == pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_1)-1 ) uiRefIdxBitsTemp--; 4431 } 4432 4433 Int iL0MVPIdx = 0; 4434 Int iL1MVPIdx = 0; 4435 4436 for (iL0MVPIdx = 0; iL0MVPIdx < aaiMvpNum[0][iL0RefIdxTemp]; iL0MVPIdx++) 4437 { 4438 for (iL1MVPIdx = 0; iL1MVPIdx < aaiMvpNum[1][iL1RefIdxTemp]; iL1MVPIdx++) 4439 { 4440 uiZeroMvdBitsTemp = uiRefIdxBitsTemp; 4441 uiZeroMvdBitsTemp += uiMbBits[2]; 4442 uiZeroMvdBitsTemp += m_auiMVPIdxCost[iL0MVPIdx][aaiMvpNum[0][iL0RefIdxTemp]] + m_auiMVPIdxCost[iL1MVPIdx][aaiMvpNum[1][iL1RefIdxTemp]]; 4443 uiZeroMvdBitsTemp += 4; //zero mvd for both directions 4444 pcCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( aacAMVPInfo[0][iL0RefIdxTemp].m_acMvCand[iL0MVPIdx], iL0RefIdxTemp, ePartSize, uiPartAddr, iPartIdx, 0 ); 4445 pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( aacAMVPInfo[1][iL1RefIdxTemp].m_acMvCand[iL1MVPIdx], iL1RefIdxTemp, ePartSize, uiPartAddr, iPartIdx, 0 ); 4446 4447 xGetInterPredictionError( pcCU, pcOrgYuv, iPartIdx, uiZeroMvdDistTemp, m_pcEncCfg->getUseHADME() ); 4448 uiZeroMvdCostTemp = uiZeroMvdDistTemp + m_pcRdCost->getCost( uiZeroMvdBitsTemp ); 4449 if (uiZeroMvdCostTemp < uiZeroMvdCost) 4450 { 4451 uiZeroMvdCost = uiZeroMvdCostTemp; 4452 iZeroMvdDir = 3; 4453 aiZeroMvdMvpIdx[0] = iL0MVPIdx; 4454 aiZeroMvdMvpIdx[1] = iL1MVPIdx; 4455 aiZeroMvdRefIdx[0] = iL0RefIdxTemp; 4456 aiZeroMvdRefIdx[1] = iL1RefIdxTemp; 4457 auiZeroMvdBits[2] = uiZeroMvdBitsTemp; 4458 } 4459 } 4448 4460 } 4449 4461 } 4450 } // for loop-iRefIdxTemp 4451 4452 if ( !bChanged ) 4453 { 4454 if ( uiCostBi <= uiCost[0] && uiCostBi <= uiCost[1] ) 4455 { 4456 xCopyAMVPInfo(&aacAMVPInfo[0][iRefIdxBi[0]], pcCU->getCUMvField(REF_PIC_LIST_0)->getAMVPInfo()); 4457 xCheckBestMVP(pcCU, REF_PIC_LIST_0, cMvBi[0], cMvPredBi[0][iRefIdxBi[0]], aaiMvpIdxBi[0][iRefIdxBi[0]], uiBits[2], uiCostBi); 4458 if(!pcCU->getSlice()->getMvdL1ZeroFlag()) 4459 { 4460 xCopyAMVPInfo(&aacAMVPInfo[1][iRefIdxBi[1]], pcCU->getCUMvField(REF_PIC_LIST_1)->getAMVPInfo()); 4461 xCheckBestMVP(pcCU, REF_PIC_LIST_1, cMvBi[1], cMvPredBi[1][iRefIdxBi[1]], aaiMvpIdxBi[1][iRefIdxBi[1]], uiBits[2], uiCostBi); 4462 } 4463 } 4464 break; 4465 } 4466 } // for loop-iter 4467 } // if (B_SLICE) 4468 #if ZERO_MVD_EST 4469 if ( (pcCU->getSlice()->isInterB()) && (pcCU->isBipredRestriction(iPartIdx) == false) ) 4470 { 4471 m_pcRdCost->getMotionCost( 1, 0 ); 4472 4473 for ( Int iL0RefIdxTemp = 0; iL0RefIdxTemp <= pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_0)-1; iL0RefIdxTemp++ ) 4474 for ( Int iL1RefIdxTemp = 0; iL1RefIdxTemp <= pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_1)-1; iL1RefIdxTemp++ ) 4475 { 4476 UInt uiRefIdxBitsTemp = 0; 4477 if ( pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_0) > 1 ) 4478 { 4479 uiRefIdxBitsTemp += iL0RefIdxTemp+1; 4480 if ( iL0RefIdxTemp == pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_0)-1 ) uiRefIdxBitsTemp--; 4481 } 4482 if ( pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_1) > 1 ) 4483 { 4484 uiRefIdxBitsTemp += iL1RefIdxTemp+1; 4485 if ( iL1RefIdxTemp == pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_1)-1 ) uiRefIdxBitsTemp--; 4486 } 4487 4488 Int iL0MVPIdx = 0; 4489 Int iL1MVPIdx = 0; 4490 4491 for (iL0MVPIdx = 0; iL0MVPIdx < aaiMvpNum[0][iL0RefIdxTemp]; iL0MVPIdx++) 4492 { 4493 for (iL1MVPIdx = 0; iL1MVPIdx < aaiMvpNum[1][iL1RefIdxTemp]; iL1MVPIdx++) 4494 { 4495 uiZeroMvdBitsTemp = uiRefIdxBitsTemp; 4496 uiZeroMvdBitsTemp += uiMbBits[2]; 4497 uiZeroMvdBitsTemp += m_auiMVPIdxCost[iL0MVPIdx][aaiMvpNum[0][iL0RefIdxTemp]] + m_auiMVPIdxCost[iL1MVPIdx][aaiMvpNum[1][iL1RefIdxTemp]]; 4498 uiZeroMvdBitsTemp += 4; //zero mvd for both directions 4499 pcCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( aacAMVPInfo[0][iL0RefIdxTemp].m_acMvCand[iL0MVPIdx], iL0RefIdxTemp, ePartSize, uiPartAddr, iPartIdx, 0 ); 4500 pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( aacAMVPInfo[1][iL1RefIdxTemp].m_acMvCand[iL1MVPIdx], iL1RefIdxTemp, ePartSize, uiPartAddr, iPartIdx, 0 ); 4501 4502 xGetInterPredictionError( pcCU, pcOrgYuv, iPartIdx, uiZeroMvdDistTemp, m_pcEncCfg->getUseHADME() ); 4503 uiZeroMvdCostTemp = uiZeroMvdDistTemp + m_pcRdCost->getCost( uiZeroMvdBitsTemp ); 4504 if (uiZeroMvdCostTemp < uiZeroMvdCost) 4505 { 4506 uiZeroMvdCost = uiZeroMvdCostTemp; 4507 iZeroMvdDir = 3; 4508 aiZeroMvdMvpIdx[0] = iL0MVPIdx; 4509 aiZeroMvdMvpIdx[1] = iL1MVPIdx; 4510 aiZeroMvdRefIdx[0] = iL0RefIdxTemp; 4511 aiZeroMvdRefIdx[1] = iL1RefIdxTemp; 4512 auiZeroMvdBits[2] = uiZeroMvdBitsTemp; 4513 } 4514 } 4515 } 4516 } 4517 } 4462 } 4518 4463 #endif 4519 4464 … … 4531 4476 pcCU->setMVPIdxSubParts( -1, REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); 4532 4477 pcCU->setMVPNumSubParts( -1, REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); 4533 4478 4534 4479 UInt uiMEBits = 0; 4535 4480 // Set Motion Field_ … … 4543 4488 #endif 4544 4489 #if ZERO_MVD_EST 4545 if (uiZeroMvdCost <= uiCostBi && uiZeroMvdCost <= uiCost[0] && uiZeroMvdCost <= uiCost[1]) 4546 { 4547 if (iZeroMvdDir == 3) 4548 { 4549 uiLastMode = 2; 4550 4551 pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvField( aacAMVPInfo[0][aiZeroMvdRefIdx[0]].m_acMvCand[aiZeroMvdMvpIdx[0]], aiZeroMvdRefIdx[0], ePartSize, uiPartAddr, iPartIdx, 0 ); 4552 pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvField( aacAMVPInfo[1][aiZeroMvdRefIdx[1]].m_acMvCand[aiZeroMvdMvpIdx[1]], aiZeroMvdRefIdx[1], ePartSize, uiPartAddr, iPartIdx, 0 ); 4553 4554 pcCU->setInterDirSubParts( 3, uiPartAddr, iPartIdx, pcCU->getDepth(0) ); 4555 4556 pcCU->setMVPIdxSubParts( aiZeroMvdMvpIdx[0], REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); 4557 pcCU->setMVPNumSubParts( aaiMvpNum[0][aiZeroMvdRefIdx[0]], REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); 4558 pcCU->setMVPIdxSubParts( aiZeroMvdMvpIdx[1], REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); 4559 pcCU->setMVPNumSubParts( aaiMvpNum[1][aiZeroMvdRefIdx[1]], REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); 4560 uiMEBits = auiZeroMvdBits[2]; 4561 } 4562 else if (iZeroMvdDir == 1) 4563 { 4564 uiLastMode = 0; 4565 4566 pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvField( aacAMVPInfo[0][aiZeroMvdRefIdx[0]].m_acMvCand[aiZeroMvdMvpIdx[0]], aiZeroMvdRefIdx[0], ePartSize, uiPartAddr, iPartIdx, 0 ); 4567 4568 pcCU->setInterDirSubParts( 1, uiPartAddr, iPartIdx, pcCU->getDepth(0) ); 4569 4570 pcCU->setMVPIdxSubParts( aiZeroMvdMvpIdx[0], REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); 4571 pcCU->setMVPNumSubParts( aaiMvpNum[0][aiZeroMvdRefIdx[0]], REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); 4572 uiMEBits = auiZeroMvdBits[0]; 4573 } 4574 else if (iZeroMvdDir == 2) 4575 { 4576 uiLastMode = 1; 4577 4578 pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvField( aacAMVPInfo[1][aiZeroMvdRefIdx[1]].m_acMvCand[aiZeroMvdMvpIdx[1]], aiZeroMvdRefIdx[1], ePartSize, uiPartAddr, iPartIdx, 0 ); 4579 4580 pcCU->setInterDirSubParts( 2, uiPartAddr, iPartIdx, pcCU->getDepth(0) ); 4581 4582 pcCU->setMVPIdxSubParts( aiZeroMvdMvpIdx[1], REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); 4583 pcCU->setMVPNumSubParts( aaiMvpNum[1][aiZeroMvdRefIdx[1]], REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); 4584 uiMEBits = auiZeroMvdBits[1]; 4490 if (uiZeroMvdCost <= uiCostBi && uiZeroMvdCost <= uiCost[0] && uiZeroMvdCost <= uiCost[1]) 4491 { 4492 if (iZeroMvdDir == 3) 4493 { 4494 uiLastMode = 2; 4495 4496 pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvField( aacAMVPInfo[0][aiZeroMvdRefIdx[0]].m_acMvCand[aiZeroMvdMvpIdx[0]], aiZeroMvdRefIdx[0], ePartSize, uiPartAddr, iPartIdx, 0 ); 4497 pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvField( aacAMVPInfo[1][aiZeroMvdRefIdx[1]].m_acMvCand[aiZeroMvdMvpIdx[1]], aiZeroMvdRefIdx[1], ePartSize, uiPartAddr, iPartIdx, 0 ); 4498 4499 pcCU->setInterDirSubParts( 3, uiPartAddr, iPartIdx, pcCU->getDepth(0) ); 4500 4501 pcCU->setMVPIdxSubParts( aiZeroMvdMvpIdx[0], REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); 4502 pcCU->setMVPNumSubParts( aaiMvpNum[0][aiZeroMvdRefIdx[0]], REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); 4503 pcCU->setMVPIdxSubParts( aiZeroMvdMvpIdx[1], REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); 4504 pcCU->setMVPNumSubParts( aaiMvpNum[1][aiZeroMvdRefIdx[1]], REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); 4505 uiMEBits = auiZeroMvdBits[2]; 4506 } 4507 else if (iZeroMvdDir == 1) 4508 { 4509 uiLastMode = 0; 4510 4511 pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvField( aacAMVPInfo[0][aiZeroMvdRefIdx[0]].m_acMvCand[aiZeroMvdMvpIdx[0]], aiZeroMvdRefIdx[0], ePartSize, uiPartAddr, iPartIdx, 0 ); 4512 4513 pcCU->setInterDirSubParts( 1, uiPartAddr, iPartIdx, pcCU->getDepth(0) ); 4514 4515 pcCU->setMVPIdxSubParts( aiZeroMvdMvpIdx[0], REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); 4516 pcCU->setMVPNumSubParts( aaiMvpNum[0][aiZeroMvdRefIdx[0]], REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); 4517 uiMEBits = auiZeroMvdBits[0]; 4518 } 4519 else if (iZeroMvdDir == 2) 4520 { 4521 uiLastMode = 1; 4522 4523 pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvField( aacAMVPInfo[1][aiZeroMvdRefIdx[1]].m_acMvCand[aiZeroMvdMvpIdx[1]], aiZeroMvdRefIdx[1], ePartSize, uiPartAddr, iPartIdx, 0 ); 4524 4525 pcCU->setInterDirSubParts( 2, uiPartAddr, iPartIdx, pcCU->getDepth(0) ); 4526 4527 pcCU->setMVPIdxSubParts( aiZeroMvdMvpIdx[1], REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); 4528 pcCU->setMVPNumSubParts( aaiMvpNum[1][aiZeroMvdRefIdx[1]], REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); 4529 uiMEBits = auiZeroMvdBits[1]; 4530 } 4531 else 4532 { 4533 assert(0); 4534 } 4585 4535 } 4586 4536 else 4587 { 4588 assert(0); 4589 } 4590 } 4591 else 4592 #endif 4593 if ( uiCostBi <= uiCost[0] && uiCostBi <= uiCost[1]) 4594 { 4595 uiLastMode = 2; 4596 { 4597 pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMv( cMvBi[0], ePartSize, uiPartAddr, 0, iPartIdx ); 4598 pcCU->getCUMvField(REF_PIC_LIST_0)->setAllRefIdx( iRefIdxBi[0], ePartSize, uiPartAddr, 0, iPartIdx ); 4599 pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMv( cMvBi[1], ePartSize, uiPartAddr, 0, iPartIdx ); 4600 pcCU->getCUMvField(REF_PIC_LIST_1)->setAllRefIdx( iRefIdxBi[1], ePartSize, uiPartAddr, 0, iPartIdx ); 4601 } 4602 { 4603 TempMv = cMvBi[0] - cMvPredBi[0][iRefIdxBi[0]]; 4604 pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvd ( TempMv, ePartSize, uiPartAddr, 0, iPartIdx ); 4605 } 4606 { 4607 TempMv = cMvBi[1] - cMvPredBi[1][iRefIdxBi[1]]; 4608 pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvd ( TempMv, ePartSize, uiPartAddr, 0, iPartIdx ); 4609 } 4610 4611 pcCU->setInterDirSubParts( 3, uiPartAddr, iPartIdx, pcCU->getDepth(0) ); 4612 4613 pcCU->setMVPIdxSubParts( aaiMvpIdxBi[0][iRefIdxBi[0]], REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); 4614 pcCU->setMVPNumSubParts( aaiMvpNum[0][iRefIdxBi[0]], REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); 4615 pcCU->setMVPIdxSubParts( aaiMvpIdxBi[1][iRefIdxBi[1]], REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); 4616 pcCU->setMVPNumSubParts( aaiMvpNum[1][iRefIdxBi[1]], REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); 4617 4618 uiMEBits = uiBits[2]; 4619 } 4620 else if ( uiCost[0] <= uiCost[1] ) 4621 { 4622 uiLastMode = 0; 4537 #endif 4538 if ( uiCostBi <= uiCost[0] && uiCostBi <= uiCost[1]) 4539 { 4540 uiLastMode = 2; 4541 pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMv( cMvBi[0], ePartSize, uiPartAddr, 0, iPartIdx ); 4542 pcCU->getCUMvField(REF_PIC_LIST_0)->setAllRefIdx( iRefIdxBi[0], ePartSize, uiPartAddr, 0, iPartIdx ); 4543 pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMv( cMvBi[1], ePartSize, uiPartAddr, 0, iPartIdx ); 4544 pcCU->getCUMvField(REF_PIC_LIST_1)->setAllRefIdx( iRefIdxBi[1], ePartSize, uiPartAddr, 0, iPartIdx ); 4545 4546 TempMv = cMvBi[0] - cMvPredBi[0][iRefIdxBi[0]]; 4547 pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvd ( TempMv, ePartSize, uiPartAddr, 0, iPartIdx ); 4548 4549 TempMv = cMvBi[1] - cMvPredBi[1][iRefIdxBi[1]]; 4550 pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvd ( TempMv, ePartSize, uiPartAddr, 0, iPartIdx ); 4551 4552 pcCU->setInterDirSubParts( 3, uiPartAddr, iPartIdx, pcCU->getDepth(0) ); 4553 4554 pcCU->setMVPIdxSubParts( aaiMvpIdxBi[0][iRefIdxBi[0]], REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); 4555 pcCU->setMVPNumSubParts( aaiMvpNum[0][iRefIdxBi[0]], REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); 4556 pcCU->setMVPIdxSubParts( aaiMvpIdxBi[1][iRefIdxBi[1]], REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); 4557 pcCU->setMVPNumSubParts( aaiMvpNum[1][iRefIdxBi[1]], REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); 4558 4559 uiMEBits = uiBits[2]; 4560 } 4561 else if ( uiCost[0] <= uiCost[1] ) 4562 { 4563 uiLastMode = 0; 4623 4564 pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMv( cMv[0], ePartSize, uiPartAddr, 0, iPartIdx ); 4624 4565 pcCU->getCUMvField(REF_PIC_LIST_0)->setAllRefIdx( iRefIdx[0], ePartSize, uiPartAddr, 0, iPartIdx ); 4625 { 4626 TempMv = cMv[0] - cMvPred[0][iRefIdx[0]]; 4627 pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvd ( TempMv, ePartSize, uiPartAddr, 0, iPartIdx ); 4628 } 4629 pcCU->setInterDirSubParts( 1, uiPartAddr, iPartIdx, pcCU->getDepth(0) ); 4630 4631 pcCU->setMVPIdxSubParts( aaiMvpIdx[0][iRefIdx[0]], REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); 4632 pcCU->setMVPNumSubParts( aaiMvpNum[0][iRefIdx[0]], REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); 4633 4634 uiMEBits = uiBits[0]; 4635 } 4636 else 4637 { 4638 uiLastMode = 1; 4566 TempMv = cMv[0] - cMvPred[0][iRefIdx[0]]; 4567 pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvd ( TempMv, ePartSize, uiPartAddr, 0, iPartIdx ); 4568 pcCU->setInterDirSubParts( 1, uiPartAddr, iPartIdx, pcCU->getDepth(0) ); 4569 4570 pcCU->setMVPIdxSubParts( aaiMvpIdx[0][iRefIdx[0]], REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); 4571 pcCU->setMVPNumSubParts( aaiMvpNum[0][iRefIdx[0]], REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); 4572 4573 uiMEBits = uiBits[0]; 4574 } 4575 else 4576 { 4577 uiLastMode = 1; 4639 4578 pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMv( cMv[1], ePartSize, uiPartAddr, 0, iPartIdx ); 4640 4579 pcCU->getCUMvField(REF_PIC_LIST_1)->setAllRefIdx( iRefIdx[1], ePartSize, uiPartAddr, 0, iPartIdx ); 4641 { 4642 TempMv = cMv[1] - cMvPred[1][iRefIdx[1]]; 4643 pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvd ( TempMv, ePartSize, uiPartAddr, 0, iPartIdx ); 4644 } 4645 pcCU->setInterDirSubParts( 2, uiPartAddr, iPartIdx, pcCU->getDepth(0) ); 4646 4647 pcCU->setMVPIdxSubParts( aaiMvpIdx[1][iRefIdx[1]], REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); 4648 pcCU->setMVPNumSubParts( aaiMvpNum[1][iRefIdx[1]], REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); 4649 4650 uiMEBits = uiBits[1]; 4651 } 4580 TempMv = cMv[1] - cMvPred[1][iRefIdx[1]]; 4581 pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvd ( TempMv, ePartSize, uiPartAddr, 0, iPartIdx ); 4582 pcCU->setInterDirSubParts( 2, uiPartAddr, iPartIdx, pcCU->getDepth(0) ); 4583 4584 pcCU->setMVPIdxSubParts( aaiMvpIdx[1][iRefIdx[1]], REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); 4585 pcCU->setMVPNumSubParts( aaiMvpNum[1][iRefIdx[1]], REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); 4586 4587 uiMEBits = uiBits[1]; 4588 } 4652 4589 #if AMP_MRG 4653 4590 } // end if bTestNormalMC … … 4712 4649 xMergeEstimation( pcCU, pcOrgYuv, iPartIdx, uiMRGInterDir, cMRGMvField, uiMRGIndex, uiMRGCost, cMvFieldNeighbours, uhInterDirNeighbours 4713 4650 #if H_3D_VSP 4714 4715 4651 , vspFlag 4652 , inheritedVSPDisInfo 4716 4653 #endif 4717 4654 #if H_3D_SPIVMP 4718 4655 , bSPIVMPFlag, pcMvFieldSP, puhInterDirSP 4719 4656 #endif 4720 4721 4657 , numValidMergeCand 4658 ); 4722 4659 if ( uiMRGCost < uiMECost ) 4723 4660 { … … 4729 4666 pcCU->setDvInfoSubParts(inheritedVSPDisInfo[uiMRGIndex].m_acDvInfo, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) ); 4730 4667 #endif 4731 4732 4668 #if MTK_DDD_G0063 4733 4669 if( uiMRGIndex == pcCU->getUseDDDCandIdx() ) 4734 4670 { 4735 4736 4737 4738 4671 assert( vspFlag[uiMRGIndex] == 0 ); 4672 assert( bSPIVMPFlag[uiMRGIndex] == 0 ); 4673 pcCU->setUseDDD( true, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) ); 4674 pcCU->setDDDepthSubParts( pcCU->getDDTmpDepth(), uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) ); 4739 4675 } 4740 4676 else 4741 4677 { 4742 pcCU->setUseDDD( false, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) ); 4743 } 4744 #endif 4745 4678 pcCU->setUseDDD( false, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) ); 4679 } 4680 #endif 4746 4681 #if H_3D_SPIVMP 4747 4682 pcCU->setSPIVMPFlagSubParts(bSPIVMPFlag[uiMRGIndex], uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) ); … … 4749 4684 { 4750 4685 UInt uiSPAddr; 4751 4752 4686 Int iNumSPInOneLine, iNumSP, iSPWidth, iSPHeight; 4753 4754 4687 pcCU->getSPPara(iRoiWidth, iRoiHeight, iNumSP, iNumSPInOneLine, iSPWidth, iSPHeight); 4755 4756 4688 for (Int iPartitionIdx = 0; iPartitionIdx < iNumSP; iPartitionIdx++) 4757 4689 { … … 4761 4693 pcCU->getCUMvField( REF_PIC_LIST_1 )->setMvFieldSP(pcCU, uiSPAddr, pcMvFieldSP[2*iPartitionIdx + 1], iSPWidth, iSPHeight); 4762 4694 } 4763 4764 4695 if ( pcCU->getInterDir(uiPartAddr) == 3 && pcCU->isBipredRestriction(iPartIdx) ) 4765 4696 { … … 4768 4699 pcCU->setInterDirSubParts( 1, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr )); 4769 4700 } 4770 4771 4701 } 4772 4702 else … … 4774 4704 #if NTT_STORE_SPDV_VSP_G0148 4775 4705 #if H_3D_DBBP 4776 if ( vspFlag[uiMRGIndex] && !pcCU->getDBBPFlag(uiPartAddr) )4706 if ( vspFlag[uiMRGIndex] && !pcCU->getDBBPFlag(uiPartAddr) ) 4777 4707 #else 4778 if ( vspFlag[uiMRGIndex] ) 4779 #endif 4780 { 4781 UInt partAddrTemp; 4782 Int vspSize; 4783 Int width, height; 4784 pcCU->getPartIndexAndSize( iPartIdx, partAddrTemp, width, height ); // true or pcCU->getTotalNumPart()==256 4785 4786 if( uiMRGInterDir & 0x01 ) 4708 if ( vspFlag[uiMRGIndex] ) 4709 #endif 4787 4710 { 4788 pcCU->setMvFieldPUForVSP( pcCU, partAddrTemp, width, height, REF_PIC_LIST_0, cMRGMvField[0].getRefIdx(), vspSize ); 4789 pcCU->setVSPFlag( partAddrTemp, vspSize ); 4711 UInt partAddrTemp; 4712 Int vspSize; 4713 Int width, height; 4714 pcCU->getPartIndexAndSize( iPartIdx, partAddrTemp, width, height ); // true or pcCU->getTotalNumPart()==256 4715 if( uiMRGInterDir & 0x01 ) 4716 { 4717 pcCU->setMvFieldPUForVSP( pcCU, partAddrTemp, width, height, REF_PIC_LIST_0, cMRGMvField[0].getRefIdx(), vspSize ); 4718 pcCU->setVSPFlag( partAddrTemp, vspSize ); 4719 } 4720 else 4721 { 4722 pcCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( cMRGMvField[0], ePartSize, uiPartAddr, 0, iPartIdx ); 4723 } 4724 if( uiMRGInterDir & 0x02 ) 4725 { 4726 pcCU->setMvFieldPUForVSP( pcCU, partAddrTemp, width, height, REF_PIC_LIST_1, cMRGMvField[1].getRefIdx(), vspSize ); 4727 pcCU->setVSPFlag( partAddrTemp, vspSize ); 4728 } 4729 else 4730 { 4731 pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( cMRGMvField[1], ePartSize, uiPartAddr, 0, iPartIdx ); 4732 } 4733 pcCU->setInterDirSubParts ( uiMRGInterDir, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) ); 4790 4734 } 4791 4735 else 4736 #if H_3D_FIX_G0148_BRACE 4792 4737 { 4793 pcCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( cMRGMvField[0], ePartSize, uiPartAddr, 0, iPartIdx ); 4794 } 4795 if( uiMRGInterDir & 0x02 ) 4796 { 4797 pcCU->setMvFieldPUForVSP( pcCU, partAddrTemp, width, height, REF_PIC_LIST_1, cMRGMvField[1].getRefIdx(), vspSize ); 4798 pcCU->setVSPFlag( partAddrTemp, vspSize ); 4799 } 4800 else 4801 { 4802 pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( cMRGMvField[1], ePartSize, uiPartAddr, 0, iPartIdx ); 4803 } 4804 pcCU->setInterDirSubParts ( uiMRGInterDir, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) ); 4805 } 4806 else 4807 #endif 4808 { 4809 pcCU->setInterDirSubParts ( uiMRGInterDir, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) ); 4810 { 4738 #endif 4739 #endif 4740 pcCU->setInterDirSubParts ( uiMRGInterDir, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) ); 4811 4741 pcCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( cMRGMvField[0], ePartSize, uiPartAddr, 0, iPartIdx ); 4812 4742 pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( cMRGMvField[1], ePartSize, uiPartAddr, 0, iPartIdx ); 4743 #if H_3D_FIX_G0148_BRACE 4813 4744 } 4814 } 4815 4816 pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvd ( cMvZero, ePartSize, uiPartAddr, 0, iPartIdx ); 4817 pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvd ( cMvZero, ePartSize, uiPartAddr, 0, iPartIdx ); 4818 4819 pcCU->setMVPIdxSubParts( -1, REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); 4820 pcCU->setMVPNumSubParts( -1, REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); 4821 pcCU->setMVPIdxSubParts( -1, REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); 4822 pcCU->setMVPNumSubParts( -1, REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); 4745 #endif 4746 pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvd ( cMvZero, ePartSize, uiPartAddr, 0, iPartIdx ); 4747 pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvd ( cMvZero, ePartSize, uiPartAddr, 0, iPartIdx ); 4748 4749 pcCU->setMVPIdxSubParts( -1, REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); 4750 pcCU->setMVPNumSubParts( -1, REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); 4751 pcCU->setMVPIdxSubParts( -1, REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); 4752 pcCU->setMVPNumSubParts( -1, REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); 4823 4753 } 4824 4754 else … … 4827 4757 pcCU->setSPIVMPFlagSubParts(0, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) ); 4828 4758 #endif 4829 4830 4759 #if MTK_DDD_G0063 4831 4760 pcCU->setUseDDD( false, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) ); … … 4838 4767 pcCU->setDvInfoSubParts(OriginalDvInfo, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) ); 4839 4768 #endif 4840 { 4841 pcCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( cMEMvField[0], ePartSize, uiPartAddr, 0, iPartIdx ); 4842 pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( cMEMvField[1], ePartSize, uiPartAddr, 0, iPartIdx ); 4843 } 4769 pcCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( cMEMvField[0], ePartSize, uiPartAddr, 0, iPartIdx ); 4770 pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( cMEMvField[1], ePartSize, uiPartAddr, 0, iPartIdx ); 4844 4771 } 4845 4772 #if H_3D_SPIVMP … … 4851 4778 // MC 4852 4779 motionCompensation ( pcCU, rpcPredYuv, REF_PIC_LIST_X, iPartIdx ); 4853 4780 4854 4781 } // end of for ( Int iPartIdx = 0; iPartIdx < iNumPart; iPartIdx++ ) 4855 4782 … … 4997 4924 4998 4925 if (iNum == 1) 4926 { 4999 4927 return 0; 4928 } 5000 4929 5001 4930 UInt uiLength = 1; … … 5177 5106 pcOrgYuv->getLumaAddr(uiPartAddr), pcOrgYuv->getStride(), 5178 5107 pcTemplateCand->getLumaAddr(uiPartAddr), pcTemplateCand->getStride(), 5179 #if NS_HAD5180 iSizeX, iSizeY, m_pcEncCfg->getUseHADME(), m_pcEncCfg->getUseNSQT() );5181 #else5182 5108 iSizeX, iSizeY, m_pcEncCfg->getUseHADME() ); 5183 #endif5184 5109 ruiDist = cDistParam.DistFunc( &cDistParam ); 5185 5110 uiCost = ruiDist + m_pcRdCost->getCost( m_auiMVPIdxCost[iMVPIdx][iMVPNum] ); 5186 5111 #else 5187 #if WEIGHTED_CHROMA_DISTORTION5188 5112 uiCost = m_pcRdCost->getDistPart(g_bitDepthY, pcTemplateCand->getLumaAddr(uiPartAddr), pcTemplateCand->getStride(), pcOrgYuv->getLumaAddr(uiPartAddr), pcOrgYuv->getStride(), iSizeX, iSizeY, TEXT_LUMA, DF_SAD ); 5189 #else5190 uiCost = m_pcRdCost->getDistPart(g_bitDepthY, pcTemplateCand->getLumaAddr(uiPartAddr), pcTemplateCand->getStride(), pcOrgYuv->getLumaAddr(uiPartAddr), pcOrgYuv->getStride(), iSizeX, iSizeY, DF_SAD );5191 #endif5192 5113 uiCost = (UInt) m_pcRdCost->calcRdCost( m_auiMVPIdxCost[iMVPIdx][iMVPNum], uiCost, false, DF_SAD ); 5193 5114 #endif … … 5288 5209 m_pcRdCost->setCostScale ( 1 ); 5289 5210 5290 { 5291 xPatternSearchFracDIF( pcCU, pcPatternKey, piRefY, iRefStride, &rcMv, cMvHalf, cMvQter, ruiCost 5292 ,bBi 5293 ); 5294 } 5211 xPatternSearchFracDIF( pcCU, pcPatternKey, piRefY, iRefStride, &rcMv, cMvHalf, cMvQter, ruiCost,bBi ); 5295 5212 5296 5213 … … 5682 5599 { 5683 5600 #endif 5684 #if WEIGHTED_CHROMA_DISTORTION5685 5601 uiDistortion = m_pcRdCost->getDistPart(g_bitDepthY, rpcYuvRec->getLumaAddr(), rpcYuvRec->getStride(), pcYuvOrg->getLumaAddr(), pcYuvOrg->getStride(), uiWidth, uiHeight ) 5686 5602 + m_pcRdCost->getDistPart(g_bitDepthC, rpcYuvRec->getCbAddr(), rpcYuvRec->getCStride(), pcYuvOrg->getCbAddr(), pcYuvOrg->getCStride(), uiWidth >> 1, uiHeight >> 1, TEXT_CHROMA_U ) 5687 5603 + m_pcRdCost->getDistPart(g_bitDepthC, rpcYuvRec->getCrAddr(), rpcYuvRec->getCStride(), pcYuvOrg->getCrAddr(), pcYuvOrg->getCStride(), uiWidth >> 1, uiHeight >> 1, TEXT_CHROMA_V ); 5688 #else5689 uiDistortion = m_pcRdCost->getDistPart(g_bitDepthY, rpcYuvRec->getLumaAddr(), rpcYuvRec->getStride(), pcYuvOrg->getLumaAddr(), pcYuvOrg->getStride(), uiWidth, uiHeight )5690 + m_pcRdCost->getDistPart(g_bitDepthC, rpcYuvRec->getCbAddr(), rpcYuvRec->getCStride(), pcYuvOrg->getCbAddr(), pcYuvOrg->getCStride(), uiWidth >> 1, uiHeight >> 1 )5691 + m_pcRdCost->getDistPart(g_bitDepthC, rpcYuvRec->getCrAddr(), rpcYuvRec->getCStride(), pcYuvOrg->getCrAddr(), pcYuvOrg->getCStride(), uiWidth >> 1, uiHeight >> 1 );5692 #endif5693 5694 5604 #if H_3D_VSO // MIgnore 5695 5605 } 5696 5606 #endif 5697 5607 5698 if( m_bUseSBACRD )5699 5608 m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[pcCU->getDepth(0)][CI_CURR_BEST]); 5700 5609 … … 5729 5638 pcCU->getTotalCost() = m_pcRdCost->calcRdCost( uiBits, uiDistortion ); 5730 5639 5731 if( m_bUseSBACRD )5732 5640 m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[pcCU->getDepth(0)][CI_TEMP_BEST]); 5733 5641 … … 5771 5679 uiBits = 0; 5772 5680 uiDistortion = 0; 5773 if( m_bUseSBACRD )5774 {5775 5681 m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ pcCU->getDepth( 0 ) ][ CI_CURR_BEST ] ); 5776 }5777 5682 5778 5683 #if H_3D_VSO // M16 // M18 … … 5836 5741 } 5837 5742 5838 if( m_bUseSBACRD )5839 {5840 5743 m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[pcCU->getDepth(0)][CI_CURR_BEST] ); 5841 }5842 5744 #if 0 // check 5843 5745 { … … 5845 5747 m_pcEntropyCoder->encodeCoeff( pcCU, 0, pcCU->getDepth(0), pcCU->getWidth(0), pcCU->getHeight(0) ); 5846 5748 const UInt uiBitsForCoeff = m_pcEntropyCoder->getNumberOfWrittenBits(); 5847 if( m_bUseSBACRD )5848 {5849 5749 m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[pcCU->getDepth(0)][CI_CURR_BEST] ); 5850 }5851 5750 if( uiBitsForCoeff != uiBits ) 5852 5751 assert( 0 ); … … 5904 5803 dCostBest = dCost; 5905 5804 qpBest = qp; 5906 if( m_bUseSBACRD ) 5907 { 5908 m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[ pcCU->getDepth( 0 ) ][ CI_TEMP_BEST ] ); 5909 } 5805 m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[ pcCU->getDepth( 0 ) ][ CI_TEMP_BEST ] ); 5910 5806 } 5911 5807 #if H_3D_VSO // M21 … … 5918 5814 #endif 5919 5815 } 5920 5921 5816 assert ( dCostBest != MAX_DOUBLE ); 5922 5817 5923 5818 if( qpMin != qpMax && qpBest != qpMax ) 5924 5819 { 5925 if( m_bUseSBACRD )5926 {5927 5820 assert( 0 ); // check 5928 5821 m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ pcCU->getDepth( 0 ) ][ CI_TEMP_BEST ] ); 5929 }5930 5822 // copy best cbf and trIdx to pcCU 5931 5823 const UInt uiQPartNum = pcCU->getPic()->getNumPartInCU() >> (pcCU->getDepth(0) << 1); … … 5957 5849 #endif 5958 5850 // update with clipped distortion and cost (qp estimation loop uses unclipped values) 5959 #if WEIGHTED_CHROMA_DISTORTION5960 5851 uiDistortionBest = m_pcRdCost->getDistPart(g_bitDepthY, rpcYuvRec->getLumaAddr(), rpcYuvRec->getStride(), pcYuvOrg->getLumaAddr(), pcYuvOrg->getStride(), uiWidth, uiHeight ) 5961 5852 + m_pcRdCost->getDistPart(g_bitDepthC, rpcYuvRec->getCbAddr(), rpcYuvRec->getCStride(), pcYuvOrg->getCbAddr(), pcYuvOrg->getCStride(), uiWidth >> 1, uiHeight >> 1, TEXT_CHROMA_U ) 5962 5853 + m_pcRdCost->getDistPart(g_bitDepthC, rpcYuvRec->getCrAddr(), rpcYuvRec->getCStride(), pcYuvOrg->getCrAddr(), pcYuvOrg->getCStride(), uiWidth >> 1, uiHeight >> 1, TEXT_CHROMA_V ); 5963 #else5964 uiDistortionBest = m_pcRdCost->getDistPart(g_bitDepthY, rpcYuvRec->getLumaAddr(), rpcYuvRec->getStride(), pcYuvOrg->getLumaAddr(), pcYuvOrg->getStride(), uiWidth, uiHeight )5965 + m_pcRdCost->getDistPart(g_bitDepthC, rpcYuvRec->getCbAddr(), rpcYuvRec->getCStride(), pcYuvOrg->getCbAddr(), pcYuvOrg->getCStride(), uiWidth >> 1, uiHeight >> 1 )5966 + m_pcRdCost->getDistPart(g_bitDepthC, rpcYuvRec->getCrAddr(), rpcYuvRec->getCStride(), pcYuvOrg->getCrAddr(), pcYuvOrg->getCStride(), uiWidth >> 1, uiHeight >> 1 );5967 #endif5968 5854 #if H_3D_VSO // M23 5969 5855 } … … 5984 5870 5985 5871 pcCU->setQPSubParts( qpBest, 0, pcCU->getDepth(0) ); 5986 5987 5872 #if H_3D_VSO // M24 // necessary?? 5988 5873 if( m_pcRdCost->getUseRenModel() && !m_pcRdCost->getUseEstimatedVSD() ) … … 6162 6047 UInt uiBits = 0; 6163 6048 TComYuv *pDummy = NULL; 6164 if( m_bUseSBACRD ) 6165 { 6166 m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[pcCU->getDepth(0)][CI_CURR_BEST] ); 6167 } 6049 m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[pcCU->getDepth(0)][CI_CURR_BEST] ); 6168 6050 6169 6051 xAddSymbolBitsInter( pcCU, 0, 0, uiBits, pDummy, NULL, pDummy ); … … 6184 6066 pcCU->getTotalCost() = rdCost; 6185 6067 6186 if( m_bUseSBACRD ) 6187 { 6188 m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[ pcCU->getDepth( 0 ) ][ CI_TEMP_BEST ] ); 6189 } 6068 m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[ pcCU->getDepth( 0 ) ][ CI_TEMP_BEST ] ); 6190 6069 } 6191 6070 … … 6216 6095 Bool bCheckFull; 6217 6096 if ( SplitFlag && uiDepth == pcCU->getDepth(uiAbsPartIdx) && ( uiLog2TrSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) ) ) 6097 { 6218 6098 bCheckFull = false; 6099 } 6219 6100 else 6101 { 6220 6102 bCheckFull = ( uiLog2TrSize <= pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() ); 6103 } 6221 6104 6222 6105 const Bool bCheckSplit = ( uiLog2TrSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) ); … … 6247 6130 UInt uiBestTransformMode[3] = {0}; 6248 6131 6249 if( m_bUseSBACRD )6250 {6251 6132 m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[ uiDepth ][ CI_QT_TRAFO_ROOT ] ); 6252 }6253 6133 6254 6134 if( bCheckFull ) … … 6316 6196 6317 6197 #if RDOQ_CHROMA_LAMBDA 6318 m_pcTrQuant->selectLambda(TEXT_CHROMA );6198 m_pcTrQuant->selectLambda(TEXT_CHROMA_U); 6319 6199 #endif 6320 6200 … … 6327 6207 curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCrQpOffset() + pcCU->getSlice()->getSliceQpDeltaCr(); 6328 6208 m_pcTrQuant->setQPforQuant( pcCU->getQP( 0 ), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset ); 6209 6210 #if RDOQ_CHROMA_LAMBDA 6211 m_pcTrQuant->selectLambda(TEXT_CHROMA_V); 6212 #endif 6213 6329 6214 m_pcTrQuant->transformNxN( pcCU, pcResi->getCrAddr(absTUPartIdxC), pcResi->getCStride(), pcCoeffCurrV, 6330 6215 #if ADAPTIVE_QP_SELECTION … … 6339 6224 m_pcEntropyCoder->resetBits(); 6340 6225 6341 {6342 6226 m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA, uiTrMode ); 6343 }6344 6227 6345 6228 m_pcEntropyCoder->encodeCoeffNxN( pcCU, pcCoeffCurrY, uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_LUMA ); … … 6350 6233 if( bCodeChroma ) 6351 6234 { 6352 {6353 6235 m_pcEntropyCoder->encodeQtCbf ( pcCU, uiAbsPartIdx, TEXT_CHROMA_U, uiTrMode ); 6354 }6355 6236 m_pcEntropyCoder->encodeCoeffNxN( pcCU, pcCoeffCurrU, uiAbsPartIdx, trWidthC, trHeightC, uiDepth, TEXT_CHROMA_U ); 6356 6237 uiSingleBitsU = m_pcEntropyCoder->getNumberOfWrittenBits() - uiSingleBitsY; 6357 6238 6358 {6359 6239 m_pcEntropyCoder->encodeQtCbf ( pcCU, uiAbsPartIdx, TEXT_CHROMA_V, uiTrMode ); 6360 }6361 6240 m_pcEntropyCoder->encodeCoeffNxN( pcCU, pcCoeffCurrV, uiAbsPartIdx, trWidthC, trHeightC, uiDepth, TEXT_CHROMA_V ); 6362 6241 uiSingleBitsV = m_pcEntropyCoder->getNumberOfWrittenBits() - ( uiSingleBitsY + uiSingleBitsU ); … … 6400 6279 6401 6280 Int scalingListType = 3 + g_eTTable[(Int)TEXT_LUMA]; 6402 assert(scalingListType < 6);6281 assert(scalingListType < SCALING_LIST_NUM); 6403 6282 m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), TEXT_LUMA,REG_DCT, pcResiCurrY, m_pcQTTempTComYuv[uiQTTempAccessLayer].getStride(), pcCoeffCurrY, trWidth, trHeight, scalingListType );//this is for inter mode only 6404 6283 … … 6423 6302 } 6424 6303 #else 6425 const UInt uiNonzeroDistY = m_pcRdCost->getDistPart(g_bitDepthY, m_pcQTTempTComYuv[uiQTTempAccessLayer].getLumaAddr( absTUPartIdx ), m_pcQTTempTComYuv[uiQTTempAccessLayer].getStride(), pcResi->getLumaAddr( absTUPartIdx ), pcResi->getStride(), trWidth,trHeight ); 6304 const UInt uiNonzeroDistY = m_pcRdCost->getDistPart(g_bitDepthY, m_pcQTTempTComYuv[uiQTTempAccessLayer].getLumaAddr( absTUPartIdx ), m_pcQTTempTComYuv[uiQTTempAccessLayer].getStride(), 6305 pcResi->getLumaAddr( absTUPartIdx ), pcResi->getStride(), trWidth,trHeight ); 6426 6306 #endif 6427 6307 if (pcCU->isLosslessCoded(0)) … … 6500 6380 { 6501 6381 uiDistU = m_pcRdCost->getDistPart(g_bitDepthC, m_pTempPel, trWidthC, pcResi->getCbAddr( absTUPartIdxC ), pcResi->getCStride(), trWidthC, trHeightC 6502 #if WEIGHTED_CHROMA_DISTORTION6503 6382 , TEXT_CHROMA_U 6504 #endif6505 6383 ); // initialized with zero residual destortion 6506 6384 if ( puiZeroDist ) … … 6516 6394 6517 6395 Int scalingListType = 3 + g_eTTable[(Int)TEXT_CHROMA_U]; 6518 assert(scalingListType < 6);6396 assert(scalingListType < SCALING_LIST_NUM); 6519 6397 m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), TEXT_CHROMA,REG_DCT, pcResiCurrU, m_pcQTTempTComYuv[uiQTTempAccessLayer].getCStride(), pcCoeffCurrU, trWidthC, trHeightC, scalingListType ); 6520 6398 6521 6399 const UInt uiNonzeroDistU = m_pcRdCost->getDistPart(g_bitDepthC, m_pcQTTempTComYuv[uiQTTempAccessLayer].getCbAddr( absTUPartIdxC), m_pcQTTempTComYuv[uiQTTempAccessLayer].getCStride(), 6522 6400 pcResi->getCbAddr( absTUPartIdxC), pcResi->getCStride(), trWidthC, trHeightC 6523 #if WEIGHTED_CHROMA_DISTORTION6524 6401 , TEXT_CHROMA_U 6525 #endif6526 6402 ); 6527 6403 … … 6559 6435 { 6560 6436 m_pcEntropyCoder->resetBits(); 6561 m_pcEntropyCoder->encodeQtCbfZero( pcCU, TEXT_CHROMA_U, uiTrMode C);6437 m_pcEntropyCoder->encodeQtCbfZero( pcCU, TEXT_CHROMA_U, uiTrMode ); 6562 6438 const UInt uiNullBitsU = m_pcEntropyCoder->getNumberOfWrittenBits(); 6563 6439 minCostU = m_pcRdCost->calcRdCost( uiNullBitsU, uiDistU ); … … 6575 6451 6576 6452 uiDistV = m_pcRdCost->getDistPart(g_bitDepthC, m_pTempPel, trWidthC, pcResi->getCrAddr( absTUPartIdxC), pcResi->getCStride(), trWidthC, trHeightC 6577 #if WEIGHTED_CHROMA_DISTORTION6578 6453 , TEXT_CHROMA_V 6579 #endif6580 6454 ); // initialized with zero residual destortion 6581 6455 if ( puiZeroDist ) … … 6590 6464 6591 6465 Int scalingListType = 3 + g_eTTable[(Int)TEXT_CHROMA_V]; 6592 assert(scalingListType < 6);6466 assert(scalingListType < SCALING_LIST_NUM); 6593 6467 m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), TEXT_CHROMA,REG_DCT, pcResiCurrV, m_pcQTTempTComYuv[uiQTTempAccessLayer].getCStride(), pcCoeffCurrV, trWidthC, trHeightC, scalingListType ); 6594 6468 6595 6469 const UInt uiNonzeroDistV = m_pcRdCost->getDistPart(g_bitDepthC, m_pcQTTempTComYuv[uiQTTempAccessLayer].getCrAddr( absTUPartIdxC ), m_pcQTTempTComYuv[uiQTTempAccessLayer].getCStride(), 6596 6470 pcResi->getCrAddr( absTUPartIdxC ), pcResi->getCStride(), trWidthC, trHeightC 6597 #if WEIGHTED_CHROMA_DISTORTION6598 6471 , TEXT_CHROMA_V 6599 #endif6600 6472 ); 6601 6473 if (pcCU->isLosslessCoded(0)) … … 6632 6504 { 6633 6505 m_pcEntropyCoder->resetBits(); 6634 m_pcEntropyCoder->encodeQtCbfZero( pcCU, TEXT_CHROMA_V, uiTrMode C);6506 m_pcEntropyCoder->encodeQtCbfZero( pcCU, TEXT_CHROMA_V, uiTrMode ); 6635 6507 const UInt uiNullBitsV = m_pcEntropyCoder->getNumberOfWrittenBits(); 6636 6508 minCostV = m_pcRdCost->calcRdCost( uiNullBitsV, uiDistV ); … … 6681 6553 } 6682 6554 6683 if( m_bUseSBACRD )6684 {6685 6555 m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ uiDepth ][ CI_QT_TRAFO_ROOT ] ); 6686 }6687 6556 6688 6557 pcCU->setTransformSkipSubParts ( 1, TEXT_LUMA, uiAbsPartIdx, uiDepth ); … … 6715 6584 6716 6585 Int scalingListType = 3 + g_eTTable[(Int)TEXT_LUMA]; 6717 assert(scalingListType < 6);6586 assert(scalingListType < SCALING_LIST_NUM); 6718 6587 6719 6588 m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), TEXT_LUMA,REG_DCT, pcResiCurrY, m_pcQTTempTComYuv[uiQTTempAccessLayer].getStride(), pcCoeffCurrY, trWidth, trHeight, scalingListType, true ); … … 6794 6663 } 6795 6664 6796 if( m_bUseSBACRD )6797 {6798 6665 m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ uiDepth ][ CI_QT_TRAFO_ROOT ] ); 6799 }6800 6666 6801 6667 pcCU->setTransformSkipSubParts ( 1, TEXT_CHROMA_U, uiAbsPartIdx, pcCU->getDepth(0)+uiTrModeC ); … … 6811 6677 6812 6678 #if RDOQ_CHROMA_LAMBDA 6813 m_pcTrQuant->selectLambda(TEXT_CHROMA );6679 m_pcTrQuant->selectLambda(TEXT_CHROMA_U); 6814 6680 #endif 6815 6681 … … 6821 6687 curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCrQpOffset() + pcCU->getSlice()->getSliceQpDeltaCr(); 6822 6688 m_pcTrQuant->setQPforQuant( pcCU->getQP( 0 ), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset ); 6689 #if RDOQ_CHROMA_LAMBDA 6690 m_pcTrQuant->selectLambda(TEXT_CHROMA_V); 6691 #endif 6823 6692 m_pcTrQuant->transformNxN( pcCU, pcResi->getCrAddr(absTUPartIdxC), pcResi->getCStride(), pcCoeffCurrV, 6824 6693 #if ADAPTIVE_QP_SELECTION … … 6844 6713 6845 6714 Int scalingListType = 3 + g_eTTable[(Int)TEXT_CHROMA_U]; 6846 assert(scalingListType < 6);6715 assert(scalingListType < SCALING_LIST_NUM); 6847 6716 6848 6717 m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), TEXT_CHROMA,REG_DCT, pcResiCurrU, m_pcQTTempTComYuv[uiQTTempAccessLayer].getCStride(), pcCoeffCurrU, trWidthC, trHeightC, scalingListType, true ); … … 6850 6719 uiNonzeroDistU = m_pcRdCost->getDistPart(g_bitDepthC, m_pcQTTempTComYuv[uiQTTempAccessLayer].getCbAddr( absTUPartIdxC), m_pcQTTempTComYuv[uiQTTempAccessLayer].getCStride(), 6851 6720 pcResi->getCbAddr( absTUPartIdxC), pcResi->getCStride(), trWidthC, trHeightC 6852 #if WEIGHTED_CHROMA_DISTORTION6853 6721 , TEXT_CHROMA_U 6854 #endif6855 6722 ); 6856 6723 … … 6888 6755 6889 6756 Int scalingListType = 3 + g_eTTable[(Int)TEXT_CHROMA_V]; 6890 assert(scalingListType < 6);6757 assert(scalingListType < SCALING_LIST_NUM); 6891 6758 6892 6759 m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), TEXT_CHROMA,REG_DCT, pcResiCurrV, m_pcQTTempTComYuv[uiQTTempAccessLayer].getCStride(), pcCoeffCurrV, trWidthC, trHeightC, scalingListType, true ); … … 6894 6761 uiNonzeroDistV = m_pcRdCost->getDistPart(g_bitDepthC, m_pcQTTempTComYuv[uiQTTempAccessLayer].getCrAddr( absTUPartIdxC ), m_pcQTTempTComYuv[uiQTTempAccessLayer].getCStride(), 6895 6762 pcResi->getCrAddr( absTUPartIdxC ), pcResi->getCStride(), trWidthC, trHeightC 6896 #if WEIGHTED_CHROMA_DISTORTION6897 6763 , TEXT_CHROMA_V 6898 #endif6899 6764 ); 6900 6765 … … 6926 6791 } 6927 6792 6928 if( m_bUseSBACRD )6929 {6930 6793 m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ uiDepth ][ CI_QT_TRAFO_ROOT ] ); 6931 }6932 6933 6794 m_pcEntropyCoder->resetBits(); 6934 6795 6935 {6936 6796 if( uiLog2TrSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) ) 6937 6797 { 6938 6798 m_pcEntropyCoder->encodeTransformSubdivFlag( 0, 5 - uiLog2TrSize ); 6939 6799 } 6940 } 6941 6942 { 6800 6943 6801 if( bCodeChroma ) 6944 6802 { … … 6948 6806 6949 6807 m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA, uiTrMode ); 6950 }6951 6808 6952 6809 m_pcEntropyCoder->encodeCoeffNxN( pcCU, pcCoeffCurrY, uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_LUMA ); … … 6972 6829 if( bCheckSplit ) 6973 6830 { 6974 if( m_bUseSBACRD &&bCheckFull )6831 if( bCheckFull ) 6975 6832 { 6976 6833 m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[ uiDepth ][ CI_QT_TRAFO_TEST ] ); … … 7012 6869 } 7013 6870 7014 if( m_bUseSBACRD )7015 {7016 6871 m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ uiDepth ][ CI_QT_TRAFO_ROOT ] ); 7017 }7018 6872 m_pcEntropyCoder->resetBits(); 7019 6873 7020 {7021 6874 xEncodeResidualQT( pcCU, uiAbsPartIdx, uiDepth, true, TEXT_LUMA ); 7022 6875 xEncodeResidualQT( pcCU, uiAbsPartIdx, uiDepth, false, TEXT_LUMA ); 7023 6876 xEncodeResidualQT( pcCU, uiAbsPartIdx, uiDepth, false, TEXT_CHROMA_U ); 7024 6877 xEncodeResidualQT( pcCU, uiAbsPartIdx, uiDepth, false, TEXT_CHROMA_V ); 7025 }7026 6878 7027 6879 uiSubdivBits = m_pcEntropyCoder->getNumberOfWrittenBits(); … … 7050 6902 } 7051 6903 assert( bCheckFull ); 7052 if( m_bUseSBACRD ) 7053 { 7054 m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ uiDepth ][ CI_QT_TRAFO_TEST ] ); 7055 } 7056 } 7057 6904 6905 m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ uiDepth ][ CI_QT_TRAFO_TEST ] ); 6906 } 7058 6907 #if H_3D_VSO // M33 7059 6908 if( m_pcRdCost->getUseRenModel() && !m_pcRdCost->getUseEstimatedVSD() ) … … 7061 6910 UInt uiWidth = 1<< uiLog2TrSize; 7062 6911 UInt uiHeight = 1<< uiLog2TrSize; 7063 7064 6912 Pel* piSrc; 7065 6913 UInt uiSrcStride; 7066 7067 6914 if ( uiAbsSumY ) 7068 6915 { … … 7077 6924 uiSrcStride = pcPred->getStride (); 7078 6925 } 7079 7080 6926 m_pcRdCost->setRenModelData( pcCU, uiAbsPartIdx, piSrc, (Int) uiSrcStride, (Int) uiWidth, (Int) uiHeight ); 7081 6927 } 7082 6928 #endif 7083 7084 6929 rdCost += dSingleCost; 7085 6930 ruiBits += uiSingleBits; … … 7106 6951 const UInt uiLog2TrSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth() >> uiDepth]+2; 7107 6952 7108 {7109 6953 if( bSubdivAndCbf && uiLog2TrSize <= pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() && uiLog2TrSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) ) 7110 6954 { 7111 6955 m_pcEntropyCoder->encodeTransformSubdivFlag( bSubdiv, 5 - uiLog2TrSize ); 7112 6956 } 7113 } 7114 7115 { 6957 7116 6958 assert( pcCU->getPredictionMode(uiAbsPartIdx) != MODE_INTRA ); 7117 6959 if( bSubdivAndCbf ) … … 7135 6977 } 7136 6978 } 7137 }7138 6979 7139 6980 if( !bSubdiv ) … … 7159 7000 if( bSubdivAndCbf ) 7160 7001 { 7161 {7162 7002 m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA, uiTrMode ); 7163 7003 } 7164 }7165 7004 else 7166 7005 { … … 7229 7068 if( bCodeChroma ) 7230 7069 { 7231 {7232 7070 m_pcQTTempTComYuv[uiQTTempAccessLayer].copyPartToPartChroma( pcResi, uiAbsPartIdx, 1 << uiLog2TrSizeC, 1 << uiLog2TrSizeC ); 7233 7071 } 7234 7072 } 7235 }7236 7073 else 7237 7074 { … … 7279 7116 UInt TEncSearch::xModeBitsIntra( TComDataCU* pcCU, UInt uiMode, UInt uiPU, UInt uiPartOffset, UInt uiDepth, UInt uiInitTrDepth ) 7280 7117 { 7281 if( m_bUseSBACRD )7282 {7283 7118 // Reload only contexts required for coding intra mode information 7284 7119 m_pcRDGoOnSbacCoder->loadIntraDirModeLuma( m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST] ); … … 7286 7121 m_pcRDGoOnSbacCoder->loadIntraDepthMode( m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST] ); 7287 7122 #endif 7288 }7289 7123 7290 7124 pcCU->setLumaIntraDirSubParts ( uiMode, uiPartOffset, uiDepth + uiInitTrDepth ); -
branches/HTM-10.0-dev0/source/Lib/TLibEncoder/TEncSearch.h
r833 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 114 114 TEncSbac*** m_pppcRDSbacCoder; 115 115 TEncSbac* m_pcRDGoOnSbacCoder; 116 Bool m_bUseSBACRD;117 116 DistParam m_cDistParam; 118 117 -
branches/HTM-10.0-dev0/source/Lib/TLibEncoder/TEncSlice.cpp
r773 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 266 266 267 267 eSliceType=B_SLICE; 268 eSliceType = (pocLast == 0 || pocCurr% m_pcCfg->getIntraPeriod() == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType;268 eSliceType = (pocLast == 0 || (pocCurr - isField) % m_pcCfg->getIntraPeriod() == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType; 269 269 270 270 rpcSlice->setSliceType ( eSliceType ); … … 296 296 if(eSliceType!=I_SLICE) 297 297 { 298 if (!(( m_pcCfg->getMaxDeltaQP() == 0 ) && (dQP == -rpcSlice->getSPS()->getQpBDOffsetY() ) && (rpcSlice->get SPS()->getUseLossless())))298 if (!(( m_pcCfg->getMaxDeltaQP() == 0 ) && (dQP == -rpcSlice->getSPS()->getQpBDOffsetY() ) && (rpcSlice->getPPS()->getTransquantBypassEnableFlag()))) 299 299 { 300 300 #if H_MV … … 312 312 dQP += pdQPs[ rpcSlice->getPOC() ]; 313 313 } 314 #if !RATE_CONTROL_LAMBDA_DOMAIN315 if ( m_pcCfg->getUseRateCtrl())316 {317 dQP = m_pcRateCtrl->getFrameQP(rpcSlice->isReferenced(), rpcSlice->getPOC());318 }319 #endif320 314 // ------------------------------------------------------------------------------------------------------------------ 321 315 // Lambda computation … … 419 413 #endif 420 414 421 #if WEIGHTED_CHROMA_DISTORTION422 415 // for RDO 423 416 // in RdCost there is only one lambda because the luma and chroma bits are not separated, instead we weight the distortion of chroma. 424 Double weight = 1.0;417 Double weight[2] = { 1.0, 1.0 }; 425 418 Int qpc; 426 419 Int chromaQPOffset; … … 428 421 chromaQPOffset = rpcSlice->getPPS()->getChromaCbQpOffset() + rpcSlice->getSliceQpDeltaCb(); 429 422 qpc = Clip3( 0, 57, iQP + chromaQPOffset); 430 weight = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset431 m_pcRdCost->setCbDistortionWeight(weight );423 weight[0] = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset 424 m_pcRdCost->setCbDistortionWeight(weight[0]); 432 425 433 426 chromaQPOffset = rpcSlice->getPPS()->getChromaCrQpOffset() + rpcSlice->getSliceQpDeltaCr(); 434 427 qpc = Clip3( 0, 57, iQP + chromaQPOffset); 435 weight = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset 436 m_pcRdCost->setCrDistortionWeight(weight); 437 #endif 428 weight[1] = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset 429 m_pcRdCost->setCrDistortionWeight(weight[1]); 430 431 const Double lambdaArray[3] = {dLambda, (dLambda / weight[0]), (dLambda / weight[1])}; 438 432 439 433 #if RDOQ_CHROMA_LAMBDA 440 434 // for RDOQ 441 m_pcTrQuant->setLambda ( dLambda, dLambda / weight );435 m_pcTrQuant->setLambdas( lambdaArray ); 442 436 #else 443 437 m_pcTrQuant->setLambda( dLambda ); 444 438 #endif 445 439 446 #if SAO_CHROMA_LAMBDA447 440 // For SAO 448 rpcSlice ->setLambda( dLambda, dLambda / weight ); 449 #else 450 rpcSlice ->setLambda( dLambda ); 451 #endif 441 rpcSlice->setLambdas( lambdaArray ); 452 442 453 443 #if HB_LAMBDA_FOR_LDC … … 460 450 } 461 451 #else 462 eSliceType = (pocLast == 0 || pocCurr% m_pcCfg->getIntraPeriod() == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType;452 eSliceType = (pocLast == 0 || (pocCurr - isField) % m_pcCfg->getIntraPeriod() == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType; 463 453 #endif 464 454 … … 570 560 } 571 561 572 #if RATE_CONTROL_LAMBDA_DOMAIN573 562 Void TEncSlice::resetQP( TComPic* pic, Int sliceQP, Double lambda ) 574 563 { … … 579 568 slice->setSliceQpBase ( sliceQP ); 580 569 m_pcRdCost ->setLambda( lambda ); 581 #if WEIGHTED_CHROMA_DISTORTION582 570 // for RDO 583 571 // in RdCost there is only one lambda because the luma and chroma bits are not separated, instead we weight the distortion of chroma. 584 Double weight ;572 Double weight[2] = { 1.0, 1.0 }; 585 573 Int qpc; 586 574 Int chromaQPOffset; … … 588 576 chromaQPOffset = slice->getPPS()->getChromaCbQpOffset() + slice->getSliceQpDeltaCb(); 589 577 qpc = Clip3( 0, 57, sliceQP + chromaQPOffset); 590 weight = pow( 2.0, (sliceQP-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset591 m_pcRdCost->setCbDistortionWeight(weight );578 weight[0] = pow( 2.0, (sliceQP-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset 579 m_pcRdCost->setCbDistortionWeight(weight[0]); 592 580 593 581 chromaQPOffset = slice->getPPS()->getChromaCrQpOffset() + slice->getSliceQpDeltaCr(); 594 582 qpc = Clip3( 0, 57, sliceQP + chromaQPOffset); 595 weight = pow( 2.0, (sliceQP-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset 596 m_pcRdCost->setCrDistortionWeight(weight); 597 #endif 583 weight[1] = pow( 2.0, (sliceQP-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset 584 m_pcRdCost->setCrDistortionWeight(weight[1]); 585 586 const Double lambdaArray[3] = {lambda, (lambda / weight[0]), (lambda / weight[1])}; 598 587 599 588 #if RDOQ_CHROMA_LAMBDA 600 589 // for RDOQ 601 m_pcTrQuant->setLambda ( lambda, lambda / weight);590 m_pcTrQuant->setLambdas( lambdaArray ); 602 591 #else 603 592 m_pcTrQuant->setLambda( lambda ); 604 593 #endif 605 594 606 #if SAO_CHROMA_LAMBDA607 595 // For SAO 608 slice ->setLambda( lambda, lambda / weight ); 609 #else 610 slice ->setLambda( lambda ); 611 #endif 596 slice->setLambdas( lambdaArray ); 612 597 } 613 #else614 /**615 - lambda re-computation based on rate control QP616 */617 Void TEncSlice::xLamdaRecalculation(Int changeQP, Int idGOP, Int depth, SliceType eSliceType, TComSPS* pcSPS, TComSlice* pcSlice)618 {619 Int qp;620 Double recalQP= (Double)changeQP;621 Double origQP = (Double)recalQP;622 Double lambda;623 624 // pre-compute lambda and QP values for all possible QP candidates625 for ( Int deltqQpIdx = 0; deltqQpIdx < 2 * m_pcCfg->getDeltaQpRD() + 1; deltqQpIdx++ )626 {627 // compute QP value628 recalQP = origQP + ((deltqQpIdx+1)>>1)*(deltqQpIdx%2 ? -1 : 1);629 630 // compute lambda value631 Int NumberBFrames = ( m_pcCfg->getGOPSize() - 1 );632 Int SHIFT_QP = 12;633 Double dLambda_scale = 1.0 - Clip3( 0.0, 0.5, 0.05*(Double)NumberBFrames );634 #if FULL_NBIT635 Int bitdepth_luma_qp_scale = 6 * (g_bitDepth - 8);636 #else637 Int bitdepth_luma_qp_scale = 0;638 #endif639 Double qp_temp = (Double) recalQP + bitdepth_luma_qp_scale - SHIFT_QP;640 #if FULL_NBIT641 Double qp_temp_orig = (Double) recalQP - SHIFT_QP;642 #endif643 // Case #1: I or P-slices (key-frame)644 Double dQPFactor = m_pcCfg->getGOPEntry(idGOP).m_QPFactor;645 if ( eSliceType==I_SLICE )646 {647 dQPFactor=0.57*dLambda_scale;648 }649 lambda = dQPFactor*pow( 2.0, qp_temp/3.0 );650 651 if ( depth>0 )652 {653 #if FULL_NBIT654 lambda *= Clip3( 2.00, 4.00, (qp_temp_orig / 6.0) ); // (j == B_SLICE && p_cur_frm->layer != 0 )655 #else656 lambda *= Clip3( 2.00, 4.00, (qp_temp / 6.0) ); // (j == B_SLICE && p_cur_frm->layer != 0 )657 #endif658 }659 660 // if hadamard is used in ME process661 if ( !m_pcCfg->getUseHADME() )662 {663 lambda *= 0.95;664 }665 666 qp = max( -pcSPS->getQpBDOffsetY(), min( MAX_QP, (Int) floor( recalQP + 0.5 ) ) );667 668 m_pdRdPicLambda[deltqQpIdx] = lambda;669 m_pdRdPicQp [deltqQpIdx] = recalQP;670 m_piRdPicQp [deltqQpIdx] = qp;671 }672 673 // obtain dQP = 0 case674 lambda = m_pdRdPicLambda[0];675 recalQP = m_pdRdPicQp [0];676 qp = m_piRdPicQp [0];677 678 if( pcSlice->getSliceType( ) != I_SLICE )679 {680 lambda *= m_pcCfg->getLambdaModifier( depth );681 }682 683 // store lambda684 m_pcRdCost ->setLambda( lambda );685 #if WEIGHTED_CHROMA_DISTORTION686 // for RDO687 // in RdCost there is only one lambda because the luma and chroma bits are not separated, instead we weight the distortion of chroma.688 Double weight = 1.0;689 Int qpc;690 Int chromaQPOffset;691 692 chromaQPOffset = pcSlice->getPPS()->getChromaCbQpOffset() + pcSlice->getSliceQpDeltaCb();693 qpc = Clip3( 0, 57, qp + chromaQPOffset);694 weight = pow( 2.0, (qp-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset695 m_pcRdCost->setCbDistortionWeight(weight);696 697 chromaQPOffset = pcSlice->getPPS()->getChromaCrQpOffset() + pcSlice->getSliceQpDeltaCr();698 qpc = Clip3( 0, 57, qp + chromaQPOffset);699 weight = pow( 2.0, (qp-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset700 m_pcRdCost->setCrDistortionWeight(weight);701 #endif702 703 #if RDOQ_CHROMA_LAMBDA704 // for RDOQ705 m_pcTrQuant->setLambda( lambda, lambda / weight );706 #else707 m_pcTrQuant->setLambda( lambda );708 #endif709 710 #if SAO_CHROMA_LAMBDA711 // For SAO712 pcSlice ->setLambda( lambda, lambda / weight );713 #else714 pcSlice ->setLambda( lambda );715 #endif716 }717 #endif718 598 // ==================================================================================================================== 719 599 // Public member functions … … 755 635 } 756 636 757 #if RATE_CONTROL_LAMBDA_DOMAIN758 637 if ( m_pcCfg->getUseRateCtrl() ) 759 638 { … … 761 640 assert(0); 762 641 } 763 #endif764 642 765 643 TComSlice* pcSlice = rpcPic->getSlice(getSliceIdx()); … … 793 671 #endif 794 672 m_pcRdCost ->setLambda ( m_pdRdPicLambda[uiQpIdx] ); 795 #if WEIGHTED_CHROMA_DISTORTION796 673 // for RDO 797 674 // in RdCost there is only one lambda because the luma and chroma bits are not separated, instead we weight the distortion of chroma. 798 675 Int iQP = m_piRdPicQp [uiQpIdx]; 799 Double weight = 1.0;676 Double weight[2] = { 1.0, 1.0 }; 800 677 Int qpc; 801 678 Int chromaQPOffset; … … 803 680 chromaQPOffset = pcSlice->getPPS()->getChromaCbQpOffset() + pcSlice->getSliceQpDeltaCb(); 804 681 qpc = Clip3( 0, 57, iQP + chromaQPOffset); 805 weight = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset806 m_pcRdCost->setCbDistortionWeight(weight );682 weight[0] = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset 683 m_pcRdCost->setCbDistortionWeight(weight[0]); 807 684 808 685 chromaQPOffset = pcSlice->getPPS()->getChromaCrQpOffset() + pcSlice->getSliceQpDeltaCr(); 809 686 qpc = Clip3( 0, 57, iQP + chromaQPOffset); 810 weight = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset811 m_pcRdCost->setCrDistortionWeight(weight );812 #endif 813 687 weight[1] = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset 688 m_pcRdCost->setCrDistortionWeight(weight[1]); 689 690 const Double lambdaArray[3] = {m_pdRdPicLambda[uiQpIdx], (m_pdRdPicLambda[uiQpIdx] / weight[0]), (m_pdRdPicLambda[uiQpIdx] / weight[1])}; 814 691 #if RDOQ_CHROMA_LAMBDA 815 692 // for RDOQ 816 m_pcTrQuant ->setLambda( m_pdRdPicLambda[uiQpIdx], m_pdRdPicLambda[uiQpIdx] / weight);693 m_pcTrQuant->setLambdas( lambdaArray ); 817 694 #else 818 695 m_pcTrQuant ->setLambda ( m_pdRdPicLambda[uiQpIdx] ); 819 696 #endif 820 #if SAO_CHROMA_LAMBDA821 697 // For SAO 822 pcSlice ->setLambda ( m_pdRdPicLambda[uiQpIdx], m_pdRdPicLambda[uiQpIdx] / weight ); 823 #else 824 pcSlice ->setLambda ( m_pdRdPicLambda[uiQpIdx] ); 825 #endif 698 pcSlice->setLambdas( lambdaArray ); 826 699 827 700 // try compress … … 857 730 #endif 858 731 m_pcRdCost ->setLambda ( m_pdRdPicLambda[uiQpIdxBest] ); 859 #if WEIGHTED_CHROMA_DISTORTION860 732 // in RdCost there is only one lambda because the luma and chroma bits are not separated, instead we weight the distortion of chroma. 861 733 Int iQP = m_piRdPicQp [uiQpIdxBest]; 862 Double weight = 1.0;734 Double weight[2] = { 1.0, 1.0 }; 863 735 Int qpc; 864 736 Int chromaQPOffset; … … 866 738 chromaQPOffset = pcSlice->getPPS()->getChromaCbQpOffset() + pcSlice->getSliceQpDeltaCb(); 867 739 qpc = Clip3( 0, 57, iQP + chromaQPOffset); 868 weight = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset869 m_pcRdCost->setCbDistortionWeight(weight );740 weight[0] = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset 741 m_pcRdCost->setCbDistortionWeight(weight[0]); 870 742 871 743 chromaQPOffset = pcSlice->getPPS()->getChromaCrQpOffset() + pcSlice->getSliceQpDeltaCr(); 872 744 qpc = Clip3( 0, 57, iQP + chromaQPOffset); 873 weight = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset874 m_pcRdCost->setCrDistortionWeight(weight );875 #endif 876 745 weight[1] = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset 746 m_pcRdCost->setCrDistortionWeight(weight[1]); 747 748 const Double lambdaArray[3] = {m_pdRdPicLambda[uiQpIdxBest], (m_pdRdPicLambda[uiQpIdxBest] / weight[0]), (m_pdRdPicLambda[uiQpIdxBest] / weight[1])}; 877 749 #if RDOQ_CHROMA_LAMBDA 878 750 // for RDOQ 879 m_pcTrQuant ->setLambda( m_pdRdPicLambda[uiQpIdxBest], m_pdRdPicLambda[uiQpIdxBest] / weight );751 m_pcTrQuant->setLambdas( lambdaArray ); 880 752 #else 881 753 m_pcTrQuant ->setLambda ( m_pdRdPicLambda[uiQpIdxBest] ); 882 754 #endif 883 #if SAO_CHROMA_LAMBDA884 755 // For SAO 885 pcSlice ->setLambda ( m_pdRdPicLambda[uiQpIdxBest], m_pdRdPicLambda[uiQpIdxBest] / weight ); 886 #else 887 pcSlice ->setLambda ( m_pdRdPicLambda[uiQpIdxBest] ); 888 #endif 756 pcSlice->setLambdas( lambdaArray ); 889 757 } 890 758 891 759 /** \param rpcPic picture class 892 760 */ 893 #if RATE_CONTROL_INTRA894 761 Void TEncSlice::calCostSliceI(TComPic*& rpcPic) 895 762 { … … 925 792 m_pcRateCtrl->getRCPic()->setTotalIntraCost(iSumHadSlice); 926 793 } 927 #endif928 794 929 795 Void TEncSlice::compressSlice( TComPic*& rpcPic ) … … 943 809 944 810 // set entropy coder 945 if( m_pcCfg->getUseSBACRD() )946 {947 811 m_pcSbacCoder->init( m_pcBinCABAC ); 948 812 m_pcEntropyCoder->setEntropyCoder ( m_pcSbacCoder, pcSlice ); … … 952 816 pppcRDSbacCoder->setBinCountingEnableFlag( false ); 953 817 pppcRDSbacCoder->setBinsCoded( 0 ); 954 }955 else956 {957 m_pcEntropyCoder->setEntropyCoder ( m_pcCavlcCoder, pcSlice );958 m_pcEntropyCoder->resetEntropy ();959 m_pcEntropyCoder->setBitstream ( m_pcBitCounter );960 }961 818 962 819 //------------------------------------------------------------------------------ … … 1016 873 } 1017 874 #endif 1018 if( m_pcCfg->getUseSBACRD() )1019 {1020 875 iNumSubstreams = pcSlice->getPPS()->getNumSubstreams(); 1021 876 uiTilesAcross = rpcPic->getPicSym()->getNumColumnsMinus1()+1; … … 1037 892 ppppcRDSbacCoders[ui][0][CI_CURR_BEST]->load(m_pppcRDSbacCoder[0][CI_CURR_BEST]); 1038 893 } 1039 }1040 //if( m_pcCfg->getUseSBACRD() )1041 {1042 894 delete[] m_pcBufferLowLatSbacCoders; 1043 895 delete[] m_pcBufferLowLatBinCoderCABACs; … … 1050 902 for (UInt ui = 0; ui < uiTilesAcross; ui++) 1051 903 m_pcBufferLowLatSbacCoders[ui].load(m_pppcRDSbacCoder[0][CI_CURR_BEST]); //init. state 1052 } 904 1053 905 UInt uiWidthInLCUs = rpcPic->getPicSym()->getFrameWidthInCU(); 1054 906 //UInt uiHeightInLCUs = rpcPic->getPicSym()->getFrameHeightInCU(); … … 1121 973 } 1122 974 #endif 1123 #if !RATE_CONTROL_LAMBDA_DOMAIN1124 if(m_pcCfg->getUseRateCtrl())1125 {1126 #if KWU_RC_MADPRED_E02271127 if(pcSlice->getLayerId() != 0 && m_pcCfg->getUseDepthMADPred() && !pcSlice->getIsDepth())1128 {1129 Double zn, zf, focallength, position, camshift;1130 Double basepos;1131 Bool bInterpolated;1132 Int direction = pcSlice->getViewId() - pcCU->getSlice()->getIvPic(false, 0)->getViewId();1133 1134 pcEncTop->getCamParam()->xGetZNearZFar(pcEncTop->getCamParam()->getBaseViewNumbers()[pcSlice->getViewIndex()], pcSlice->getPOC(), zn, zf);1135 pcEncTop->getCamParam()->xGetGeometryData(pcEncTop->getCamParam()->getBaseViewNumbers()[0], pcSlice->getPOC(), focallength, basepos, camshift, bInterpolated);1136 pcEncTop->getCamParam()->xGetGeometryData(pcEncTop->getCamParam()->getBaseViewNumbers()[pcSlice->getViewIndex()], pcSlice->getPOC(), focallength, position, camshift, bInterpolated);1137 1138 m_pcRateCtrl->updateLCUDataEnhancedView(pcCU, pcCU->getTotalBits(), pcCU->getQP(0), basepos, position, focallength, zn, zf, (direction > 0 ? 1 : -1));1139 }1140 #endif1141 if(m_pcRateCtrl->calculateUnitQP())1142 {1143 xLamdaRecalculation(m_pcRateCtrl->getUnitQP(), m_pcRateCtrl->getGOPId(), pcSlice->getDepth(), pcSlice->getSliceType(), pcSlice->getSPS(), pcSlice );1144 }1145 }1146 #endif1147 975 // inherit from TR if necessary, select substream to use. 1148 if( m_pcCfg->getUseSBACRD() )1149 {1150 976 uiTileCol = rpcPic->getPicSym()->getTileIdxMap(uiCUAddr) % (rpcPic->getPicSym()->getNumColumnsMinus1()+1); // what column of tiles are we in? 1151 977 uiTileStartLCU = rpcPic->getPicSym()->getTComTile(rpcPic->getPicSym()->getTileIdxMap(uiCUAddr))->getFirstCUAddr(); … … 1192 1018 } 1193 1019 m_pppcRDSbacCoder[0][CI_CURR_BEST]->load( ppppcRDSbacCoders[uiSubStrm][0][CI_CURR_BEST] ); //this load is used to simplify the code 1194 }1195 1020 1196 1021 // reset the entropy coder … … 1210 1035 m_pcEntropyCoder->setEntropyCoder ( m_pcSbacCoder, pcSlice ); 1211 1036 } 1212 // if RD based on SBAC is used 1213 if( m_pcCfg->getUseSBACRD() ) 1214 { 1037 1215 1038 // set go-on entropy coder 1216 1039 m_pcEntropyCoder->setEntropyCoder ( m_pcRDGoOnSbacCoder, pcSlice ); … … 1219 1042 ((TEncBinCABAC*)m_pcRDGoOnSbacCoder->getEncBinIf())->setBinCountingEnableFlag(true); 1220 1043 1221 #if RATE_CONTROL_LAMBDA_DOMAIN1222 1044 Double oldLambda = m_pcRdCost->getLambda(); 1223 1045 if ( m_pcCfg->getUseRateCtrl() ) … … 1227 1049 Double bpp = -1.0; 1228 1050 1229 #if M0036_RC_IMPROVEMENT1230 1051 if ( ( rpcPic->getSlice( 0 )->getSliceType() == I_SLICE && m_pcCfg->getForceIntraQP() ) || !m_pcCfg->getLCULevelRC() ) 1231 #else1232 if ( rpcPic->getSlice( 0 )->getSliceType() == I_SLICE || !m_pcCfg->getLCULevelRC() )1233 #endif1234 1052 { 1235 1053 estQP = pcSlice->getSliceQp(); … … 1255 1073 { 1256 1074 #endif 1257 #if RATE_CONTROL_INTRA1258 1075 bpp = m_pcRateCtrl->getRCPic()->getLCUTargetBpp(pcSlice->getSliceType()); 1259 1076 if ( rpcPic->getSlice( 0 )->getSliceType() == I_SLICE) … … 1266 1083 estQP = m_pcRateCtrl->getRCPic()->getLCUEstQP ( estLambda, pcSlice->getSliceQp() ); 1267 1084 } 1268 #else1269 bpp = m_pcRateCtrl->getRCPic()->getLCUTargetBpp();1270 estLambda = m_pcRateCtrl->getRCPic()->getLCUEstLambda( bpp );1271 estQP = m_pcRateCtrl->getRCPic()->getLCUEstQP ( estLambda, pcSlice->getSliceQp() );1272 #endif1273 #if KWU_RC_MADPRED_E02271274 }1275 #endif1276 1085 #if KWU_RC_MADPRED_E0227 1277 1086 estLambda = m_pcRateCtrl->getRCPic()->getLCUEstLambda( bpp ); … … 1281 1090 1282 1091 m_pcRdCost->setLambda(estLambda); 1283 #if M0036_RC_IMPROVEMENT1284 1092 #if RDOQ_CHROMA_LAMBDA 1285 1093 // set lambda for RDOQ 1286 1094 Double weight=m_pcRdCost->getChromaWeight(); 1287 m_pcTrQuant->setLambda( estLambda, estLambda / weight ); 1095 const Double lambdaArray[3] = { estLambda, (estLambda / weight), (estLambda / weight) }; 1096 m_pcTrQuant->setLambdas( lambdaArray ); 1288 1097 #else 1289 1098 m_pcTrQuant->setLambda( estLambda ); 1290 #endif1291 1099 #endif 1292 1100 } … … 1295 1103 pcCU->getSlice()->setSliceQpBase( estQP ); 1296 1104 } 1297 #endif1298 1105 1299 1106 // run CU encoder 1300 1107 m_pcCuEncoder->compressCU( pcCU ); 1301 1108 1302 #if !TICKET_1090_FIX1303 #if RATE_CONTROL_LAMBDA_DOMAIN1304 if ( m_pcCfg->getUseRateCtrl() )1305 {1306 #if !M0036_RC_IMPROVEMENT1307 UInt SAD = m_pcCuEncoder->getLCUPredictionSAD();1308 Int height = min( pcSlice->getSPS()->getMaxCUHeight(),pcSlice->getSPS()->getPicHeightInLumaSamples() - uiCUAddr / rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUHeight() );1309 Int width = min( pcSlice->getSPS()->getMaxCUWidth(),pcSlice->getSPS()->getPicWidthInLumaSamples() - uiCUAddr % rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUWidth() );1310 Double MAD = (Double)SAD / (Double)(height * width);1311 MAD = MAD * MAD;1312 ( m_pcRateCtrl->getRCPic()->getLCU(uiCUAddr) ).m_MAD = MAD;1313 #endif1314 1315 Int actualQP = g_RCInvalidQPValue;1316 Double actualLambda = m_pcRdCost->getLambda();1317 Int actualBits = pcCU->getTotalBits();1318 Int numberOfEffectivePixels = 0;1319 for ( Int idx = 0; idx < rpcPic->getNumPartInCU(); idx++ )1320 {1321 if ( pcCU->getPredictionMode( idx ) != MODE_NONE && ( !pcCU->isSkipped( idx ) ) )1322 {1323 numberOfEffectivePixels = numberOfEffectivePixels + 16;1324 break;1325 }1326 }1327 1328 if ( numberOfEffectivePixels == 0 )1329 {1330 actualQP = g_RCInvalidQPValue;1331 }1332 else1333 {1334 actualQP = pcCU->getQP( 0 );1335 }1336 m_pcRdCost->setLambda(oldLambda);1337 #if RATE_CONTROL_INTRA1338 m_pcRateCtrl->getRCPic()->updateAfterLCU( m_pcRateCtrl->getRCPic()->getLCUCoded(), actualBits, actualQP, actualLambda,1339 pcCU->getSlice()->getSliceType() == I_SLICE ? 0 : m_pcCfg->getLCULevelRC() );1340 #else1341 m_pcRateCtrl->getRCPic()->updateAfterLCU( m_pcRateCtrl->getRCPic()->getLCUCoded(), actualBits, actualQP, actualLambda, m_pcCfg->getLCULevelRC() );1342 #endif1343 }1344 #endif1345 #endif1346 1347 1109 // restore entropy coder to an initial stage 1348 1110 m_pcEntropyCoder->setEntropyCoder ( m_pppcRDSbacCoder[0][CI_CURR_BEST], pcSlice ); … … 1366 1128 break; 1367 1129 } 1368 if( m_pcCfg->getUseSBACRD() )1369 {1370 ppppcRDSbacCoders[uiSubStrm][0][CI_CURR_BEST]->load( m_pppcRDSbacCoder[0][CI_CURR_BEST] );1371 1130 1131 ppppcRDSbacCoders[uiSubStrm][0][CI_CURR_BEST]->load( m_pppcRDSbacCoder[0][CI_CURR_BEST] ); 1372 1132 //Store probabilties of second LCU in line into buffer 1373 1133 if ( ( uiCol == uiTileLCUX+1) && (depSliceSegmentsEnabled || (pcSlice->getPPS()->getNumSubstreams() > 1)) && m_pcCfg->getWaveFrontsynchro()) … … 1375 1135 m_pcBufferSbacCoders[uiTileCol].loadContexts(ppppcRDSbacCoders[uiSubStrm][0][CI_CURR_BEST]); 1376 1136 } 1377 } 1378 1379 #if TICKET_1090_FIX 1380 #if RATE_CONTROL_LAMBDA_DOMAIN 1137 1381 1138 if ( m_pcCfg->getUseRateCtrl() ) 1382 1139 { 1383 #if !M0036_RC_IMPROVEMENT ||KWU_RC_MADPRED_E02271140 #if KWU_RC_MADPRED_E0227 1384 1141 UInt SAD = m_pcCuEncoder->getLCUPredictionSAD(); 1385 1142 Int height = min( pcSlice->getSPS()->getMaxCUHeight(),pcSlice->getSPS()->getPicHeightInLumaSamples() - uiCUAddr / rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUHeight() ); … … 1413 1170 m_pcRdCost->setLambda(oldLambda); 1414 1171 1415 #if RATE_CONTROL_INTRA1416 1172 m_pcRateCtrl->getRCPic()->updateAfterLCU( m_pcRateCtrl->getRCPic()->getLCUCoded(), actualBits, actualQP, actualLambda, 1417 1173 pcCU->getSlice()->getSliceType() == I_SLICE ? 0 : m_pcCfg->getLCULevelRC() ); 1418 #else1419 m_pcRateCtrl->getRCPic()->updateAfterLCU( m_pcRateCtrl->getRCPic()->getLCUCoded(), actualBits, actualQP, actualLambda, m_pcCfg->getLCULevelRC() );1420 #endif1421 }1422 #endif1423 #endif1424 }1425 // other case: encodeCU is not called1426 else1427 {1428 m_pcCuEncoder->compressCU( pcCU );1429 m_pcCuEncoder->encodeCU( pcCU );1430 if (m_pcCfg->getSliceMode()==FIXED_NUMBER_OF_BYTES && ( ( pcSlice->getSliceBits()+ m_pcEntropyCoder->getNumberOfWrittenBits() ) ) > m_pcCfg->getSliceArgument()<<3)1431 {1432 pcSlice->setNextSlice( true );1433 break;1434 }1435 if (m_pcCfg->getSliceSegmentMode()==FIXED_NUMBER_OF_BYTES && pcSlice->getSliceSegmentBits()+ m_pcEntropyCoder->getNumberOfWrittenBits()> m_pcCfg->getSliceSegmentArgument()<<3 &&pcSlice->getSliceCurEndCUAddr()!=pcSlice->getSliceSegmentCurEndCUAddr())1436 {1437 pcSlice->setNextSliceSegment( true );1438 break;1439 }1440 1174 } 1441 1175 … … 1443 1177 m_dPicRdCost += pcCU->getTotalCost(); 1444 1178 m_uiPicDist += pcCU->getTotalDistortion(); 1445 #if !RATE_CONTROL_LAMBDA_DOMAIN1446 if(m_pcCfg->getUseRateCtrl())1447 {1448 m_pcRateCtrl->updateLCUData(pcCU, pcCU->getTotalBits(), pcCU->getQP(0));1449 m_pcRateCtrl->updataRCUnitStatus();1450 }1451 #endif1452 1179 } 1453 1180 if ((pcSlice->getPPS()->getNumSubstreams() > 1) && !depSliceSegmentsEnabled) … … 1455 1182 pcSlice->setNextSlice( true ); 1456 1183 } 1184 if(m_pcCfg->getSliceMode()==FIXED_NUMBER_OF_BYTES || m_pcCfg->getSliceSegmentMode()==FIXED_NUMBER_OF_BYTES) 1185 { 1186 if(pcSlice->getSliceCurEndCUAddr()<=pcSlice->getSliceSegmentCurEndCUAddr()) 1187 { 1188 pcSlice->setNextSlice( true ); 1189 } 1190 else 1191 { 1192 pcSlice->setNextSliceSegment( true ); 1193 } 1194 } 1457 1195 if( depSliceSegmentsEnabled ) 1458 1196 { … … 1464 1202 } 1465 1203 xRestoreWPparam( pcSlice ); 1466 #if !RATE_CONTROL_LAMBDA_DOMAIN1467 if(m_pcCfg->getUseRateCtrl())1468 {1469 m_pcRateCtrl->updateFrameData(m_uiPicTotalBits);1470 }1471 #endif1472 1204 } 1473 1205 … … 1582 1314 uiCUAddr = rpcPic->getPicSym()->getCUOrderMap(++uiEncCUOrder) ) 1583 1315 { 1584 if( m_pcCfg->getUseSBACRD() )1585 {1586 1316 uiTileCol = rpcPic->getPicSym()->getTileIdxMap(uiCUAddr) % (rpcPic->getPicSym()->getNumColumnsMinus1()+1); // what column of tiles are we in? 1587 1317 uiTileStartLCU = rpcPic->getPicSym()->getTComTile(rpcPic->getPicSym()->getTileIdxMap(uiCUAddr))->getFirstCUAddr(); … … 1632 1362 } 1633 1363 m_pcSbacCoder->load(&pcSbacCoders[uiSubStrm]); //this load is used to simplify the code (avoid to change all the call to m_pcSbacCoder) 1634 } 1364 1635 1365 // reset the entropy coder 1636 1366 if( uiCUAddr == rpcPic->getPicSym()->getTComTile(rpcPic->getPicSym()->getTileIdxMap(uiCUAddr))->getFirstCUAddr() && // must be first CU of tile … … 1676 1406 #endif 1677 1407 TComDataCU*& pcCU = rpcPic->getCU( uiCUAddr ); 1678 if ( pcSlice->getSPS()->getUseSAO() && (pcSlice->getSaoEnabledFlag()||pcSlice->getSaoEnabledFlagChroma()) ) 1679 { 1680 SAOParam *saoParam = pcSlice->getPic()->getPicSym()->getSaoParam(); 1681 Int iNumCuInWidth = saoParam->numCuInWidth; 1682 Int iCUAddrInSlice = uiCUAddr - rpcPic->getPicSym()->getCUOrderMap(pcSlice->getSliceCurStartCUAddr()/rpcPic->getNumPartInCU()); 1683 Int iCUAddrUpInSlice = iCUAddrInSlice - iNumCuInWidth; 1684 Int rx = uiCUAddr % iNumCuInWidth; 1685 Int ry = uiCUAddr / iNumCuInWidth; 1686 Int allowMergeLeft = 1; 1687 Int allowMergeUp = 1; 1688 if (rx!=0) 1689 { 1690 if (rpcPic->getPicSym()->getTileIdxMap(uiCUAddr-1) != rpcPic->getPicSym()->getTileIdxMap(uiCUAddr)) 1691 { 1692 allowMergeLeft = 0; 1693 } 1694 } 1695 if (ry!=0) 1696 { 1697 if (rpcPic->getPicSym()->getTileIdxMap(uiCUAddr-iNumCuInWidth) != rpcPic->getPicSym()->getTileIdxMap(uiCUAddr)) 1698 { 1699 allowMergeUp = 0; 1700 } 1701 } 1702 Int addr = pcCU->getAddr(); 1703 allowMergeLeft = allowMergeLeft && (rx>0) && (iCUAddrInSlice!=0); 1704 allowMergeUp = allowMergeUp && (ry>0) && (iCUAddrUpInSlice>=0); 1705 if( saoParam->bSaoFlag[0] || saoParam->bSaoFlag[1] ) 1706 { 1707 Int mergeLeft = saoParam->saoLcuParam[0][addr].mergeLeftFlag; 1708 Int mergeUp = saoParam->saoLcuParam[0][addr].mergeUpFlag; 1709 if (allowMergeLeft) 1710 { 1711 m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoMerge(mergeLeft); 1712 } 1713 else 1714 { 1715 mergeLeft = 0; 1716 } 1717 if(mergeLeft == 0) 1718 { 1719 if (allowMergeUp) 1720 { 1721 m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoMerge(mergeUp); 1722 } 1723 else 1724 { 1725 mergeUp = 0; 1726 } 1727 if(mergeUp == 0) 1728 { 1729 for (Int compIdx=0;compIdx<3;compIdx++) 1730 { 1731 if( (compIdx == 0 && saoParam->bSaoFlag[0]) || (compIdx > 0 && saoParam->bSaoFlag[1])) 1732 { 1733 m_pcEntropyCoder->encodeSaoOffset(&saoParam->saoLcuParam[compIdx][addr], compIdx); 1734 } 1735 } 1736 } 1737 } 1738 } 1739 } 1740 else if (pcSlice->getSPS()->getUseSAO()) 1741 { 1742 Int addr = pcCU->getAddr(); 1743 SAOParam *saoParam = pcSlice->getPic()->getPicSym()->getSaoParam(); 1744 for (Int cIdx=0; cIdx<3; cIdx++) 1745 { 1746 SaoLcuParam *saoLcuParam = &(saoParam->saoLcuParam[cIdx][addr]); 1747 if ( ((cIdx == 0) && !pcSlice->getSaoEnabledFlag()) || ((cIdx == 1 || cIdx == 2) && !pcSlice->getSaoEnabledFlagChroma())) 1748 { 1749 saoLcuParam->mergeUpFlag = 0; 1750 saoLcuParam->mergeLeftFlag = 0; 1751 saoLcuParam->subTypeIdx = 0; 1752 saoLcuParam->typeIdx = -1; 1753 saoLcuParam->offset[0] = 0; 1754 saoLcuParam->offset[1] = 0; 1755 saoLcuParam->offset[2] = 0; 1756 saoLcuParam->offset[3] = 0; 1757 } 1408 if ( pcSlice->getSPS()->getUseSAO() ) 1409 { 1410 if (pcSlice->getSaoEnabledFlag()||pcSlice->getSaoEnabledFlagChroma()) 1411 { 1412 SAOBlkParam& saoblkParam = (rpcPic->getPicSym()->getSAOBlkParam())[uiCUAddr]; 1413 Bool sliceEnabled[NUM_SAO_COMPONENTS]; 1414 sliceEnabled[SAO_Y] = pcSlice->getSaoEnabledFlag(); 1415 sliceEnabled[SAO_Cb]= sliceEnabled[SAO_Cr]= pcSlice->getSaoEnabledFlagChroma(); 1416 1417 Bool leftMergeAvail = false; 1418 Bool aboveMergeAvail= false; 1419 //merge left condition 1420 Int rx = (uiCUAddr % uiWidthInLCUs); 1421 if(rx > 0) 1422 { 1423 leftMergeAvail = rpcPic->getSAOMergeAvailability(uiCUAddr, uiCUAddr-1); 1424 } 1425 1426 //merge up condition 1427 Int ry = (uiCUAddr / uiWidthInLCUs); 1428 if(ry > 0) 1429 { 1430 aboveMergeAvail = rpcPic->getSAOMergeAvailability(uiCUAddr, uiCUAddr-uiWidthInLCUs); 1431 } 1432 1433 m_pcEntropyCoder->encodeSAOBlkParam(saoblkParam,sliceEnabled, leftMergeAvail, aboveMergeAvail); 1758 1434 } 1759 1435 } … … 1773 1449 g_bJustDoIt = g_bEncDecTraceDisable; 1774 1450 #endif 1775 if( m_pcCfg->getUseSBACRD() )1776 {1777 1451 pcSbacCoders[uiSubStrm].load(m_pcSbacCoder); //load back status of the entropy coder after encoding the LCU into relevant bitstream entropy coder 1778 1452 … … 1783 1457 m_pcBufferSbacCoders[uiTileCol].loadContexts( &pcSbacCoders[uiSubStrm] ); 1784 1458 } 1785 }1786 1459 #if H_3D_QTLPC 1787 1460 rpcPic->setReduceBitsFlag(false); -
branches/HTM-10.0-dev0/source/Lib/TLibEncoder/TEncSlice.h
r833 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 107 107 UInt m_uiSliceIdx; 108 108 std::vector<TEncSbac*> CTXMem; 109 110 109 #if MTK_DDD_G0063 111 110 Int m_iDDDScale; … … 129 128 Int iGOPid, TComSlice*& rpcSlice, TComSPS* pSPS, TComPPS *pPPS, bool isField ); 130 129 #endif 131 #if RATE_CONTROL_LAMBDA_DOMAIN132 130 Void resetQP ( TComPic* pic, Int sliceQP, Double lambda ); 133 #else134 Void xLamdaRecalculation ( Int changeQP, Int idGOP, Int depth, SliceType eSliceType, TComSPS* pcSPS, TComSlice* pcSlice);135 #endif136 131 // compress and encode slice 137 132 Void precompressSlice ( TComPic*& rpcPic ); ///< precompress slice for multi-loop opt. 138 133 Void compressSlice ( TComPic*& rpcPic ); ///< analysis stage of slice 139 #if RATE_CONTROL_INTRA140 134 Void calCostSliceI ( TComPic*& rpcPic ); 141 #endif142 135 Void encodeSlice ( TComPic*& rpcPic, TComOutputBitstream* pcSubstreams ); 143 136 -
branches/HTM-10.0-dev0/source/Lib/TLibEncoder/TEncTop.cpp
r773 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 106 106 if (m_bUseSAO) 107 107 { 108 m_cEncSAO.setSaoLcuBoundary(getSaoLcuBoundary()); 109 m_cEncSAO.setSaoLcuBasedOptimization(getSaoLcuBasedOptimization()); 110 m_cEncSAO.setMaxNumOffsetsPerPic(getMaxNumOffsetsPerPic()); 111 m_cEncSAO.create( getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight ); 112 m_cEncSAO.createEncBuffer(); 108 m_cEncSAO.create( getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth ); 109 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 110 m_cEncSAO.createEncData(getSaoLcuBoundary()); 111 #else 112 m_cEncSAO.createEncData(); 113 #endif 113 114 } 114 115 #if ADAPTIVE_QP_SELECTION … … 120 121 m_cLoopFilter. create( g_uiMaxCUDepth ); 121 122 122 #if RATE_CONTROL_LAMBDA_DOMAIN123 123 if ( m_RCEnableRateControl ) 124 124 { … … 131 131 #endif 132 132 } 133 #else134 #if KWU_FIX_URQ135 if(m_enableRateCtrl)136 #endif137 m_cRateCtrl.create(getIntraPeriod(), getGOPSize(), getFrameRate(), getTargetBitrate(), getQP(), getNumLCUInUnit(), getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight);138 #endif139 // if SBAC-based RD optimization is used140 if( m_bUseSBACRD )141 {142 133 m_pppcRDSbacCoder = new TEncSbac** [g_uiMaxCUDepth+1]; 143 134 #if FAST_BIT_EST … … 168 159 } 169 160 } 170 }171 161 172 162 /** … … 195 185 m_pcSbacCoders[ui].init( &m_pcBinCoderCABACs[ui] ); 196 186 } 197 if( m_bUseSBACRD ) 198 { 187 199 188 m_ppppcRDSbacCoders = new TEncSbac*** [iNumSubstreams]; 200 189 m_ppppcBinCodersCABAC = new TEncBinCABAC***[iNumSubstreams]; … … 218 207 } 219 208 } 220 }221 209 222 210 Void TEncTop::destroy () … … 228 216 if (m_cSPS.getUseSAO()) 229 217 { 218 m_cEncSAO.destroyEncData(); 230 219 m_cEncSAO.destroy(); 231 m_cEncSAO.destroyEncBuffer();232 220 } 233 221 m_cLoopFilter. destroy(); 234 222 m_cRateCtrl. destroy(); 235 // SBAC RD 236 if( m_bUseSBACRD ) 237 { 223 238 224 Int iDepth; 239 225 for ( iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ ) … … 276 262 delete[] m_ppppcRDSbacCoders; 277 263 delete[] m_ppppcBinCodersCABAC; 278 }279 264 delete[] m_pcSbacCoders; 280 265 delete[] m_pcBinCoderCABACs; … … 439 424 #endif 440 425 441 #if RATE_CONTROL_LAMBDA_DOMAIN442 426 if ( m_RCEnableRateControl ) 443 427 { 444 428 m_cRateCtrl.initRCGOP( m_iNumPicRcvd ); 445 429 } 446 #endif447 448 430 #if H_MV 449 431 } … … 457 439 #endif 458 440 459 #if RATE_CONTROL_LAMBDA_DOMAIN460 441 if ( m_RCEnableRateControl ) 461 442 { 462 443 m_cRateCtrl.destroyRCGOP(); 463 444 } 464 #endif465 445 466 446 iNumEncoded = m_iNumPicRcvd; … … 510 490 TComPic *pcTopField; 511 491 xGetNewPicBuffer( pcTopField ); 512 pcTopField->getPicSym()->allocSaoParam(&m_cEncSAO);513 492 pcTopField->setReconMark (false); 514 493 … … 532 511 Pel * pcTopFieldV = pcTopField->getPicYuvOrg()->getCrAddr(); 533 512 534 // compute image characteristics535 if ( getUseAdaptiveQP() )536 {537 m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcTopField ) );538 }539 540 513 /* -- Defield -- */ 541 514 … … 546 519 separateFields(PicBufV + nPadChroma + (nStride >> 1)*nPadChroma, pcTopFieldV, nStride >> 1, nWidth >> 1, nHeight >> 1, isTop); 547 520 521 // compute image characteristics 522 if ( getUseAdaptiveQP() ) 523 { 524 m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcTopField ) ); 525 } 548 526 } 549 527 … … 562 540 TComPic* pcBottomField; 563 541 xGetNewPicBuffer( pcBottomField ); 564 pcBottomField->getPicSym()->allocSaoParam(&m_cEncSAO);565 542 pcBottomField->setReconMark (false); 566 543 567 TComPicYuv* rpcPicYuvRec = new TComPicYuv;544 TComPicYuv* rpcPicYuvRec; 568 545 if ( rcListPicYuvRecOut.size() == (UInt)m_iGOPSize ) 569 546 { … … 572 549 else 573 550 { 551 rpcPicYuvRec = new TComPicYuv; 574 552 rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth ); 575 553 } … … 595 573 Pel * pcBottomFieldV = pcBottomField->getPicYuvOrg()->getCrAddr(); 596 574 597 // Compute image characteristics598 if ( getUseAdaptiveQP() )599 {600 m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcBottomField ) );601 }602 603 575 /* -- Defield -- */ 604 576 … … 609 581 separateFields(PicBufV + nPadChroma + (nStride >> 1)*nPadChroma, pcBottomFieldV, nStride >> 1, nWidth >> 1, nHeight >> 1, isTop); 610 582 583 // Compute image characteristics 584 if ( getUseAdaptiveQP() ) 585 { 586 m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcBottomField ) ); 587 } 611 588 } 612 589 … … 625 602 } 626 603 #endif 627 628 629 630 604 // ==================================================================================================================== 631 605 // Protected member functions … … 671 645 rpcPic->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 672 646 m_conformanceWindow, m_defaultDisplayWindow, m_numReorderPics); 673 }674 if (getUseSAO())675 {676 rpcPic->getPicSym()->allocSaoParam(&m_cEncSAO);677 647 } 678 648 m_cListPic.pushBack( rpcPic ); … … 760 730 761 731 m_cSPS.setTMVPFlagsPresent(false); 762 m_cSPS.setUseLossless ( m_useLossless );763 732 764 733 m_cSPS.setMaxTrSize ( 1 << m_uiQuadtreeTULog2MaxSize ); … … 794 763 m_cSPS.setMaxTLayers( m_maxTempLayer ); 795 764 m_cSPS.setTemporalIdNestingFlag( ( m_maxTempLayer == 1 ) ? true : false ); 796 for ( i = 0; i < m _cSPS.getMaxTLayers(); i++ )765 for ( i = 0; i < min(m_cSPS.getMaxTLayers(),(UInt) MAX_TLAYER); i++ ) 797 766 { 798 767 m_cSPS.setMaxDecPicBuffering(m_maxDecPicBuffering[i], i); … … 860 829 m_cPPS.setSPSId( getLayerIdInVps() ); 861 830 #endif 862 863 831 #if H_3D 864 832 m_cPPS.setDLT( getDLT() ); 865 833 #endif 866 867 834 m_cPPS.setConstrainedIntraPred( m_bUseConstrainedIntraPred ); 868 835 Bool bUseDQP = (getMaxCuDQPDepth() > 0)? true : false; 869 836 870 Int lowestQP = - m_cSPS.getQpBDOffsetY();871 872 if(getUseLossless())873 {874 if ((getMaxCuDQPDepth() == 0) && (getMaxDeltaQP() == 0 ) && (getQP() == lowestQP) )875 {876 bUseDQP = false;877 }878 else879 {880 bUseDQP = true;881 }882 }883 else884 {885 if(bUseDQP == false)886 {887 837 if((getMaxDeltaQP() != 0 )|| getUseAdaptiveQP()) 888 838 { 889 839 bUseDQP = true; 890 840 } 891 }892 }893 841 894 842 if(bUseDQP) … … 905 853 } 906 854 907 #if RATE_CONTROL_LAMBDA_DOMAIN908 855 if ( m_RCEnableRateControl ) 909 856 { … … 912 859 m_cPPS.setMinCuDQPSize( m_cPPS.getSPS()->getMaxCUWidth() >> ( m_cPPS.getMaxCuDQPDepth()) ); 913 860 } 914 #endif915 #if !RATE_CONTROL_LAMBDA_DOMAIN && KWU_FIX_URQ916 if ( m_enableRateCtrl )917 {918 m_cPPS.setUseDQP(true);919 m_cPPS.setMaxCuDQPDepth( 0 );920 m_cPPS.setMinCuDQPSize( m_cPPS.getSPS()->getMaxCUWidth() >> ( m_cPPS.getMaxCuDQPDepth()) );921 }922 #endif923 861 924 862 m_cPPS.setChromaCbQpOffset( m_chromaCbQpOffset ); -
branches/HTM-10.0-dev0/source/Lib/TLibEncoder/TEncTop.h
r655 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 82 82 // encoder search 83 83 TEncSearch m_cSearch; ///< encoder search class 84 TEncEntropy* m_pcEntropyCoder; ///< entropy encoder84 //TEncEntropy* m_pcEntropyCoder; ///< entropy encoder 85 85 TEncCavlc* m_pcCavlcCoder; ///< CAVLC encoder 86 86 // coding tool -
branches/HTM-10.0-dev0/source/Lib/TLibEncoder/WeightPredAnalysis.cpp
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/TLibEncoder/WeightPredAnalysis.h
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/TLibVideoIO/TVideoIOYuv.cpp
r655 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/TLibVideoIO/TVideoIOYuv.h
r655 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/libmd5/MD5.h
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0-dev0/source/Lib/libmd5/libmd5.h
r608 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 *
Note: See TracChangeset for help on using the changeset viewer.