Add av1_exponential_entropy & av1_laplace_entropy

Change-Id: I02e66dcaead6666e83fe10d81e1ddd60c7535f99
diff --git a/av1/encoder/tpl_model.c b/av1/encoder/tpl_model.c
index 8da310a..c1ac34d 100644
--- a/av1/encoder/tpl_model.c
+++ b/av1/encoder/tpl_model.c
@@ -1647,3 +1647,19 @@
   }
   aom_clear_system_state();
 }
+
+#define EPSILON (0.0000001)
+
+double av1_exponential_entropy(double q_step, double b) {
+  double z = fmax(exp(-q_step / b), EPSILON);
+  return -log2(1 - z) - z * log2(z) / (1 - z);
+}
+
+double av1_laplace_entropy(double q_step, double b, double zero_bin_ratio) {
+  // zero bin's size is zero_bin_ratio * q_step
+  // non-zero bin's size is q_step
+  double z = fmax(exp(-zero_bin_ratio / 2 * q_step / b), EPSILON);
+  double h = av1_exponential_entropy(q_step, b);
+  double r = -(1 - z) * log2(1 - z) - z * log2(z) + z * (h + 1);
+  return r;
+}
diff --git a/av1/encoder/tpl_model.h b/av1/encoder/tpl_model.h
index 58714f8..3209cdb 100644
--- a/av1/encoder/tpl_model.h
+++ b/av1/encoder/tpl_model.h
@@ -223,6 +223,35 @@
 
 void av1_mc_flow_dispenser_row(struct AV1_COMP *cpi, MACROBLOCK *x, int mi_row,
                                BLOCK_SIZE bsize, TX_SIZE tx_size);
+
+/*!\brief  Compute the entropy of an exponential probability distribution
+ * function (pdf) subjected to uniform quantization.
+ *
+ * pdf(x) = b*exp(-b*x)
+ *
+ *\ingroup tpl_modelling
+ *
+ * \param[in]    q_step        quantizer step size
+ * \param[in]    b             parameter of exponential distribution
+ *
+ * \return entropy cost
+ */
+double av1_exponential_entropy(double q_step, double b);
+
+/*!\brief  Compute the entropy of a Laplace probability distribution
+ * function (pdf) subjected to non-uniform quantization.
+ *
+ * pdf(x) = 0.5*b*exp(-0.5*b*|x|)
+ *
+ *\ingroup tpl_modelling
+ *
+ * \param[in]    q_step          quantizer step size for non-zero bins
+ * \param[in]    b               parameter of Laplace distribution
+ * \param[in]    zero_bin_ratio  zero bin's size is zero_bin_ratio * q_step
+ *
+ * \return entropy cost
+ */
+double av1_laplace_entropy(double q_step, double b, double zero_bin_ratio);
 /*!\endcond */
 #ifdef __cplusplus
 }  // extern "C"