public bool IsSatisfiedBy(FileBlockParameters parameters)
        {
            var length = parameters.Data.Length;

            if (length < 9)
            {
                return(false);
            }

            uint height  = ArrayToUshort(parameters.Data, 0);
            uint width   = ArrayToUshort(parameters.Data, 2);
            var  widthPx = width * 8;

            if (widthPx == 0 || height == 0 || widthPx > 320 || height > 200)
            {
                return(false);
            }

            uint itemCount = parameters.Data[8];

            const int egaDataOffset = 17;
            var       egaDataSize   = height * width * 4;

            if (parameters.Data.Length == (egaDataSize * (itemCount + 1)) + egaDataOffset)
            {
                // Death Knights of Krynn
                itemCount += 1;
            }

            return(parameters.Data.Length == ((egaDataSize * itemCount) + egaDataOffset));
        }
        public bool IsSatisfiedBy(FileBlockParameters parameters)
        {
            var data = parameters.Data;

            if (data.Length < 20)
            {
                return(false);
            }

            int height = ArrayToUshort(data, 0);
            int width  = ArrayToUshort(data, 2);

            var widthPx  = width * 8;
            var heightPx = height;

            if (widthPx < 1 || heightPx < 1 || widthPx > 320 || heightPx > 200)
            {
                return(false);
            }

            int picCount = data[8];

            var dataOffset = getDataOffset(9, data);
            var dataLen    = (((5 * width * height) * picCount) + dataOffset);

            if (data.Length != dataLen)
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 3
0
        public bool IsSatisfiedBy(FileBlockParameters parameters)
        {
            var data = parameters.Data;

            if (data.Length < 20)
                return false;

            int height = ArrayToUshort(data, 0);
            int width = ArrayToUshort(data, 2);

            var widthPx = width * 8;
            var heightPx = height;

            if (widthPx < 1 || heightPx < 1 || widthPx > 320 || heightPx > 200)
                return false;

            int picCount = data[8];

            var dataOffset = getDataOffset(9, data);
            var dataLen = (((5 * width * height) * picCount) + dataOffset);

            if (data.Length != dataLen)
                return false;

            return true;
        }
Ejemplo n.º 4
0
        private int getBitmapCount(int daxBlockId, string fileName)
        {
            // load 8x8 bitmaps from daxBlockId in fileName into the list bitmaps8x8 to simulate the order the bitmaps would be in memory in the game

            if (File.Exists(fileName) == false)
            {
                return(0);
            }
            var file = new DaxImageFile(string.Format(fileName));

            foreach (DaxFileBlock block in file.Blocks)
            {
                if (block.Id == daxBlockId)
                {
                    var parameters = new FileBlockParameters
                    {
                        Data = block.Data,
                        Name = block.File,
                        Id   = block.Id,
                    };

                    var render = new RenderBlockFactory().CreateUsing(parameters);

                    var x = render.GetBitmaps().Count();
                    return(x);
                }
            }

            return(0);
        }
Ejemplo n.º 5
0
        public bool IsSatisfiedBy(FileBlockParameters parameters)
        {
            var length = parameters.Data.Length;

            if( length < 9 ) return false;

            uint height = ArrayToUshort(parameters.Data, 0);
            uint width = ArrayToUshort(parameters.Data, 2);
            var widthPx = width*8;

            if( widthPx == 0 || height == 0 || widthPx > 320 || height > 200 )
                return false;

            uint itemCount = parameters.Data[8];

            const int egaDataOffset = 17;
            var egaDataSize = height * width * 4;

            if (parameters.Data.Length == (egaDataSize * (itemCount + 1)) + egaDataOffset)
            {
                // Death Knights of Krynn
                itemCount += 1;
            }

            return parameters.Data.Length == ((egaDataSize * itemCount) + egaDataOffset);
        }
Ejemplo n.º 6
0
        public bool IsSatisfiedBy(FileBlockParameters parameters)
        {
            var data = parameters.Data;
            var origData = data;

            if (data.Length < 20)
                return false;

            if (data[1] != 0)
                return false;

            int height = data[0];
            int width = data[2];
            var widthPx = width*8;
            var heightPx = height;

            if (widthPx < 1 || heightPx < 1 || widthPx > 320 || heightPx > 200)
                return false;

            int frames = data[8];
            int clrBase = data[9];
            int clrCount = data[10];

            if (clrBase == 0)
                return false;

            if (clrCount == 0)
                return false;

            var dataStart = (clrCount*3) + 132 + (3*frames);

            if (Path.GetFileName(parameters.Name).ToUpper().StartsWith("SPRIT") && clrBase == 176 && clrCount == 80)
            {
                dataStart = 306;    
            }
            
            data = UnpackSpriteData(data, dataStart);

            if (data.Length <= 0)
                return false;

            var picSize = widthPx * heightPx;
            if (picSize <= 0)
                return false;

            if (data.Length % picSize != 0)
                return false;

            var frameCount = data.Length / picSize;
            if (picSize * frameCount > data.Length)
                return false;

            var clrs = EgaVgaPalette.ExtractPalette(origData, clrCount, clrBase, 11);
            if (clrs == null)
                return false;

            return true;
        }
Ejemplo n.º 7
0
        private bool isCombatPicture = false; // images used in combat mode have a slightly different EGA palette (colors 0 and 8 are swapped)
        public EgaBlock(FileBlockParameters parameters)
        {
            setBlockId(parameters.Id);
            var       data          = parameters.Data;
            uint      height        = ArrayToUshort(data, 0);
            uint      width         = ArrayToUshort(data, 2);
            uint      xPos          = ArrayToUshort(data, 4);
            uint      yPos          = ArrayToUshort(data, 6);
            uint      itemCount     = data[8];
            var       widthPx       = width * 8;
            var       heightPx      = height;
            var       xPosPx        = xPos * 8;
            var       yPosPx        = yPos * 8;
            const int egaDataOffset = 17;
            var       egaDataSize   = height * width * 4;

            EgaColors = EgaVgaPalette.EgaColors;

            var filename = Path.GetFileName(parameters.Name).ToUpper();

            if (filename.Contains("CPIC") || filename.Contains("CHEAD") || filename.Contains("CBODY") ||
                filename.Contains("DUNGCOM") || filename.Contains("WILDCOM") || filename.Contains("RANDCOM") ||
                filename.Contains("COMSPR"))
            {
                isCombatPicture = true;
                EgaColors       = EgaVgaPalette.EgaCombatColors;
            }

            if (data.Length == (egaDataSize * (itemCount + 1)) + egaDataOffset)
            {
                // Death Knights of Krynn
                itemCount += 1;
            }

            if (data.Length == (egaDataSize * itemCount) + egaDataOffset)
            {
                var offset = 0;
                for (var i = 0; i < itemCount; i++, offset += (int)egaDataSize)
                {
                    var bitmap = new Bitmap((int)(widthPx + xPosPx), (int)(heightPx + yPosPx),
                                            PixelFormat.Format16bppArgb1555);
                    for (var y = 0; y < heightPx; y++)
                    {
                        for (var x = 0; x < widthPx; x += 2)
                        {
                            var   b     = data[egaDataOffset + (y * width * 4) + (x / 2) + offset];
                            var   pxX   = (int)(x + 0 + xPosPx);
                            var   pxY   = (int)(y + yPosPx);
                            Color ctest = Color.FromArgb((int)EgaColors[b >> 4]);
                            bitmap.SetPixel(pxX, pxY, Color.FromArgb((int)EgaColors[b >> 4]));
                            bitmap.SetPixel(pxX + 1, pxY, Color.FromArgb((int)EgaColors[b & 0xF]));
                        }
                    }

                    Bitmaps.Add(bitmap);
                }
            }
        }
Ejemplo n.º 8
0
        public VgaSpriteBlock(FileBlockParameters parameters)
        {
            setBlockId(parameters.Id);
            var data     = parameters.Data;
            var origData = data;

            int height       = data[0];
            int width        = data[2];
            var widthPx      = width * 8;
            var heightPx     = height;
            int frames       = data[8];
            int clrBase      = data[9];
            int clrCount     = data[10];
            var picSize      = widthPx * heightPx;
            var isSpriteFile = false;

            var clrs      = EgaVgaPalette.ExtractPalette(origData, clrCount, clrBase, 11);
            var dataStart = (clrCount * 3) + 132 + (3 * frames);

            if (Path.GetFileName(parameters.Name).ToUpper().StartsWith("SPRIT"))
            {
                clrs[0]      = Color.FromArgb(0);
                clrs[13]     = Color.FromArgb(0, 0, 0);
                isSpriteFile = true;
                if (clrBase == 176 && clrCount == 80)
                {
                    dataStart = 306;
                }
            }

            data = UnpackSpriteData(data, dataStart);
            var frameCount = data.Length / picSize;

            int mframe = origData[(clrCount * 3) + 132 - 5];

            if (isSpriteFile)
            {
                mframe = frameCount - 1;
            }

            for (var frame = 0; frame < frameCount; frame++)
            {
                var bitmap = new Bitmap(widthPx, heightPx, System.Drawing.Imaging.PixelFormat.Format16bppArgb1555);

                for (var y = 0; y < heightPx; y++)
                {
                    for (var x = 0; x < widthPx; x += 1)
                    {
                        var b1 = data[(y * widthPx) + x + (picSize * frame)];
                        var b3 = data[(y * widthPx) + x + (picSize * mframe)];
                        bitmap.SetPixel(x, y, frame != mframe ? clrs[b1 ^ b3] : clrs[b1]);
                    }
                }

                Bitmaps.Add(bitmap);
            }
        }
Ejemplo n.º 9
0
        private bool isCombatPicture = false; // images used in combat mode have a slightly different EGA palette (colors 0 and 8 are swapped)
        public EgaBlock(FileBlockParameters parameters)
        {
            setBlockId(parameters.Id);
            var data = parameters.Data;
            uint height = ArrayToUshort(data, 0);
            uint width = ArrayToUshort(data, 2);
            uint xPos = ArrayToUshort(data, 4);
            uint yPos = ArrayToUshort(data, 6);
            uint itemCount = data[8];
            var widthPx = width * 8;
            var heightPx = height;
            var xPosPx = xPos * 8;
            var yPosPx = yPos * 8;
            const int egaDataOffset = 17;
            var egaDataSize = height * width * 4;
            EgaColors = EgaVgaPalette.EgaColors;

            var filename = Path.GetFileName(parameters.Name).ToUpper();
            if (filename.Contains("CPIC") || filename.Contains("CHEAD") || filename.Contains("CBODY")
                || filename.Contains("DUNGCOM") || filename.Contains("WILDCOM") || filename.Contains("RANDCOM")
                || filename.Contains("COMSPR"))
            {
                isCombatPicture = true;
                EgaColors = EgaVgaPalette.EgaCombatColors;
            }

            if (data.Length == (egaDataSize * (itemCount + 1)) + egaDataOffset)
            {
                // Death Knights of Krynn
                itemCount += 1;
            }

            if (data.Length == (egaDataSize * itemCount) + egaDataOffset)
            {
                var offset = 0;
                for (var i = 0; i < itemCount; i++, offset += (int)egaDataSize)
                {
                    var bitmap = new Bitmap((int)(widthPx + xPosPx), (int)(heightPx + yPosPx),
                                            PixelFormat.Format16bppArgb1555);
                    for (var y = 0; y < heightPx; y++)
                    {
                        for (var x = 0; x < widthPx; x += 2)
                        {
                            var b = data[egaDataOffset + (y * width * 4) + (x / 2) + offset];
                            var pxX = (int)(x + 0 + xPosPx);
                            var pxY = (int)(y + yPosPx);
                            Color ctest = Color.FromArgb((int)EgaColors[b >> 4]);
                            bitmap.SetPixel(pxX, pxY, Color.FromArgb((int)EgaColors[b >> 4]));
                            bitmap.SetPixel(pxX + 1, pxY, Color.FromArgb((int)EgaColors[b & 0xF]));
                        }
                    }

                    Bitmaps.Add(bitmap);
                }
            }
        }
Ejemplo n.º 10
0
        public VgaSpriteBlock(FileBlockParameters parameters)
        {
            setBlockId(parameters.Id);
            var data = parameters.Data;
            var origData = data;

            int height = data[0];
            int width = data[2];
            var widthPx = width * 8;
            var heightPx = height;
            int frames = data[8];
            int clrBase = data[9];
            int clrCount = data[10];
            var picSize = widthPx * heightPx;
            var isSpriteFile = false;

            var clrs = EgaVgaPalette.ExtractPalette(origData, clrCount, clrBase, 11);
            var dataStart = (clrCount * 3) + 132 + (3 * frames);

            if (Path.GetFileName(parameters.Name).ToUpper().StartsWith("SPRIT"))
            {
                clrs[0] = Color.FromArgb(0);
                clrs[13] = Color.FromArgb(0, 0, 0);
                isSpriteFile = true;
                if (clrBase == 176 && clrCount == 80)
                    dataStart = 306;
            }

            data = UnpackSpriteData(data, dataStart);
            var frameCount = data.Length / picSize;

            int mframe = origData[(clrCount * 3) + 132 - 5];

            if (isSpriteFile)
            {
                mframe = frameCount - 1;
            }

            for (var frame = 0; frame < frameCount; frame++)
            {
                var bitmap = new Bitmap(widthPx, heightPx, System.Drawing.Imaging.PixelFormat.Format16bppArgb1555);

                for (var y = 0; y < heightPx; y++)
                {
                    for (var x = 0; x < widthPx; x += 1)
                    {
                        var b1 = data[(y * widthPx) + x + (picSize * frame)];
                        var b3 = data[(y * widthPx) + x + (picSize * mframe)];
                        bitmap.SetPixel(x, y, frame != mframe ? clrs[b1 ^ b3] : clrs[b1]);
                    }
                }

                Bitmaps.Add(bitmap);
            }
        }
Ejemplo n.º 11
0
        public bool IsSatisfiedBy(FileBlockParameters parameters)
        {
            var data = parameters.Data;
            int frames = data[0];

            int offset = 1;
            if (frames == 0 || frames > 8) 
                return false;

            for (int frame = 0; frame < frames; frame++)
            {
                if (data.Length < 21 + offset) 
                    return false;

                offset += 4;
                int height = ArrayToUshort(data, offset);
                offset += 2;
                int width = ArrayToUshort(data, offset);
                offset += 2;
                int x_pos = ArrayToUshort(data, offset);
                offset += 2;
                int y_pos = ArrayToUshort(data, offset);
                offset += 3;
                offset += 8;

                // skip 1 byte
                // skip 8 bytes
                int width_px = width * 8;
                int height_px = height;
                int x_pos_px = x_pos * 8;
                int y_pos_px = y_pos * 8;

                if (width_px < 1 || height_px < 1 || width_px > 320 || height_px > 200)
                    return false;

                int egaDataSize = height * width * 4;

                if (data.Length < egaDataSize + offset) 
                    return false;

                offset += egaDataSize;
            }

            if (data.Length > offset)
            {
                return false;
            }
            else
            {
                return true;
            }

        }
        public bool IsSatisfiedBy(FileBlockParameters parameters)
        {
            var data = parameters.Data;

            if (data.Length < 5)
            {
                return(false);
            }

            uint frames = data[0];

            if (frames > 8)
            {
                return(false);
            }

            int offset = 5;

            if (data.Length < 20 + offset)
            {
                return(false);
            }

            int height = ArrayToUshort(data, 0 + offset);
            int width  = ArrayToUshort(data, 2 + offset);

            int width_px = width * 8;

            int clr_count = data[9 + offset];
            int clr_start = data[10 + offset];

            if (width_px < 1 || height < 1 || width_px > 320 || height > 200)
            {
                return(false);
            }

            bool egaBlock  = (data[9 + offset] & 0xCC) == 0;
            int  blocksize = egaBlock ? (4 * width * height) : ((5 * width * height) + 14);

            if (data.Length < blocksize + 9 + offset)
            {
                return(false);
            }

            int data_offset = getDataOffset(9 + offset, data);

            if (data.Length < frames * blocksize)
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 13
0
        public VgaBlock(FileBlockParameters parameters)
        {
            setBlockId(parameters.Id);

            var data = parameters.Data;

            int       height     = data[0];
            int       width      = data[1];
            const int xPos       = 0;
            const int yPos       = 0;
            var       widthPx    = width * 8;
            var       heightPx   = height;
            const int xPosPx     = xPos * 8;
            const int yPosPx     = yPos * 8;
            int       clrBase    = data[8];
            int       clrCount   = data[9] + 1;
            var       paletteEnd = 10 + (clrCount * 3);
            var       chunkSize  = (widthPx * heightPx);
            var       chunkCount = ArrayToUshort(data, 6);
            var       dataStart  = data.Length - (chunkCount * chunkSize);

            for (var chunk = 0; chunk < chunkCount; chunk++, dataStart += chunkSize)
            {
                var clrs = EgaVgaPalette.ExtractPalette(data, clrCount, clrBase, 10);

                if (clrs == null)
                {
                    return;
                }

                var bitmap = new Bitmap((widthPx + xPosPx), (heightPx + yPosPx), PixelFormat.Format16bppArgb1555);
                for (var y = 0; y < heightPx; y++)
                {
                    for (var x = 0; x < widthPx; x += 1)
                    {
                        var b   = data[dataStart + (y * widthPx) + x];
                        var pxX = (x + 0 + xPosPx);
                        var pxY = (y + yPosPx);
                        bitmap.SetPixel(pxX, pxY, clrs[b]);
                    }
                }

                Bitmaps.Add(bitmap);
            }
        }
Ejemplo n.º 14
0
        public VgaBlock(FileBlockParameters parameters)
        {
            setBlockId(parameters.Id);

            var data = parameters.Data;

            int height = data[0];
            int width = data[1];
            const int xPos = 0;
            const int yPos = 0;
            var widthPx = width * 8;
            var heightPx = height;
            const int xPosPx = xPos * 8;
            const int yPosPx = yPos * 8;
            int clrBase = data[8];
            int clrCount = data[9] + 1;
            var paletteEnd = 10 + (clrCount * 3);
            var chunkSize = (widthPx * heightPx);
            var chunkCount = ArrayToUshort(data, 6);
            var dataStart = data.Length - (chunkCount * chunkSize);

            for (var chunk = 0; chunk < chunkCount; chunk++, dataStart += chunkSize)
            {
                var clrs = EgaVgaPalette.ExtractPalette(data, clrCount, clrBase, 10);

                if (clrs == null)
                {
                    return;
                }

                var bitmap = new Bitmap((widthPx + xPosPx), (heightPx + yPosPx), PixelFormat.Format16bppArgb1555);
                for (var y = 0; y < heightPx; y++)
                {
                    for (var x = 0; x < widthPx; x += 1)
                    {
                        var b = data[dataStart + (y * widthPx) + x];
                        var pxX = (x + 0 + xPosPx);
                        var pxY = (y + yPosPx);
                        bitmap.SetPixel(pxX, pxY, clrs[b]);
                    }
                }

                Bitmaps.Add(bitmap);
            }
        }
Ejemplo n.º 15
0
        public bool IsSatisfiedBy(FileBlockParameters parameters)
        {
            var data = parameters.Data;

            if (data.Length < 5)
                return false;

            uint frames = data[0];
            if (frames > 8)
                return false;

            int offset = 5;
            if (data.Length < 20 + offset)
                return false;

            int height = ArrayToUshort(data, 0 + offset);
            int width = ArrayToUshort(data, 2 + offset);
            
            int width_px = width * 8;

            int clr_count = data[9 + offset];
            int clr_start = data[10 + offset];

            if (width_px < 1 || height < 1 || width_px > 320 || height > 200)
                return false;

            bool egaBlock = (data[9 + offset] & 0xCC) == 0;
            int blocksize = egaBlock ? (4 * width * height) : ((5 * width * height) + 14);

            if (data.Length < blocksize + 9 + offset)
                return false;

            int data_offset = getDataOffset(9 + offset, data);

            if (data.Length < frames * blocksize)
                return false;

            return true;
        }
Ejemplo n.º 16
0
        private void loadBitmaps(int daxBlockId, string fileName, List <Bitmap> bitmaps8x8)
        {
            // load 8x8 bitmaps from daxBlockId in fileName into the list bitmaps8x8 to simulate the order the bitmaps would be in memory in the game
            var file = new DaxImageFile(string.Format(fileName));

            foreach (DaxFileBlock block in file.Blocks)
            {
                if (block.Id == daxBlockId)
                {
                    var parameters = new FileBlockParameters
                    {
                        Data = block.Data,
                        Name = block.File,
                        Id   = block.Id,
                    };
                    var render = new RenderBlockFactory().CreateUsing(parameters);
                    foreach (var bitmap in render.GetBitmaps())
                    {
                        bitmaps8x8.Add(bitmap);
                    }
                }
            }
        }
Ejemplo n.º 17
0
        public MonoBlock(FileBlockParameters parameters)
        {
            setBlockId(parameters.Id);

            int[] monoBitMask = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 };
            var   count       = parameters.Data.Length / 8;

            for (var ch = 0; ch < count; ch++)
            {
                var bitmap = new Bitmap(8, 8, PixelFormat.Format16bppArgb1555);

                for (var y = 0; y < 8; y++)
                {
                    for (var x = 0; x < 8; x++)
                    {
                        var b = parameters.Data[(ch * 8) + y];
                        var c = ((b & monoBitMask[x]) != 0) ? Color.White : Color.Black;
                        bitmap.SetPixel(x, y, c);
                    }
                }

                Bitmaps.Add(bitmap);
            }
        }
Ejemplo n.º 18
0
        public MonoBlock(FileBlockParameters parameters)
        {
            setBlockId(parameters.Id);

            int[] monoBitMask = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 }; 
            var count = parameters.Data.Length / 8;

            for (var ch = 0; ch < count; ch++)
            {
                var bitmap = new Bitmap(8, 8, PixelFormat.Format16bppArgb1555);

                for (var y = 0; y < 8; y++)
                {
                    for (var x = 0; x < 8; x++)
                    {
                        var b = parameters.Data[(ch * 8) + y];
                        var c = ((b & monoBitMask[x]) != 0) ? Color.White : Color.Black;
                        bitmap.SetPixel(x, y, c);
                    }
                }
                
                Bitmaps.Add(bitmap);
            }
        }
