Exemplo n.º 1
0
Arquivo: BC4.cs Projeto: Frassle/Ibasa
 public override Size3i GetPhysicalSize(Size3i size)
 {
     return new Size3i(
         Functions.Max((size.Width + 3) & ~3, 4), //& ~3 = mask of 2 low bits, makes it multiple of 4, rounded up
         Functions.Max((size.Height + 3) & ~3, 4), //5 -> 8, 3 -> 4, 7 -> 8
         Functions.Max(size.Depth, 1));
 }
Exemplo n.º 2
0
Arquivo: Raw.cs Projeto: Frassle/Ibasa
 public Raw(string path, Size3i size, Format format)
 {
     using (var stream = File.OpenRead(path))
     {
         Load(stream, size, format);
     }
 }
Exemplo n.º 3
0
        public static Resource Convert(Resource resource, Format newFormat)
        {
            Resource newResource = new Resource(
                resource.Size, resource.MipLevels, resource.ArraySize,
                newFormat);

            for (int mipSlice = 0; mipSlice < resource.MipLevels; ++mipSlice)
            {
                for (int arraySlice = 0; arraySlice < resource.ArraySize; ++arraySlice)
                {
                    Size3i size = resource.ComputeMipSliceSize(mipSlice);

                    System.IO.MemoryStream source = new System.IO.MemoryStream(resource[mipSlice, arraySlice]);
                    int sourceRowPitch, sourceSlicePitch;
                    resource.Format.GetByteCount(size, out sourceRowPitch, out sourceSlicePitch);

                    System.IO.MemoryStream destination = new System.IO.MemoryStream(newResource[mipSlice, arraySlice]);
                    int destinationRowPitch, destinationSlicePitch;
                    newResource.Format.GetByteCount(size, out destinationRowPitch, out destinationSlicePitch);

                    Format.Convert(resource.Format, newResource.Format,
                                   source, sourceRowPitch, sourceSlicePitch,
                                   destination, destinationRowPitch, destinationSlicePitch,
                                   new Boxi(Point3i.Zero, size), Point3i.Zero);
                }
            }

            return(newResource);
        }
Exemplo n.º 4
0
 public override Size3i GetPhysicalSize(Size3i size)
 {
     return(new Size3i(
                Functions.Max((size.Width + 3) & ~3, 4),  //& ~3 = mask of 2 low bits, makes it multiple of 4, rounded up
                Functions.Max((size.Height + 3) & ~3, 4), //5 -> 8, 3 -> 4, 7 -> 8
                Functions.Max(size.Depth, 1)));
 }
Exemplo n.º 5
0
 public override Size3i GetPhysicalSize(Size3i size)
 {
     return(new Size3i(
                Functions.Max(size.Width, 1),
                Functions.Max(size.Height, 1),
                Functions.Max(size.Depth, 1)));
 }
Exemplo n.º 6
0
 public Raw(string path, Size3i size, Format format)
 {
     using (var stream = File.OpenRead(path))
     {
         Load(stream, size, format);
     }
 }
Exemplo n.º 7
0
        public static int ComputeMiplevels(Size3i size)
        {
            Contract.Requires(size.Width > 0, "size must be greater than zero.");
            Contract.Requires(size.Height > 0, "size must be greater than zero.");
            Contract.Requires(size.Depth > 0, "size must be greater than zero.");
            Contract.Ensures(Contract.Result <int>() > 0, "Result must be greater than zero.");

            return(Binary.CeilingLog2(Functions.Max(Functions.Max(size.Width, size.Height), size.Depth)) + 1);
        }
Exemplo n.º 8
0
        public override int GetByteCount(Size3i size, out int rowPitch, out int slicePitch)
        {
            Contract.Requires(size.Width > 0, "width must be greater than 0");
            Contract.Requires(size.Height > 0, "height must be greater than 0");
            Contract.Requires(size.Depth > 0, "depth must be greater than 0");

            rowPitch   = size.Width * 12; //12 bytes per color
            slicePitch = rowPitch * size.Height;
            return(slicePitch * size.Depth);
        }
Exemplo n.º 9
0
 public override int GetByteCount(Size3i size, out int rowPitch, out int slicePitch)
 {
     if ((size.Width & 0x3) != 0 || (size.Height & 0x3) != 0)
     {
         throw new ArgumentException("size Width and Height must be a multiple of 4.", "size");
     }
     rowPitch   = BlockSize * (size.Width / 4);
     slicePitch = rowPitch * (size.Height / 4);
     return(slicePitch * size.Depth);
 }
