gallivm/nir: add support for indirect image loading
[mesa.git] / src / gallium / auxiliary / vl / vl_rbsp.h
index 7867238c49e6e12f09528f97e96cf5808cd532a9..4d90c2de09c85af79224c5b2bfe8093c7692cec7 100644 (file)
@@ -50,22 +50,34 @@ struct vl_rbsp {
  */
 static inline void vl_rbsp_init(struct vl_rbsp *rbsp, struct vl_vlc *nal, unsigned num_bits)
 {
-   unsigned bits_left = vl_vlc_bits_left(nal);
+   unsigned valid, bits_left = vl_vlc_bits_left(nal);
+   int i;
 
    /* copy the position */
    rbsp->nal = *nal;
 
-   rbsp->escaped = 0;
-
    /* search for the end of the NAL unit */
    while (vl_vlc_search_byte(nal, num_bits, 0x00)) {
       if (vl_vlc_peekbits(nal, 24) == 0x000001 ||
           vl_vlc_peekbits(nal, 32) == 0x00000001) {
          vl_vlc_limit(&rbsp->nal, bits_left - vl_vlc_bits_left(nal));
-         return;
+         break;
       }
       vl_vlc_eatbits(nal, 8);
    }
+
+   valid = vl_vlc_valid_bits(&rbsp->nal);
+   /* search for the emulation prevention three byte */
+   for (i = 24; i <= valid; i += 8) {
+      if ((vl_vlc_peekbits(&rbsp->nal, i) & 0xffffff) == 0x3) {
+         vl_vlc_removebits(&rbsp->nal, i - 8, 8);
+         i += 8;
+      }
+   }
+
+   valid = vl_vlc_valid_bits(&rbsp->nal);
+
+   rbsp->escaped = (valid >= 16) ? 16 : ((valid >= 8) ? 8 : 0);
 }
 
 /**