Ejemplo n.º 19
0
        public VgaStrataBlock(FileBlockParameters parameters)
        {
            setBlockId(parameters.Id);

            var data = parameters.Data;
            int height = ArrayToUshort(data, 0);
            int width = ArrayToUshort(data, 2);
            int xPos = ArrayToUshort(data, 4);
            int yPos = ArrayToUshort(data, 6);
            int picCount = data[8];
            var widthPx = width * 8;
            var heightPx = height;
            var pxlClrs = new int[heightPx, widthPx];
            var xPosPx = xPos * 8;
            var yPosPx = yPos * 8;
            var tempPalette = new byte[59];
            var dataOffset = GetDataOffset(tempPalette, 9, data);

            var dd = new int[48];
            const int paletteBase = 0x20;
            for (var i = 0; i < 24; i++)
            {
                var b = tempPalette[paletteBase + i];
                dd[0 + i] = (b & 0x0f) * 4;
                dd[24 + i] = (b & 0xf0) / 4;
            }

            var egaPalette = EgaVgaPalette.PaletteBase();
            for (var i = 0; i < 14; i += 1)
            {
                var r = dd[(i * 3) + 6 + 0];
                var g = dd[(i * 3) + 6 + 1];
                var b = dd[(i * 3) + 6 + 2];
                egaPalette[i + 18] = Color.FromArgb(r * 4, g * 4, b * 4);
            }

            for (int pic = 0; pic < picCount; pic++)
            {
                var inOffset = dataOffset;

                for (var y = 0; y < height; y++)
                {
                    for (var x = 0; x < widthPx; x++)
                    {
                        var mask = 0x80 >> (x & 7);
                        var inputByte = x / 8;
                        byte pxClr = 0;

                        if ((data[inOffset + inputByte] & mask) != 0)
                        {
                            pxClr = 1;
                        }

                        if ((data[inOffset + inputByte + width] & mask) != 0)
                        {
                            pxClr += 2;
                        }

                        if ((data[inOffset + inputByte + (width * 2)] & mask) != 0)
                        {
                            pxClr += 4;
                        }

                        if ((data[inOffset + inputByte + (width * 3)] & mask) != 0)
                        {
                            pxClr += 8;
                        }

                        if ((data[inOffset + inputByte + (width * 4)] & mask) != 0)
                        {
                            pxClr += 0x10;
                        }

                        pxlClrs[y, x] = pxClr;
                    }

                    inOffset += width * 5;
                }

                dataOffset = inOffset;

                var bitmap = new Bitmap(widthPx + xPosPx, heightPx + yPosPx, System.Drawing.Imaging.PixelFormat.Format16bppArgb1555);
                for (var y = 0; y < heightPx; y++)
                {
                    for (var x = 0; x < widthPx; x += 1)
                    {
                        var pxX = x + xPosPx;
                        var pxY = y + yPosPx;
                        bitmap.SetPixel(pxX, pxY, egaPalette[pxlClrs[y, x]]);
                    }
                }

                Bitmaps.Add(bitmap);
            }
        }
