forked from tvspelsfreak/texconv
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtwiddler.cpp
More file actions
39 lines (32 loc) · 1005 Bytes
/
Copy pathtwiddler.cpp
File metadata and controls
39 lines (32 loc) · 1005 Bytes
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
#include "twiddler.h"
Twiddler::Twiddler(int w, int h) {
m_width = w;
m_height = h;
m_index = new int[m_width * m_height];
int index = 0;
if (m_width < m_height)
for (int y=0; y<m_height; y+=m_width)
index += twiddle(m_index, m_width, 0, y, m_width, index);
else
for (int x=0; x<m_width; x+=m_height)
index += twiddle(m_index, m_width, x, 0, m_height, index);
}
Twiddler::~Twiddler() {
delete[] m_index;
}
int Twiddler::twiddle(int* output, int stride, int x, int y, int blocksize, int seq) const {
int before = seq;
switch (blocksize) {
case 1:
output[seq++] = y * stride + x;
break;
default:
blocksize = blocksize >> 1;
seq += twiddle(output, stride, x, y, blocksize, seq);
seq += twiddle(output, stride, x, y + blocksize, blocksize, seq);
seq += twiddle(output, stride, x + blocksize, y, blocksize, seq);
seq += twiddle(output, stride, x + blocksize, y + blocksize, blocksize, seq);
break;
}
return (seq - before);
}