Skip to content

Instantly share code, notes, and snippets.

@hoheinzollern
Created June 2, 2010 15:09
Show Gist options
  • Save hoheinzollern/422483 to your computer and use it in GitHub Desktop.
Save hoheinzollern/422483 to your computer and use it in GitHub Desktop.
void DWT::transform1d(float *src, int length, int step)
{
float *tmp = new float[length];
float W = 1/sqrt(2.0f);
for (int len = length/2; len >= PREVIEW; len /= 2) {
for (int i = 0; i < len; i++) {
float c = src[i*2*step];
float w = src[(i*2+1)*step];
tmp[i] = (c+w)*W;
tmp[i+len] = (c-w)*W;
}
for (int i = 0; i < len*2; i++)
src[i*step] = tmp[i];
}
delete[] tmp;
}
void DWT::untransform1d(float *src, int length, int step)
{
float *tmp = new float[length];
float W = 1/sqrt(2.0f);
for (int len = PREVIEW; len < length; len *= 2) {
for (int i = 0; i < len; i++) {
float c = src[i*step];
float w = src[(i+len)*step];
tmp[i*2] = (c+w)*W;
tmp[i*2+1] = (c-w)*W;
}
for (int i = 0; i < len*2; i++)
src[i*step] = tmp[i];
}
delete[] tmp;
}
void DWT::transform()
{
for (int i = 0; i < height; i++)
transform1d(coeff + i * width, width, 1);
for (int i = 0; i < width; i++)
transform1d(coeff + i, height, width);
}
void DWT::untrasform()
{
for (int i = 0; i < height; i++)
untransform1d(coeff + i * width, width, 1);
for (int i = 0; i < width; i++)
untransform1d(coeff + i, height, width);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment