@@ -100,6 +100,7 @@ typedef struct {
100100 HapCodecTaskGroupRef taskGroup ;
101101
102102 unsigned int sliceCount ;
103+ unsigned int sliceHeight ;
103104#ifdef DEBUG
104105 unsigned int debugFrameCount ;
105106 uint64_t debugStartTime ;
@@ -229,6 +230,7 @@ Hap_COpen(
229230 glob -> dxtFormat = 0 ;
230231 glob -> taskGroup = NULL ;
231232 glob -> sliceCount = 1 ;
233+ glob -> sliceHeight = 4 ;
232234
233235bail :
234236 debug_print_err (glob , err );
@@ -664,13 +666,26 @@ Hap_CPrepareToCompressFrames(
664666
665667 glob -> taskGroup = HapCodecTasksCreateGroup (Background_Encode , maxTasks );
666668
667- glob -> sliceCount = roundUpToMultipleOf4 (glob -> height ) / 4 ;
668- if (glob -> sliceCount > 32 )
669- glob -> sliceCount = 32 ;
670-
671- // decrease slice count until it yeilds whole DXT rows
672- while ((roundUpToMultipleOf4 (glob -> height ) / 4 ) % glob -> sliceCount != 0 )
673- glob -> sliceCount -- ;
669+ {
670+ // Slice on DXT row boundaries
671+ unsigned int totalDXTRows = roundUpToMultipleOf4 (glob -> height ) / 4 ;
672+ unsigned int remainder ;
673+ glob -> sliceCount = totalDXTRows < 30 ? totalDXTRows : 30 ;
674+ glob -> sliceHeight = (totalDXTRows / glob -> sliceCount ) * 4 ;
675+ remainder = (totalDXTRows % glob -> sliceCount ) * 4 ;
676+ while (remainder > 0 )
677+ {
678+ glob -> sliceCount ++ ;
679+ if (remainder > glob -> sliceHeight )
680+ {
681+ remainder -= glob -> sliceHeight ;
682+ }
683+ else
684+ {
685+ remainder = 0 ;
686+ }
687+ }
688+ }
674689
675690#ifdef DEBUG
676691 glob -> debugStartTime = CVGetCurrentHostTime ();
@@ -860,7 +875,7 @@ dxtEncode(HapCompressorGlobals glob, CVPixelBufferRef sourcePixelBuffer, HapCode
860875 dxtTask .width = glob -> width ;
861876 dxtTask .height = glob -> height ;
862877 dxtTask .encoder = encoder ;
863- dxtTask .sliceHeight = roundUpToMultipleOf4 ( glob -> height ) / glob -> sliceCount ;
878+ dxtTask .sliceHeight = glob -> sliceHeight ;
864879 dxtTask .sourceBytesPerRow = CVPixelBufferGetBytesPerRow (sourcePixelBuffer );
865880 dxtTask .sourcePixelFormat = sourceFormat ;
866881 dxtTask .source = CVPixelBufferGetBaseAddress (sourcePixelBuffer );
0 commit comments