aee_mutators.c 4.16 KB
Newer Older
1 2 3 4 5
#include <inttypes.h>
#include "libae.h"
#include "aee.h"
#include "aee_mutators.h"

6
uint32_t get_lsb_32(ae_streamp strm)
7
{
8
    uint32_t data;
9

10 11 12 13
    data = ((uint32_t)strm->next_in[3] << 24)
        | ((uint32_t)strm->next_in[2] << 16)
        | ((uint32_t)strm->next_in[1] << 8)
        | (uint32_t)strm->next_in[0];
14 15 16 17 18 19 20

    strm->next_in += 4;
    strm->total_in += 4;
    strm->avail_in -= 4;
    return data;
}

21
uint32_t get_lsb_16(ae_streamp strm)
22
{
23
    uint32_t data;
24

25 26
    data = ((uint32_t)strm->next_in[1] << 8)
        | (uint32_t)strm->next_in[0];
27 28 29 30 31 32 33

    strm->next_in += 2;
    strm->total_in += 2;
    strm->avail_in -= 2;
    return data;
}

34
uint32_t get_msb_32(ae_streamp strm)
35
{
36
    uint32_t data;
37

38 39 40 41
    data = ((uint32_t)strm->next_in[0] << 24)
        | ((uint32_t)strm->next_in[1] << 16)
        | ((uint32_t)strm->next_in[2] << 8)
        | (uint32_t)strm->next_in[3];
42 43 44 45 46 47 48

    strm->next_in += 4;
    strm->total_in += 4;
    strm->avail_in -= 4;
    return data;
}

49
uint32_t get_msb_16(ae_streamp strm)
50
{
51
    uint32_t data;
52

53 54
    data = ((uint32_t)strm->next_in[0] << 8)
        | (uint32_t)strm->next_in[1];
55 56 57 58 59 60 61

    strm->next_in += 2;
    strm->total_in += 2;
    strm->avail_in -= 2;
    return data;
}

62
uint32_t get_8(ae_streamp strm)
63 64 65 66 67 68 69 70
{
    strm->avail_in--;
    strm->total_in++;
    return *strm->next_in++;
}

void get_block_msb_16_bs_8(ae_streamp strm)
{
71
    int i;
72
    uint32_t *block = strm->state->block_buf;
73 74 75

    for (i = 0; i < 8 * strm->rsi; i += 8)
    {
76 77 78 79 80 81 82 83
        block[i + 0] = ((uint32_t)strm->next_in[0] << 8) | (uint32_t)strm->next_in[1];
        block[i + 1] = ((uint32_t)strm->next_in[2] << 8) | (uint32_t)strm->next_in[3];
        block[i + 2] = ((uint32_t)strm->next_in[4] << 8) | (uint32_t)strm->next_in[5];
        block[i + 3] = ((uint32_t)strm->next_in[6] << 8) | (uint32_t)strm->next_in[7];
        block[i + 4] = ((uint32_t)strm->next_in[8] << 8) | (uint32_t)strm->next_in[9];
        block[i + 5] = ((uint32_t)strm->next_in[10] << 8) | (uint32_t)strm->next_in[11];
        block[i + 6] = ((uint32_t)strm->next_in[12] << 8) | (uint32_t)strm->next_in[13];
        block[i + 7] = ((uint32_t)strm->next_in[14] << 8) | (uint32_t)strm->next_in[15];
84 85 86 87 88

        strm->next_in += 16;
    }
    strm->total_in += 16 * strm->rsi;
    strm->avail_in -= 16 * strm->rsi;
89 90
}

91
void get_block_msb_16(ae_streamp strm)
92 93
{
    int i;
94
    uint32_t *block = strm->state->block_buf;
95

96
    for (i = 0; i < strm->block_size * strm->rsi; i++)
97
    {
98 99
        block[i] = ((uint32_t)strm->next_in[2 * i] << 8)
            | (uint32_t)strm->next_in[2 * i + 1];
100
    }
101 102 103
    strm->next_in += 2 * strm->block_size * strm->rsi;
    strm->total_in += 2 * strm->block_size * strm->rsi;
    strm->avail_in -= 2 * strm->block_size * strm->rsi;
104 105 106 107 108
}

void get_block_msb_32(ae_streamp strm)
{
    int i;
109
    uint32_t *block = strm->state->block_buf;
110

111
    for (i = 0; i < strm->block_size * strm->rsi; i++)
112
    {
113 114 115 116
        block[i] = ((uint32_t)strm->next_in[4 * i] << 24)
            | ((uint32_t)strm->next_in[4 * i + 1] << 16)
            | ((uint32_t)strm->next_in[4 * i + 2] << 8)
            | (uint32_t)strm->next_in[4 * i + 3];
117
    }
118 119 120
    strm->next_in += 4 * strm->block_size * strm->rsi;
    strm->total_in += 4 * strm->block_size * strm->rsi;
    strm->avail_in -= 4 * strm->block_size * strm->rsi;
121 122 123 124
}

void get_block_8_bs_8(ae_streamp strm)
{
125
    int i;
126
    uint32_t *block = strm->state->block_buf;
127 128 129

    for (i = 0; i < 8 * strm->rsi; i += 8)
    {
130 131 132 133 134 135 136 137
        block[i + 0] = strm->next_in[i + 0];
        block[i + 1] = strm->next_in[i + 1];
        block[i + 2] = strm->next_in[i + 2];
        block[i + 3] = strm->next_in[i + 3];
        block[i + 4] = strm->next_in[i + 4];
        block[i + 5] = strm->next_in[i + 5];
        block[i + 6] = strm->next_in[i + 6];
        block[i + 7] = strm->next_in[i + 7];
138
    }
139 140 141
    strm->next_in += 8 * strm->rsi;
    strm->total_in += 8 * strm->rsi;
    strm->avail_in -= 8 * strm->rsi;
142 143
}

144
void get_block_8(ae_streamp strm)
145
{
146
    int i;
147
    uint32_t *block = strm->state->block_buf;
148

149
    for (i = 0; i < strm->block_size * strm->rsi; i++)
150
        block[i] = strm->next_in[i];
151

152 153 154
    strm->next_in += strm->block_size * strm->rsi;
    strm->total_in += strm->block_size * strm->rsi;
    strm->avail_in -= strm->block_size * strm->rsi;
155
}