Exemplo n.º 10
0
        public Image(Size3i size)
        {
            Contract.Requires(size.Width > 0);
            Contract.Requires(size.Height > 0);
            Contract.Requires(size.Depth > 0);

            Size   = size;
            Pixels = new Colord[Width * Height * Depth];

            AddressX = AddressMode.Clamp;
            AddressY = AddressMode.Clamp;
            AddressZ = AddressMode.Clamp;
        }
Exemplo n.º 11
0
        public Image(Colord[] pixels)
        {
            Contract.Requires(pixels != null);

            Size   = new Size3i(pixels.GetLength(0), 1, 1);
            Pixels = new Colord[Width];
            for (int x = 0; x < Width; ++x)
            {
                this[x] = pixels[x];
            }

            AddressX = AddressMode.Clamp;
            AddressY = AddressMode.Clamp;
            AddressZ = AddressMode.Clamp;
        }
Exemplo n.º 12
0
        public static Image Initialize(Size3i size, Func <Point3i, Colord> initalizer)
        {
            Image image = new Image(size);

            for (int z = 0; z < image.Depth; ++z)
            {
                for (int y = 0; y < image.Height; ++y)
                {
                    for (int x = 0; x < image.Width; ++x)
                    {
                        image[x, y, z] = initalizer(new Point3i(x, y, z));
                    }
                }
            }

            return(image);
        }
Exemplo n.º 13
0
Arquivo: Raw.cs Projeto: Frassle/Ibasa
        private void Load(Stream stream, Size3i size, Format format)
        {
            BinaryReader reader = new BinaryReader(stream, System.Text.Encoding.ASCII);

            Resource resource = new Resource(size, 1, 1, format);

            int count = format.GetByteCount(size);
            int offset = 0;

            while(count != 0)
            {
                int read = stream.Read(resource[0], offset, count);
                if (read == 0)
                    throw new EndOfStreamException();
                offset += read;
                count -= read;
            }
        }
Exemplo n.º 14
0
        public Image(Colord[,] pixels)
        {
            Contract.Requires(pixels != null);

            Size   = new Size3i(pixels.GetLength(0), pixels.GetLength(1), 1);
            Pixels = new Colord[Width * Height];
            for (int y = 0; y < Height; ++y)
            {
                for (int x = 0; x < Width; ++x)
                {
                    this[x, y] = pixels[x, y];
                }
            }

            AddressX = AddressMode.Clamp;
            AddressY = AddressMode.Clamp;
            AddressZ = AddressMode.Clamp;
        }
Exemplo n.º 15
0
        private void Load(Stream stream, Size3i size, Format format)
        {
            BinaryReader reader = new BinaryReader(stream, System.Text.Encoding.ASCII);

            Resource resource = new Resource(size, 1, 1, format);

            int count  = format.GetByteCount(size);
            int offset = 0;

            while (count != 0)
            {
                int read = stream.Read(resource[0], offset, count);
                if (read == 0)
                {
                    throw new EndOfStreamException();
                }
                offset += read;
                count  -= read;
            }
        }
Exemplo n.º 16
0
        public Resource(Size3i size, int mipLevels, int arraySize, Format format)
        {
            Contract.Requires(mipLevels >= 0, "mipLevels must be zero or greater.");
            Contract.Requires(arraySize > 0, "arraySize must be greater than zero.");
            Contract.Requires(format != null, "format cannot be null.");

            Size         = new Size3i(Functions.Max(size.Width, 1), Functions.Max(size.Height, 1), Functions.Max(size.Depth, 1));
            MipLevels    = mipLevels == 0 ? ComputeMiplevels(Size) : mipLevels;
            ArraySize    = arraySize;
            Format       = format;
            Subresources = new byte[MipLevels * ArraySize][];


            for (int mipSlice = 0; mipSlice < MipLevels; ++mipSlice)
            {
                int byteCount = Format.GetByteCount(ComputeMipSliceSize(mipSlice));
                for (int arraySlice = 0; arraySlice < ArraySize; ++arraySlice)
                {
                    this[mipSlice, arraySlice] = new byte[byteCount];
                }
            }
        }
Exemplo n.º 17
0
 // Finds if the two sizes are equal to each other
 public bool equals(Size3i size)
 {
     return ((int)width== size.width && (int)height== size.height && (int)depth== size.depth);
 }
Exemplo n.º 18
0
        // Gets the minimum value of the size
        public static Size3i min(Size3i value, Size3i min)
        {
            // Variables
            Size3i	temp=	value;

            if(value.width< min.width)
                temp.width=	min.width;
            if(value.height< min.height)
                temp.height=	min.height;
            if(value.depth< min.depth)
                temp.depth=	min.depth;

            return temp;
        }
