From patchwork Sun Apr 10 17:51:22 2005 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luca Olivetti X-Patchwork-Id: 11854 Received: from 232.red-213-97-27.pooles.rima-tde.net ([213.97.27.232]) by www.linuxtv.org with esmtp (Exim 4.34) id 1DKgbI-00088e-Nc for vdr@linuxtv.org; Sun, 10 Apr 2005 19:52:01 +0200 Received: from [127.0.0.1] (localhost.localdomain [127.0.0.1]) by 232.Red-213-97-27.pooles.rima-tde.net (Postfix) with ESMTP id 5EBAF18ACEC8 for ; Sun, 10 Apr 2005 19:51:29 +0200 (CEST) Message-ID: <4259679A.2030605@ventoso.org> Date: Sun, 10 Apr 2005 19:51:22 +0200 From: Luca Olivetti User-Agent: Mozilla Thunderbird 0.9 (X11/20041103) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Klaus Schmidinger's VDR Subject: Re: [vdr] [PATCH] dxr3 better (hopefully) color management References: <42592DF2.9040704@ventoso.org> In-Reply-To: <42592DF2.9040704@ventoso.org> X-Enigmail-Version: 0.89.0.0 X-Enigmail-Supports: pgp-inline, pgp-mime X-BeenThere: vdr@linuxtv.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Klaus Schmidinger's VDR List-Id: Klaus Schmidinger's VDR List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 10 Apr 2005 17:52:01 -0000 Status: O X-Status: X-Keywords: X-UID: 1516 Luca Olivetti wrote: > I still couldn't find the cause of color bleeding: both the color > manager (apart from the error fixed by the patch) and the spu encoder > seems ok to me. I found it and now it's gone :-) Apply the attached patch, additional to the previous one. Apart from the name change of a couple of variables, it only removes the bogus optimization that avoided calculating the index if the color hadn't changed (but since it might be in a different region/section it could well have a different index even if it's the same color). Bye --- dxr3colormanager.c.orig 2005-04-10 19:44:53.279555663 +0200 +++ dxr3colormanager.c 2005-04-10 19:42:13.417600365 +0200 @@ -81,19 +81,11 @@ // ================================== // Opens a new highlight region -void cColorManager::OpenRegion(int y, int NrOfSecToCopy) +void cColorManager::OpenRegion(int y) { hlr[NrOfRegions] = new yRegion(); hlr[NrOfRegions]->Y1 = y; isopen = true; - - if (NrOfSecToCopy > 0) - { - for (int i = 0; i < NrOfSecToCopy; i++) - { - hlr[NrOfRegions]->Section[i] = hlr[NrOfRegions - 1]->Section[i]; - } - } } // ================================== @@ -103,6 +95,7 @@ hlr[NrOfRegions]->Y2 = y; isopen = false; + if (hlr[NrOfRegions]->N != 0) // skip this region if there is no section defined { @@ -117,60 +110,100 @@ // ================================== void cColorManager::EncodeColors(int width, int height, unsigned char* map, unsigned char* dmap) { - unsigned char color = 0xFF, ccol = 0xFF; - unsigned char ColorIndex = 0xFF; + unsigned char color; + unsigned char ColorIndex; unsigned char buffer[1024] = {0}; - for (int y = 0; y < height; ++y) - { - color = 0xFF; - for(int x = 0; x < width; ++x) - { - ccol = map[y * width + x]; - if (ccol != 0) MaxY = y; - if (ccol != color) - { - color = ccol; // save this color - if (!AddColor(x,y,color, ColorIndex)) - { - // add this color to highlight regions - color = 0xFF; - x = -1; - } - else - { - // color successfully added - buffer[x] = ColorIndex; - } + for (int y = 0; y < height; ++y) { + for(int x = 0; x < width; ++x) { + color = map[y * width + x]; + if (color != 0) MaxY = y; + if (AddColor(x,y,color, ColorIndex)) { + // store as the highlight region index + buffer[x]=ColorIndex; + } else { + //retry with another region - FIXME: check limits to avoid infinite loop + x = -1; } - else - { - buffer[x] = ColorIndex;//*(dmap+(y * width + x)) = ColorIndex; - } } dxr3_memcpy(dmap+y*width, buffer,width); } + +/* + { + 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; dumpyY1==dumpy) { + fprintf(fp,"%i",hlr[curregion]->N); + for(int sec=0; secN; sec++) fprintf(fp,",%i",hlr[curregion]->Section[sec]->X1); + for(int dumpx=0; dumpxN) { + 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; dumpxN) { + if(hlr[curregion]->Section[cursection]->X1==dumpx) { + fprintf(fp,"|"); + cursection++; + } + } + } + fprintf(fp,"%01X",*pippo & 0xF); + pippo++; + } + fprintf(fp,"\n"); + } + printf("**** dumped\n"); + } +*/ + } // ================================== unsigned char cColorManager::AddColor(int x, int y, unsigned char color, unsigned char &ColorIndex) { static int yold = -1; - xSection* Section = 0; - int SectionIndex = 0; + xSection *curSection; if (isopen) { - // there is an opened highlight-region - Section = GetSection(x, SectionIndex); - + curSection=GetSection(x); // checks whether we have a section defined on the formerly line on this x-position - if (Section != NULL) + if (curSection != NULL) { // there was a section - if (!Section->HasColor(color, ColorIndex)) + if (!curSection->HasColor(color, ColorIndex)) { // this color is new for this section - if (Section->AllColorsUsed()) + if (curSection->AllColorsUsed()) { // no more free colors if (yold != y) @@ -178,14 +211,10 @@ CloseRegion(y-1); // terminate region return(0); - //yold = y; - // // open new region - //OpenRegion(y,SectionIndex+1); } - - Section = NewSection(x); + curSection = NewSection(x); } // and add new color - ColorIndex = Section->AddColor(color); + ColorIndex = curSection->AddColor(color); } } else @@ -198,9 +227,9 @@ // open new region OpenRegion(y); // create new section - Section = NewSection(x); + curSection = NewSection(x); // and add new color - ColorIndex = Section->AddColor(color); + ColorIndex = curSection->AddColor(color); } } else @@ -211,25 +240,23 @@ // open new region OpenRegion(y); // create new section - Section = NewSection(x); + curSection = NewSection(x); // and add new color - ColorIndex = Section->AddColor(color); + ColorIndex = curSection->AddColor(color); } return(1); } // ================================== -xSection *cColorManager::GetSection(int x, int &n) +xSection *cColorManager::GetSection(int x) { int i; - n = 0; // for every section in the current region for (i = 0; i < hlr[NrOfRegions]->N; i++) { if ((x <= hlr[NrOfRegions]->Section[i]->X2) && (x >= hlr[NrOfRegions]->Section[i]->X1)) // x-pos is in section { - n = i; return (hlr[NrOfRegions]->Section[i]); } } --- dxr3colormanager.h.orig 2005-04-10 19:44:53.294551063 +0200 +++ dxr3colormanager.h 2005-04-10 19:39:57.125414307 +0200 @@ -109,14 +109,14 @@ unsigned char spudata[2*4096]; unsigned int BgCol; int MaxY; - + /** Opens a new highlight region */ - void OpenRegion(int y, int NrOfSecToCopy = 0); + void OpenRegion(int y); /** Closes the spu-highlight region */ void CloseRegion(int y); xSection* NewSection(int x); - xSection *GetSection(int x, int &n); + xSection *GetSection(int x); }; #endif /*_DXR3COLORMANAGER_H_*/