Ejemplo n.º 20
0
        public EgaSpriteBlock(FileBlockParameters parameters)
        {
            var data = parameters.Data;

            setBlockId(parameters.Id);
            uint frames = data[0];
            int  offset = 1;

            if (frames > 8)
            {
                return;
            }

            Color[] clrs = new Color[16];
            for (int i = 0; i < 16; i++)
            {
                clrs[i] = Color.FromArgb((int)EgaVgaPalette.EgaColors[i]);
            }

            var  filename  = Path.GetFileName(parameters.Name).ToUpper();
            bool xorFrames = filename.StartsWith("PIC", true, System.Globalization.CultureInfo.CurrentCulture);

            xorFrames |= filename.StartsWith("FINAL", true, System.Globalization.CultureInfo.CurrentCulture);

            if (filename.StartsWith("SPRI", true, System.Globalization.CultureInfo.CurrentCulture))
            {
                clrs[0]  = Color.FromArgb(0, 0, 0, 0);
                clrs[13] = Color.FromArgb((int)EgaVgaPalette.EgaColors[0]);
            }


            byte[] first_frame_ega_layout = null;

            for (int frame = 0; frame < frames; frame++)
            {
                if (data.Length < 21 + offset)
                {
                    return;
                }

                uint delay = ArrayToUint(data, offset);
                offset += 4;
                int height = ArrayToUshort(data, offset);
                offset += 2;
                int width = ArrayToUshort(data, offset);
                offset += 2;
                int x_pos = ArrayToUshort(data, offset);
                offset += 2;
                int y_pos = ArrayToUshort(data, offset);
                offset += 3;
                offset += 8;

                // skip 1 byte
                // skip 8 bytes
                int width_px  = width * 8;
                int height_px = height;
                int x_pos_px  = x_pos * 8;
                int y_pos_px  = y_pos * 8;

                if (width_px < 1 || height_px < 1 || width_px > 320 || height_px > 200)
                {
                    return;
                }

                int egaDataSize = height * width * 4;

                if (data.Length < egaDataSize + offset)
                {
                    return;
                }

                if (xorFrames)
                {
                    if (frame == 0)
                    {
                        first_frame_ega_layout = new byte[egaDataSize + 1];

                        System.Array.Copy(data, offset, first_frame_ega_layout, 0, egaDataSize);
                    }
                    else
                    {
                        for (int i = 0; i < egaDataSize; i++)
                        {
                            byte b = first_frame_ega_layout[i];
                            data[offset + i] ^= b;
                        }
                    }
                }

                var bitmap = new Bitmap((int)(width_px + x_pos_px), (int)(height_px + y_pos_px), System.Drawing.Imaging.PixelFormat.Format16bppArgb1555);
                for (int y = 0; y < height_px; y++)
                {
                    for (int x = 0; x < width_px; x += 2)
                    {
                        byte b   = data[(y * width * 4) + (x / 2) + offset];
                        int  pxX = (int)(x + 0 + x_pos_px);
                        int  pxY = (int)(y + y_pos_px);
                        bitmap.SetPixel(pxX, pxY, clrs[b >> 4]);
                        bitmap.SetPixel(pxX + 1, pxY, clrs[b & 0xF]);
                    }
                }

                Bitmaps.Add(bitmap);

                offset += egaDataSize;
            }
        }