Exemplo n.º 19
0
 // Adds the two sizes together
 public Size3f add(Size3i size)
 {
     return new Size3f(width+(float)size.width, height+(float)size.height, depth+(float)size.depth);
 }
Exemplo n.º 20
0
 public override Size3i GetPhysicalSize(Size3i size)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 21
0
 // Subtracts the point with a size to get another point
 public Point2i subtract(Size3i size)
 {
     return new Point2i(x-size.width, y-size.height);
 }
Exemplo n.º 22
0
 // Adds the point with a size to get another point
 public Point3i add(Size3i size)
 {
     return new Point3i(x+size.width, y+size.height, z+size.depth);
 }
Exemplo n.º 23
0
 // Subtracts the point with a size to get another point
 public Point3f subtract(Size3i size)
 {
     return new Point3f(x-(float)size.width, y-(float)size.height, z-(float)size.depth);
 }
Exemplo n.º 24
0
        public Image(Colord[] pixels)
        {
            Contract.Requires(pixels != null);

            Size = new Size3i(pixels.GetLength(0), 1, 1);
            Pixels = new Colord[Width];
            for (int x = 0; x < Width; ++x)
            {
                this[x] = pixels[x];
            }

            AddressX = AddressMode.Clamp;
            AddressY = AddressMode.Clamp;
            AddressZ = AddressMode.Clamp;
        }
Exemplo n.º 25
0
Arquivo: BC5.cs Projeto: Frassle/Ibasa
 public override int GetByteCount(Size3i size, out int rowPitch, out int slicePitch)
 {
     if ((size.Width & 0x3) != 0 || (size.Height & 0x3) != 0)
         throw new ArgumentException("size Width and Height must be a multiple of 4.", "size");
     rowPitch = BlockSize * (size.Width / 4);
     slicePitch = rowPitch * (size.Height / 4);
     return slicePitch * size.Depth;
 }
Exemplo n.º 26
0
Arquivo: Raw.cs Projeto: Frassle/Ibasa
 public Raw(Stream stream, Size3i size, Format format)
 {
     Load(stream, size, format);
 }
Exemplo n.º 27
0
 // Adds the point with a size to get another point
 public Point2f add(Size3i size)
 {
     return new Point2f(x+(float)size.width, y+(float)size.height);
 }
Exemplo n.º 28
0
 // Subtracts the point with a size to get another point
 public Point2f subtract(Size3i size)
 {
     return new Point2f(x-(float)size.width, y-(float)size.height);
 }
Exemplo n.º 29
0
 public override Size3i GetPhysicalSize(Size3i size)
 {
     return(Size.Max(Size3i.Unit, size));
 }
Exemplo n.º 30
0
        public void Blit(Image source, Point3i sourcePoint, Point3i destinationPoint, Size3i size)
        {
            for (int z = 0; z < size.Depth; ++z)
            {
                int zsrc = (sourcePoint.Z + z) * (source.Width * source.Height);
                int zdst = (destinationPoint.Z + z) * (Width * Height);
                for (int y = 0; y < size.Height; ++y)
                {
                    int xysrc = sourcePoint.X + (sourcePoint.Y + y) * source.Width + zsrc;
                    int xydst = destinationPoint.X + (destinationPoint.Y + y) * Width + zdst;

                    for (int x = 0; x < size.Width; ++x)
                    {
                        Pixels[xydst++] = source.Pixels[xysrc++];
                    }
                }
            }
        }
Exemplo n.º 31
0
 // Subtracts the two sizes together
 public Size3f subtract(Size3i size)
 {
     return new Size3f(width-(float)size.width, height-(float)size.height, depth-(float)size.depth);
 }
Exemplo n.º 32
0
        public void Blit(Image source, Point3i sourcePoint, Point3i destinationPoint, Size3i size)
        {
            for (int z = 0; z < size.Depth; ++z)
            {
                int zsrc = (sourcePoint.Z + z) * (source.Width * source.Height);
                int zdst = (destinationPoint.Z + z) * (Width * Height);
                for (int y = 0; y < size.Height; ++y)
                {
                    int xysrc = sourcePoint.X + (sourcePoint.Y + y) * source.Width + zsrc;
                    int xydst = destinationPoint.X + (destinationPoint.Y + y) * Width + zdst;

                    for (int x = 0; x < size.Width; ++x)
                    {
                        Pixels[xydst++] = source.Pixels[xysrc++];
                    }
                }
            }
        }
Exemplo n.º 33
0
 // Subtracts the point with a size to get another point
 public Point3i subtract(Size3i size)
 {
     return new Point3i(x-size.width, y-size.height, z-size.depth);
 }
