示例#1
0
            public static BluRaySupPalette DecodePalette(IList <PaletteInfo> paletteInfos)
            {
                BluRaySupPalette palette = new BluRaySupPalette(256);
                // by definition, index 0xff is always completely transparent
                // also all entries must be fully transparent after initialization

                bool fadeOut = false;

                for (int j = 0; j < paletteInfos.Count; j++)
                {
                    PaletteInfo p     = paletteInfos[j];
                    int         index = 0;

                    for (int i = 0; i < p.PaletteSize; i++)
                    {
                        // each palette entry consists of 5 bytes
                        int palIndex = p.PaletteBuffer[index];
                        int y        = p.PaletteBuffer[++index];
                        int cr       = p.PaletteBuffer[++index];
                        int cb       = p.PaletteBuffer[++index];
                        int alpha    = p.PaletteBuffer[++index];

                        int alphaOld = palette.GetAlpha(palIndex);
                        // avoid fading out
                        if (alpha >= alphaOld)
                        {
                            if (alpha < AlphaCrop)
                            {// to not mess with scaling algorithms, make transparent color black
                                y  = 16;
                                cr = 128;
                                cb = 128;
                            }
                            palette.SetAlpha(palIndex, alpha);
                        }
                        else
                        {
                            fadeOut = true;
                        }

                        palette.SetYCbCr(palIndex, y, cb, cr);
                        index++;
                    }
                }
                if (fadeOut)
                {
                    System.Diagnostics.Debug.Print("fade out detected -> patched palette\n");
                }
                return(palette);
            }
            public static BluRaySupPalette DecodePalette(IList<PaletteInfo> paletteInfos)
            {
                BluRaySupPalette palette = new BluRaySupPalette(256);
                // by definition, index 0xff is always completely transparent
                // also all entries must be fully transparent after initialization

                bool fadeOut = false;
                for (int j = 0; j < paletteInfos.Count; j++)
                {
                    PaletteInfo p = paletteInfos[j];
                    int index = 0;

                    for (int i = 0; i < p.PaletteSize; i++)
                    {
                        // each palette entry consists of 5 bytes
                        int palIndex = p.PaletteBuffer[index];
                        int y = p.PaletteBuffer[++index];
                        int cr = p.PaletteBuffer[++index];
                        int cb = p.PaletteBuffer[++index];
                        int alpha = p.PaletteBuffer[++index];

                        int alphaOld = palette.GetAlpha(palIndex);
                        // avoid fading out
                        if (alpha >= alphaOld)
                        {
                            if (alpha < AlphaCrop)
                            {// to not mess with scaling algorithms, make transparent color black
                                y = 16;
                                cr = 128;
                                cb = 128;
                            }
                            palette.SetAlpha(palIndex, alpha);
                        }
                        else
                        {
                            fadeOut = true;
                        }

                        palette.SetYCbCr(palIndex, y, cb, cr);
                        index++;
                    }
                }
                if (fadeOut)
                {
                    System.Diagnostics.Debug.Print("fade out detected -> patched palette\n");
                }
                return palette;
            }