This commit is contained in:
Daveo 2001-08-02 18:45:20 +00:00
parent 98ff69a23e
commit 5a8d2b0d90
11 changed files with 267 additions and 198 deletions

View file

@ -25,9 +25,10 @@ u8 *Ptr=(u8*)LayerHdr;
iPtr=(int*)(Ptr+sizeof(sExpLayerHdr));
ShadeFlag=*iPtr++;
sRGBCol *RGB=(sRGBCol*)iPtr;
ShadeRGB=*RGB++;
for (int Y=0; Y<Height; Y++)
{
for (int X=0; X<Width; X++)
@ -101,8 +102,10 @@ int ColorCount=0;
printf("RGB remapped to %i colors\n",ColorCount);
// Build Out RGB Table
OutRGBTable.SetSize(ColorCount,16);
int RGBInc=6;
if (ShadeFlag) RGBInc=-6;
int RInc=(ShadeRGB.R-128)/16;
int GInc=(ShadeRGB.G-128)/16;
int BInc=(ShadeRGB.B-128)/16;
for (int c=0;c<ColorCount;c++)
{
int R=DestPal[(c*3)+0];
@ -114,146 +117,15 @@ int RGBInc=6;
RGB.R=R; RGB.G=G; RGB.B=B;
OutRGBTable.Set(c,s,RGB);
R+=RGBInc;
G+=RGBInc;
B+=RGBInc;
R+=RInc;
G+=GInc;
B+=BInc;
if (R<0) R=0; else if (R>255) R=255;
if (G<0) G=0; else if (G>255) G=255;
if (B<0) B=0; else if (B>255) B=255;
}
}
}
#if 0
void CMkLevelLayerRGB::PreProcess(CMkLevel *Core)
{
int X,Y;
int ColorCount;
int c;
// build RGB List
for (Y=0; Y<Height; Y++)
{
for (X=0; X<Width; X++)
{
sRGBElem &ThisElem=RGBMap.Get(X,Y);
sRGBList ThisRGB;
ThisRGB.RGB=ThisElem.RGB;
ThisRGB.Count=0;
int Idx=InRGBList.Add(ThisRGB);
ThisElem.TableIdx=Idx;
InRGBList[Idx].Count++;
}
}
ColorCount=InRGBList.size();
printf("------ %i Colors ------\n",ColorCount);
// Sort RGB List by usage
for (c=0; c<ColorCount; c++)
{
sRGBList &ThisRGB=InRGBList[c];
int s=0;
int SortListSize=SortRGBList.size();
for (; s<SortListSize; s++)
{
if (SortRGBList[s].Count<ThisRGB.Count) break;
}
SortRGBList.insert(s,ThisRGB);
}
// Build Remap table
for (c=0; c<ColorCount; c++)
{
int Idx=SortRGBList.Find(InRGBList[c]);
RemapTable.push_back(Idx);
/*
sRGBCol &In=InRGBList[c].RGB;
sRGBCol &Out=SortRGBList[RemapTable[c]].RGB;
if (In.R!=Out.R || In.G!=Out.G || In.B!=Out.B)
{
printf("%i %i %i\t%i %i %i\n",In.R,In.G,In.B,Out.R,Out.G,Out.B);
}
*/
}
// Remap all above 256
for (c=256;c<ColorCount;c++)
{
sRGBCol &ThisRGB=InRGBList[RemapTable[c]].RGB;
RemapTable[c ]=FindClosestRGB(ThisRGB);
}
// Build Out Map
OutMap.SetSize(Width,Height);
for (Y=0; Y<Height; Y++)
{
for (X=0; X<Width; X++)
{
sRGBElem &ThisElem=RGBMap.Get(X,Y);
u8 Idx=RemapTable[ThisElem.TableIdx];
OutMap.Set(X,Y,Idx);
}
}
// Build Out RGB Table
if (ColorCount>256) ColorCount=256;
OutRGBTable.SetSize(ColorCount,16);
int RGBInc=6;
if (ShadeFlag) RGBInc=-6;
for (c=0;c<ColorCount;c++)
{
sRGBCol &ThisRGB=SortRGBList[c].RGB;
int R=ThisRGB.R;
int G=ThisRGB.G;
int B=ThisRGB.B;
for (int s=0; s<16; s++)
{
sRGBCol RGB;
RGB.R=R; RGB.G=G; RGB.B=B;
OutRGBTable.Set(c,s,RGB);
R+=RGBInc;
G+=RGBInc;
B+=RGBInc;
if (R<0) R=0; else if (R>255) R=255;
if (G<0) G=0; else if (G>255) G=255;
if (B<0) B=0; else if (B>255) B=255;
}
}
}
/*****************************************************************************/
int CMkLevelLayerRGB::FindClosestRGB(sRGBCol const &RGB)
{
int CIdx=-1;
int CVal=0;
for (int i=0; i<256; i++)
{
sRGBCol &ListRGB=SortRGBList[i].RGB;
int Dr=abs(ListRGB.R-RGB.R);
int Dg=abs(ListRGB.G-RGB.G);
int Db=abs(ListRGB.B-RGB.B);
/*
int ThisVal=(SortRGBList[i].RGB.R*SortRGBList[i].RGB.R)+
(SortRGBList[i].RGB.G*SortRGBList[i].RGB.G)+
(SortRGBList[i].RGB.B*SortRGBList[i].RGB.B);
*/
int ThisVal=Dr+Dg+Db;
if (CIdx==-1 || ThisVal<CVal)
{
CIdx=i;
CVal=ThisVal;
}
}
return(CIdx);
}
#endif
/*****************************************************************************/
/*****************************************************************************/
/*** Process *****************************************************************/