Exemplo n.º 34
0
        public Image(Colord[,,] pixels)
        {
            Contract.Requires(pixels != null);

            Size = new Size3i(pixels.GetLength(0), pixels.GetLength(1), pixels.GetLength(2));
            Pixels = new Colord[Width * Height * Depth];
            for (int z = 0; z < Depth; ++z)
            {
                for (int y = 0; y < Height; ++y)
                {
                    for (int x = 0; x < Width; ++x)
                    {
                        this[x, y, z] = pixels[x, y, z];
                    }
                }
            }

            AddressX = AddressMode.Clamp;
            AddressY = AddressMode.Clamp;
            AddressZ = AddressMode.Clamp;
        }
Exemplo n.º 35
0
 public Raw(Stream stream, Size3i size, Format format)
 {
     Load(stream, size, format);
 }
Exemplo n.º 36
0
 // Adds the point with a size to get another point
 public Point3f add(Size3i size)
 {
     return new Point3f(x+(float)size.width, y+(float)size.height, z+(float)size.depth);
 }
Exemplo n.º 37
0
        public static Image Initialize(Size3i size, Func<Point3i, Colord> initalizer)
        {
            Image image = new Image(size);

            for (int z = 0; z < image.Depth; ++z)
            {
                for (int y = 0; y < image.Height; ++y)
                {
                    for (int x = 0; x < image.Width; ++x)
                    {
                        image[x, y, z] = initalizer(new Point3i(x, y, z));
                    }
                }
            }

            return image;
        }
Exemplo n.º 38
0
        // Clamps the size to the given min and max bounds
        public static Size3i clamp(Size3i value, Size3i min, Size3i max)
        {
            // Variables
            Size3i	temp=	value;

            if(value.width< min.width)
                temp.width=	min.width;
            else if(value.width> max.width)
                temp.width=	max.width;
            if(value.height< min.height)
                temp.height=	min.height;
            else if(value.height> max.height)
                temp.height=	max.height;
            if(value.depth< min.depth)
                temp.depth=	min.depth;
            else if(value.depth> max.depth)
                temp.depth=	max.depth;

            return temp;
        }
Exemplo n.º 39
0
 public override int GetByteCount(Size3i size, out int rowPitch, out int slicePitch)
 {
     rowPitch   = BlockSize * ((size.Width + 3) / 4);
     slicePitch = rowPitch * ((size.Height + 3) / 4);
     return(slicePitch * size.Depth);
 }
Exemplo n.º 40
0
        // Gets the most minimum size of the two given sizes
        public static Size3i getMostMin(Size3i val1, Size3i val2)
        {
            // Variables
            Size3i	size=	Size3i.NO_SIZE;

            if(val1.width< val2.width)
                size.width=	val1.width;
            else
                size.width=	val2.width;
            if(val1.height< val2.height)
                size.height=	val1.height;
            else
                size.height=	val2.height;
            if(val1.depth< val2.depth)
                size.depth=	val1.depth;
            else
                size.depth=	val2.depth;

            return size;
        }
Exemplo n.º 41
0
 public override int GetByteCount(Size3i size, out int rowPitch, out int slicePitch)
 {
     rowPitch   = size.Width * 3; //3 bytes per color
     slicePitch = rowPitch * size.Height;
     return(slicePitch * size.Depth);
 }
Exemplo n.º 42
0
        // Gets the maximum value of the size
        public static Size3i max(Size3i value, Size3i max)
        {
            // Variables
            Size3i	temp=	value;

            if(value.width> max.width)
                temp.width=	max.width;
            if(value.height> max.height)
                temp.height=	max.height;
            if(value.depth> max.depth)
                temp.depth=	max.depth;

            return temp;
        }
Exemplo n.º 43
0
 public override int GetByteCount(Size3i size, out int rowPitch, out int slicePitch)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 44
0
 // Adds the point with a size to get another point
 public Point2i add(Size3i size)
 {
     return new Point2i(x+size.width, y+size.height);
 }
Exemplo n.º 45
0
Arquivo: BC4.cs Projeto: Frassle/Ibasa
 public override int GetByteCount(Size3i size, out int rowPitch, out int slicePitch)
 {
     rowPitch = BlockSize * ((size.Width + 3) / 4);
     slicePitch = rowPitch * ((size.Height + 3) / 4);
     return slicePitch * size.Depth;
 }
Exemplo n.º 46
0
        public Image(Size3i size)
        {
            Contract.Requires(size.Width > 0);
            Contract.Requires(size.Height > 0);
            Contract.Requires(size.Depth > 0);

            Size = size;
            Pixels = new Colord[Width * Height * Depth];

            AddressX = AddressMode.Clamp;
            AddressY = AddressMode.Clamp;
            AddressZ = AddressMode.Clamp;
        }