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)); }
public Raw(string path, Size3i size, Format format) { using (var stream = File.OpenRead(path)) { Load(stream, size, format); } }
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); }
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))); }
public override Size3i GetPhysicalSize(Size3i size) { return(new Size3i( Functions.Max(size.Width, 1), Functions.Max(size.Height, 1), Functions.Max(size.Depth, 1))); }
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); }
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); }
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); }
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; }
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; }
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); }
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; } }
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; }
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; } }
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]; } } }
// 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); }
// 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; }
// 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); }
public override Size3i GetPhysicalSize(Size3i size) { throw new NotImplementedException(); }
// Subtracts the point with a size to get another point public Point2i subtract(Size3i size) { return new Point2i(x-size.width, y-size.height); }
// 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); }
// 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); }
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; }
public Raw(Stream stream, Size3i size, Format format) { Load(stream, size, format); }
// 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); }
// 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); }
public override Size3i GetPhysicalSize(Size3i size) { return(Size.Max(Size3i.Unit, size)); }
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++]; } } } }
// 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); }
// 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); }
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; }
// 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); }
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; }
// 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; }
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); }
// 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; }
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); }
// 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; }
public override int GetByteCount(Size3i size, out int rowPitch, out int slicePitch) { throw new NotImplementedException(); }
// Adds the point with a size to get another point public Point2i add(Size3i size) { return new Point2i(x+size.width, y+size.height); }
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; }