45 #ifndef AVIR_CLANCIR_INCLUDED
46 #define AVIR_CLANCIR_INCLUDED
58 #define LANCIR_PI 3.1415926535897932
140 const int SrcHeight,
int SrcScanlineSize, T*
const NewBuf,
141 const int NewWidth,
const int NewHeight,
const int ElCount,
142 const double kx0 = 0.0,
const double ky0 = 0.0,
double ox = 0.0,
145 if( NewWidth <= 0 || NewHeight <= 0 )
150 if( SrcWidth <= 0 || SrcHeight <= 0 )
152 memset( NewBuf, 0, (
size_t) NewWidth * NewHeight * ElCount *
158 const double la = 3.0;
164 kx = (double) SrcWidth / NewWidth;
165 ox += ( kx - 1.0 ) * 0.5;
171 ox += ( kx0 - 1.0 ) * 0.5;
180 ky = (double) SrcHeight / NewHeight;
181 oy += ( ky - 1.0 ) * 0.5;
187 oy += ( ky0 - 1.0 ) * 0.5;
218 rsv.
update( ky, oy, ElCount, SrcHeight, NewHeight, *rfv );
220 const int NewWidthE = NewWidth * ElCount;
222 if( SrcScanlineSize < 1 )
224 SrcScanlineSize = SrcWidth * ElCount;
229 const size_t FltBufLenNew = (size_t) NewWidthE * (
size_t) SrcHeight;
240 const T* ips = SrcBuf;
246 for( i = 0; i < SrcHeight; i++ )
248 copyScanline3h( ips,
rsh, SrcWidth );
250 ips += SrcScanlineSize;
257 for( i = 0; i < SrcHeight; i++ )
261 ips += SrcScanlineSize;
268 for( i = 0; i < SrcHeight; i++ )
270 copyScanline4h( ips,
rsh, SrcWidth );
272 ips += SrcScanlineSize;
279 for( i = 0; i < SrcHeight; i++ )
281 copyScanline2h( ips,
rsh, SrcWidth );
283 ips += SrcScanlineSize;
290 const int spvlennew = NewHeight * ElCount;
299 const bool IsIOFloat = ( (T) 0.25 != 0 );
300 const int Clamp = (
sizeof( T ) == 1 ? 255 : 65535 );
306 for( i = 0; i < NewWidth; i++ )
308 copyScanline3v( ip,
rsv, SrcHeight, NewWidthE );
309 resize3(
spv, NewHeight,
rsv.
pos, rfv -> KernelLen );
310 copyOutput3(
spv, opd, NewHeight, NewWidthE, IsIOFloat,
320 for( i = 0; i < NewWidth; i++ )
334 for( i = 0; i < NewWidth; i++ )
336 copyScanline4v( ip,
rsv, SrcHeight, NewWidthE );
337 resize4(
spv, NewHeight,
rsv.
pos, rfv -> KernelLen );
338 copyOutput4(
spv, opd, NewHeight, NewWidthE, IsIOFloat,
348 for( i = 0; i < NewWidth; i++ )
350 copyScanline2v( ip,
rsv, SrcHeight, NewWidthE );
351 resize2(
spv, NewHeight,
rsv.
pos, rfv -> KernelLen );
352 copyOutput2(
spv, opd, NewHeight, NewWidthE, IsIOFloat,
385 const int vr = (int) ( v + 0.5f );
408 static void copyOutput1(
const float* ip, T* op,
int l,
const int opinc,
409 const bool IsIOFloat,
const int Clamp )
415 op[ 0 ] = (T) ip[ 0 ];
434 static void copyOutput2(
const float* ip, T* op,
int l,
const int opinc,
435 const bool IsIOFloat,
const int Clamp )
441 op[ 0 ] = (T) ip[ 0 ];
442 op[ 1 ] = (T) ip[ 1 ];
462 static void copyOutput3(
const float* ip, T* op,
int l,
const int opinc,
463 const bool IsIOFloat,
const int Clamp )
469 op[ 0 ] = (T) ip[ 0 ];
470 op[ 1 ] = (T) ip[ 1 ];
471 op[ 2 ] = (T) ip[ 2 ];
492 static void copyOutput4(
const float* ip, T* op,
int l,
const int opinc,
493 const bool IsIOFloat,
const int Clamp )
499 op[ 0 ] = (T) ip[ 0 ];
500 op[ 1 ] = (T) ip[ 1 ];
501 op[ 2 ] = (T) ip[ 2 ];
502 op[ 3 ] = (T) ip[ 3 ];
523 class CResizeScanline;
563 bool update(
const double la,
const double k )
573 NormFreq = ( k <= 1.0 ? 1.0 : 1.0 / k );
616 const int Frac = (int) floor( x *
FracCount );
680 CSinGen(
const double si,
const double ph,
const double g = 1.0 )
681 : svalue1( sin( ph ) * g )
682 , svalue2( sin( ph - si ) * g )
683 , sincr( 2.0 * cos( si ))
693 const double res = svalue1;
695 svalue1 = sincr * res - svalue2;
729 if( t + FracDelay < -
Len2 )
738 int mt = ( FracDelay >= 1.0 - 1e-13 && FracDelay <= 1.0 + 1e-13 ?
743 double ut = t + FracDelay;
749 double ut = t + FracDelay;
751 if( fabs( ut ) <= 1e-13 )
809 p[ i ] = (T) ( p[ i ] * s );
891 void update(
const double k,
const double o0,
const int ElCount,
906 const int fl2m1 = rf.
fl2 - 1;
907 padl = fl2m1 - (int) floor( o0 );
914 padr = (int) floor( o0 + k * ( DstLen - 1 )) + rf.
fl2 + 1 -
922 const int splennew = (
padl + SrcLen +
padr ) * ElCount;
924 if( splennew >
splen )
938 const float*
const spo =
sp + (
padl - fl2m1 ) * ElCount;
941 for( i = 0; i < DstLen; i++ )
943 const double o = o0 + k * i;
944 const int ix = (int) floor( o );
945 pos[ i ].
ip = spo + ix * ElCount;
994 for( i = 0; i < rs.
padl; i++ )
1000 for( i = 0; i < l - 1; i++ )
1007 for( i = 0; i <= rs.
padr; i++ )
1015 static void copyScanline2h(
const T* ip, CResizeScanline& rs,
const int l )
1020 for( i = 0; i < rs.padl; i++ )
1027 for( i = 0; i < l - 1; i++ )
1035 for( i = 0; i <= rs.padr; i++ )
1044 static void copyScanline3h(
const T* ip, CResizeScanline& rs,
const int l )
1049 for( i = 0; i < rs.padl; i++ )
1057 for( i = 0; i < l - 1; i++ )
1066 for( i = 0; i <= rs.padr; i++ )
1076 static void copyScanline4h(
const T* ip, CResizeScanline& rs,
const int l )
1081 for( i = 0; i < rs.padl; i++ )
1090 for( i = 0; i < l - 1; i++ )
1100 for( i = 0; i <= rs.padr; i++ )
1128 for( i = 0; i < rs.
padl; i++ )
1134 for( i = 0; i < l - 1; i++ )
1141 for( i = 0; i <= rs.
padr; i++ )
1149 static void copyScanline2v(
const T* ip, CResizeScanline& rs,
const int l,
1155 for( i = 0; i < rs.padl; i++ )
1162 for( i = 0; i < l - 1; i++ )
1170 for( i = 0; i <= rs.padr; i++ )
1179 static void copyScanline3v(
const T* ip, CResizeScanline& rs,
const int l,
1185 for( i = 0; i < rs.padl; i++ )
1193 for( i = 0; i < l - 1; i++ )
1202 for( i = 0; i <= rs.padr; i++ )
1212 static void copyScanline4v(
const T* ip, CResizeScanline& rs,
const int l,
1218 for( i = 0; i < rs.padl; i++ )
1227 for( i = 0; i < l - 1; i++ )
1237 for( i = 0; i <= rs.padr; i++ )
1247 #define LANCIR_LF_PRE \
1248 CResizePos* const rpe = rp + DstLen; \
1251 const float* ip = rp -> ip; \
1252 const float* const flt = rp -> flt;
1254 #define LANCIR_LF_POST \
1274 flt[ 0 ] * ip[ 0 ] +
1275 flt[ 1 ] * ip[ 1 ] +
1276 flt[ 2 ] * ip[ 2 ] +
1277 flt[ 3 ] * ip[ 3 ] +
1278 flt[ 4 ] * ip[ 4 ] +
1290 for( i = 0; i < kl; i++ )
1292 sum += flt[ i ] * ip[ i ];
1301 static void resize2(
float* op,
int DstLen, CResizePos* rp,
const int kl )
1307 flt[ 0 ] * ip[ 0 ] +
1308 flt[ 1 ] * ip[ 2 ] +
1309 flt[ 2 ] * ip[ 4 ] +
1310 flt[ 3 ] * ip[ 6 ] +
1311 flt[ 4 ] * ip[ 8 ] +
1312 flt[ 5 ] * ip[ 10 ];
1315 flt[ 0 ] * ip[ 1 ] +
1316 flt[ 1 ] * ip[ 3 ] +
1317 flt[ 2 ] * ip[ 5 ] +
1318 flt[ 3 ] * ip[ 7 ] +
1319 flt[ 4 ] * ip[ 9 ] +
1320 flt[ 5 ] * ip[ 11 ];
1333 for( i = 0; i < kl; i++ )
1335 const float xx = flt[ i ];
1336 sum[ 0 ] += xx * ip[ 0 ];
1337 sum[ 1 ] += xx * ip[ 1 ];
1348 static void resize3(
float* op,
int DstLen, CResizePos* rp,
const int kl )
1354 flt[ 0 ] * ip[ 0 ] +
1355 flt[ 1 ] * ip[ 3 ] +
1356 flt[ 2 ] * ip[ 6 ] +
1357 flt[ 3 ] * ip[ 9 ] +
1358 flt[ 4 ] * ip[ 12 ] +
1359 flt[ 5 ] * ip[ 15 ];
1362 flt[ 0 ] * ip[ 1 ] +
1363 flt[ 1 ] * ip[ 4 ] +
1364 flt[ 2 ] * ip[ 7 ] +
1365 flt[ 3 ] * ip[ 10 ] +
1366 flt[ 4 ] * ip[ 13 ] +
1367 flt[ 5 ] * ip[ 16 ];
1370 flt[ 0 ] * ip[ 2 ] +
1371 flt[ 1 ] * ip[ 5 ] +
1372 flt[ 2 ] * ip[ 8 ] +
1373 flt[ 3 ] * ip[ 11 ] +
1374 flt[ 4 ] * ip[ 14 ] +
1375 flt[ 5 ] * ip[ 17 ];
1389 for( i = 0; i < kl; i++ )
1391 const float xx = flt[ i ];
1392 sum[ 0 ] += xx * ip[ 0 ];
1393 sum[ 1 ] += xx * ip[ 1 ];
1394 sum[ 2 ] += xx * ip[ 2 ];
1406 static void resize4(
float* op,
int DstLen, CResizePos* rp,
const int kl )
1416 for( i = 0; i < kl; i++ )
1418 const float xx = flt[ i ];
1419 sum[ 0 ] += xx * ip[ 0 ];
1420 sum[ 1 ] += xx * ip[ 1 ];
1421 sum[ 2 ] += xx * ip[ 2 ];
1422 sum[ 3 ] += xx * ip[ 3 ];
1434 #undef LANCIR_LF_PRE
1435 #undef LANCIR_LF_POST
1442 #endif // AVIR_CLANCIR_INCLUDED
LANCIR image resizer class.
Definition: lancir.h:77
static void resize1(float *op, int DstLen, CResizePos *rp, const int kl)
Definition: lancir.h:1268
CResizeScanline rsh
Definition: lancir.h:972
#define LANCIR_PI
Definition: lancir.h:58
static int roundclamp(const float v, const int Clamp)
Definition: lancir.h:378
float * FltBuf
Definition: lancir.h:362
double Prevk
Definition: lancir.h:955
const float * ip
Definition: lancir.h:821
int splen
Definition: lancir.h:961
int spvlen
Definition: lancir.h:368
double FreqA
Definition: lancir.h:634
void makeFilter(const double FracDelay, T *op) const
Definition: lancir.h:722
int FilterBufLen
Definition: lancir.h:655
CSinGen(const double si, const double ph, const double g=1.0)
Definition: lancir.h:680
static void copyOutput1(const float *ip, T *op, int l, const int opinc, const bool IsIOFloat, const int Clamp)
Definition: lancir.h:408
int PrevElCount
Definition: lancir.h:959
double generate()
Definition: lancir.h:691
CResizeScanline rsv
Definition: lancir.h:974
float * FilterBuf
Definition: lancir.h:646
void normalizeFilter(T *const p) const
Definition: lancir.h:795
double Freq
Definition: lancir.h:632
int PrevSrcLen
Definition: lancir.h:951
int KernelLen
Definition: lancir.h:534
int poslen
Definition: lancir.h:963
int FiltersLen
Definition: lancir.h:657
Sine signal generator class.
Definition: lancir.h:668
CResizeFilters rfh
Definition: lancir.h:967
float * getFilter(const double x)
Definition: lancir.h:614
size_t FltBufLen
Definition: lancir.h:364
double Prevo
Definition: lancir.h:957
int FracCount
Definition: lancir.h:640
static void copyScanline1v(const T *ip, CResizeScanline &rs, const int l, const int ipinc)
Definition: lancir.h:1122
float * flt
Definition: lancir.h:823
float ** Filters
Definition: lancir.h:648
static void copyScanline1h(const T *ip, CResizeScanline &rs, const int l)
Definition: lancir.h:989
double Len2
Definition: lancir.h:636
void resizeImage(const T *const SrcBuf, const int SrcWidth, const int SrcHeight, int SrcScanlineSize, T *const NewBuf, const int NewWidth, const int NewHeight, const int ElCount, const double kx0=0.0, const double ky0=0.0, double ox=0.0, double oy=0.0)
Definition: lancir.h:139
void reset()
Definition: lancir.h:874
int PrevDstLen
Definition: lancir.h:953
double Prevla
Definition: lancir.h:651
CResizePos * pos
Definition: lancir.h:844
int FracFill
Definition: lancir.h:643
float * sp
Definition: lancir.h:841
double Prevk
Definition: lancir.h:653
int padr
Definition: lancir.h:838
int fl2
Definition: lancir.h:638
float * spv
Definition: lancir.h:366
bool update(const double la, const double k)
Definition: lancir.h:563
int padl
Definition: lancir.h:835
void update(const double k, const double o0, const int ElCount, const int SrcLen, const int DstLen, CResizeFilters &rf)
Definition: lancir.h:891
CResizeFilters rfv0
Definition: lancir.h:969
double NormFreq
Definition: lancir.h:630