From patchwork Sun Apr 3 13:07:42 2005 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Luca Olivetti X-Patchwork-Id: 11842 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 1DI4qI-0003OD-VL for vdr@linuxtv.org; Sun, 03 Apr 2005 15:08:45 +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 F2E161800087 for ; Sun, 3 Apr 2005 15:07:50 +0200 (CEST) Message-ID: <424FEA9E.1050207@ventoso.org> Date: Sun, 03 Apr 2005 15:07:42 +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: dxr3plugin OSD don't turn pink References: <424A9224.4000608@compuserve.de> <1112217417.31596.17.camel@bobcat.mine.nu> <424E66B0.1030901@ventoso.org> <424E6E6E.9000307@compuserve.de> <424E72B6.8000903@ventoso.org> <424E757F.2040804@ventoso.org> <424E7743.8060801@ventoso.org> <424E7852.60808@ventoso.org> <424E793E.9040202@ventoso.org> <1112448795.23456.48.camel@bobcat.mine.nu> <424ECCA5.1030309@ventoso.org> <1112461894.12964.1.camel@bobcat.mine.nu> <424FD272.2050808@ventoso.org> In-Reply-To: <424FD272.2050808@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, 03 Apr 2005 13:08:45 -0000 Status: O X-Status: X-Keywords: X-UID: 1378 Luca Olivetti wrote: > Ville Skyttä wrote: > >> On Sat, 2005-04-02 at 18:47 +0200, Luca Olivetti wrote: >> >>> Ville Skyttä wrote: >>> >>> >>>> Yep, that's expected. Before the patch, colors weren't being >>>> "freed" in >>>> OSD_Close, but were left reserved even though nothing in the OSD was >>>> using them any more. That obviously resulted in the whole whopping >>>> limit of 16 colors reaching the top sooner than supposed. >>> >>> >>> Since freeing colours should be better, then why the strange problem >>> after using the yaepg plugin? >> >> >> >> Beats me, I've never looked at yaepg... perhaps it's not closing the OSD >> properly or something. > > > Ok, your fix is wrong, I have (what seems to be) the correct one. I will > try it a bit more, clean it up a bit and send it later. Here's the patch, to apply with neither yours or Martin's one applied. Since things are starting to get confusing, I'm also attaching the complete files I'm using in a tgz. Basically there were 2 problems: 1) colors are added multiple times but removed only once[*] when the osd is closed, so the usage count would never get to 0 and the colors would never actually be freed. The fix is to set m_colors to one instead of incrementing it each time. [*]that's not exactly true but it doesn't matter since the osd is being closed anyway. 2) RemoveColor expected a color, but the colors in m_window are actually indexes coupled to transparency values. The fix is to change RemoveColor to accept an index instead. There's also a futile attempt to use the nearest color when the palette is full, but I doubt it's really useful. Bye --- dxr3interface_spu_encoder.c.nopink 2005-04-02 12:38:23.403634330 +0200 +++ dxr3interface_spu_encoder.c 2005-04-03 14:50:08.967010815 +0200 @@ -287,6 +287,7 @@ switch (cmd) { case OSD_SetWindow: + //printf("OSD_SetWindow %d\n",x0); // (x0) set window with number 0 0) { @@ -298,6 +299,7 @@ break; case OSD_Open: + //printf("OSD_Open\n"); // (x0,y0,x1,y1,BitPerPixel[2/4/8](color&0x0F),mix[0..15](color&0xF0)) // Opens OSD with this size and bit depth // returns 0 on success, -1 on DRAM allocation error, -2 on "already open" @@ -310,6 +312,7 @@ break; case OSD_SetPalette: + //printf("OSD_SetPalette\n"); // Spu->Cmd(OSD_SetPalette, 0, NumColors - 1, 0, 0, 0, Colors); // (firstcolor{color},lastcolor{x0},data) // Set a number of entries in the palette @@ -328,9 +331,7 @@ for (int x = color, i = 0; x <= x0; x++,i++) { - m_palManager.AddColor((int)*col & 0xFFFFFF); - - idx = m_palManager.GetIndex((int)*col & 0xFFFFFF); + idx = m_palManager.AddColor((int)*col & 0xFFFFFF); if (m_palManager.HasChanged()) { cDxr3Interface::Instance().SetPalette(m_palManager.GetPalette()); @@ -388,27 +389,19 @@ break; case OSD_Close: - // clear colors from plattemanager + // printf("OSD_Close\n"); - #if VDRVERSNUM >= 10307 - if ((col = (tColor*)m_windows[m_lastwindow].colors) != NULL) - #else - if ((col = (eDvbColor*)m_windows[m_lastwindow].colors) != NULL) - #endif - { - for (int i = 0; i < m_windows[m_lastwindow].NumColors; ++i) - { - m_palManager.RemoveColor((int)(col[i]) & 0xFFFFFF); - } - } + // clear colors from palettemanager + for (unsigned int i = 0; i < m_windows[m_lastwindow].NumColors; ++i) + m_palManager.RemoveColor(m_windows[m_lastwindow].colors[i] & 0xF); // clear osd - for (int i = m_windows[m_lastwindow].y0; i <= m_windows[m_lastwindow].y1; ++i) + for (unsigned int i = m_windows[m_lastwindow].y0; i <= m_windows[m_lastwindow].y1; ++i) { cp = &OSD_Screen[i*OSDWIDTH + m_windows[m_lastwindow].x0]; if ((cp+m_windows[m_lastwindow].x1-m_windows[m_lastwindow].x0+1) < &OSD_Screen[OSDWIDTH * OSDHEIGHT-1]) { - for (int xx=0; xx <= (m_windows[m_lastwindow].x1-m_windows[m_lastwindow].x0); xx++) + for (unsigned int xx=0; xx <= (m_windows[m_lastwindow].x1-m_windows[m_lastwindow].x0); xx++) { *(cp+xx) = 0x00; } @@ -444,6 +437,7 @@ break; case OSD_Clear: + //printf("OSD_Clear\n"); // Sets all pixel to color 0 // returns 0 on success --- dxr3palettemanager.c.nopink 2005-04-02 12:38:23.416630349 +0200 +++ dxr3palettemanager.c 2005-04-03 14:45:52.423561263 +0200 @@ -21,64 +21,69 @@ memset(m_colors, 0, sizeof(int) * MAX_COLORS); memset(m_users, 0, sizeof(int) * MAX_COLORS); memset(m_pal, 0, sizeof(int) * MAX_COLORS); - m_changed = false; + m_changed = true; }; +int ColorDistance (int color1, int color2) +{ + int d1=(color1>>24)-(color2>>24); + int d2=((color1>>16) & 0xFF)-((color2>>16) & 0xFF); + int d3=(color1 & 0xFF)-(color2 & 0xFF); + return d1*d1+d2*d2+d3*d3; +} + // ================================== -void cDxr3PaletteManager::AddColor(int color) +int cDxr3PaletteManager::AddColor(int color) { int freeIndex = MAX_COLORS; - bool found = false; - - for (int i = 0; i < MAX_COLORS && !found; ++i) + int curDistance = ColorDistance(color, m_colors[0]); + int nearestIndex = 0; + //printf("AddColor %x ",color); + for (int i = 0; i < MAX_COLORS ; ++i) { if (color == m_colors[i]) { if (m_users[i] == 0) m_changed = true; - ++m_users[i]; - found = true; + m_users[i]=1; + //printf("existing index %d\n",i); + return i; } if (m_users[i] == 0 && freeIndex >= MAX_COLORS) { freeIndex = i; } + if (m_users[i] > 0) { + int newDistance=ColorDistance(color, m_colors[i]); + if (newDistance 0) --m_users[i]; - found = true; - } - } -} -// ================================== -int cDxr3PaletteManager::GetIndex(int color) -{ - bool found = false; - int index = 0; - for (int i = 0; i < MAX_COLORS && !found; ++i) - { - if (color == m_colors[i]) - { - index = i; - found = true; - } - } - return index; + //printf("RemoveColor %d %x ",idx,m_colors[idx]); + if(idx>=0 && idx 0) { + //printf("in use "); + m_users[idx]=0; + m_colors[idx]=0; + m_changed=true; + } + } + //printf("\n"); } // ================================== @@ -90,7 +95,7 @@ // ================================== int cDxr3PaletteManager::operator[](int index) { - assert(index < MAX_COLORS && index > 0); + assert(index < MAX_COLORS && index >= 0); return m_colors[index]; } --- dxr3palettemanager.h.nopink 2005-04-02 12:48:25.569215354 +0200 +++ dxr3palettemanager.h 2005-04-03 13:53:36.284257712 +0200 @@ -20,11 +20,10 @@ cDxr3PaletteManager(); ~cDxr3PaletteManager() {}; - void AddColor(int color); - void RemoveColor(int color); + int AddColor(int color); + void RemoveColor(int idx); int GetCount(); int operator[](int index); - int GetIndex(int color); bool HasChanged(); uint32_t* GetPalette();