📄 trans_cdf22.c
字号:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <crblib/inc.h>
#include "transform.h"
// @@ can I do better rounding here, like a (+1) in each * 0.5f ?
void forwardCDF22(float *data,float *low,float *high,int half)
{
int x;
float *ptr;
assert( half >= 2 );
ptr = data;
*high = ptr[1] - ((ptr[2] + ptr[0]) * 0.5f);
*low = ptr[0] + (high[0] * 0.5f);
ptr += 2; high++; low++;
for(x=(half-2);x--;)
{
*high = ptr[1] - ((ptr[2] + ptr[0]) * 0.5f);
*low = ptr[0] + ((high[0] + high[-1])*0.25f);
/*
p0 + 1/4*(p1 - (p0 +p2)/2 + p-1 - (p0 + p-2)/2 )
1/4 * [ 3 * p0 + p1 + p-1 - (p2 + p-2)/2 ) ]
*/
ptr += 2;
high++; low++;
}
*high = ptr[1] - ptr[0];
*low = *ptr + ((high[0] + high[-1])*0.25f);
}
void inverseCDF22(float *data,float *low,float *high,int half)
{
float *ptr;
int x;
ptr = data;
ptr[0] = low[0] - ((high[0])*0.5f);
ptr += 2; high++; low++;
for(x=(half-1);x--;)
{
ptr[ 0] = low[0] - ((high[0] + high[-1])*0.25f);
ptr[-1] = high[-1] + ((ptr[0] + ptr[-2])*0.5f);
ptr += 2; high++; low++;
}
ptr[-1] = high[-1] + ptr[-2];
}
void inverseCDF22rows(RowAbstract *out,RowBuffer * lowTB,RowBuffer * highTB,int y)
{
float *low0,*high0,*high1;
int x,width;
width = out->width;
low0 = RowBuffer_Row(lowTB,0);
high0 = RowBuffer_Row(highTB,0);
high1 = RowBuffer_Row(highTB,-1);
// we normally write two rows out;
// the first time we can only do one, the last time we can do three
// 3dnow : PAVGUSB does 8 ubyte averages: A = (B+C+1)>>1 !!!
// katmai-mmx has one too;
// however, we can't get the wavelet coefficients in bytes;
// is there a PAVGW ?
if ( y == 0 ) // first one
{
float *out0;
out0 = RowAbstract_Row(out,0);
for(x=width;x--;)
{
*out0++ = (*low0++) - ((*high0++)*0.5f);
}
RowAbstract_Advance(out,1);
}
else if ( y == (out->halfh-1) ) // last one
{
float *out0,*out1,*outP,*out2;
outP = RowAbstract_Row(out,-1);
out0 = RowAbstract_Row(out,0);
out1 = RowAbstract_Row(out,1);
out2 = RowAbstract_Row(out,2);
for(x=width;x--;)
{
*out1 = *low0 - ((*high0 + *high1)*0.25f);
*out0 = *high1 + ((*out1 + *outP )*0.5f );
*out2 = *high0 + *out1;
low0++; high0++; high1++;
out0++; out1++; out2++; outP++;
}
RowAbstract_Advance(out,3);
}
else
{
float *out0,*out1,*outP;
outP = RowAbstract_Row(out,-1);
out0 = RowAbstract_Row(out,0);
out1 = RowAbstract_Row(out,1);
for(x=width;x--;)
{
*out1 = *low0 - ((*high0 + *high1)*0.25f);
*out0 = *high1 + ((*out1 + *outP )*0.5f);
low0++; high0++; high1++;
out0++; out1++; outP++;
}
RowAbstract_Advance(out,2);
}
}
Transform transformCDF22 =
{
forwardCDF22,
inverseCDF22,
"CDF22",
1,2,
inverseCDF22rows
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -