aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Graphics/VDec/VpxBitStreamWriter.cs
blob: 97ada333e7476bff8b0864dd4242578fd09128a4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using System.IO;

namespace Ryujinx.Graphics.VDec
{
    class VpxBitStreamWriter : BitStreamWriter
    {
        public VpxBitStreamWriter(Stream baseStream) : base(baseStream) { }

        public void WriteU(int value, int valueSize)
        {
            WriteBits(value, valueSize);
        }

        public void WriteS(int value, int valueSize)
        {
            bool sign = value < 0;

            if (sign)
            {
                value = -value;
            }

            WriteBits((value << 1) | (sign ? 1 : 0), valueSize + 1);
        }

        public void WriteDeltaQ(int value)
        {
            bool deltaCoded = value != 0;

            WriteBit(deltaCoded);

            if (deltaCoded)
            {
                WriteBits(value, 4);
            }
        }
    }
}