summaryrefslogtreecommitdiff
path: root/caching.cpp
blob: c35189e922bd196fd8ee1070ac933ec5afc25b92 (plain)
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171

#if 0
static void
CacheFrame(cache *Cache, pixel_buffer *CompBuffer)
{

    int MinX = 0;
    int MinY = 0;
    int MaxX = CompBuffer->Width;
    int MaxY = CompBuffer->Height;


    uint8 *Row = ((uint8 *)Cache->Address +
                     CompBuffer->BytesPerPixel +
                     MinY*CompBuffer->Pitch);
    uint8 *CompRow = ((uint8 *)CompBuffer->OriginalBuffer +
                     CompBuffer->BytesPerPixel +
                     CompBuffer->Pitch);
    for(int Y = MinY;
        Y < MaxY;
        ++Y)
    {
        uint32 *Pixel = (uint32 *)Row + MinX;
        uint32 *CompPixel = (uint32 *)CompRow;
        for(int X = MinX;
            X < MaxX;
            ++X)
        {
            *(uint32 *)Pixel++ = *(uint32 *)CompPixel;
            CompPixel++;
        }
        Row += CompBuffer->Pitch;
        CompRow += CompBuffer->Pitch;
    }
}

static void
FetchCache(cache *Cache, pixel_buffer *CompBuffer)
{

    int MinX = 0;
    int MinY = 0;
    int MaxX = CompBuffer->Width;
    int MaxY = CompBuffer->Height;


    uint8 *Row = ((uint8 *)Cache->Address +
                     CompBuffer->BytesPerPixel +
                     MinY*CompBuffer->Pitch);
    uint8 *CompRow = ((uint8 *)CompBuffer->OriginalBuffer +
                     CompBuffer->BytesPerPixel +
                     CompBuffer->Pitch);
    for(int Y = MinY;
        Y < MaxY;
        ++Y)
    {
        uint32 *Pixel = (uint32 *)Row + MinX;
        uint32 *CompPixel = (uint32 *)CompRow;
        for(int X = MinX;
            X < MaxX;
            ++X)
        {
            *(uint32 *)CompPixel = *(uint32 *)Pixel++;
            CompPixel++;
        }
        Row += CompBuffer->Pitch;
        CompRow += CompBuffer->Pitch;
    }
}

static void
InteractToComp(pixel_buffer *CompBuffer, cache_pool *Cache)
{
    int MinX = 0;
    int MinY = 0;
    int MaxX = CompBuffer->Width;
    int MaxY = CompBuffer->Height;

    uint8 *CompRow = ((uint8 *)CompBuffer->OriginalBuffer +
                     CompBuffer->BytesPerPixel +
                     CompBuffer->Pitch);
    uint8 *Row0 = ((uint8 *)Cache->Intermediate[0].Address +
                     CompBuffer->BytesPerPixel +
                     CompBuffer->Pitch);
    uint8 *Row1 = ((uint8 *)Cache->Intermediate[1].Address +
                     CompBuffer->BytesPerPixel +
                     CompBuffer->Pitch);
    uint8 *Row2 = ((uint8 *)Cache->Intermediate[2].Address +
                     CompBuffer->BytesPerPixel +
                     CompBuffer->Pitch);
    for(int Y = MinY;
        Y < MaxY;
        ++Y)
    {
        uint32 *CompPixel = (uint32 *)CompRow;
        uint32 *Pixel0 = (uint32 *)Row0;
        uint32 *Pixel1 = (uint32 *)Row1;
        uint32 *Pixel2 = (uint32 *)Row2;
        for(int X = MinX;
            X < MaxX;
            ++X)
        {
            RenderAlpha(CompPixel, *Pixel0);
            RenderAlpha(CompPixel, *Pixel1);
            RenderAlpha(CompPixel, *Pixel2);
            CompPixel++;
            Pixel0++;
            Pixel1++;
            Pixel2++;
        }
        CompRow += CompBuffer->Pitch;
        Row0 += CompBuffer->Pitch;
        Row1 += CompBuffer->Pitch;
        Row2 += CompBuffer->Pitch;
    }
}

static void
UncacheFrames(int16 Min, int16 Max, cache_pool *Cache)
{
    for (int16 i = Min; i < Max; i++)
        Cache->Frame[i].Cached = false;
};

static void
CacheKeyframeAtIndex(uint16 i, struct property_channel *Property, cache_pool *Cache)
{
    Assert(Property->NumberOfKeyframes > 0);
    uint16 *Sorted = Property->Sorted + i;
    if (Property->NumberOfKeyframes == 1) {
        // nothing happens
    } else if (Property->NumberOfKeyframes == 2) {
        UncacheFrames(Property->Keyframe[0].FrameNumber, Property->Keyframe[1].FrameNumber, Cache);
    } else if (i == 0) {
        UncacheFrames(Property->Keyframe[*Sorted].FrameNumber, Property->Keyframe[*(Sorted+1)].FrameNumber, Cache);
    } else if (i == Property->NumberOfKeyframes - 1) {
        UncacheFrames(Property->Keyframe[*(Sorted-1)].FrameNumber, Property->Keyframe[*Sorted].FrameNumber, Cache);
    } else {
        UncacheFrames(Property->Keyframe[*(Sorted-1)].FrameNumber, Property->Keyframe[*(Sorted+1)].FrameNumber, Cache);
    }
}

static void
SortAndCacheKeyframeAtFrame(uint16 f, struct property_channel *Property, cache_pool *Cache)
{
    Assert(Property->NumberOfKeyframes > 0);
    if (Property->NumberOfKeyframes == 1) {
    } else if (Property->NumberOfKeyframes == 2) {
        UncacheFrames(Property->KeyframePTR[0]->FrameNumber, Property->KeyframePTR[1]->FrameNumber, Cache);
    } else {
        int i = 0;
        for (; i < Property->NumberOfKeyframes - 1; i++) {
            if (Property->KeyframePTR[i]->FrameNumber > Property->KeyframePTR[i+1]->FrameNumber) {
                struct keyframe *Temp = Property->KeyframePTR[i];
                Property->KeyframePTR[i] = Property->KeyframePTR[i+1];
                Property->KeyframePTR[i+1] = Temp;
                break;
            }
            if (Property->KeyframePTR[i]->FrameNumber >= f)
                break;
        }
        if (i == 0) {
            UncacheFrames(Property->KeyframePTR[i]->FrameNumber, Property->KeyframePTR[i+1]->FrameNumber, Cache);
        } else if (i == Property->NumberOfKeyframes - 1) {
            UncacheFrames(Property->KeyframePTR[i-1]->FrameNumber, Property->KeyframePTR[i]->FrameNumber, Cache);
        } else {
            UncacheFrames(Property->KeyframePTR[i-1]->FrameNumber, Property->KeyframePTR[i+1]->FrameNumber, Cache);
        }
    }
}
#endif