This commit is contained in:
parent
4f2649a592
commit
057cb931bb
19 changed files with 919 additions and 590 deletions
|
@ -1,19 +1,18 @@
|
|||
/*******************/
|
||||
/*** Layer Shade ***/
|
||||
/*******************/
|
||||
/*****************/
|
||||
/*** Layer RGB ***/
|
||||
/*****************/
|
||||
|
||||
#include <DaveLib.h>
|
||||
#include <List2d.h>
|
||||
|
||||
#include "MkLevelLayer.h"
|
||||
#include "MkLevelLayerShade.h"
|
||||
#include "MkLevelLayerRGB.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
/*****************************************************************************/
|
||||
/*****************************************************************************/
|
||||
CMkLevelLayerShade::CMkLevelLayerShade(sExpLayerHdr *LayerHdr)
|
||||
CMkLevelLayerRGB::CMkLevelLayerRGB(sExpLayerHdr *LayerHdr)
|
||||
{
|
||||
int i,ListSize;
|
||||
int *iPtr;
|
||||
u8 *Ptr=(u8*)LayerHdr;
|
||||
|
||||
|
@ -22,36 +21,27 @@ u8 *Ptr=(u8*)LayerHdr;
|
|||
Width=LayerHdr->Width;
|
||||
Height=LayerHdr->Height;
|
||||
|
||||
RGBMap.SetSize(Width,Height);
|
||||
|
||||
iPtr=(int*)(Ptr+sizeof(sExpLayerHdr));
|
||||
|
||||
ShadeHdr.BandCount=*iPtr++;
|
||||
ShadeFlag=*iPtr++;
|
||||
|
||||
sRGBCol *RGB=(sRGBCol*)iPtr;
|
||||
for (i=0; i<LAYER_SHADE_RGB_MAX; i++)
|
||||
for (int Y=0; Y<Height; Y++)
|
||||
{
|
||||
ShadeHdr.RGB[i][0]=RGB->R;
|
||||
ShadeHdr.RGB[i][1]=RGB->G;
|
||||
ShadeHdr.RGB[i][2]=RGB->B;
|
||||
RGB++;
|
||||
}
|
||||
iPtr=(int*)RGB;
|
||||
|
||||
ListSize=*iPtr++;
|
||||
GfxList.resize(ListSize);
|
||||
sLayerShadeGfx *GfxPtr=(sLayerShadeGfx*)iPtr;
|
||||
for (i=0; i<ListSize; i++)
|
||||
{
|
||||
sLayerShadeGfx &ThisGfx=GfxList[i];
|
||||
GfxList[i]=*GfxPtr++;
|
||||
}
|
||||
|
||||
iPtr=(int*)GfxPtr;
|
||||
ListSize=*iPtr++;
|
||||
TypeNameList.resize(ListSize);
|
||||
char *TypePtr=(char*)iPtr;
|
||||
for (i=0; i<ListSize; i++)
|
||||
{
|
||||
TypeNameList[i]=TypePtr;
|
||||
TypePtr+=strlen(TypePtr)+1;
|
||||
for (int X=0; X<Width; X++)
|
||||
{
|
||||
sRGBElem ThisElem;
|
||||
ThisElem.RGB=*RGB++;
|
||||
ThisElem.RGB.P=0;
|
||||
ThisElem.TableIdx=0;
|
||||
// ThisElem.RGB.R&=-8;
|
||||
// ThisElem.RGB.G&=-8;
|
||||
// ThisElem.RGB.B&=-8;
|
||||
RGBMap.Set(X,Y,ThisElem);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -60,33 +50,123 @@ char *TypePtr=(char*)iPtr;
|
|||
/*** Pre-Process *************************************************************/
|
||||
/*****************************************************************************/
|
||||
/*****************************************************************************/
|
||||
// Build unique tiles, including pre-genned flips, and replace tile idx with new one
|
||||
void CMkLevelLayerShade::PreProcess(CMkLevel *Core)
|
||||
void CMkLevelLayerRGB::PreProcess(CMkLevel *Core)
|
||||
{
|
||||
int i,ListSize=GfxList.size();
|
||||
int Idx;
|
||||
GString Path=Core->GetConfigStr("MISC","BackGfxDir");
|
||||
CTexGrab &TexGrab=Core->GetTexGrab();
|
||||
int X,Y;
|
||||
int ColorCount;
|
||||
int c;
|
||||
|
||||
for (i=0; i<ListSize; i++)
|
||||
// build RGB List
|
||||
for (Y=0; Y<Height; Y++)
|
||||
{
|
||||
sLayerShadeGfx &ThisGfx=GfxList[i];
|
||||
sBackGfxList NewType;
|
||||
|
||||
NewType.Name=Path+TypeNameList[ThisGfx.Gfx]+".Bmp";
|
||||
Idx=OutTypeList.Find(NewType);
|
||||
|
||||
if (Idx==-1)
|
||||
for (X=0; X<Width; X++)
|
||||
{
|
||||
TexGrab.ZeroColZero(true);
|
||||
NewType.TexID=TexGrab.AddFile(NewType.Name);
|
||||
TexGrab.ZeroColZero(false);
|
||||
|
||||
Idx=OutTypeList.Add(NewType);
|
||||
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++;
|
||||
}
|
||||
ThisGfx.Gfx=Idx;
|
||||
}
|
||||
|
||||
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++)
|
||||
{
|
||||
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);
|
||||
|
||||
if (CIdx==-1 || ThisVal<CVal)
|
||||
{
|
||||
CIdx=i;
|
||||
CVal=ThisVal;
|
||||
}
|
||||
}
|
||||
return(CIdx);
|
||||
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -94,26 +174,8 @@ CTexGrab &TexGrab=Core->GetTexGrab();
|
|||
/*** Process *****************************************************************/
|
||||
/*****************************************************************************/
|
||||
/*****************************************************************************/
|
||||
void CMkLevelLayerShade::Process(CMkLevel *Core)
|
||||
void CMkLevelLayerRGB::Process(CMkLevel *Core)
|
||||
{
|
||||
int i,ListSize=OutTypeList.size();
|
||||
CTexGrab &TexGrab=Core->GetTexGrab();
|
||||
|
||||
//printf("Process Shade Layer\n");
|
||||
for (i=0; i<ListSize; i++)
|
||||
{
|
||||
sBackGfxList &ThisType=OutTypeList[i];
|
||||
|
||||
sTexOutInfo &ThisTex=TexGrab.GetTexInfo()[ThisType.TexID];
|
||||
ThisType.Out.TPage=ThisTex.Tpage;
|
||||
ThisType.Out.Clut=ThisTex.Clut;
|
||||
ThisType.Out.U=ThisTex.u;
|
||||
ThisType.Out.V=ThisTex.v;
|
||||
ThisType.Out.W=ThisTex.w;
|
||||
ThisType.Out.H=ThisTex.h;
|
||||
// ThisType.TPage|=Trans[i]<<5;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -121,10 +183,11 @@ CTexGrab &TexGrab=Core->GetTexGrab();
|
|||
/** Write ********************************************************************/
|
||||
/*****************************************************************************/
|
||||
/*****************************************************************************/
|
||||
int CMkLevelLayerShade::Write(CMkLevel *Core,FILE *File,const char *LayerName)
|
||||
int CMkLevelLayerRGB::Write(CMkLevel *Core,FILE *File,const char *LayerName)
|
||||
{
|
||||
sLayerHdr Hdr;
|
||||
int ThisPos=ftell(File);
|
||||
sLayerHdr Hdr;
|
||||
sLayerRGBHdr RGBHdr;
|
||||
|
||||
Hdr.Type=Type;
|
||||
Hdr.SubType=SubType;
|
||||
|
@ -133,65 +196,53 @@ int ThisPos=ftell(File);
|
|||
fwrite(&Hdr,sizeof(sLayerHdr),1,File);
|
||||
|
||||
int HdrPos=ftell(File);
|
||||
fwrite(&ShadeHdr,sizeof(sLayerShadeHdr),1,File);
|
||||
|
||||
|
||||
// Write Gfx Stuff
|
||||
ShadeHdr.GfxList=(sLayerShadeBackGfx*)(WriteGfxList(File)-ThisPos);
|
||||
ShadeHdr.TypeList=(sLayerShadeBackGfxType*)(WriteTypeList(File)-ThisPos);
|
||||
fwrite(&RGBHdr,sizeof(sLayerRGBHdr),1,File);
|
||||
|
||||
RGBHdr.RGBMap=WriteRGBMap(File);
|
||||
PadFile(File);
|
||||
RGBHdr.RGBTable=WriteRGBTable(File);
|
||||
PadFile(File);
|
||||
// rewrite header
|
||||
int RetPos=ftell(File);
|
||||
fseek(File,HdrPos,SEEK_SET);
|
||||
fwrite(&ShadeHdr,sizeof(sLayerShadeHdr),1,File);
|
||||
fwrite(&RGBHdr,sizeof(sLayerRGBHdr),1,File);
|
||||
fseek(File,RetPos,SEEK_SET);
|
||||
|
||||
|
||||
Size=ftell(File)-ThisPos;
|
||||
|
||||
return(ThisPos);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
int CMkLevelLayerShade::WriteTypeList(FILE *File)
|
||||
int CMkLevelLayerRGB::WriteRGBMap(FILE *File)
|
||||
{
|
||||
int Pos=ftell(File);
|
||||
int i,ListSize=OutTypeList.size();
|
||||
int ThisPos=ftell(File);
|
||||
|
||||
for (i=0; i<ListSize; i++)
|
||||
for (int Y=0; Y<Height; Y++)
|
||||
{
|
||||
sBackGfxList &ThisType=OutTypeList[i];
|
||||
|
||||
fwrite(&ThisType.Out,sizeof(sLayerShadeBackGfxType),1,File);
|
||||
}
|
||||
return(Pos);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
int CMkLevelLayerShade::WriteGfxList(FILE *File)
|
||||
{
|
||||
int Pos=ftell(File);
|
||||
int i,ListSize=GfxList.size();
|
||||
|
||||
ShadeHdr.GfxCount=ListSize;
|
||||
|
||||
for (i=0; i<ListSize; i++)
|
||||
{
|
||||
sLayerShadeGfx &ThisGfx=GfxList[i];
|
||||
sLayerShadeBackGfx Out;
|
||||
|
||||
Out.Type=ThisGfx.Gfx;
|
||||
Out.PosX=ThisGfx.Pos.x;
|
||||
Out.PosY=ThisGfx.Pos.y;
|
||||
Out.Trans=ThisGfx.TransMode;
|
||||
for (int p=0; p<4; p++)
|
||||
for (int X=0; X<Width; X++)
|
||||
{
|
||||
Out.Ofs[p][0]=ThisGfx.Ofs[p].x;
|
||||
Out.Ofs[p][1]=ThisGfx.Ofs[p].y;
|
||||
Out.RGB[p][0]=ThisGfx.RGB[p].R;
|
||||
Out.RGB[p][1]=ThisGfx.RGB[p].G;
|
||||
Out.RGB[p][2]=ThisGfx.RGB[p].B;
|
||||
u8 Idx=OutMap.Get(X,Y);
|
||||
fwrite(&Idx,1,sizeof(u8),File);
|
||||
}
|
||||
fwrite(&Out,sizeof(sLayerShadeBackGfx),1,File);
|
||||
}
|
||||
return(Pos);
|
||||
printf("--> RGBMap %i %i\n",ThisPos,ftell(File)-ThisPos);
|
||||
return(ThisPos);
|
||||
}
|
||||
/*****************************************************************************/
|
||||
int CMkLevelLayerRGB::WriteRGBTable(FILE *File)
|
||||
{
|
||||
int ThisPos=ftell(File);
|
||||
int ListSize=OutRGBTable.GetWidth();
|
||||
|
||||
for (int c=0; c<ListSize; c++)
|
||||
{
|
||||
for (int s=0; s<16; s++)
|
||||
{
|
||||
sRGBCol &RGB=OutRGBTable.Get(c,s);
|
||||
fwrite(&RGB,1,sizeof(sRGBCol),File);
|
||||
}
|
||||
}
|
||||
printf("--> RGBTable %i %i\n",ThisPos,ftell(File)-ThisPos);
|
||||
return(ThisPos);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue