1584 lines
39 KiB
C++
1584 lines
39 KiB
C++
#include "SCENE.h"
|
|
|
|
//#pragma optimize("",off)
|
|
#define BACK_TileSize_Po2 2
|
|
#define BACK_TileSize_Po2x2 (BACK_TileSize_Po2<<1)
|
|
#define BACK_TileSize (1<<BACK_TileSize_Po2)
|
|
|
|
|
|
u32 BACKGroundStat = 0;
|
|
u32 DISTANCETOLERANCE = 300;
|
|
Vector BACKVirtualGain = Vector(1,1,1);
|
|
|
|
typedef struct BACK_Tile_Sign_
|
|
{
|
|
// s32 Hist;
|
|
u8 Neighboroud_POS;
|
|
u8 Neighboroud_NEG;
|
|
u8 Neighboroud_UND;
|
|
u32 Learn;
|
|
u8 Local_Neighboroud_POS;
|
|
u8 Local_Neighboroud_NEG;
|
|
u8 Local_Neighboroud_UND;
|
|
u32 History_FRONT;
|
|
u32 History_BACK;
|
|
u32 History_BACK_ERRORS;
|
|
u32 MASK[3];
|
|
s32 Average_FRONT;
|
|
s32 Average_FRONT_IM;
|
|
s32 Average_FRONT_RE;
|
|
s32 Average_BACK;
|
|
s32 Average_BACK_IM;
|
|
s32 Average_BACK_RE;
|
|
|
|
} BACK_Tile_Sign;
|
|
|
|
u32 BCK_ComputeAverage(u8 *pBase,s32 *OptPitch)
|
|
{
|
|
u32 Counter = 1<<(BACK_TileSize_Po2*2);
|
|
u32 Avergae = 0;
|
|
while (Counter--) {Avergae += pBase[*(OptPitch++)];};
|
|
return Avergae>>(BACK_TileSize_Po2 * 2);
|
|
}
|
|
|
|
s32 BCK_ComputeMaxMinusMin(u8 *pBase,s32 *OptPitch)
|
|
{
|
|
/*
|
|
C D E F
|
|
8 9 A B
|
|
4 5 6 7
|
|
0 1 2 3
|
|
*/
|
|
s32 Et = 0,Vm = 0;
|
|
s32 Value[16];
|
|
u32 *pValue = (u32*)Value;
|
|
u32 *pValueLas = pValue+16;
|
|
while (pValue<pValueLas) {*(pValue++) = pBase[*(OptPitch++)];};
|
|
/* Eq = e{Vi²} - e{Vi}² / N */
|
|
pValue = (u32*)Value;
|
|
s32 Local;
|
|
//while (pValue<pValueLas) {Local = *(pValue++);Et += Local * Local;Vm += Local;};
|
|
Vm >>= 4;
|
|
Et >>= 4;
|
|
|
|
Et = 0;Vm = 0;
|
|
Local = Value[0x0] - Value[0x5];Et += Local * Local;Vm += Local;
|
|
Local = Value[0x4] - Value[0x1];Et += Local * Local;Vm += Local;
|
|
Local = Value[0x2] - Value[0x7];Et += Local * Local;Vm += Local;
|
|
Local = Value[0x6] - Value[0x3];Et += Local * Local;Vm += Local;
|
|
Local = Value[0x8] - Value[0xD];Et += Local * Local;Vm += Local;
|
|
Local = Value[0xC] - Value[0x9];Et += Local * Local;Vm += Local;
|
|
Local = Value[0xE] - Value[0xB];Et += Local * Local;Vm += Local;
|
|
Local = Value[0xA] - Value[0xF];Et += Local * Local;Vm += Local;
|
|
Local = Value[0x0] - Value[0xF];Et += Local * Local;Vm += Local;
|
|
Local = Value[0xC] - Value[0x3];Et += Local * Local;Vm += Local;//*/
|
|
Vm /= 10;
|
|
Et /= 10;
|
|
return Et - (Vm * Vm)/10;
|
|
}
|
|
|
|
u32 GetBits(s32 Va,s32 Vb,s32 thresh)
|
|
{
|
|
s32 Cmp = (Va-Vb);
|
|
if (Cmp > thresh) return 1;
|
|
if (Cmp < -thresh) return 4;
|
|
return 2;
|
|
}
|
|
u32 BCK_ComputeSignIndex(u8 *pBase,s32 *OptPitch,s32 Add = 0)
|
|
{
|
|
/*
|
|
C D E F
|
|
8 9 A B
|
|
4 5 6 7
|
|
0 1 2 3
|
|
*/
|
|
u32 BitIndex = 0;
|
|
s32 Value[16],*pValue = Value,*pValueLas = pValue+16;
|
|
u32 Et = ((u32)sqrtf(BCK_ComputeMaxMinusMin(pBase,OptPitch)))>>1;
|
|
while (pValue<pValueLas) *(pValue++) = pBase[*(OptPitch++)];
|
|
if (Et < 4) Et = 4;
|
|
#define DELTASUB (Et)
|
|
BitIndex |= GetBits(Value[0x0],Value[0x5],DELTASUB)<<0;
|
|
BitIndex |= GetBits(Value[0x4],Value[0x1],DELTASUB)<<3;
|
|
BitIndex |= GetBits(Value[0x2],Value[0x7],DELTASUB)<<6;
|
|
BitIndex |= GetBits(Value[0x6],Value[0x3],DELTASUB)<<9;
|
|
BitIndex |= GetBits(Value[0x8],Value[0xD],DELTASUB)<<12;
|
|
BitIndex |= GetBits(Value[0xC],Value[0x9],DELTASUB)<<15;
|
|
BitIndex |= GetBits(Value[0xE],Value[0xB],DELTASUB)<<18;
|
|
BitIndex |= GetBits(Value[0xA],Value[0xF],DELTASUB)<<21;
|
|
BitIndex |= GetBits(Value[0x0],Value[0xF],DELTASUB)<<24;
|
|
BitIndex |= GetBits(Value[0xC],Value[0x3],DELTASUB)<<27;
|
|
return BitIndex;
|
|
}
|
|
u8 *BCK_GetBestPointer(u8 *pBase,u32 Pitch, s32 *OptPitch)
|
|
{
|
|
u32 Index,MFinder,IFInder;
|
|
u8 *IFinder;
|
|
IFinder = pBase;
|
|
if (BACK_TileSize_Po2 != 3) return pBase;
|
|
|
|
Index = BCK_ComputeMaxMinusMin(pBase,OptPitch);
|
|
MFinder = BCK_ComputeMaxMinusMin(pBase+1,OptPitch);
|
|
|
|
if (MFinder > Index) {IFinder = pBase+1;Index = MFinder;};
|
|
|
|
MFinder = BCK_ComputeMaxMinusMin(pBase+1+Pitch,OptPitch);
|
|
if (MFinder > Index) {IFinder = pBase+1+Pitch;Index = MFinder;};
|
|
|
|
MFinder = BCK_ComputeMaxMinusMin(pBase+Pitch,OptPitch);
|
|
if (MFinder > Index) {IFinder = pBase+Pitch;Index = MFinder;};
|
|
return IFinder;
|
|
}
|
|
|
|
u32 BCK_GetMask(u8 *pBase,u32 Pitch, s32 *OptPitch,u32 Mode)
|
|
{
|
|
u32 Index;
|
|
if (Mode)
|
|
pBase = BCK_GetBestPointer(pBase,Pitch, OptPitch);
|
|
#define ErrorNumberOne 8
|
|
Index = BCK_ComputeSignIndex(pBase,OptPitch,ErrorNumberOne);
|
|
return Index;
|
|
}
|
|
|
|
static u32 bffF = 0;
|
|
|
|
BACK_Tile_Sign BackComp1[(640*640)>>(BACK_TileSize_Po2<<1)];
|
|
|
|
void BCK_SetTile(u8 *pBase,s32 *OptPitch,s32 Pitch)
|
|
{
|
|
for (u32 Counter1 = 0; Counter1 < BACK_TileSize*BACK_TileSize ; Counter1++)
|
|
{
|
|
pBase[*(OptPitch)] >>= 3;
|
|
if (BACK_TileSize_Po2 == 3)
|
|
{
|
|
pBase[*(OptPitch) + 1] >>= 3;
|
|
pBase[*(OptPitch) + 1 + Pitch] >>= 3;
|
|
pBase[*(OptPitch++) + Pitch] >>= 3;
|
|
}
|
|
}
|
|
}
|
|
void BCK_SetTile32(u32 *pBase,s32 *OptPitch,s32 Pitch,u32 Color,u32 And = 0xffffffff)
|
|
{
|
|
for (u32 Counter1 = 0; Counter1 < 16 ; Counter1++)
|
|
{
|
|
pBase[*(OptPitch)] &= And;
|
|
pBase[*(OptPitch)] |= Color;
|
|
if (BACK_TileSize_Po2 == 3)
|
|
{
|
|
pBase[*(OptPitch) + 1] &= And;
|
|
pBase[*(OptPitch) + 1 + Pitch] &= And;
|
|
pBase[*(OptPitch) + Pitch] &= And;
|
|
pBase[*(OptPitch) + 1] |= Color;
|
|
pBase[*(OptPitch) + 1 + Pitch] |= Color;
|
|
pBase[*(OptPitch) + Pitch] |= Color;
|
|
}
|
|
OptPitch++;
|
|
}
|
|
}
|
|
void BCK_SetTile8(u8 *pBase,s32 *OptPitch,u8 Color)
|
|
{
|
|
s32 *OptPitchLast = OptPitch + BACK_TileSize*BACK_TileSize;
|
|
while (OptPitch < OptPitchLast)
|
|
{
|
|
pBase[*(OptPitch++)] = Color;
|
|
}
|
|
}
|
|
void BCK_CopyTile8(u8 *pSrc,u8 *pDst,s32 *OptPitch)
|
|
{
|
|
s32 *OptPitchLast = OptPitch + BACK_TileSize*BACK_TileSize;
|
|
while (OptPitch < OptPitchLast)
|
|
{
|
|
pDst[*(OptPitch)] = pSrc[*(OptPitch++)];
|
|
}
|
|
}
|
|
void BCK_BlendTile8(u8 *pSrc,u8 *pDst,s32 *OptPitch)
|
|
{
|
|
s32 *OptPitchLast = OptPitch + BACK_TileSize*BACK_TileSize;
|
|
while (OptPitch < OptPitchLast)
|
|
{
|
|
pDst[*(OptPitch)] -= pDst[*(OptPitch)]>>1;
|
|
pDst[*(OptPitch)] = ((u32)pDst[*(OptPitch)] + (u32)(pSrc[*(OptPitch++)]>>1));
|
|
}
|
|
}
|
|
void BCK_SetTileColor(u8 *pBase,s32 *OptPitch,s32 Pitch,u8 Color)
|
|
{
|
|
for (u32 Counter1 = 0; Counter1 < BACK_TileSize*BACK_TileSize ; Counter1++)
|
|
{
|
|
pBase[*(OptPitch)] = Color;
|
|
pBase[*(OptPitch) + 1] = Color;
|
|
pBase[*(OptPitch) + 1 + Pitch] = Color;
|
|
pBase[*(OptPitch++) + Pitch] = Color;
|
|
}
|
|
}
|
|
u32 CompatibleComplexDistance(s32 BRI , s32 RE , s32 IM , s32 *Color , Vector *VirtualGain )
|
|
{
|
|
/*if (abs(((s32)(BRI>>4) - (s32)(((u8*)(Color))[2]))) > 40+(BRI>>6))
|
|
return 0;//*/
|
|
|
|
#if 1
|
|
/* Stupid RGB mode */
|
|
s32 C_RE,C_IM,Distance;
|
|
|
|
BRI = (s32)(VirtualGain->x * (float)BRI);
|
|
RE = (s32)(VirtualGain->y * (float)RE);
|
|
IM = (s32)(VirtualGain->z * (float)IM);
|
|
RE >>= 4;
|
|
IM >>= 4;
|
|
BRI >>= 4;
|
|
if (BRI > 255) BRI = 255;
|
|
if (RE > 255) RE = 255;
|
|
if (IM > 255) IM = 255;
|
|
|
|
|
|
RE -= (s32)(((u8*)(Color))[0]);
|
|
IM -= (s32)(((u8*)(Color))[1]);
|
|
BRI -= (s32)(((u8*)(Color))[2]);
|
|
|
|
Distance = IM*IM + RE*RE + BRI * BRI;
|
|
|
|
if (Distance > DISTANCETOLERANCE)
|
|
return 0;
|
|
else
|
|
return 1;//*/
|
|
#else
|
|
/* Spectrum mode */
|
|
s32 C_RE,C_IM,Distance;
|
|
RE >>= 4;
|
|
IM >>= 4;
|
|
|
|
BRI = (s32)(VirtualGain * (float)BRI);
|
|
BRI >>= 4;
|
|
if (BRI > 255) BRI = 255;
|
|
|
|
|
|
C_IM = (s32)(((u8*)(Color))[1]) - 128;
|
|
C_RE = (s32)(((u8*)(Color))[0]) - 128;
|
|
C_IM -= IM;
|
|
C_RE -= RE;
|
|
BRI -= (s32)(((u8*)(Color))[2]);
|
|
BRI >>= 2;
|
|
|
|
Distance = C_IM*C_IM + C_RE*C_RE + BRI * BRI;
|
|
|
|
if (Distance > 64)
|
|
return 0;
|
|
else
|
|
return 1;//*/
|
|
#endif
|
|
}
|
|
|
|
u32 BCK_TestAllSignFAST(MAP8 *MapSRC,MAP *SectroMap,BACK_Tile_Sign *pBaseBack,Vector *VirtualGain ,u32 FirstPass = 0)
|
|
{
|
|
s32 OptPitch[BACK_TileSize*BACK_TileSize];
|
|
u32 CurrentIndex = 0;
|
|
u8 *pbase;
|
|
pbase = MapSRC->GetBase();
|
|
for (int X = 0 ; X < BACK_TileSize ; X++)
|
|
for (int Y = 0 ; Y < BACK_TileSize ; Y++)
|
|
OptPitch[X+Y*BACK_TileSize] = (X + Y*MapSRC->PITCH)/*<<(BACK_TileSize_Po2 - 2)*/;
|
|
u32 BitIndex = 0;
|
|
BACKGroundStat= 0;
|
|
for (u32 Counter1 = 0; Counter1 < MapSRC->SY>>BACK_TileSize_Po2 ; Counter1++)
|
|
{
|
|
for (u32 Counter2 = 0; Counter2 < MapSRC->SX>>BACK_TileSize_Po2 ; Counter2++)
|
|
{
|
|
if (FirstPass) pBaseBack->MASK[2] = BCK_GetMask(pbase + (Counter2<<BACK_TileSize_Po2) ,MapSRC->PITCH,OptPitch,1);
|
|
if (pBaseBack->History_FRONT < 16)
|
|
{
|
|
} else
|
|
if ((GetBitNumber(pBaseBack->MASK[2] & pBaseBack->MASK[0]) > 8)
|
|
&& CompatibleComplexDistance(pBaseBack->Average_FRONT, pBaseBack->Average_FRONT_RE , pBaseBack->Average_FRONT_IM , SectroMap->GetBase() + ((Counter1*SectroMap->PITCH + Counter2)<<(BACK_TileSize_Po2 - 2)),VirtualGain)
|
|
)
|
|
{
|
|
BACKGroundStat++;
|
|
}
|
|
pBaseBack++;
|
|
}
|
|
pbase += MapSRC->PITCH<<BACK_TileSize_Po2;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
u32 BCK_TestAllSign(MAP8 *MapSRC,MAP *SectroMap,BACK_Tile_Sign *pBaseBack,u32 Learn,Vector *VirtualGain )
|
|
{
|
|
s32 OptPitch[BACK_TileSize*BACK_TileSize];
|
|
u32 CurrentIndex = 0;
|
|
u8 *pbase;
|
|
pbase = MapSRC->GetBase();
|
|
for (int X = 0 ; X < BACK_TileSize ; X++)
|
|
for (int Y = 0 ; Y < BACK_TileSize ; Y++)
|
|
OptPitch[X+Y*BACK_TileSize] = (X + Y*MapSRC->PITCH)/*<<(BACK_TileSize_Po2 - 2)*/;
|
|
u32 BitIndex = 0;
|
|
BACKGroundStat= 0;
|
|
for (u32 Counter1 = 0; Counter1 < MapSRC->SY>>BACK_TileSize_Po2 ; Counter1++)
|
|
{
|
|
for (u32 Counter2 = 0; Counter2 < MapSRC->SX>>BACK_TileSize_Po2 ; Counter2++)
|
|
{
|
|
u32 Index,UNDEFINED,iN;
|
|
u32 GetBitNumber(u32 Value);
|
|
pBaseBack->Neighboroud_POS =
|
|
pBaseBack->Neighboroud_NEG =
|
|
pBaseBack->Neighboroud_UND = 0;
|
|
|
|
Index = BCK_ComputeMaxMinusMin(pbase + (Counter2<<BACK_TileSize_Po2),OptPitch);
|
|
iN = BCK_GetMask(pbase + (Counter2<<BACK_TileSize_Po2) ,MapSRC->PITCH,OptPitch,1);
|
|
UNDEFINED = 0;
|
|
if (Index < 4)
|
|
{
|
|
//pBaseBack->Neighboroud_UND = 1;
|
|
//iN = 0xffffffff;
|
|
}
|
|
{
|
|
pBaseBack->Learn = 0;
|
|
|
|
if (pBaseBack->History_FRONT < 16)
|
|
{
|
|
pBaseBack->History_FRONT++;
|
|
pBaseBack->Average_FRONT += ((u8*)(SectroMap->GetBase() + ((Counter1*SectroMap->PITCH + Counter2)<<(BACK_TileSize_Po2 - 2))))[2];
|
|
pBaseBack->Average_FRONT_IM += (s32)((u8*)(SectroMap->GetBase() + ((Counter1*SectroMap->PITCH + Counter2)<<(BACK_TileSize_Po2 - 2))))[1];
|
|
pBaseBack->Average_FRONT_RE += (s32)((u8*)(SectroMap->GetBase() + ((Counter1*SectroMap->PITCH + Counter2)<<(BACK_TileSize_Po2 - 2))))[0];
|
|
|
|
#define MAX_BitLearned 15
|
|
#define MAX_BitLearned_C 15
|
|
if (GetBitNumber(iN | pBaseBack->MASK[0]) < MAX_BitLearned)
|
|
pBaseBack->MASK[0] |= iN ;
|
|
} else
|
|
if ((GetBitNumber(iN & pBaseBack->MASK[0]) > 8)
|
|
&& CompatibleComplexDistance(pBaseBack->Average_FRONT, pBaseBack->Average_FRONT_RE , pBaseBack->Average_FRONT_IM , SectroMap->GetBase() + ((Counter1*SectroMap->PITCH + Counter2)<<(BACK_TileSize_Po2 - 2)),VirtualGain)
|
|
// (abs(((s32)(pBaseBack->Average_FRONT>>4) - (s32)BCK_ComputeAverage(pbase + (Counter2<<BACK_TileSize_Po2),OptPitch))) < 10+(pBaseBack->Average_FRONT>>6))
|
|
)
|
|
{
|
|
//pBaseBack->MASK[0] |= iN ;
|
|
BACKGroundStat++;
|
|
pBaseBack->History_FRONT++;
|
|
// Blue pass
|
|
pBaseBack->Neighboroud_POS = 255;
|
|
}
|
|
if (pBaseBack->History_BACK < 16)
|
|
{
|
|
pBaseBack->History_BACK++;
|
|
pBaseBack->Average_BACK += ((u8*)(SectroMap->GetBase() + ((Counter1*SectroMap->PITCH + Counter2)<<(BACK_TileSize_Po2 - 2))))[2];
|
|
pBaseBack->Average_BACK_IM += ((u8*)(SectroMap->GetBase() + ((Counter1*SectroMap->PITCH + Counter2)<<(BACK_TileSize_Po2 - 2))))[1];
|
|
pBaseBack->Average_BACK_RE += ((u8*)(SectroMap->GetBase() + ((Counter1*SectroMap->PITCH + Counter2)<<(BACK_TileSize_Po2 - 2))))[0];
|
|
pBaseBack->History_BACK_ERRORS = 0;
|
|
if (GetBitNumber(iN | pBaseBack->MASK[1]) < MAX_BitLearned_C)
|
|
pBaseBack->MASK[1] |= iN ;
|
|
} else
|
|
if ((GetBitNumber(iN & pBaseBack->MASK[1]) > 8)
|
|
&& CompatibleComplexDistance(pBaseBack->Average_BACK, pBaseBack->Average_BACK_RE , pBaseBack->Average_BACK_IM , SectroMap->GetBase() + ((Counter1*SectroMap->PITCH + Counter2)<<(BACK_TileSize_Po2 - 2)),VirtualGain)
|
|
)
|
|
{
|
|
//pBaseBack->MASK[1] |= iN ;
|
|
pBaseBack->History_BACK++;
|
|
}
|
|
pBaseBack->History_BACK_ERRORS++;
|
|
|
|
|
|
if (pBaseBack->History_BACK > pBaseBack->History_FRONT)
|
|
{
|
|
pBaseBack->MASK[0] = pBaseBack->MASK[1];
|
|
pBaseBack->History_FRONT = pBaseBack->History_BACK;
|
|
pBaseBack->Average_FRONT = pBaseBack->Average_BACK;
|
|
pBaseBack->Average_FRONT_IM = pBaseBack->Average_BACK_IM;
|
|
pBaseBack->Average_FRONT_RE = pBaseBack->Average_BACK_RE;
|
|
pBaseBack->Average_BACK = pBaseBack->Average_BACK_IM = pBaseBack->Average_BACK_RE = pBaseBack->History_BACK = pBaseBack->MASK[1] = 0;
|
|
}
|
|
if (pBaseBack->History_FRONT > 128)
|
|
pBaseBack->History_FRONT = 128;
|
|
if ((!Learn) || (pBaseBack->History_BACK_ERRORS > pBaseBack->History_BACK<<1))
|
|
{
|
|
pBaseBack->Learn = 1;
|
|
pBaseBack->Average_BACK = pBaseBack->Average_BACK_RE = pBaseBack->Average_BACK_IM = pBaseBack->History_BACK = pBaseBack->MASK[1] = 0;
|
|
}
|
|
|
|
}
|
|
if (pBaseBack->Neighboroud_UND)
|
|
{
|
|
//pBaseBack->Neighboroud_NEG = pBaseBack->Neighboroud_POS = 0;
|
|
}
|
|
pBaseBack++;
|
|
}
|
|
pbase += MapSRC->PITCH<<BACK_TileSize_Po2;
|
|
}
|
|
return 0;
|
|
}
|
|
#define BLURPATCH(a) pBaseBack->a + (pBaseBack+1)->a + (pBaseBack-1)->a + (pBaseBack+BasePitch)->a + (pBaseBack-BasePitch)->a + (pBaseBack+BasePitch+1)->a + (pBaseBack+BasePitch-1)->a + (pBaseBack-BasePitch+1)->a + (pBaseBack-BasePitch-1)->a
|
|
|
|
u32 BCK_BlurAllSign(MAP *MapSRC,BACK_Tile_Sign *pBaseBackBase)
|
|
{
|
|
BACK_Tile_Sign *pBaseBack;
|
|
u32 CurrentIndex = 0;
|
|
s32 BasePitch;
|
|
u32 BitIndex = 0;
|
|
u32 Continue;
|
|
BasePitch = MapSRC->SX>>BACK_TileSize_Po2;
|
|
pBaseBack = pBaseBackBase;
|
|
for (u32 Counter1 = 0; Counter1 < (MapSRC->SY>>BACK_TileSize_Po2) ; Counter1++)
|
|
{
|
|
for (u32 Counter2 = 0; Counter2 < (MapSRC->SX>>BACK_TileSize_Po2) ; Counter2++)
|
|
{
|
|
if (pBaseBack->Neighboroud_POS > 128)
|
|
{
|
|
pBaseBack->Neighboroud_POS = 1;
|
|
pBaseBack->Neighboroud_NEG = 0;
|
|
}
|
|
else
|
|
{
|
|
pBaseBack->Neighboroud_POS = 0;
|
|
pBaseBack->Neighboroud_NEG = 1;
|
|
}
|
|
if (pBaseBack->Neighboroud_UND) pBaseBack->Neighboroud_POS = pBaseBack->Neighboroud_NEG = 0;
|
|
pBaseBack++;
|
|
}
|
|
}
|
|
|
|
Continue = 1;
|
|
while (Continue && (BitIndex < 30))
|
|
{
|
|
BitIndex++;
|
|
pBaseBack = pBaseBackBase;
|
|
for (u32 Counter1 = 0; Counter1 < (MapSRC->SY>>BACK_TileSize_Po2) ; Counter1++)
|
|
{
|
|
for (u32 Counter2 = 0; Counter2 < (MapSRC->SX>>BACK_TileSize_Po2) ; Counter2++)
|
|
{
|
|
pBaseBack->Local_Neighboroud_POS = pBaseBack->Local_Neighboroud_NEG =pBaseBack->Local_Neighboroud_UND = 0;
|
|
pBaseBack++;
|
|
}
|
|
}
|
|
|
|
pBaseBack = pBaseBackBase + BasePitch + 1;
|
|
for (u32 Counter1 = 1; Counter1 < (MapSRC->SY>>BACK_TileSize_Po2)-1 ; Counter1++)
|
|
{
|
|
for (u32 Counter2 = 1; Counter2 < (MapSRC->SX>>BACK_TileSize_Po2)-1 ; Counter2++)
|
|
{
|
|
if ((BitIndex<3) || pBaseBack->Neighboroud_UND)
|
|
{
|
|
pBaseBack->Local_Neighboroud_POS = BLURPATCH(Neighboroud_POS);
|
|
pBaseBack->Local_Neighboroud_NEG = BLURPATCH(Neighboroud_NEG);
|
|
pBaseBack->Local_Neighboroud_UND = BLURPATCH(Neighboroud_UND);
|
|
} else
|
|
{
|
|
pBaseBack->Local_Neighboroud_POS = pBaseBack->Neighboroud_POS*9;
|
|
pBaseBack->Local_Neighboroud_NEG = pBaseBack->Neighboroud_NEG*9;
|
|
}
|
|
|
|
pBaseBack++;
|
|
}
|
|
pBaseBack += 2;
|
|
}
|
|
Continue = 0;
|
|
|
|
pBaseBack = pBaseBackBase + BasePitch + 1;
|
|
|
|
for (u32 Counter1 = 1; Counter1 < (MapSRC->SY>>BACK_TileSize_Po2)-1 ; Counter1++)
|
|
{
|
|
for (u32 Counter2 = 1; Counter2 < (MapSRC->SX>>BACK_TileSize_Po2)-1 ; Counter2++)
|
|
{
|
|
pBaseBack->Neighboroud_POS =
|
|
pBaseBack->Neighboroud_NEG =
|
|
pBaseBack->Neighboroud_UND = 0;
|
|
pBaseBack->Local_Neighboroud_UND>>=1;
|
|
if (pBaseBack->Local_Neighboroud_POS > pBaseBack->Local_Neighboroud_NEG)
|
|
{
|
|
if (pBaseBack->Local_Neighboroud_UND> pBaseBack->Local_Neighboroud_POS)
|
|
pBaseBack->Neighboroud_UND = 1;
|
|
else
|
|
pBaseBack->Neighboroud_POS = 1;
|
|
} else
|
|
{
|
|
if (pBaseBack->Local_Neighboroud_NEG > pBaseBack->Local_Neighboroud_UND)
|
|
pBaseBack->Neighboroud_NEG = 1;
|
|
else
|
|
if (pBaseBack->Local_Neighboroud_UND> pBaseBack->Local_Neighboroud_POS)
|
|
pBaseBack->Neighboroud_UND = 1;
|
|
else
|
|
pBaseBack->Neighboroud_POS = 1;
|
|
}
|
|
Continue |= pBaseBack->Neighboroud_UND;
|
|
pBaseBack++;
|
|
}
|
|
pBaseBack+=2;
|
|
}
|
|
pBaseBack = pBaseBackBase;
|
|
for (u32 Counter1 = 0; Counter1 < (MapSRC->SY>>BACK_TileSize_Po2) ; Counter1++)
|
|
{
|
|
pBaseBack->Neighboroud_NEG = (pBaseBack+1)->Neighboroud_NEG;
|
|
pBaseBack->Neighboroud_POS = (pBaseBack+1)->Neighboroud_POS;
|
|
pBaseBack->Neighboroud_UND = (pBaseBack+1)->Neighboroud_UND;
|
|
pBaseBack+=(MapSRC->SX>>BACK_TileSize_Po2) - 1;
|
|
pBaseBack->Neighboroud_NEG = (pBaseBack-1)->Neighboroud_NEG;
|
|
pBaseBack->Neighboroud_POS = (pBaseBack-1)->Neighboroud_POS;
|
|
pBaseBack->Neighboroud_UND = (pBaseBack-1)->Neighboroud_UND;
|
|
pBaseBack++;
|
|
}
|
|
|
|
pBaseBack = pBaseBackBase;
|
|
for (u32 Counter1 = 0; Counter1 < (MapSRC->SX>>BACK_TileSize_Po2) ; Counter1++)
|
|
{
|
|
pBaseBack->Neighboroud_NEG = (pBaseBack+BasePitch)->Neighboroud_NEG;
|
|
pBaseBack->Neighboroud_POS = (pBaseBack+BasePitch)->Neighboroud_POS;
|
|
pBaseBack->Neighboroud_UND = (pBaseBack+BasePitch)->Neighboroud_UND;
|
|
pBaseBack+=((MapSRC->SY)>>BACK_TileSize_Po2) * (BasePitch);
|
|
pBaseBack -= BasePitch;
|
|
pBaseBack->Neighboroud_NEG = (pBaseBack-BasePitch)->Neighboroud_NEG;
|
|
pBaseBack->Neighboroud_POS = (pBaseBack-BasePitch)->Neighboroud_POS;
|
|
pBaseBack->Neighboroud_UND = (pBaseBack-BasePitch)->Neighboroud_UND;
|
|
pBaseBack-=((MapSRC->SY)>>BACK_TileSize_Po2) * (BasePitch);
|
|
pBaseBack += BasePitch;
|
|
pBaseBack++;
|
|
}//*/
|
|
|
|
}
|
|
pBaseBack = pBaseBackBase;
|
|
for (u32 Counter1 = 0; Counter1 < (MapSRC->SY>>BACK_TileSize_Po2) ; Counter1++)
|
|
{
|
|
for (u32 Counter2 = 0; Counter2 < (MapSRC->SX>>BACK_TileSize_Po2) ; Counter2++)
|
|
{
|
|
pBaseBack->Neighboroud_POS *= 255;
|
|
pBaseBack->Neighboroud_NEG *= 255;
|
|
pBaseBack++;
|
|
}
|
|
}
|
|
return CurrentIndex;
|
|
}
|
|
u32 BCK_DrawAllSign(MAP8 *MapSRC,MAP8 *MapCurrent,MAP8 *MapBack,BACK_Tile_Sign *pBaseBack)
|
|
{
|
|
s32 OptPitch[BACK_TileSize*BACK_TileSize];
|
|
for (int X = 0 ; X < BACK_TileSize ; X++)
|
|
for (int Y = 0 ; Y < BACK_TileSize ; Y++)
|
|
OptPitch[X+Y*BACK_TileSize] = (X + Y*MapSRC->PITCH)/*<<(BACK_TileSize_Po2 - 2)*/;
|
|
u32 CurrentIndex = 0;
|
|
u8 *pbase,*pCurrent,*pBackBuffer;
|
|
pbase = (u8*)MapSRC->GetBase();
|
|
pCurrent = (u8*)MapCurrent->GetBase();
|
|
pBackBuffer = (u8*)MapBack->GetBase();
|
|
u32 BitIndex = 0;
|
|
for (u32 Counter1 = 0; Counter1 < MapSRC->SY>>BACK_TileSize_Po2 ; Counter1++)
|
|
{
|
|
for (u32 Counter2 = 0; Counter2 < MapSRC->SX>>BACK_TileSize_Po2 ; Counter2++)
|
|
{
|
|
|
|
if (pBaseBack->Neighboroud_POS < 128)
|
|
{
|
|
BCK_SetTile8(pbase + (Counter2<<BACK_TileSize_Po2),OptPitch,255);
|
|
}
|
|
else
|
|
{
|
|
BCK_CopyTile8(pCurrent+ (Counter2<<BACK_TileSize_Po2),pBackBuffer+ (Counter2<<BACK_TileSize_Po2),OptPitch);
|
|
BCK_SetTile8(pbase + (Counter2<<BACK_TileSize_Po2),OptPitch,0);
|
|
}
|
|
pBaseBack++;
|
|
}
|
|
pbase += MapSRC->PITCH<<BACK_TileSize_Po2;
|
|
pCurrent += MapCurrent->PITCH<<BACK_TileSize_Po2;
|
|
pBackBuffer += MapBack->PITCH<<BACK_TileSize_Po2;
|
|
}
|
|
return CurrentIndex;
|
|
}
|
|
|
|
u32 Saturate(u8 K)
|
|
{
|
|
if (K < 128) return K<<1;
|
|
return 255;
|
|
}
|
|
u32 Blend(u32 a , u32 b , u32 Factor)
|
|
{
|
|
u32 Res = ((((a & 0xff00ff) * Factor) + ((b & 0xff00ff) * (255-Factor)))>>8)&0xff00ff;
|
|
a >>= 8;
|
|
b >>= 8;
|
|
u32 Res1 = ((((a & 0xff00ff) * Factor) + ((b & 0xff00ff) * (255-Factor)))>>8)&0xff00ff;
|
|
return Res | (Res1<<8);
|
|
}
|
|
void MAP_2_SPECTRUM(/*IN*/MAP *pSrc)
|
|
{
|
|
s32 *PPs,*PPl,*PPll;
|
|
u32 MINMAX_TABLE[8] = {0x120,0x210,0x102,0x012,0x021,0x201,0x201,0x102};
|
|
u32 IT_TABLE_U[8] = {0x000,0x2FF,0x1ff,0x200,0x0FF,0x100,0x100,0x1FF};
|
|
u32 Oo256[256];
|
|
for (int i = 1 ; i < 256 ; i ++)
|
|
{
|
|
Oo256[i] = 65535/i;
|
|
}
|
|
Oo256[0] = 0;
|
|
|
|
/* 1 Compute 8b */
|
|
PPs = pSrc->GetBase();
|
|
PPl = pSrc->GetBase() + pSrc->PITCH * pSrc->SY;
|
|
while (PPs < PPl)
|
|
{
|
|
PPll = PPs + pSrc->SX;
|
|
while (PPs < PPll)
|
|
{
|
|
u32 RGB[3],Index,MINMAX;
|
|
u32 Brg,Sat,Spc;
|
|
RGB[0] = (u32)((u8*)PPs)[2];
|
|
RGB[1] = (u32)((u8*)PPs)[1];
|
|
RGB[2] = (u32)((u8*)PPs)[0];
|
|
Index = ((RGB[0]-RGB[1]))>>31;
|
|
Index <<= 1;
|
|
Index |= ((RGB[0]-RGB[2]))>>31;
|
|
Index <<= 1;
|
|
Index |= ((RGB[1]-RGB[2]))>>31;
|
|
MINMAX = MINMAX_TABLE[Index];
|
|
Brg = RGB[MINMAX & 0xf]; // MAX
|
|
Sat = RGB[(MINMAX>>4) & 0xf]; // MIN
|
|
Spc = RGB[(MINMAX>>8) & 0xf]; // AVE
|
|
|
|
u32 OoB;
|
|
Spc -= Sat;
|
|
OoB = Oo256[Brg-Sat];
|
|
/* Normalize with 1 / MAX */
|
|
Spc = ((u32)Spc * OoB)>>9;
|
|
OoB = IT_TABLE_U[Index];
|
|
Spc = (OoB & 0xf00) + (Spc ^ (OoB & 0xff));
|
|
|
|
// Divide SPC by 3
|
|
Spc += Spc >> 2;
|
|
Spc += Spc >> 4;
|
|
Spc >>= 2;
|
|
|
|
Spc &= 0xff;
|
|
|
|
RGB[0] = (Brg+Sat)>>1;
|
|
RGB[1] = Spc;
|
|
RGB[2] = (Brg-Sat);
|
|
((u8*)PPs)[2] = RGB[0];
|
|
((u8*)PPs)[1] = RGB[1];
|
|
((u8*)PPs)[0] = RGB[2];
|
|
|
|
PPs ++;
|
|
}
|
|
PPs += pSrc->PITCH - pSrc->SX;
|
|
}
|
|
}
|
|
void SPECTRUM_2_ComplexSpectrum(/*IN*/MAP *pSrc)
|
|
{
|
|
s32 *PPs,*PPl,*PPll;
|
|
signed char Spectrum_2_Complex_Im[256] ;
|
|
signed char Spectrum_2_Complex_Re[256] ;
|
|
/* Compute Complex table */
|
|
for (int i = 0 ; i < 256 ; i ++)
|
|
{
|
|
Spectrum_2_Complex_Im[i] = (signed char)(cosf((float)i * 3.1415927f * 2.0f / 256.0f) * 127.0f);
|
|
Spectrum_2_Complex_Re[i] = (signed char)(sinf((float)i * 3.1415927f * 2.0f / 256.0f) * 127.0f);
|
|
}
|
|
|
|
/* 1 Compute 8b */
|
|
PPs = pSrc->GetBase();
|
|
PPl = pSrc->GetBase() + pSrc->PITCH * pSrc->SY;
|
|
while (PPs < PPl)
|
|
{
|
|
PPll = PPs + pSrc->SX;
|
|
while (PPs < PPll)
|
|
{
|
|
s32 Imag,Real;
|
|
Imag = Spectrum_2_Complex_Im[((u8*)PPs)[1]];
|
|
Real = Spectrum_2_Complex_Re[((u8*)PPs)[1]];
|
|
Imag *= ((u8*)PPs)[0];
|
|
Real *= ((u8*)PPs)[0];
|
|
Imag>>= 8;
|
|
Real>>= 8;
|
|
//RGB[1] // Spc;
|
|
//RGB[2] // (Brg-Sat);
|
|
((u8*)PPs)[1] = Imag + 128;
|
|
((u8*)PPs)[0] = Real + 128;
|
|
//((u8*)PPs)[2] = 0;
|
|
|
|
PPs ++;
|
|
}
|
|
PPs += pSrc->PITCH - pSrc->SX;
|
|
}
|
|
}
|
|
|
|
void SPECTRUM_2_MAP(/*IN*/MAP *pSrc)
|
|
{
|
|
s32 *PPs,*PPl,*PPll;
|
|
u32 SPETRUM_TABLE[256];
|
|
for (int X = 0 ; X < 85 ; X ++)
|
|
{
|
|
u32 Color;
|
|
Color = Saturate((85 - X)*3)<<16;
|
|
Color |= Saturate((X)*3)<<8;
|
|
SPETRUM_TABLE[(X)] = Color;
|
|
Color >>= 8;
|
|
SPETRUM_TABLE[((X + 85))] = Color;
|
|
Color = Saturate((85 - X)*3)<<0;
|
|
Color |= Saturate(((X)*3)<<0)<<16;
|
|
SPETRUM_TABLE[((X + 170))] = Color;
|
|
}
|
|
SPETRUM_TABLE[255] = SPETRUM_TABLE[254];
|
|
/* 1 Compute 8b */
|
|
PPs = pSrc->GetBase();
|
|
PPl = pSrc->GetBase() + pSrc->PITCH * pSrc->SY;
|
|
while (PPs < PPl)
|
|
{
|
|
PPll = PPs + pSrc->SX;
|
|
while (PPs < PPll)
|
|
{
|
|
u32 RGB[3],Index,MINMAX;
|
|
u32 Brg,Sat,Spc,Selector,Selector2;
|
|
Brg = (u32)((u8*)PPs)[2];
|
|
Spc = (u32)((u8*)PPs)[1] ;
|
|
Sat = (u32)((u8*)PPs)[0] ;
|
|
Selector2 = Selector = 0;
|
|
Spc += 256-16;
|
|
Spc &= 255;
|
|
if (Spc < 32)
|
|
{
|
|
Selector = Spc << 3;
|
|
Selector ^= 255;
|
|
} else
|
|
{
|
|
Spc ^= 255;
|
|
if (Spc < 32)
|
|
{
|
|
Selector = Spc << 3;
|
|
Selector ^= 255;
|
|
}
|
|
Spc ^= 255;
|
|
}
|
|
if (Sat < 80)
|
|
Selector2 = 80-Sat;
|
|
else
|
|
Selector2 = Sat-80;
|
|
|
|
if (Selector2 < 64)
|
|
{
|
|
Selector2 = Selector2<<2;
|
|
Selector2 ^= 255;
|
|
Selector *= Selector2;
|
|
Selector >>= 8;
|
|
} else
|
|
Selector = 0;
|
|
|
|
Selector <<= 3;
|
|
if (Selector>255) Selector = 255;
|
|
|
|
Brg |= Brg<<8;
|
|
Brg |= Brg<<8;
|
|
*PPs = Blend(SPETRUM_TABLE[Spc],Brg,Sat);//*/
|
|
//MINMAX = 0&(0xffffff^*PPs);
|
|
//Selector ^= 255;
|
|
*PPs |= Selector<<24;//Blend(MINMAX,*PPs,Selector^0xff);
|
|
PPs ++;
|
|
}
|
|
PPs += pSrc->PITCH - pSrc->SX;
|
|
}
|
|
}
|
|
void MAP_2_MAP8_Shift(/*IN*/MAP8 *pSrc,MAP *pDst,u32 Shift)
|
|
{
|
|
u8 *PPs;
|
|
s32 *PPd,*PPl,*PPll,*PPDeriv;
|
|
/* 1 Compute 8b */
|
|
PPs = pSrc->GetBase();
|
|
PPd = pDst->GetBase();
|
|
PPl = pDst->GetBase() + pDst->PITCH * pDst->SY;
|
|
while (PPd < PPl)
|
|
{
|
|
PPll = PPd + pDst->SX;
|
|
while (PPd < PPll)
|
|
{
|
|
*PPs = ((u8*)PPd)[Shift];
|
|
PPd ++;
|
|
PPs ++;
|
|
}
|
|
PPs += pSrc->PITCH - pSrc->SX;
|
|
PPd += pDst->PITCH - pDst->SX;
|
|
}
|
|
}
|
|
void MAP8_2_MAP_Shift(/*IN*/MAP8 *pSrc,MAP *pDst,u32 Shift)
|
|
{
|
|
u8 *PPs;
|
|
s32 *PPd,*PPl,*PPll,*PPDeriv;
|
|
/* 1 Compute 8b */
|
|
PPs = pSrc->GetBase();
|
|
PPd = pDst->GetBase();
|
|
PPl = pDst->GetBase() + pDst->PITCH * pDst->SY;
|
|
while (PPd < PPl)
|
|
{
|
|
PPll = PPd + pDst->SX;
|
|
while (PPd < PPll)
|
|
{
|
|
((u8*)PPd)[Shift] = *PPs;
|
|
PPd ++;
|
|
PPs ++;
|
|
}
|
|
PPs += pSrc->PITCH - pDst->SX;
|
|
PPd += pDst->PITCH - pDst->SX;
|
|
}
|
|
}
|
|
|
|
void MAP8_CopySqr(/*IN*/MAP8 *pSrc,MAP8 *pDst)
|
|
{
|
|
u8 *PPs;
|
|
u8 *PPd,*PPl,*PPll,*PPDeriv;
|
|
/* 1 Compute 8b */
|
|
PPs = pSrc->GetBase();
|
|
PPd = pDst->GetBase();
|
|
PPl = pDst->GetBase() + pDst->PITCH * pDst->SY;
|
|
while (PPd < PPl)
|
|
{
|
|
PPll = PPd + pDst->SX;
|
|
while (PPd < PPll)
|
|
{
|
|
*PPd = ((u32)*PPs * (u32)*PPs)>>8;
|
|
PPd ++;
|
|
PPs ++;
|
|
}
|
|
PPs += pSrc->PITCH - pSrc->SX;
|
|
PPd += pDst->PITCH - pDst->SX;
|
|
}
|
|
}
|
|
void MAP8_Copy(/*IN*/MAP8 *pSrc,MAP8 *pDst)
|
|
{
|
|
u8 *PPs;
|
|
u8 *PPd,*PPl,*PPll,*PPDeriv;
|
|
/* 1 Compute 8b */
|
|
PPs = pSrc->GetBase();
|
|
PPd = pDst->GetBase();
|
|
PPl = pDst->GetBase() + pDst->PITCH * pDst->SY;
|
|
while (PPd < PPl)
|
|
{
|
|
PPll = PPd + pDst->SX;
|
|
while (PPd < PPll)
|
|
{
|
|
*PPd = *PPs;
|
|
PPd ++;
|
|
PPs ++;
|
|
}
|
|
PPs += pSrc->PITCH - pSrc->SX;
|
|
PPd += pDst->PITCH - pDst->SX;
|
|
}
|
|
}
|
|
|
|
void MAP8_Add(/*IN*/MAP8 *pSrc,MAP8 *pDst)
|
|
{
|
|
u8 *PPs;
|
|
u8 *PPd,*PPl,*PPll,*PPDeriv;
|
|
/* 1 Compute 8b */
|
|
PPs = pSrc->GetBase();
|
|
PPd = pDst->GetBase();
|
|
PPl = pDst->GetBase() + pDst->PITCH * pDst->SY;
|
|
while (PPd < PPl)
|
|
{
|
|
PPll = PPd + pDst->SX;
|
|
while (PPd < PPll)
|
|
{
|
|
*PPd += *PPs;
|
|
PPd ++;
|
|
PPs ++;
|
|
}
|
|
PPs += pSrc->PITCH - pSrc->SX;
|
|
PPd += pDst->PITCH - pDst->SX;
|
|
}
|
|
}
|
|
void MAP8_2_MAP_BD_EFFECT(/*IN*/MAP8 *pSrc,MAP *pDst)
|
|
{
|
|
u8 *PPs;
|
|
s32 *PPd,*PPl,*PPll,*PPDeriv;
|
|
/* 1 Compute 8b */
|
|
PPs = pSrc->GetBase();
|
|
PPd = pDst->GetBase();
|
|
PPl = pDst->GetBase() + pDst->PITCH * pDst->SY;
|
|
while (PPd < PPl)
|
|
{
|
|
PPll = PPd + pDst->SX;
|
|
while (PPd < PPll)
|
|
{
|
|
u8 R,G,B,MAX,MIN;
|
|
R = (*PPd>>16)&0xff;
|
|
G = (*PPd>>8)&0xff;
|
|
B = (*PPd>>0)&0xff;
|
|
if (R > G)
|
|
{
|
|
// ma Red or Blue
|
|
if (R > B)
|
|
//Red
|
|
MAX = 0;
|
|
else
|
|
//blue
|
|
MAX = 2;
|
|
} else // Gren or blue
|
|
if (G > B)
|
|
{
|
|
// Green
|
|
MAX = 1;
|
|
} else
|
|
{
|
|
MAX = 2;
|
|
//blue
|
|
}
|
|
if (R < G)
|
|
{
|
|
// ma Red or Blue
|
|
if (R < B)
|
|
//Red
|
|
MIN = 0;
|
|
else
|
|
//blue
|
|
MIN = 2;
|
|
} else // Gren or blue
|
|
if (G < B)
|
|
{
|
|
// Green
|
|
MIN = 1;
|
|
} else
|
|
{
|
|
MIN = 2;
|
|
//blue
|
|
}
|
|
u32 Res,Average;
|
|
/* MAX = 2-MAX;
|
|
MIN = 2-MIN;*/
|
|
*PPd = 0x808080;
|
|
*PPd |= 0xff<<(MAX<<3);
|
|
*PPd &= ~(0xff<<(MIN<<3));
|
|
MIN = (MIN == 2) ? R : ((MIN == 1) ? G : B) ;
|
|
MAX = (MAX == 2) ? R : ((MAX == 1) ? G : B) ;
|
|
Average = (R+G+G+B)>>3;
|
|
Average |= Average<<8;
|
|
Average |= Average<<8;
|
|
if (MIN > MAX>>1)
|
|
{
|
|
*PPd &= 0xfefefe;
|
|
*PPd >>= 1;
|
|
*PPd += Average;
|
|
}
|
|
if (MIN > MAX - (MAX>>2))
|
|
{
|
|
*PPd &= 0xfefefe;
|
|
*PPd >>= 1;
|
|
*PPd += Average;
|
|
}
|
|
if (MIN > 0x80)
|
|
{
|
|
*PPd &= 0xfefefe;
|
|
*PPd >>= 1;
|
|
*PPd += 0x7f7f7f;
|
|
}
|
|
if (MIN > 0xA0)
|
|
{
|
|
*PPd &= 0xfefefe;
|
|
*PPd >>= 1;
|
|
*PPd += 0x7f7f7f;
|
|
}
|
|
if (MAX < 0x80)
|
|
{
|
|
*PPd &= 0xfefefe;
|
|
*PPd >>= 1;
|
|
}
|
|
if (MAX < 0x40)
|
|
{
|
|
*PPd &= 0xfefefe;
|
|
*PPd >>= 1;
|
|
}
|
|
|
|
Res = (((((u32)*PPd & 0xff00ff) * (u32)(*PPs))>>8)& 0xff00ff) | (((((u32)*PPd & 0xff00) * (u32)(*PPs))>>8)& 0xff00);
|
|
Res &= 0xF0F0F0;
|
|
*PPd = Res;//*/
|
|
PPd ++;
|
|
PPs ++;
|
|
}
|
|
PPs += pSrc->PITCH - pSrc->SX;
|
|
PPd += pDst->PITCH - pDst->SX;
|
|
}
|
|
}
|
|
|
|
void MAP8_Denoise_Inplace_FAST(MAP8 *pSrc)
|
|
{
|
|
// In place denoise with crown pattern
|
|
u8 *PPd,*PPl,*PPll,*PPDeriv;
|
|
/* H_Denoise */
|
|
PPd = pSrc->GetBase();
|
|
PPl = pSrc->GetBase() + pSrc->PITCH * pSrc->SY;
|
|
while (PPd < PPl)
|
|
{
|
|
u32 Save,SaveN;
|
|
PPll = PPd + pSrc->SX - 1;
|
|
Save = (u32)*PPd++;
|
|
while (PPd < PPll)
|
|
{
|
|
SaveN = *PPd;
|
|
*PPd = ((u32)*(PPd+1) + Save)>>1;
|
|
Save = SaveN;
|
|
PPd ++;
|
|
}
|
|
PPd += pSrc->PITCH - pSrc->SX + 1;
|
|
}
|
|
/* V_Denoise */
|
|
u32 *pSaveV,SaveV[2048],SaveN;
|
|
|
|
PPd = pSrc->GetBase();
|
|
PPll = PPd + pSrc->SX;
|
|
pSaveV = SaveV;
|
|
while (PPd < PPll)
|
|
{
|
|
*(pSaveV++) = *(PPd++);
|
|
}
|
|
|
|
PPl = pSrc->GetBase() + pSrc->PITCH * pSrc->SY - pSrc->PITCH;
|
|
while (PPd < PPl)
|
|
{
|
|
PPll = PPd + pSrc->SX;
|
|
pSaveV = SaveV;
|
|
while (PPd < PPll)
|
|
{
|
|
SaveN = *PPd;
|
|
*PPd = ((u32)*(PPd+pSrc->PITCH) + *pSaveV)>>1;
|
|
*pSaveV = SaveN;
|
|
PPd ++;
|
|
pSaveV++;
|
|
}
|
|
PPd += pSrc->PITCH - pSrc->SX;
|
|
}
|
|
}
|
|
|
|
|
|
void MAP8_MIN_Inplace_FAST(MAP8 *pSrc)
|
|
{
|
|
// In place denoise with crown pattern
|
|
u8 *PPd,*PPl,*PPll,*PPDeriv;
|
|
/* H_Denoise */
|
|
PPd = pSrc->GetBase();
|
|
PPl = pSrc->GetBase() + pSrc->PITCH * pSrc->SY;
|
|
while (PPd < PPl)
|
|
{
|
|
u32 Save,SaveN;
|
|
PPll = PPd + pSrc->SX - 1;
|
|
Save = (u32)*PPd++;
|
|
while (PPd < PPll)
|
|
{
|
|
SaveN = *PPd;
|
|
if (*PPd > *(PPd+1)) *PPd = *(PPd+1);
|
|
if (*PPd > Save) *PPd = Save;
|
|
Save = SaveN;
|
|
PPd ++;
|
|
}
|
|
PPd += pSrc->PITCH - pSrc->SX + 1;
|
|
}
|
|
/* V_Denoise */
|
|
u32 *pSaveV,SaveV[2048],SaveN;
|
|
|
|
PPd = pSrc->GetBase();
|
|
PPll = PPd + pSrc->SX;
|
|
pSaveV = SaveV;
|
|
while (PPd < PPll)
|
|
{
|
|
*(pSaveV++) = *(PPd++);
|
|
}
|
|
|
|
PPl = pSrc->GetBase() + pSrc->PITCH * pSrc->SY - pSrc->PITCH;
|
|
while (PPd < PPl)
|
|
{
|
|
PPll = PPd + pSrc->SX;
|
|
pSaveV = SaveV;
|
|
while (PPd < PPll)
|
|
{
|
|
SaveN = *PPd;
|
|
if (*PPd > *(PPd+pSrc->PITCH)) *PPd = *(PPd+pSrc->PITCH);
|
|
if (*PPd > *pSaveV) *PPd = *pSaveV;
|
|
*pSaveV = SaveN;
|
|
PPd ++;
|
|
pSaveV++;
|
|
}
|
|
PPd += pSrc->PITCH - pSrc->SX;
|
|
}
|
|
}
|
|
|
|
u32 Activated = 0;
|
|
u32 ComputeBack = -1;
|
|
u32 MaskOr = -1;
|
|
|
|
|
|
void SetBackGround(MAP *CurrentMap,MAP *ZMap,s32 Mode)
|
|
{
|
|
static u8 *WorkingBuf = NULL;
|
|
static u32 WorkingBufSize = 0;
|
|
u8 TransTable[256];
|
|
u8 TransTable2[256];
|
|
//return;
|
|
if ((ComputeBack == -1) && (Mode == 1)) return;
|
|
if (Mode == 1)
|
|
{
|
|
if (!Activated) return;
|
|
u32 CompuSetBackGroundErnergy(MAP *CurrentMap,MAP *ZMap,s32 Mode);
|
|
MaskOr = CompuSetBackGroundErnergy(CurrentMap,ZMap,ComputeBack);
|
|
if (ComputeBack < 50) MaskOr |= 1;
|
|
ComputeBack++;
|
|
return;//*/
|
|
}
|
|
|
|
|
|
for (int i = 0 ; i < 256 ; i ++)
|
|
{
|
|
float V;
|
|
V = (fabs((float)(i - 128) * 80.0f)) - 54;
|
|
if (V>255) V = 255;
|
|
if (V<0) V = 0;
|
|
TransTable2[i] = ((u8)V);
|
|
V = (((float)(i - 130) * 60.0f));
|
|
if (V>255) V = 255;
|
|
if (V<0) V = 0;
|
|
TransTable[i] = ((u8)V)^255;
|
|
|
|
}
|
|
MAP8 M1,M2,M3,M4,M5,M6;
|
|
if (CurrentMap->SX * CurrentMap->SY == 0) return;
|
|
|
|
/**************** Init working maps **************/
|
|
if (WorkingBufSize < CurrentMap->SX * CurrentMap->SY)
|
|
{
|
|
if(WorkingBuf) CC_free(WorkingBuf);
|
|
WorkingBufSize = CurrentMap->SX * CurrentMap->SY;
|
|
WorkingBuf = (u8*)CC_malloc(WorkingBufSize * 6);
|
|
memset(WorkingBuf,0,WorkingBufSize * 6);
|
|
ComputeBack = 0;
|
|
}
|
|
M1.SX = CurrentMap->SX;
|
|
M1.SY = CurrentMap->SY;
|
|
M2 = M3 = M4 = M5 = M6 = M1;
|
|
M6.PITCH = M5.PITCH = M4.PITCH = M3.PITCH = M2.PITCH = M1.PITCH = CurrentMap->SX;
|
|
M1.SetBase(WorkingBuf);
|
|
M2.SetBase(WorkingBuf + CurrentMap->SX * CurrentMap->SY);
|
|
M3.SetBase(WorkingBuf + CurrentMap->SX * CurrentMap->SY * 2);
|
|
M4.SetBase(WorkingBuf + CurrentMap->SX * CurrentMap->SY * 3);
|
|
M5.SetBase(WorkingBuf + CurrentMap->SX * CurrentMap->SY * 4);
|
|
M6.SetBase(WorkingBuf + CurrentMap->SX * CurrentMap->SY * 5);
|
|
|
|
MAP BB2,BB = *CurrentMap;
|
|
|
|
BB.SX>>=1;
|
|
BB.SY>>=1;
|
|
//COPY_O2_RGBA(CurrentMap,&BB);
|
|
BB2 = BB;
|
|
BB2.SX>>=1;
|
|
BB2.SY>>=1;
|
|
//COPY_O2_RGBA(&BB,&BB2);
|
|
|
|
u8 *Pscr,*Pdst,*Pend;
|
|
MAP_2_MAP8(CurrentMap,&M1,NULL);
|
|
memcpy(M2.GetBase(),M1.GetBase(),WorkingBufSize);
|
|
|
|
|
|
if (Mode == 0)
|
|
{
|
|
MAP8_BLUR8_H_Inplace(&M1,3);
|
|
MAP8_BLUR8_V_Inplace(&M1,3);
|
|
Pscr = M1.GetBase();
|
|
Pdst = M2.GetBase();
|
|
Pend = Pscr+WorkingBufSize;
|
|
while (Pscr<Pend)
|
|
{
|
|
*Pscr = TransTable[(u8)(((u32)((*Pdst ^ 0xff) + *Pscr))>>1)];
|
|
Pscr++;
|
|
Pdst++;
|
|
}//*/
|
|
MAP_2_MAP8_Shift(/*IN*/&M2,CurrentMap,3);
|
|
MAP8_2_MAP(&M1,CurrentMap);
|
|
MAP8_2_MAP_Shift(/*IN*/&M2,CurrentMap,3);
|
|
}
|
|
else
|
|
if (Mode == 1)
|
|
{
|
|
u32 CompuSetBackGroundErnergy(MAP *CurrentMap,MAP *ZMap,s32 Mode);
|
|
MaskOr = CompuSetBackGroundErnergy(CurrentMap,ZMap,ComputeBack);
|
|
if (ComputeBack < 50) MaskOr |= 1;
|
|
ComputeBack++;
|
|
return;//*/
|
|
BB = *CurrentMap;
|
|
BB.SX>>=1;
|
|
BB.SY>>=1;
|
|
BB.SetBase((s32*)M4.GetBase());
|
|
COPY_O2_RGBA(CurrentMap,&BB);
|
|
BB2 = BB;
|
|
BB2.SX>>=1;
|
|
BB2.SY>>=1;
|
|
COPY_O2_RGBA(&BB,&BB2);
|
|
MAP8_BLUR8_H_Inplace(&M1,2);
|
|
MAP8_BLUR8_V_Inplace(&M1,2);// */
|
|
if ((ComputeBack < 8))
|
|
{
|
|
if (ComputeBack == 0)
|
|
{
|
|
memset(BackComp1,0,sizeof(BackComp1));
|
|
}
|
|
}
|
|
/* *****************************************************************/
|
|
/* Active Model Of Gain Computation: ***********************/
|
|
/* *****************************************************************/
|
|
if (ComputeBack > 256)
|
|
{
|
|
u32 SAveBACKGroundStat,Counter;
|
|
float VirtualGainFac = 0.95f;
|
|
DISTANCETOLERANCE = 500;
|
|
Counter = 4;
|
|
BCK_TestAllSignFAST(&M1,&BB2,BackComp1,&BACKVirtualGain,1);
|
|
|
|
while (Counter--)
|
|
{
|
|
for (int RGB = -1; RGB < 3 ; RGB ++)
|
|
{
|
|
Vector LocalGain;
|
|
SAveBACKGroundStat = BACKGroundStat;
|
|
LocalGain = BACKVirtualGain;
|
|
if (RGB == -1)
|
|
LocalGain = BACKVirtualGain * VirtualGainFac;
|
|
else
|
|
LocalGain.Scalar[RGB] = BACKVirtualGain.Scalar[RGB] * VirtualGainFac;
|
|
BCK_TestAllSignFAST(&M1,&BB2,BackComp1,&LocalGain);
|
|
if (BACKGroundStat > SAveBACKGroundStat)
|
|
{
|
|
BACKVirtualGain = LocalGain;
|
|
SAveBACKGroundStat = BACKGroundStat;
|
|
} else
|
|
{
|
|
LocalGain = BACKVirtualGain;
|
|
if (RGB == -1)
|
|
LocalGain = BACKVirtualGain * (1.0f/VirtualGainFac);
|
|
else
|
|
LocalGain.Scalar[RGB] = BACKVirtualGain.Scalar[RGB] * (1.0f/VirtualGainFac);
|
|
|
|
BCK_TestAllSignFAST(&M1,&BB2,BackComp1,&LocalGain);
|
|
if (BACKGroundStat > SAveBACKGroundStat)
|
|
{
|
|
BACKVirtualGain = LocalGain;
|
|
SAveBACKGroundStat = BACKGroundStat;
|
|
}
|
|
}
|
|
BACKVirtualGain.Max(Vector(0.125f,0.125f,0.125f));
|
|
BACKVirtualGain.Min(Vector(8.0f,8.0f,8.0f));
|
|
}
|
|
VirtualGainFac += 1.0f;
|
|
VirtualGainFac /= 2.0f;
|
|
DISTANCETOLERANCE = ((DISTANCETOLERANCE - 300)>>1) + 300;
|
|
}//*/
|
|
} else BACKVirtualGain = Vector(1,1,1);
|
|
|
|
|
|
BCK_TestAllSign(&M1,&BB2,BackComp1,ComputeBack < 256 ? 1 : 0,&BACKVirtualGain);
|
|
|
|
|
|
|
|
ComputeBack++;
|
|
BCK_BlurAllSign(CurrentMap,BackComp1);
|
|
BCK_DrawAllSign(&M4,&M2,&M3,BackComp1);
|
|
|
|
MAP8_BLUR8_H_Inplace(&M4,3);
|
|
MAP8_BLUR8_V_Inplace(&M4,3);// */
|
|
u8 *pMask;
|
|
MaskOr = 0;
|
|
Pscr = M2.GetBase();
|
|
Pdst = M3.GetBase();
|
|
pMask = M4.GetBase();
|
|
Pend = Pscr+WorkingBufSize;
|
|
BACKGroundStat = 0;
|
|
while (Pscr<Pend)
|
|
{
|
|
if ((*pMask < 250) && (*pMask > 10))
|
|
*pMask = TransTable2[(u8)(((u32)((*Pdst ^ 0xff) + *Pscr))>>1)];
|
|
else
|
|
if ((*pMask >= 250) ) BACKGroundStat++;
|
|
MaskOr |= *pMask;
|
|
Pscr++;
|
|
pMask++;
|
|
Pdst++;
|
|
}
|
|
|
|
{
|
|
MAP8_BLUR8_H_Inplace(&M4,3);
|
|
MAP8_BLUR8_V_Inplace(&M4,3);// */
|
|
u8 *pMaskLast;
|
|
pMask = M4.GetBase();
|
|
pMaskLast = pMask +M4.SX *M4.SY;
|
|
while (pMask<pMaskLast)
|
|
{
|
|
if (*pMask > 160)
|
|
*pMask = 0xff;
|
|
else
|
|
*pMask = 0;
|
|
pMask++;
|
|
}
|
|
}
|
|
|
|
MAP8_Denoise_Inplace_FAST(&M4);
|
|
MAP8_MIN_Inplace_FAST(&M4);
|
|
MAP8_Denoise_Inplace_FAST(&M4);
|
|
MAP8_2_MAP_Shift(/*IN*/&M4,CurrentMap,3);
|
|
|
|
/* TRI MAP TEST */
|
|
//MAP8_2_MAP_Shift(/*IN*/&M4,CurrentMap,1);
|
|
MAP8_2_MAP_Shift(/*IN*/&M4,CurrentMap,3);
|
|
|
|
/*
|
|
char DEDEDE[1024];
|
|
sprintf(DEDEDE,"%2.2f\n%2.2f\n%2.2f\n",BACKVirtualGain.x,BACKVirtualGain.y,BACKVirtualGain.z);
|
|
DRawTEXT_Soft_B((u8*)DEDEDE,(u32*)CurrentMap->GetBase(),16, 32, CurrentMap->PITCH, CurrentMap->SY, 0xff00f0f0);*/
|
|
return ;
|
|
}
|
|
if (Mode == 2)
|
|
{
|
|
MAP_2_SPECTRUM(/*IN*/CurrentMap);
|
|
MAP_2_MAP8_Shift(/*IN*/&M1,CurrentMap,0);
|
|
MAP8_BLUR8_H_Inplace(&M1,2);
|
|
MAP8_BLUR8_V_Inplace(&M1,2);// */
|
|
|
|
MAP8_2_MAP_Shift(/*IN*/&M1,CurrentMap,0);
|
|
SPECTRUM_2_MAP(/*IN*/CurrentMap);
|
|
//MAP8_2_MAP(&M1,CurrentMap);
|
|
//BCK_DrawStats(CurrentMap,&M1);
|
|
return ;
|
|
}
|
|
if (Mode == 3)
|
|
{
|
|
void MAP16_CopySqr8(MAP8 *pSrc,MAP16 *pDst);
|
|
void MAP16_BLUR_H_Inplace(MAP16 *pSrc,u32 Rpo2);
|
|
void MAP16_BLUR_V_Inplace(MAP16 *pSrc,u32 Rpo2);
|
|
#define BBBBB 3
|
|
MAP8_2_MAP_Shift(/*IN*/&M1,CurrentMap,0);
|
|
MAP8_2_MAP_Shift(/*IN*/&M1,CurrentMap,1);
|
|
MAP8_2_MAP_Shift(/*IN*/&M1,CurrentMap,2);
|
|
|
|
|
|
MAP8_BLUR8_H_Inplace(&M2,BBBBB);
|
|
MAP8_BLUR8_V_Inplace(&M2,BBBBB);
|
|
MAP8_BLUR8_H_Inplace(&M2,BBBBB);
|
|
MAP8_BLUR8_V_Inplace(&M2,BBBBB);
|
|
MAP8_BLUR8_H_Inplace(&M2,BBBBB);
|
|
MAP8_BLUR8_V_Inplace(&M2,BBBBB);
|
|
MAP8_BLUR8_H_Inplace(&M2,BBBBB);
|
|
MAP8_BLUR8_V_Inplace(&M2,BBBBB);
|
|
MAP8_BLUR8_H_Inplace(&M2,BBBBB);
|
|
MAP8_BLUR8_V_Inplace(&M2,BBBBB);
|
|
|
|
|
|
Pscr = M1.GetBase();
|
|
Pdst = M2.GetBase();
|
|
Pend = Pscr+WorkingBufSize;
|
|
while (Pscr<Pend)
|
|
{
|
|
*Pdst = (u8)(((u32)((*Pdst ^ 0xff) + *Pscr))>>1)>>0;
|
|
Pscr++;
|
|
Pdst++;
|
|
}
|
|
MAP8_Copy(&M2,&M1);//*/
|
|
|
|
|
|
|
|
MAP16 SqrBlur,Blur;
|
|
SqrBlur.SetBase((s16*)M5.GetBase());
|
|
SqrBlur.SX = M1.SX;
|
|
SqrBlur.SY = M1.SY;
|
|
SqrBlur.PITCH = SqrBlur.SX;
|
|
Blur.SetBase((s16*)M3.GetBase());
|
|
Blur.SX = M1.SX;
|
|
Blur.SY = M1.SY;
|
|
Blur.PITCH = Blur.SX;
|
|
|
|
|
|
|
|
|
|
for (int i = 0 ; i < 1 ; i ++)
|
|
{
|
|
|
|
MAP16_CopySqr8(&M2,&SqrBlur);
|
|
MAP16_Copy8(&M2,&Blur);
|
|
|
|
#undef BBBBB
|
|
#define BBBBB ((i<<0)+1)
|
|
|
|
/* MAP16_Denoise_Inplace_FAST(&SqrBlur);
|
|
MAP16_Denoise_Inplace_FAST(&Blur);
|
|
MAP16_Denoise_Inplace_FAST(&SqrBlur);
|
|
MAP16_Denoise_Inplace_FAST(&Blur);*/
|
|
MAP16_BLUR_H_Inplace(&SqrBlur,BBBBB);
|
|
MAP16_BLUR_V_Inplace(&SqrBlur,BBBBB);
|
|
MAP16_BLUR_H_Inplace(&SqrBlur,BBBBB);
|
|
MAP16_BLUR_V_Inplace(&SqrBlur,BBBBB);
|
|
MAP16_BLUR_H_Inplace(&Blur,BBBBB);
|
|
MAP16_BLUR_V_Inplace(&Blur,BBBBB);
|
|
MAP16_BLUR_H_Inplace(&Blur,BBBBB);
|
|
MAP16_BLUR_V_Inplace(&Blur,BBBBB);
|
|
|
|
|
|
|
|
s16 *pSqrPtr,*pBlurPtr;
|
|
pSqrPtr = SqrBlur.GetBase();
|
|
pBlurPtr = Blur.GetBase();
|
|
Pscr = M1.GetBase();
|
|
Pdst = M2.GetBase();
|
|
Pend = Pscr+WorkingBufSize;
|
|
while (Pscr<Pend)
|
|
{
|
|
s32 SQr,Root;
|
|
SQr = (s32)*pSqrPtr;
|
|
Root = (((s32)(*pBlurPtr) * (s32)(*pBlurPtr))>>14);
|
|
if (Root > SQr) Root = SQr;
|
|
*pSqrPtr = ((s16)((((SQr - Root)))))<<0;
|
|
Pscr++;
|
|
Pdst++;
|
|
pSqrPtr++;
|
|
pBlurPtr++;
|
|
}//*/
|
|
void MAP16_Copy(MAP16*,MAP16*);
|
|
MAP16_Copy(&SqrBlur,&Blur);
|
|
MAP16_BLUR_H_Inplace(&Blur,1);
|
|
MAP16_BLUR_V_Inplace(&Blur,1);
|
|
void MAP16_Sub(MAP16 *pSrc,MAP16 *pDst);
|
|
|
|
pSqrPtr = SqrBlur.GetBase();
|
|
pBlurPtr = Blur.GetBase();
|
|
Pscr = M1.GetBase();
|
|
Pdst = M2.GetBase();
|
|
Pend = Pscr+WorkingBufSize;
|
|
while (Pscr<Pend)
|
|
{
|
|
|
|
if (*pBlurPtr < 2) *pSqrPtr = 0;
|
|
else *pSqrPtr /= *pBlurPtr;
|
|
if (*pSqrPtr < 0)
|
|
*Pscr = 0;
|
|
else
|
|
if(((s32)*pSqrPtr< 255>>7))
|
|
*Pscr = *pSqrPtr<<7;//*/
|
|
else
|
|
*Pscr = 255;
|
|
*Pscr ^= 255;
|
|
Pscr++;
|
|
Pdst++;
|
|
pSqrPtr++;
|
|
pBlurPtr++;
|
|
}//*/
|
|
|
|
//
|
|
|
|
CurrentMap->SX>>=1;
|
|
MAP8_2_MAP_Shift(/*IN*/&M1,CurrentMap,0);
|
|
MAP8_2_MAP_Shift(/*IN*/&M1,CurrentMap,1);
|
|
MAP8_2_MAP_Shift(/*IN*/&M1,CurrentMap,2);
|
|
CurrentMap->SX<<=1;
|
|
//MAP8_Copy(&M2,&M1);
|
|
}
|
|
return ;
|
|
}
|
|
}
|
|
|
|
|
|
u32 TRK_AE_ComputeBackground(u32 Activate, u32 Relearn)
|
|
{
|
|
Activated = Activate;
|
|
if (Activate)
|
|
{
|
|
if ((ComputeBack == -1)
|
|
|| (Relearn && (ComputeBack < 100)))
|
|
{
|
|
ComputeBack = 0;
|
|
MaskOr = 522;
|
|
}
|
|
} else
|
|
ComputeBack = -1;
|
|
return MaskOr >> 7;
|
|
}
|
|
|
|
float MotionNoise(s32 BX , s32 BY ,s32 SX , s32 SY, s32* base1, s32* base2, s32 pitch)
|
|
{
|
|
s32* base1Init = base1;
|
|
s32* base2Init = base2;
|
|
|
|
base1 = base1 + BX + BY*pitch;
|
|
base2 = base2 + BX + BY*pitch;
|
|
|
|
short int a = 3;
|
|
|
|
float Result = 0;
|
|
while (SY--)
|
|
{
|
|
s32 SXX;
|
|
SXX = SX;
|
|
while (SXX--)
|
|
{
|
|
Result += (float)(*((s8*)base1+a) - *((s8*)base2)+a) * (float)(*((s8*)base1+a) - *((s8*)base2)+a);
|
|
base1 ++;
|
|
base2 ++;
|
|
}
|
|
base1 += pitch - SX;
|
|
base2 += pitch - SX;
|
|
}
|
|
|
|
base1 = base1Init;
|
|
base2 = base2Init;
|
|
|
|
return Result;
|
|
}
|
|
|
|
|
|
void ComputeBackground(MAP *map, MAP *destMap)
|
|
{
|
|
static bool firstTime = true;
|
|
int size = map->SX*map->SY*sizeof(s32);
|
|
int sx = map->SX;
|
|
int sy = map->SY;
|
|
static s32* initBase = (s32*)ZeroAlloc(size);
|
|
|
|
int blocSize = 4;
|
|
|
|
if (firstTime)
|
|
{
|
|
memcpy(initBase, map->GetBase(), size);
|
|
}
|
|
|
|
for (int i=0; i<sx; i+=blocSize)
|
|
{
|
|
for (int j=0; j<sy; j+=blocSize)
|
|
{
|
|
int bx = blocSize;
|
|
if (i+bx>sx) bx = sx%blocSize;
|
|
int by = blocSize;
|
|
if (j+by>sy) by = sy%blocSize;
|
|
if (MotionNoise(i,j,bx,by,initBase, map->GetBase(), map->PITCH)<200*bx*by)
|
|
{
|
|
for (int i2=0; i2<bx; i2++)
|
|
for (int j2=0; j2<by; j2++)
|
|
*(destMap->GetBase() + i+i2 + (j+j2)*destMap->PITCH) = 0;
|
|
}
|
|
else
|
|
{
|
|
for (int i2=0; i2<bx; i2++)
|
|
for (int j2=0; j2<by; j2++)
|
|
*(destMap->GetBase() + i+i2 + (j+j2)*destMap->PITCH) = -1;
|
|
}
|
|
}
|
|
}
|
|
|
|
firstTime = false;
|
|
|
|
extern void Map2Regions(MAP * map);
|
|
Map2Regions(destMap);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|