[x264-devel] Fix float division by zero in weightp analysis

Anton Mitrofanov git at videolan.org
Tue Aug 7 00:05:25 CEST 2018


x264 | branch: master | Anton Mitrofanov <BugMaster at narod.ru> | Fri Jul 20 08:37:43 2018 +0300| [34843deb060248514ecd9edd88d72c2c2d6b906a] | committer: Henrik Gramner

Fix float division by zero in weightp analysis

> http://git.videolan.org/gitweb.cgi/x264.git/?a=commit;h=34843deb060248514ecd9edd88d72c2c2d6b906a
---

 encoder/slicetype.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/encoder/slicetype.c b/encoder/slicetype.c
index 1775c25a..3454fb88 100644
--- a/encoder/slicetype.c
+++ b/encoder/slicetype.c
@@ -297,11 +297,12 @@ void x264_weights_analyse( x264_t *h, x264_frame_t *fenc, x264_frame_t *ref, int
     float ref_mean[3];
     for( int plane = 0; plane <= 2*!b_lookahead; plane++ )
     {
-        float fenc_var = fenc->i_pixel_ssd[plane] + !ref->i_pixel_ssd[plane];
-        float ref_var  =  ref->i_pixel_ssd[plane] + !ref->i_pixel_ssd[plane];
+        int zero_bias = !ref->i_pixel_ssd[plane];
+        float fenc_var = fenc->i_pixel_ssd[plane] + zero_bias;
+        float ref_var  =  ref->i_pixel_ssd[plane] + zero_bias;
         guess_scale[plane] = sqrtf( fenc_var / ref_var );
-        fenc_mean[plane] = (float)fenc->i_pixel_sum[plane] / (fenc->i_lines[!!plane] * fenc->i_width[!!plane]) / (1 << (BIT_DEPTH - 8));
-        ref_mean[plane]  = (float) ref->i_pixel_sum[plane] / (fenc->i_lines[!!plane] * fenc->i_width[!!plane]) / (1 << (BIT_DEPTH - 8));
+        fenc_mean[plane] = (float)(fenc->i_pixel_sum[plane] + zero_bias) / (fenc->i_lines[!!plane] * fenc->i_width[!!plane]) / (1 << (BIT_DEPTH - 8));
+        ref_mean[plane]  = (float)( ref->i_pixel_sum[plane] + zero_bias) / (fenc->i_lines[!!plane] * fenc->i_width[!!plane]) / (1 << (BIT_DEPTH - 8));
     }
 
     int chroma_denom = 7;



More information about the x264-devel mailing list