コード例 #1
0
        /// <summary>
        /// parse an PDS packet which contain palette info
        /// </summary>
        /// <param name="buffer">Buffer of raw byte data, starting right after segment</param>
        /// <param name="segment">object containing info about the current segment</param>
        /// <param name="pic">SubPicture object containing info about the current caption</param>
        /// <param name="msg">reference to message string</param>
        /// <returns>number of valid palette entries (-1 for fault)</returns>
        private static PdsData ParsePds(byte[] buffer, SupSegment segment)
        {
            int paletteId = buffer[0];  // 8bit palette ID (0..7)
            // 8bit palette version number (incremented for each palette change)
            int paletteUpdate = buffer[1];

            var p = new PaletteInfo();

            p.PaletteSize = (segment.Size - 2) / 5;

            if (p.PaletteSize <= 0)
            {
                return new PdsData {
                           Message = "Empty palette"
                }
            }
            ;

            p.PaletteBuffer = new byte[p.PaletteSize * 5];
            Buffer.BlockCopy(buffer, 2, p.PaletteBuffer, 0, p.PaletteSize * 5); // save palette buffer in palette object

            return(new PdsData
            {
                Message = "PalId: " + paletteId + ", update: " + paletteUpdate + ", " + p.PaletteSize + " entries",
                PaletteId = paletteId,
                PaletteVersion = paletteUpdate,
                PaletteInfo = p,
            });
        }
コード例 #2
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);
            }
コード例 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PaletteInfo"/> class.
 /// </summary>
 /// <param name="paletteInfo">
 /// The palette info.
 /// </param>
 public PaletteInfo(PaletteInfo paletteInfo)
 {
     this.PaletteSize = paletteInfo.PaletteSize;
     this.PaletteBuffer = new byte[paletteInfo.PaletteBuffer.Length];
     Buffer.BlockCopy(paletteInfo.PaletteBuffer, 0, this.PaletteBuffer, 0, this.PaletteBuffer.Length);
 }
コード例 #4
0
        /// <summary>
        /// parse an PDS packet which contain palette info
        /// </summary>
        /// <param name="buffer">Buffer of raw byte data, starting right after segment</param>
        /// <param name="segment">object containing info about the current segment</param>
        /// <returns>number of valid palette entries (-1 for fault)</returns>
        private static PdsData ParsePds(byte[] buffer, SupSegment segment)
        {
            int paletteId = buffer[0];  // 8bit palette ID (0..7)
            // 8bit palette version number (incremented for each palette change)
            int paletteUpdate = buffer[1];

            var p = new PaletteInfo();
            p.PaletteSize = (segment.Size - 2) / 5;

            if (p.PaletteSize <= 0)
                return new PdsData { Message = "Empty palette" };

            p.PaletteBuffer = new byte[p.PaletteSize * 5];
            Buffer.BlockCopy(buffer, 2, p.PaletteBuffer, 0, p.PaletteSize * 5); // save palette buffer in palette object

            return new PdsData
            {
                Message = "PalId: " + paletteId + ", update: " + paletteUpdate + ", " + p.PaletteSize + " entries",
                PaletteId = paletteId,
                PaletteVersion = paletteUpdate,
                PaletteInfo = p,
            };
        }
コード例 #5
0
 public PaletteInfo(PaletteInfo paletteInfo)
 {
     PaletteSize   = paletteInfo.PaletteSize;
     PaletteBuffer = new byte[paletteInfo.PaletteBuffer.Length];
     Buffer.BlockCopy(paletteInfo.PaletteBuffer, 0, PaletteBuffer, 0, PaletteBuffer.Length);
 }