Ejemplo n.º 1
0
        void LoadFrame()
        {
            if (CurrentFrameIndex >= FrameCount)
            {
                return;
            }

            stream.Seek(frameOffsets[CurrentFrameIndex], SeekOrigin.Begin);

            var dataLength = frameOffsets[CurrentFrameIndex + 1] - frameOffsets[CurrentFrameIndex];

            var rawData          = StreamExts.ReadBytes(stream, (int)dataLength);
            var intermediateData = new byte[Width * Height];

            // Format80 decompression
            LCWCompression.DecodeInto(rawData, intermediateData);

            // and Format40 decompression
            currentFramePaletteIndexData = new byte[Width * Height];
            if (previousFramePaletteIndexData == null)
            {
                Array.Clear(currentFramePaletteIndexData, 0, currentFramePaletteIndexData.Length);
            }
            else
            {
                Array.Copy(previousFramePaletteIndexData, currentFramePaletteIndexData, currentFramePaletteIndexData.Length);
            }

            XORDeltaCompression.DecodeInto(intermediateData, currentFramePaletteIndexData, 0);

            var c        = 0;
            var position = 0;

            for (var y = 0; y < Height; y++)
            {
                for (var x = 0; x < Width; x++)
                {
                    var colorIndex = currentFramePaletteIndexData[c++];
                    CurrentFrameData[position++] = paletteBytes[colorIndex * 4];
                    CurrentFrameData[position++] = paletteBytes[colorIndex * 4 + 1];
                    CurrentFrameData[position++] = paletteBytes[colorIndex * 4 + 2];
                    CurrentFrameData[position++] = paletteBytes[colorIndex * 4 + 3];
                }

                // Recalculate the position in the byte array to the start of the next pixel row just in case there is padding in the frame.
                position = (y + 1) * totalFrameWidth * 4;
            }
        }
Ejemplo n.º 2
0
        void LoadFrame()
        {
            if (currentFrame >= frameCount)
            {
                return;
            }

            stream.Seek(frameOffsets[currentFrame], SeekOrigin.Begin);

            var dataLength = frameOffsets[currentFrame + 1] - frameOffsets[currentFrame];

            var rawData          = StreamExts.ReadBytes(stream, (int)dataLength);
            var intermediateData = new byte[width * height];

            // Format80 decompression
            LCWCompression.DecodeInto(rawData, intermediateData);

            // and Format40 decompression
            currentFrameData = new byte[width * height];
            if (previousFrameData == null)
            {
                Array.Clear(currentFrameData, 0, currentFrameData.Length);
            }
            else
            {
                Array.Copy(previousFrameData, currentFrameData, currentFrameData.Length);
            }

            XORDeltaCompression.DecodeInto(intermediateData, currentFrameData, 0);

            var c         = 0;
            var frameSize = Exts.NextPowerOf2(Math.Max(width, height));

            coloredFrameData = new uint[frameSize, frameSize];
            for (var y = 0; y < height; y++)
            {
                for (var x = 0; x < width; x++)
                {
                    coloredFrameData[y, x] = palette[currentFrameData[c++]];
                }
            }
        }