[CFL] Alpha signaling

Writes and reads alpha to and from the bitstream.

A special case is needed on the encoder side to handle prediction block
skips. Since whether or not a prediction block is skipped during CfL, a
rollback is required if the block was skipped and the alpha index was
not zero. The advantage of this is that no signaling is required when
the prediction block is skipped as it is assumed tha the alpha index is
zero.

A encode facade is added to the intra prediction facade as CfL requires
special encoder side operations.

Change-Id: Ic3b11d0fdbd51389d862112eb09d8785127a6b06
diff --git a/av1/encoder/bitstream.c b/av1/encoder/bitstream.c
index a2c85ce..eea8a0b 100644
--- a/av1/encoder/bitstream.c
+++ b/av1/encoder/bitstream.c
@@ -1690,6 +1690,21 @@
 #endif
 }
 
+#if CONFIG_CFL
+static void write_cfl_alphas(FRAME_CONTEXT *const frame_ctx, const int ind,
+                             const CFL_SIGN_TYPE signs[CFL_SIGNS],
+                             aom_writer *w) {
+  // Write a symbol representing a combination of alpha Cb and alpha Cr.
+  aom_write_symbol(w, ind, frame_ctx->cfl_alpha_cdf, CFL_ALPHABET_SIZE);
+
+  // Signs are only signaled for nonzero codes.
+  if (cfl_alpha_codes[ind][CFL_PRED_U] != 0)
+    aom_write_bit(w, signs[CFL_PRED_U]);
+  if (cfl_alpha_codes[ind][CFL_PRED_V] != 0)
+    aom_write_bit(w, signs[CFL_PRED_V]);
+}
+#endif
+
 static void pack_inter_mode_mvs(AV1_COMP *cpi, const int mi_row,
                                 const int mi_col,
 #if CONFIG_SUPERTX
@@ -2172,6 +2187,18 @@
   write_intra_uv_mode(ec_ctx, mbmi->uv_mode, mbmi->mode, w);
 #endif  // CONFIG_CB4X4
 
+#if CONFIG_CFL
+  if (mbmi->uv_mode == DC_PRED) {
+    if (mbmi->skip) {
+      assert(mbmi->cfl_alpha_ind == 0);
+      assert(mbmi->cfl_alpha_signs[CFL_PRED_U] == CFL_SIGN_POS);
+      assert(mbmi->cfl_alpha_signs[CFL_PRED_V] == CFL_SIGN_POS);
+    } else {
+      write_cfl_alphas(ec_ctx, mbmi->cfl_alpha_ind, mbmi->cfl_alpha_signs, w);
+    }
+  }
+#endif
+
 #if CONFIG_EXT_INTRA
   write_intra_angle_info(xd, ec_ctx, w);
 #endif  // CONFIG_EXT_INTRA