summaryrefslogtreecommitdiff
path: root/dxr3colormanager.c
diff options
context:
space:
mode:
authorscop <scop>2005-04-19 18:19:34 +0000
committerscop <scop>2005-04-19 18:19:34 +0000
commitf9c59e544ada17055c3ed15b3d80f0d285c3928d (patch)
treecd7b038c17b040beb435e0a16aab02346854c9ad /dxr3colormanager.c
parentdea137eddfe1017e9ff85a8c221aee2bca4647ad (diff)
downloadvdr-plugin-dxr3-f9c59e544ada17055c3ed15b3d80f0d285c3928d.tar.gz
vdr-plugin-dxr3-f9c59e544ada17055c3ed15b3d80f0d285c3928d.tar.bz2
Mass indentation/whitespace cleanup.
Diffstat (limited to 'dxr3colormanager.c')
-rw-r--r--dxr3colormanager.c377
1 files changed, 202 insertions, 175 deletions
diff --git a/dxr3colormanager.c b/dxr3colormanager.c
index 1ddca35..1e40711 100644
--- a/dxr3colormanager.c
+++ b/dxr3colormanager.c
@@ -60,166 +60,189 @@
//! constructor
cColorManager::cColorManager()
{
- NrOfRegions = -1;
- for(int i = 0; i < MAX_NO_OF_REGIONS; i++)
- hlr[i] = NULL;
+ NrOfRegions = -1;
+ for(int i = 0; i < MAX_NO_OF_REGIONS; i++)
+ hlr[i] = NULL;
}
// ==================================
cColorManager::~cColorManager()
{
- for (int i = 0; i < NrOfRegions; i++)
+ for (int i = 0; i < NrOfRegions; i++)
+ {
+ if (hlr[i])
{
- if (hlr[i])
- {
- delete(hlr[i]);
- }
+ delete(hlr[i]);
}
+ }
}
// ==================================
// Opens a new highlight region
void cColorManager::OpenRegion(int y)
{
- // Calling method (cColorManager::EncodeColors)
- // already checks MAX_NO_OF_REGIONS
- curRegion = new yRegion();
- curRegion->Y1 = y;
- NrOfRegions++;
- hlr[NrOfRegions] = curRegion;
- NewSection(0); //there's always at least a section
+ // Calling method (cColorManager::EncodeColors)
+ // already checks MAX_NO_OF_REGIONS
+ curRegion = new yRegion();
+ curRegion->Y1 = y;
+ NrOfRegions++;
+ hlr[NrOfRegions] = curRegion;
+ NewSection(0); //there's always at least a section
}
// ==================================
// Closes the spu-highlight region
void cColorManager::CloseRegion(int y)
{
- curRegion->Y2 = y;
+ curRegion->Y2 = y;
}
-// ==================================
-void cColorManager::EncodeColors(int width, int height, unsigned char* map, unsigned char* dmap)
+// ==================================
+void cColorManager::EncodeColors(int width, int height, unsigned char* map,
+ unsigned char* dmap)
{
unsigned char color;
- unsigned char oldcolor=0xFF;
+ unsigned char oldcolor = 0xFF;
unsigned char ColorIndex;
- int mapoffset=0;
+ int mapoffset = 0;
OpenRegion(0);
- for (int y = 0; y < height; ++y) {
- oldcolor=0xFF;
- FirstSection();
- for(int x = 0; x < width; ++x) {
- if(x>curSection->X2) {
- oldcolor=0xFF;
- NextSection();
- }
- color = map[mapoffset + x];
- if (color==oldcolor) dmap[mapoffset + x]=ColorIndex; else {
- //try to map the color in the current region
- if (AddColor(x,y,color, ColorIndex)) {
- // store as the highlight region index
- dmap[mapoffset + x]=ColorIndex;
- } else {
- CloseRegion(y-1);
- if(NrOfRegions<=MAX_NO_OF_REGIONS-1) {
- //retry with another region
- OpenRegion(y);
- x = -1;
- oldcolor=0xFF;
- } else
- {
- //give up
- cLog::Instance() << "dxr3colormanager: too many regions!\n";
- return;
- }
- }
- }
- }
- mapoffset+=width;
+ for (int y = 0; y < height; ++y)
+ {
+ oldcolor = 0xFF;
+ FirstSection();
+ for(int x = 0; x < width; ++x)
+ {
+ if (x > curSection->X2)
+ {
+ oldcolor = 0xFF;
+ NextSection();
+ }
+ color = map[mapoffset + x];
+ if (color == oldcolor)
+ dmap[mapoffset + x] = ColorIndex;
+ else
+ {
+ // try to map the color in the current region
+ if (AddColor(x, y, color, ColorIndex))
+ {
+ // store as the highlight region index
+ dmap[mapoffset + x] = ColorIndex;
+ }
+ else
+ {
+ CloseRegion(y - 1);
+ if (NrOfRegions <= MAX_NO_OF_REGIONS - 1)
+ {
+ // retry with another region
+ OpenRegion(y);
+ x = -1;
+ oldcolor = 0xFF;
+ }
+ else
+ {
+ // give up
+ cLog::Instance() << "dxr3colormanager: too many regions!\n";
+ return;
+ }
+ }
+ }
+ }
+ mapoffset += width;
}
- //close the last highligt region
+ // close the last highlight region
CloseRegion(height);
-//#define colordebug
-#ifdef colordebug
- {
- FILE *fp;
- fp = fopen("OSD.dump","w+");
- u_char *pippo=dmap;
- u_char *pippo2=map;
- int curregion=0;
- int cursection=0;
-
-
- for (int dumpy=0; dumpy<height; dumpy++)
- {
- if(curregion<NrOfRegions) {
- if(hlr[curregion]->Y1==dumpy) {
- fprintf(fp,"%i",hlr[curregion]->N);
- for(int sec=0; sec<hlr[curregion]->N; sec++) fprintf(fp,",%i",hlr[curregion]->Section[sec]->X1);
- for(int dumpx=0; dumpx<width; dumpx++) fprintf(fp,"=");
- fprintf(fp,"\n");
- curregion++;
- }
- }
-
- cursection=0;
- for(int dumpx=0; dumpx<width; dumpx++) {
- if(curregion<NrOfRegions) {
- if(cursection<hlr[curregion]->N) {
- if(hlr[curregion]->Section[cursection]->X1==dumpx) {
- fprintf(fp,"|");
- cursection++;
- }
- }
- }
- fprintf(fp,"%01X",*pippo2 & 0xF);
- pippo2++;
- }
- fprintf(fp,"\n");
-
-
- cursection=0;
- for(int dumpx=0; dumpx<width; dumpx++) {
- if(curregion<NrOfRegions) {
- if(cursection<hlr[curregion]->N) {
- if(hlr[curregion]->Section[cursection]->X1==dumpx) {
- fprintf(fp,"|");
- cursection++;
- }
- }
- }
- fprintf(fp,"%01X",*pippo & 0xF);
- pippo++;
- }
- fprintf(fp,"\n");
- }
- fclose(fp);
- printf("**** dumped\n");
+//#define colordebug
+#ifdef colordebug
+ {
+ FILE *fp;
+ fp = fopen("OSD.dump","w+");
+ u_char *pippo = dmap;
+ u_char *pippo2 = map;
+ int curregion = 0;
+ int cursection = 0;
+
+
+ for (int dumpy = 0; dumpy < height; dumpy++)
+ {
+ if(curregion < NrOfRegions)
+ {
+ if(hlr[curregion]->Y1 == dumpy)
+ {
+ fprintf(fp, "%i", hlr[curregion]->N);
+ for (int sec = 0; sec < hlr[curregion]->N; sec++)
+ fprintf(fp, ",%i", hlr[curregion]->Section[sec]->X1);
+ for (int dumpx = 0; dumpx < width; dumpx++)
+ fprintf(fp, "=");
+ fprintf(fp, "\n");
+ curregion++;
+ }
+ }
+
+ cursection = 0;
+ for (int dumpx = 0; dumpx < width; dumpx++)
+ {
+ if (curregion < NrOfRegions)
+ {
+ if (cursection < hlr[curregion]->N)
+ {
+ if (hlr[curregion]->Section[cursection]->X1 == dumpx)
+ {
+ fprintf(fp, "|");
+ cursection++;
+ }
+ }
+ }
+ fprintf(fp, "%01X", *pippo2 & 0xF);
+ pippo2++;
+ }
+ fprintf(fp, "\n");
+
+ cursection = 0;
+ for (int dumpx = 0; dumpx < width; dumpx++)
+ {
+ if(curregion < NrOfRegions)
+ {
+ if (cursection < hlr[curregion]->N)
+ {
+ if (hlr[curregion]->Section[cursection]->X1 == dumpx)
+ {
+ fprintf(fp, "|");
+ cursection++;
+ }
+ }
+ }
+ fprintf(fp, "%01X", *pippo & 0xF);
+ pippo++;
+ }
+ fprintf(fp, "\n");
+ }
+ fclose(fp);
+ printf("**** dumped\n");
}
#endif
-
}
// ==================================
-unsigned char cColorManager::AddColor(int x, int y, unsigned char color, unsigned char &ColorIndex) {
-
- if (!curSection->HasColor(color, ColorIndex))
- {
- // this color is new for this section
- if (curSection->AllColorsUsed())
- {
- // no more free colors
- if (y != curRegion->Y1)
- {
- // terminate region
- return(0);
- }
- NewSection(x);
- }
- // and add new color
- ColorIndex = curSection->AddColor(color);
+unsigned char cColorManager::AddColor(int x, int y, unsigned char color,
+ unsigned char &ColorIndex) {
+
+ if (!curSection->HasColor(color, ColorIndex))
+ {
+ // this color is new for this section
+ if (curSection->AllColorsUsed())
+ {
+ // no more free colors
+ if (y != curRegion->Y1)
+ {
+ // terminate region
+ return(0);
+ }
+ NewSection(x);
+ }
+ // and add new color
+ ColorIndex = curSection->AddColor(color);
}
return(1);
}
@@ -227,27 +250,28 @@ unsigned char cColorManager::AddColor(int x, int y, unsigned char color, unsigne
// ==================================
void cColorManager::FirstSection(void)
{
- curSectionIndex=0;
- curSection=curRegion->Section[0];
+ curSectionIndex = 0;
+ curSection = curRegion->Section[0];
}
// ==================================
void cColorManager::NextSection(void)
{
curSectionIndex++;
- if(curSectionIndex<curRegion->N) curSection=curRegion->Section[curSectionIndex];
- //it shouldn't happen
+ if (curSectionIndex < curRegion->N)
+ curSection=curRegion->Section[curSectionIndex];
+ // it shouldn't happen
else cLog::Instance() <<
- "dxr3colormanager: no more sections in NextSection!\n";
+ "dxr3colormanager: no more sections in NextSection!\n";
}
// ==================================
// convert into SPU - hope is correct description
unsigned char* cColorManager::GetSpuData(int& len)
{
- if (NrOfRegions >= 0)
+ if (NrOfRegions >= 0)
{
- int ptr = 0;
+ int ptr = 0;
spudata[ptr++] = 0x07; // CHG_COLCON command
spudata[ptr++] = 0x00; // total size of parameter area
spudata[ptr++] = 0x00; // will be filled later
@@ -255,21 +279,21 @@ unsigned char* cColorManager::GetSpuData(int& len)
for(int i = 0; i <= NrOfRegions;i++)
{
- spudata[ptr++] = (hlr[i]->Y1 >> 8) & 0x0f;
- spudata[ptr++] = (hlr[i]->Y1 & 0xff);
- spudata[ptr++] = ( ( (hlr[i]->N) & 0x0f) << 4) | ((hlr[i]->Y2 >> 8) & 0x0f);
- spudata[ptr++] = (hlr[i]->Y2 & 0xff);
-
- for(int c = 0; c < hlr[i]->N; c++)
- {
- spudata[ptr++] = hlr[i]->Section[c]->X1 >> 8;
- spudata[ptr++] = hlr[i]->Section[c]->X1 & 0xff;
- spudata[ptr++] = (hlr[i]->Section[c]->Colors[3] << 4) | (hlr[i]->Section[c]->Colors[2] & 0x0F);
- spudata[ptr++] = (hlr[i]->Section[c]->Colors[1] << 4) | (hlr[i]->Section[c]->Colors[0] & 0x0F);
-
- spudata[ptr++] = (hlr[i]->Section[c]->Opac[3] << 4) | hlr[i]->Section[c]->Opac[2];
- spudata[ptr++] = (hlr[i]->Section[c]->Opac[1] << 4) | hlr[i]->Section[c]->Opac[0];
- }
+ spudata[ptr++] = (hlr[i]->Y1 >> 8) & 0x0f;
+ spudata[ptr++] = (hlr[i]->Y1 & 0xff);
+ spudata[ptr++] = (((hlr[i]->N) & 0x0f) << 4) | ((hlr[i]->Y2 >> 8) & 0x0f);
+ spudata[ptr++] = (hlr[i]->Y2 & 0xff);
+
+ for(int c = 0; c < hlr[i]->N; c++)
+ {
+ spudata[ptr++] = hlr[i]->Section[c]->X1 >> 8;
+ spudata[ptr++] = hlr[i]->Section[c]->X1 & 0xff;
+ spudata[ptr++] = (hlr[i]->Section[c]->Colors[3] << 4) | (hlr[i]->Section[c]->Colors[2] & 0x0F);
+ spudata[ptr++] = (hlr[i]->Section[c]->Colors[1] << 4) | (hlr[i]->Section[c]->Colors[0] & 0x0F);
+
+ spudata[ptr++] = (hlr[i]->Section[c]->Opac[3] << 4) | hlr[i]->Section[c]->Opac[2];
+ spudata[ptr++] = (hlr[i]->Section[c]->Opac[1] << 4) | hlr[i]->Section[c]->Opac[0];
+ }
}
spudata[ptr++] = 0x0f; // termination of parameter block
spudata[ptr++] = 0xff;
@@ -282,34 +306,37 @@ unsigned char* cColorManager::GetSpuData(int& len)
len = ptr;
}
else
- len = 0;
+ {
+ len = 0;
+ }
#if OSD_SPU_CM_DUMP
- FILE *fp;
- fp = fopen("CM.dump","a+");
- fprintf(fp,"len:%03d ",len);
+ FILE *fp;
+ fp = fopen("CM.dump", "a+");
+ fprintf(fp, "len:%03d ", len);
for (int i = 0; i < len; i++)
- fprintf(fp,"%02X",*(spudata+i));
- fprintf(fp,"\n");
+ fprintf(fp, "%02X", *(spudata + i));
+ fprintf(fp, "\n");
fclose(fp);
#endif
- return(spudata);
+ return(spudata);
}
// ==================================
void cColorManager::NewSection(int x)
{
int N = curRegion->N;
- if (N>=MAX_NO_OF_SECTIONS-1) {
- cLog::Instance() << "dxr3colormanager: bummer, too many sections\n";
- return; //reuse last section, not optimal but there's no other way out
- }
+ if (N >= MAX_NO_OF_SECTIONS - 1) {
+ cLog::Instance() << "dxr3colormanager: bummer, too many sections\n";
+ return; // reuse last section, not optimal but there's no other way out
+ }
curSection = new xSection(x);
curRegion->Section[N] = curSection;
- if (N > 0) curRegion->Section[N-1]->X2 = x-1;
+ if (N > 0)
+ curRegion->Section[N-1]->X2 = x - 1;
(curRegion->N)++;
- curSectionIndex=N;
+ curSectionIndex = N;
}
// ==================================
@@ -320,22 +347,22 @@ xSection::xSection(int x)
NrOfColors = 0;
for (int i = 0; i < 4; i++)
{
- Opac[i] = 0xFF;
- Colors[i] = 0;
+ Opac[i] = 0xFF;
+ Colors[i] = 0;
}
}
// ==================================
unsigned char xSection::AddColor(unsigned int color)
{
- unsigned char ColorIndex = 0;
+ unsigned char ColorIndex = 0;
- if (NrOfColors <= 3)
+ if (NrOfColors <= 3)
{
- Colors[NrOfColors] = color;
- Opac[NrOfColors] = color >> 4;
- ColorIndex = NrOfColors;
- NrOfColors++;
+ Colors[NrOfColors] = color;
+ Opac[NrOfColors] = color >> 4;
+ ColorIndex = NrOfColors;
+ NrOfColors++;
}
return(ColorIndex);
}
@@ -343,13 +370,13 @@ unsigned char xSection::AddColor(unsigned int color)
// ==================================
bool xSection::HasColor(unsigned int color, unsigned char &ColorIndex)
{
- for(int i = 0; i < NrOfColors; i++)
+ for(int i = 0; i < NrOfColors; i++)
{
- if (Colors[i] == color)
- {
- ColorIndex = i;
- return (true);
- }
+ if (Colors[i] == color)
+ {
+ ColorIndex = i;
+ return (true);
+ }
}
return(false);
}