Ejemplo n.º 21
0
 public bool IsSatisfiedBy(FileBlockParameters parameters)
 {
     return((parameters.Data.Length % 8) == 0 &&
            (Path.GetFileName(parameters.Name).ToUpper().StartsWith("8X8")));
 }
Ejemplo n.º 22
0
        private int getBitmapCount(int daxBlockId, string fileName)
        {
            // load 8x8 bitmaps from daxBlockId in fileName into the list bitmaps8x8 to simulate the order the bitmaps would be in memory in the game

            if (File.Exists(fileName) == false) return 0;
            var file = new DaxImageFile(string.Format(fileName));
            foreach (DaxFileBlock block in file.Blocks)
            {

                if (block.Id == daxBlockId)
                {
                    var parameters = new FileBlockParameters
                    {
                        Data = block.Data,
                        Name = block.File,
                        Id = block.Id,
                    };

                    var render = new RenderBlockFactory().CreateUsing(parameters);

                    var x = render.GetBitmaps().Count();
                    return x;

                }
            }

            return 0;
        }
        public bool IsSatisfiedBy(FileBlockParameters parameters)
        {
            var data     = parameters.Data;
            var origData = data;

            if (data.Length < 20)
            {
                return(false);
            }

            if (data[1] != 0)
            {
                return(false);
            }

            int height   = data[0];
            int width    = data[2];
            var widthPx  = width * 8;
            var heightPx = height;

            if (widthPx < 1 || heightPx < 1 || widthPx > 320 || heightPx > 200)
            {
                return(false);
            }

            int frames   = data[8];
            int clrBase  = data[9];
            int clrCount = data[10];

            if (clrBase == 0)
            {
                return(false);
            }

            if (clrCount == 0)
            {
                return(false);
            }

            var dataStart = (clrCount * 3) + 132 + (3 * frames);

            if (Path.GetFileName(parameters.Name).ToUpper().StartsWith("SPRIT") && clrBase == 176 && clrCount == 80)
            {
                dataStart = 306;
            }

            data = UnpackSpriteData(data, dataStart);

            if (data.Length <= 0)
            {
                return(false);
            }

            var picSize = widthPx * heightPx;

            if (picSize <= 0)
            {
                return(false);
            }

            if (data.Length % picSize != 0)
            {
                return(false);
            }

            var frameCount = data.Length / picSize;

            if (picSize * frameCount > data.Length)
            {
                return(false);
            }

            var clrs = EgaVgaPalette.ExtractPalette(origData, clrCount, clrBase, 11);

            if (clrs == null)
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 24
0
        public VgaStrataBlock(FileBlockParameters parameters)
        {
            setBlockId(parameters.Id);

            var data        = parameters.Data;
            int height      = ArrayToUshort(data, 0);
            int width       = ArrayToUshort(data, 2);
            int xPos        = ArrayToUshort(data, 4);
            int yPos        = ArrayToUshort(data, 6);
            int picCount    = data[8];
            var widthPx     = width * 8;
            var heightPx    = height;
            var pxlClrs     = new int[heightPx, widthPx];
            var xPosPx      = xPos * 8;
            var yPosPx      = yPos * 8;
            var tempPalette = new byte[59];
            var dataOffset  = GetDataOffset(tempPalette, 9, data);

            var       dd          = new int[48];
            const int paletteBase = 0x20;

            for (var i = 0; i < 24; i++)
            {
                var b = tempPalette[paletteBase + i];
                dd[0 + i]  = (b & 0x0f) * 4;
                dd[24 + i] = (b & 0xf0) / 4;
            }

            var egaPalette = EgaVgaPalette.PaletteBase();

            for (var i = 0; i < 14; i += 1)
            {
                var r = dd[(i * 3) + 6 + 0];
                var g = dd[(i * 3) + 6 + 1];
                var b = dd[(i * 3) + 6 + 2];
                egaPalette[i + 18] = Color.FromArgb(r * 4, g * 4, b * 4);
            }

            for (int pic = 0; pic < picCount; pic++)
            {
                var inOffset = dataOffset;

                for (var y = 0; y < height; y++)
                {
                    for (var x = 0; x < widthPx; x++)
                    {
                        var  mask      = 0x80 >> (x & 7);
                        var  inputByte = x / 8;
                        byte pxClr     = 0;

                        if ((data[inOffset + inputByte] & mask) != 0)
                        {
                            pxClr = 1;
                        }

                        if ((data[inOffset + inputByte + width] & mask) != 0)
                        {
                            pxClr += 2;
                        }

                        if ((data[inOffset + inputByte + (width * 2)] & mask) != 0)
                        {
                            pxClr += 4;
                        }

                        if ((data[inOffset + inputByte + (width * 3)] & mask) != 0)
                        {
                            pxClr += 8;
                        }

                        if ((data[inOffset + inputByte + (width * 4)] & mask) != 0)
                        {
                            pxClr += 0x10;
                        }

                        pxlClrs[y, x] = pxClr;
                    }

                    inOffset += width * 5;
                }

                dataOffset = inOffset;

                var bitmap = new Bitmap(widthPx + xPosPx, heightPx + yPosPx, System.Drawing.Imaging.PixelFormat.Format16bppArgb1555);
                for (var y = 0; y < heightPx; y++)
                {
                    for (var x = 0; x < widthPx; x += 1)
                    {
                        var pxX = x + xPosPx;
                        var pxY = y + yPosPx;
                        bitmap.SetPixel(pxX, pxY, egaPalette[pxlClrs[y, x]]);
                    }
                }

                Bitmaps.Add(bitmap);
            }
        }
Ejemplo n.º 25
0
        public EgaSpriteBlock(FileBlockParameters parameters)
        {
            var data = parameters.Data;

            setBlockId(parameters.Id);
            uint frames = data[0];
            int offset = 1;
            if (frames > 8)
                return;

            Color[] clrs = new Color[16];
            for (int i = 0; i < 16; i++)
            {
                clrs[i] = Color.FromArgb((int)EgaVgaPalette.EgaColors[i]);
            }

            var filename = Path.GetFileName(parameters.Name).ToUpper();
            bool xorFrames = filename.StartsWith("PIC", true, System.Globalization.CultureInfo.CurrentCulture);
            xorFrames |= filename.StartsWith("FINAL", true, System.Globalization.CultureInfo.CurrentCulture);

            if (filename.StartsWith("SPRI", true, System.Globalization.CultureInfo.CurrentCulture))
            {
                clrs[0] = Color.FromArgb(0, 0, 0, 0);
                clrs[13] = Color.FromArgb((int)EgaVgaPalette.EgaColors[0]);
            }


            byte[] first_frame_ega_layout = null;

            for (int frame = 0; frame < frames; frame++)
            {
                if (data.Length < 21 + offset) return;

                uint delay = ArrayToUint(data, offset);
                offset += 4;
                int height = ArrayToUshort(data, offset);
                offset += 2;
                int width = ArrayToUshort(data, offset);
                offset += 2;
                int x_pos = ArrayToUshort(data, offset);
                offset += 2;
                int y_pos = ArrayToUshort(data, offset);
                offset += 3;
                offset += 8;

                // skip 1 byte
                // skip 8 bytes
                int width_px = width * 8;
                int height_px = height;
                int x_pos_px = x_pos * 8;
                int y_pos_px = y_pos * 8;

                if (width_px < 1 || height_px < 1 || width_px > 320 || height_px > 200)
                    return;

                int egaDataSize = height * width * 4;

                if (data.Length < egaDataSize + offset) return;

                if (xorFrames)
                {
                    if (frame == 0)
                    {
                        first_frame_ega_layout = new byte[egaDataSize + 1];

                        System.Array.Copy(data, offset, first_frame_ega_layout, 0, egaDataSize);
                    }
                    else
                    {
                        for (int i = 0; i < egaDataSize; i++)
                        {
                            byte b = first_frame_ega_layout[i];
                            data[offset + i] ^= b;
                        }
                    }
                }

                var bitmap = new Bitmap((int)(width_px + x_pos_px), (int)(height_px + y_pos_px), System.Drawing.Imaging.PixelFormat.Format16bppArgb1555);
                for (int y = 0; y < height_px; y++)
                {
                    for (int x = 0; x < width_px; x += 2)
                    {
                        byte b = data[(y * width * 4) + (x / 2) + offset];
                        int pxX = (int)(x + 0 + x_pos_px);
                        int pxY = (int)(y + y_pos_px);
                        bitmap.SetPixel(pxX, pxY, clrs[b >> 4]);
                        bitmap.SetPixel(pxX + 1, pxY, clrs[b & 0xF]);
                    }
                }

                Bitmaps.Add(bitmap);

                offset += egaDataSize;

            }
        }
Ejemplo n.º 26
0
        public bool IsSatisfiedBy(FileBlockParameters parameters)
        {
            var data   = parameters.Data;
            int frames = data[0];

            int offset = 1;

            if (frames == 0 || frames > 8)
            {
                return(false);
            }

            for (int frame = 0; frame < frames; frame++)
            {
                if (data.Length < 21 + offset)
                {
                    return(false);
                }

                offset += 4;
                int height = ArrayToUshort(data, offset);
                offset += 2;
                int width = ArrayToUshort(data, offset);
                offset += 2;
                int x_pos = ArrayToUshort(data, offset);
                offset += 2;
                int y_pos = ArrayToUshort(data, offset);
                offset += 3;
                offset += 8;

                // skip 1 byte
                // skip 8 bytes
                int width_px  = width * 8;
                int height_px = height;
                int x_pos_px  = x_pos * 8;
                int y_pos_px  = y_pos * 8;

                if (width_px < 1 || height_px < 1 || width_px > 320 || height_px > 200)
                {
                    return(false);
                }

                int egaDataSize = height * width * 4;

                if (data.Length < egaDataSize + offset)
                {
                    return(false);
                }

                offset += egaDataSize;
            }

            if (data.Length > offset)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Ejemplo n.º 27
0
 public bool IsSatisfiedBy(FileBlockParameters parameters)
 {
     return (parameters.Data.Length%8) == 0 &&
            (Path.GetFileName(parameters.Name).ToUpper().StartsWith("8X8"));
 }
Ejemplo n.º 28
0
        public VgaMixedBlock(FileBlockParameters parameters)
        {
            setBlockId(parameters.Id);

            var data = parameters.Data;
            var origData = data;

            if (data.Length < 5)
                return;

            uint frames = data[0];
            int offset = 5;
            if (frames > 8)
                return;

            if (data.Length < 20 + offset)
                return;

            // try single frame
            int height = ArrayToUshort(data, 0 + offset);
            int width = ArrayToUshort(data, 2 + offset);
            int x_pos = ArrayToUshort(data, 4 + offset);
            int y_pos = ArrayToUshort(data, 6 + offset);
            int item_count = data[8 + offset];

            int width_px = width * 8;
            int height_px = height;
            int x_pos_px = x_pos * 8;
            int y_pos_px = y_pos * 8;

            if (width_px < 1 || height_px < 1 || width_px > 320 || height_px > 200)
                return;

            bool egaBlock = (data[9 + offset] & 0xCC) == 0;
            int blocksize = egaBlock ? (4 * width * height) : (5 * width * height);

            if (data.Length < blocksize + 9 + offset)
                return;


            byte[] tempPalette = new byte[0x3B];
            int data_offset = DecodePaletteData(tempPalette, 9 + offset, data);

            int[] dd = new int[48];
            int _base = 0x20;
            for (int i = 0; i < 24; i++)
            {
                int b = tempPalette[_base + i];
                int a1 = (b & 0x0f);
                int a2 = (b & 0xf0);
                dd[0 + i] = (b & 0x0f) * 4;
                dd[24 + i] = (b & 0xf0) / 4;
            }

            var clrs = PaletteBase();

            for (int i = 0; i < 14; i += 1)
            {
                int r = dd[(i * 3) + 6 + 0];
                int g = dd[(i * 3) + 6 + 1];
                int b = dd[(i * 3) + 6 + 2];
                clrs[i + 18] = Color.FromArgb(r * 4, g * 4, b * 4);
            }

            int[,] pxl_clrs = new int[height_px, width_px];

            for (int frame = 0; frame < frames; frame++)
            {
                if (egaBlock)
                {
                    int in_offset = data_offset;
                    for (int y = 0; y < height; y++)
                    {
                        for (int x = 0; x < width_px; x += 2)
                        {
                            pxl_clrs[y, x] = data[in_offset] >> 4;
                            pxl_clrs[y, x + 1] = data[in_offset] & 0x0F;

                            in_offset += 1;
                        }
                    }

                    data_offset = in_offset;
                }
                else
                {
                    int in_offset = data_offset;
                    int out_offset = 0;
                    for (int y = 0; y < height; y++)
                    {
                        for (int x = 0; x < width_px; x++)
                        {
                            int mask = 0x80 >> (x & 7);
                            int input_byte = x / 8;
                            byte px_clr = 0;

                            if ((data[in_offset + input_byte] & mask) != 0)
                            {
                                px_clr = 1;
                            }

                            if ((data[in_offset + input_byte + width] & mask) != 0)
                            {
                                px_clr += 2;
                            }

                            if ((data[in_offset + input_byte + (width * 2)] & mask) != 0)
                            {
                                px_clr += 4;
                            }

                            if ((data[in_offset + input_byte + (width * 3)] & mask) != 0)
                            {
                                px_clr += 8;
                            }

                            if ((data[in_offset + input_byte + (width * 4)] & mask) != 0)
                            {
                                px_clr += 0x10;
                            }

                            pxl_clrs[y, x] ^= px_clr;
                        }

                        in_offset += width * 5;
                        out_offset += width * 8;
                    }

                    data_offset = in_offset + 14;
                }

                var bitmap = new Bitmap(width_px + x_pos_px, height_px + y_pos_px, System.Drawing.Imaging.PixelFormat.Format16bppArgb1555);
                for (int y = 0; y < height_px; y++)
                {
                    for (int x = 0; x < width_px; x += 1)
                    {
                        int pxX = x + x_pos_px;
                        int pxY = y + y_pos_px;
                        bitmap.SetPixel(pxX, pxY, clrs[pxl_clrs[y, x]]);
                    }
                }

                Bitmaps.Add(bitmap);
            }
        }
Ejemplo n.º 29
0
        public VgaMixedBlock(FileBlockParameters parameters)
        {
            setBlockId(parameters.Id);

            var data     = parameters.Data;
            var origData = data;

            if (data.Length < 5)
            {
                return;
            }

            uint frames = data[0];
            int  offset = 5;

            if (frames > 8)
            {
                return;
            }

            if (data.Length < 20 + offset)
            {
                return;
            }

            // try single frame
            int height     = ArrayToUshort(data, 0 + offset);
            int width      = ArrayToUshort(data, 2 + offset);
            int x_pos      = ArrayToUshort(data, 4 + offset);
            int y_pos      = ArrayToUshort(data, 6 + offset);
            int item_count = data[8 + offset];

            int width_px  = width * 8;
            int height_px = height;
            int x_pos_px  = x_pos * 8;
            int y_pos_px  = y_pos * 8;

            if (width_px < 1 || height_px < 1 || width_px > 320 || height_px > 200)
            {
                return;
            }

            bool egaBlock  = (data[9 + offset] & 0xCC) == 0;
            int  blocksize = egaBlock ? (4 * width * height) : (5 * width * height);

            if (data.Length < blocksize + 9 + offset)
            {
                return;
            }


            byte[] tempPalette = new byte[0x3B];
            int    data_offset = DecodePaletteData(tempPalette, 9 + offset, data);

            int[] dd    = new int[48];
            int   _base = 0x20;

            for (int i = 0; i < 24; i++)
            {
                int b  = tempPalette[_base + i];
                int a1 = (b & 0x0f);
                int a2 = (b & 0xf0);
                dd[0 + i]  = (b & 0x0f) * 4;
                dd[24 + i] = (b & 0xf0) / 4;
            }

            var clrs = PaletteBase();

            for (int i = 0; i < 14; i += 1)
            {
                int r = dd[(i * 3) + 6 + 0];
                int g = dd[(i * 3) + 6 + 1];
                int b = dd[(i * 3) + 6 + 2];
                clrs[i + 18] = Color.FromArgb(r * 4, g * 4, b * 4);
            }

            int[,] pxl_clrs = new int[height_px, width_px];

            for (int frame = 0; frame < frames; frame++)
            {
                if (egaBlock)
                {
                    int in_offset = data_offset;
                    for (int y = 0; y < height; y++)
                    {
                        for (int x = 0; x < width_px; x += 2)
                        {
                            pxl_clrs[y, x]     = data[in_offset] >> 4;
                            pxl_clrs[y, x + 1] = data[in_offset] & 0x0F;

                            in_offset += 1;
                        }
                    }

                    data_offset = in_offset;
                }
                else
                {
                    int in_offset  = data_offset;
                    int out_offset = 0;
                    for (int y = 0; y < height; y++)
                    {
                        for (int x = 0; x < width_px; x++)
                        {
                            int  mask       = 0x80 >> (x & 7);
                            int  input_byte = x / 8;
                            byte px_clr     = 0;

                            if ((data[in_offset + input_byte] & mask) != 0)
                            {
                                px_clr = 1;
                            }

                            if ((data[in_offset + input_byte + width] & mask) != 0)
                            {
                                px_clr += 2;
                            }

                            if ((data[in_offset + input_byte + (width * 2)] & mask) != 0)
                            {
                                px_clr += 4;
                            }

                            if ((data[in_offset + input_byte + (width * 3)] & mask) != 0)
                            {
                                px_clr += 8;
                            }

                            if ((data[in_offset + input_byte + (width * 4)] & mask) != 0)
                            {
                                px_clr += 0x10;
                            }

                            pxl_clrs[y, x] ^= px_clr;
                        }

                        in_offset  += width * 5;
                        out_offset += width * 8;
                    }

                    data_offset = in_offset + 14;
                }

                var bitmap = new Bitmap(width_px + x_pos_px, height_px + y_pos_px, System.Drawing.Imaging.PixelFormat.Format16bppArgb1555);
                for (int y = 0; y < height_px; y++)
                {
                    for (int x = 0; x < width_px; x += 1)
                    {
                        int pxX = x + x_pos_px;
                        int pxY = y + y_pos_px;
                        bitmap.SetPixel(pxX, pxY, clrs[pxl_clrs[y, x]]);
                    }
                }

                Bitmaps.Add(bitmap);
            }
        }
Ejemplo n.º 30
0
        private void loadBitmaps(int daxBlockId, string fileName, List<Bitmap> bitmaps8x8)
        {
            // load 8x8 bitmaps from daxBlockId in fileName into the list bitmaps8x8 to simulate the order the bitmaps would be in memory in the game
            var file = new DaxImageFile(string.Format(fileName));
            foreach (DaxFileBlock block in file.Blocks)
            {

                if (block.Id == daxBlockId)
                {
                    var parameters = new FileBlockParameters
                    {
                        Data = block.Data,
                        Name = block.File,
                        Id = block.Id,
                    };
                    var render = new RenderBlockFactory().CreateUsing(parameters);
                    foreach (var bitmap in render.GetBitmaps())
                    {
                        bitmaps8x8.Add(bitmap);
                    }
                }
            }
        }