Beispiel #1
0
        private byte[] DecodeUnkCStripe(ScummBinaryReader reader, byte codingShift, int stripHeight, Color[] roomPalette)
        {
            var data = new byte[32 * stripHeight];

            var color            = (int)reader.ReadByte();
            var stripePixelsLeft = 8 * stripHeight;

            var pixelIndex = 0;
            int inc        = -1;

            while (stripePixelsLeft > 0)
            {
                var x = pixelIndex / stripHeight;
                var y = pixelIndex % stripHeight;

                var pixelAddress = y * 32 + x * 4;

                data[pixelAddress]     = roomPalette[color].R;
                data[pixelAddress + 1] = roomPalette[color].G;
                data[pixelAddress + 2] = roomPalette[color].B;
                data[pixelAddress + 3] = 255;

                stripePixelsLeft--;
                pixelIndex++;

                if (reader.ReadBit() > 0)
                {
                    if (reader.ReadBit() == 0)
                    {
                        color = reader.ReadBits(codingShift);
                        inc   = -1;
                    }

                    else
                    {
                        if (reader.ReadBit() > 0)
                        {
                            inc = -inc;
                        }

                        color += inc;
                    }
                }
            }

            reader.ResetBitCursor();

            return(data);
        }
Beispiel #2
0
        private byte[] DecodeUnkAStripe(ScummBinaryReader reader, byte codingShift, int stripHeight, Color[] roomPalette)
        {
            var data = new byte[32 * stripHeight];

            var color            = reader.ReadByte();
            var stripePixelsLeft = 8 * stripHeight;

            data[0] = roomPalette[color].R;
            data[1] = roomPalette[color].G;
            data[2] = roomPalette[color].B;
            data[3] = 255;

            var pixelIndex = 1;

            stripePixelsLeft--;

            while (stripePixelsLeft > 0)
            {
                var pixelsCount = 1;

                if (reader.ReadBit() > 0)
                {
                    if (reader.ReadBit() == 0)
                    {
                        color = reader.ReadBits(codingShift);
                    }

                    else
                    {
                        var inc = (reader.ReadBits(3) - 4);

                        if (inc != 0)
                        {
                            color += (byte)inc;
                        }

                        else
                        {
                            pixelsCount = reader.ReadBits(8);
                        }
                    }
                }

                for (int j = 0; j < pixelsCount; j++)
                {
                    var x = pixelIndex % 8;
                    var y = pixelIndex / 8;

                    var pixelAddress = y * 32 + x * 4;

                    data[pixelAddress]     = roomPalette[color].R;
                    data[pixelAddress + 1] = roomPalette[color].G;
                    data[pixelAddress + 2] = roomPalette[color].B;
                    data[pixelAddress + 3] = 255;

                    stripePixelsLeft--;
                    pixelIndex++;

                    if (stripePixelsLeft == 0)
                    {
                        break;
                    }
                }
            }

            reader.ResetBitCursor();

            return(data);
        }