Exemplo n.º 1
0
        /// <summary>
        /// Read a part of a SND file and created a new byte[] from the contained sound.
        /// </summary>
        /// <param name="file">The file where the sound to be loaded from. The read position must be set at the beginning the sound part of the file.</param>
        /// <param name="length">The length of the sound in the filestream.</param>
        /// <returns></returns>
        private byte[] CreateSoundBuffer(IO.File file, int length)
        {
            if (file == null)
            {
                throw new ArgumentNullException(nameof(file));
            }
            if (length <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(length), "length must be greater than zero.");
            }

            var buffer = file.ReadBytes(length);

            return(buffer);
        }
Exemplo n.º 2
0
        public Texture2D LoadPaletteFile(String filepath)
        {
            if (filepath == null)
            {
                throw new ArgumentNullException("filepath");
            }

            Texture2D palette;

            if (m_palettefilecache.TryGetValue(filepath, out palette) == true)
            {
                return(palette);
            }

            palette = GetSubSystem <Video.VideoSystem>().CreatePaletteTexture();
            m_palettefilecache.Add(filepath, palette);

            using (IO.File file = GetSubSystem <IO.FileSystem>().OpenFile(filepath))
            {
                if (file.FileLength != (256 * 3))
                {
                    Log.Write(LogLevel.Error, LogSystem.SpriteSystem, "{0} is not a character palette file", filepath);
                }
                else
                {
                    Byte[] buffer   = new Byte[256 * 4];
                    Byte[] filedata = file.ReadBytes(256 * 3);

                    for (Int32 i = 0; i != 256; ++i)
                    {
                        Int32 bufferindex = (255 - i) * 4;
                        Int32 fileindex   = i * 3;

                        buffer[bufferindex + 0] = filedata[fileindex + 2];
                        buffer[bufferindex + 1] = filedata[fileindex + 1];
                        buffer[bufferindex + 2] = filedata[fileindex + 0];
                        buffer[bufferindex + 3] = 255;
                    }

                    palette.SetData <Byte>(buffer, 0, 256 * 4, SetDataOptions.None);
                }
            }

            return(palette);
        }
Exemplo n.º 3
0
        public bool Load(IO.File file, int pcxsize, out Point size, out Texture2D pixels, out Texture2D palette)
        {
            if (file == null)
            {
                throw new ArgumentNullException(nameof(file));
            }

            size    = new Point(int.MinValue, int.MinValue);
            pixels  = null;
            palette = null;

            var filedata = file.ReadBytes(pcxsize);

            if (filedata.Length != pcxsize)
            {
                return(false);
            }

            var header   = new IO.FileHeaders.PcxFileHeader(filedata);
            var tempsize = new Point(header.XMax - header.XMin + 1, header.YMax - header.YMin + 1);

            if (header.Manufacturer != 10 || header.Encoding != 1 || header.Version > 5 || header.BitsPerPixel != 8)
            {
                return(false);
            }
            if (header.ColorPlanes != 1)
            {
                return(false);
            }
            if (tempsize.X <= 0 || tempsize.Y <= 0)
            {
                return(false);
            }

            size = tempsize;

            var readoffset = 0;

            pixels  = LoadPixels(filedata, size, header.BytesPerLine, ref readoffset);
            palette = LoadPalette(filedata, ref readoffset);
            return(true);
        }