public Texture(BufferReader reader, SectionHeader header, TxdFile parent) { this.reader = reader; reader.SkipStream(8); reader.PrewarmBuffer(64); Name = reader.ReadBytes(32).GetNullTerminatedString(); AlphaName = reader.ReadBytes(32).GetNullTerminatedString(); FullName = string.Format(FULLNAME_FORMAT, parent.FileNameWithoutExtension, Name); FullALphaName = string.Format(FULLNAME_FORMAT, parent.FileNameWithoutExtension, AlphaName); reader.PrewarmBuffer(12); rawRasterFormat = (RasterFormat)reader.ReadInt32(); reader.Skip(4); //Alpha or four CC Width = reader.ReadInt16(); Height = reader.ReadInt16(); reader.SkipStream(4); //BPP, Mipmaps, RasterType and DXTnumber offset = (int)reader.Position; reader.SkipStream(header.Size - 88); }
public TextureNative(SectionHeader header, Stream stream) : base(header, stream) { SectionHeader.Read(stream); var reader = new BinaryReader(stream); PlatformID = reader.ReadUInt32(); FilterFlags = (Filter) reader.ReadUInt16(); WrapV = (WrapMode) reader.ReadByte(); WrapU = (WrapMode) reader.ReadByte(); DiffuseName = reader.ReadString(32); AlphaName = reader.ReadString(32); Format = (RasterFormat) reader.ReadUInt32(); if (PlatformID == 9) { var dxt = reader.ReadString(4); switch (dxt) { case "DXT1": Compression = CompressionMode.DXT1; break; case "DXT3": Compression = CompressionMode.DXT3; break; default: Compression = CompressionMode.None; break; } } else { Alpha = reader.ReadUInt32() == 0x1; } Width = reader.ReadUInt16(); Height = reader.ReadUInt16(); BPP = (byte) (reader.ReadByte() >> 3); MipMapCount = reader.ReadByte(); RasterType = reader.ReadByte(); if (RasterType != 0x4) { throw new Exception("Unexpected RasterType, expected 0x04."); } if (PlatformID == 9) { Alpha = (reader.ReadByte() & 0x1) == 0x1; } else { Compression = (CompressionMode) reader.ReadByte(); } ImageDataSize = reader.ReadInt32(); ImageData = reader.ReadBytes(ImageDataSize); if ((Format & RasterFormat.ExtMipMap) != 0) { var tot = ImageDataSize; for (var i = 0; i < MipMapCount; ++i) { tot += ImageDataSize >> (2 * i); } ImageLevelData = reader.ReadBytes(tot); } else { ImageLevelData = ImageData; } }
//--------------------------------------------------------------------- public void BindExtensionToFormat(string fileExtension, RasterFormat format) { if (fileExtension == null) { throw new ArgumentNullException("fileExtension"); } if (fileExtension.Length == 0 || fileExtension[0] != '.') { throw new ArgumentException("fileExtension does not start with a period"); } if (format == null) { extToDriver.Remove(fileExtension); } else { Driver driver = OSGeo.GDAL.Gdal.GetDriverByName(format.Code); if (driver == null) { throw new ArgumentException(string.Format("Unknown format code: \"{0}\"", format.Code)); } extToDriver[fileExtension] = driver; } }
/// <summary> /// Initializes a new instance of the <see cref="SpectralTransformationService" /> class. /// </summary> /// <param name="format">The format.</param> /// <param name="operation">The operation.</param> /// <param name="numberOfBands">The number of spectral bands.</param> /// <param name="numberOfRows">The number of rows.</param> /// <param name="numberOfColumns">The number of columns.</param> /// <param name="radiometricResolutions">The radiometric resolutions.</param> public SpectralTransformationService(SpectralTransformation operation, RasterFormat format, RasterDimensions dimensions) { _operation = operation; Dimensions = dimensions; Format = format; }
public TextureNativeSectionData( SectionHeader header, FramedStream stream ) { SectionHeader dataHeader = new SectionHeader( stream ); BinaryReader reader = new BinaryReader( stream ); PlatformID = reader.ReadUInt32(); FilterFlags = (Filter) reader.ReadUInt16(); WrapV = (WrapMode) reader.ReadByte(); WrapU = (WrapMode) reader.ReadByte(); DiffuseName = reader.ReadString( 32 ); AlphaName = reader.ReadString( 32 ); Format = (RasterFormat) reader.ReadUInt32(); if ( PlatformID == 9 ) { String dxt = reader.ReadString( 4 ); switch ( dxt ) { case "DXT1": Compression = CompressionMode.DXT1; break; case "DXT3": Compression = CompressionMode.DXT3; break; default: Compression = CompressionMode.None; break; } } else Alpha = reader.ReadUInt32() == 0x1; Width = reader.ReadUInt16(); Height = reader.ReadUInt16(); BPP = (byte) ( reader.ReadByte() >> 3 ); MipMapCount = reader.ReadByte(); RasterType = reader.ReadByte(); if ( RasterType != 0x4 ) throw new Exception( "Unexpected RasterType, expected 0x04." ); if ( PlatformID == 9 ) Alpha = ( reader.ReadByte() & 0x1 ) == 0x1; else Compression = (CompressionMode) reader.ReadByte(); ImageDataSize = reader.ReadUInt32(); if ( ( Format & RasterFormat.ExtMipMap ) != 0 ) { ImageLevelData = new byte[ MipMapCount ][]; for ( int i = 0; i < MipMapCount; ++i ) ImageLevelData[ i ] = reader.ReadBytes( (int) ImageDataSize >> ( 2 * i ) ); } else { ImageLevelData = new byte[ 1 ][]; ImageLevelData[ 0 ] = reader.ReadBytes( (int) ImageDataSize ); } }
/// <summary> /// Creates a raster image. /// </summary> /// <param name="format">The format of the raster.</param> /// <param name="numberOfBands">The number of bands.</param> /// <param name="numberOfRows">The number of rows.</param> /// <param name="numberOfColumns">The number of columns.</param> /// <param name="radiometricResolutions">The list of radiometric resolutions.</param> /// <param name="mapper">The mapper.</param> /// <returns>The produced raster image.</returns> /// <exception cref="System.ArgumentOutOfRangeException"> /// The number of bands is less than 1. /// or /// The number of rows is less than 0. /// or /// The number of columns is less than 0. /// or /// The radiometric resolution is less than 1. /// or /// The radiometric resolution is greater than 64. /// </exception> public IRaster CreateRaster(RasterFormat format, Int32 numberOfBands, Int32 numberOfRows, Int32 numberOfColumns, Int32 radiometricResolution, RasterMapper mapper) { if (numberOfBands < 1) { throw new ArgumentOutOfRangeException(nameof(numberOfBands), "The number of bands is less than 1."); } if (numberOfRows < 0) { throw new ArgumentOutOfRangeException(nameof(numberOfRows), "The number of rows is less than 0."); } if (numberOfColumns < 0) { throw new ArgumentOutOfRangeException(nameof(numberOfColumns), "The number of columns is less than 0."); } if (radiometricResolution < 1) { throw new ArgumentOutOfRangeException(nameof(radiometricResolution), "The radiometric resolution is less than 1."); } if (radiometricResolution > 64) { throw new ArgumentOutOfRangeException(nameof(radiometricResolution), "The radiometric resolution is greater than 64."); } switch (format) { case RasterFormat.Any: case RasterFormat.Integer: if (radiometricResolution <= 8) { return(new Raster8(this, numberOfBands, numberOfRows, numberOfColumns, radiometricResolution, mapper)); } if (radiometricResolution <= 16) { return(new Raster16(this, numberOfBands, numberOfRows, numberOfColumns, radiometricResolution, mapper)); } if (radiometricResolution <= 32) { return(new Raster32(this, numberOfBands, numberOfRows, numberOfColumns, radiometricResolution, mapper)); } return(new RasterFloat64(this, numberOfBands, numberOfRows, numberOfColumns, radiometricResolution, mapper)); case RasterFormat.Floating: if (radiometricResolution <= 32) { return(new RasterFloat32(this, numberOfBands, numberOfRows, numberOfColumns, radiometricResolution, mapper)); } return(new RasterFloat64(this, numberOfBands, numberOfRows, numberOfColumns, radiometricResolution, mapper)); } return(null); }
//--------------------------------------------------------------------- // Bind a file extension to a raster format if the format is supported // by the raster factory. private void BindExtensionToFormat(string fileExtension, string formatCode) { RasterFormat rasterFormat = rasterFactory.GetFormat(formatCode); if (rasterFormat != null) { rasterFactory.BindExtensionToFormat(fileExtension, rasterFormat); } }
/// <summary> /// Initializes a new instance of the <see cref="SpectralOperationMethod" /> class. /// </summary> /// <param name="identifier">The identifier.</param> /// <param name="name">The name.</param> /// <param name="remarks">The remarks.</param> /// <param name="aliases">The aliases.</param> /// <param name="version">The version.</param> /// <param name="isReversible">Indicates whether the method is reversible.</param> /// <param name="spectralDomain">The spectral domain of the operation.</param> /// <param name="sourceType">The source type of the method.</param> /// <param name="resultType">The result type of the method.</param> /// <param name="supportedModels">The supported geometry models.</param> /// <param name="supportedFormats">The supported raster formats.</param> /// <param name="supportedModes">The supported execution modes of the method.</param> /// <param name="parameters">The parameters of the operation.</param> /// <exception cref="System.ArgumentNullException">The identifier is null.</exception> public SpectralOperationMethod(String identifier, String name, String remarks, String[] aliases, Version version, Boolean isReversible, SpectralOperationDomain spectralDomain, Type sourceType, Type resultType, GeometryModel supportedModels, RasterFormat supportedFormats, ExecutionMode supportedModes, params OperationParameter[] parameters) : base(identifier, name, remarks, aliases, version, isReversible, sourceType, resultType, supportedModels, supportedModes, parameters) { _supportedFormats = ExtractRasterFormats(supportedFormats); _spectralDomain = spectralDomain; }
/// <summary> /// Creates a general <see cref="SpectralOperationMethod" /> instance for spectral transformations. /// </summary> /// <param name="identifier">The identifier.</param> /// <param name="name">The name.</param> /// <param name="remarks">The remarks.</param> /// <param name="aliases">The aliases.</param> /// <param name="version">The version.</param> /// <param name="isReversible">Indicates whether the method is reversible.</param> /// <param name="spectralDomain">The spectral domain of the operation.</param> /// <param name="supportedFormats">The supported raster formats of the method.</param> /// <param name="parameters">The parameters of the operation.</param> /// <returns>The <see cref="SpectralOperationMethod" /> instance produced by the method.</returns> /// <exception cref="System.ArgumentNullException">The identifier is null.</exception> public static SpectralOperationMethod CreateSpectralTransformation(String identifier, String name, String remarks, String[] aliases, String version, Boolean isReversible, SpectralOperationDomain spectralDomain, RasterFormat supportedFormats, params OperationParameter[] parameters) { return(new SpectralOperationMethod(identifier, name, remarks, aliases, Version.Parse(version), isReversible, spectralDomain, typeof(ISpectralGeometry), typeof(ISpectralGeometry), GeometryModel.Any, supportedFormats, ExecutionMode.Any, parameters)); }
public override string GetStepParameters() { var parameters = new List <string>(); parameters.Add(RepeatS != null ? RepeatS.ToStepValue() : "$"); parameters.Add(RepeatT != null ? RepeatT.ToStepValue() : "$"); parameters.Add(Mode != null ? Mode.ToStepValue() : "$"); parameters.Add(TextureTransform != null ? TextureTransform.ToStepValue() : "$"); parameters.Add(Parameter != null ? Parameter.ToStepValue() : "$"); parameters.Add(RasterFormat != null ? RasterFormat.ToStepValue() : "$"); parameters.Add(RasterCode != null ? RasterCode.ToStepValue() : "$"); return(string.Join(", ", parameters.ToArray())); }
/// <summary> /// Sets the properties of the result. /// </summary> /// <param name="format">The raster format.</param> /// <param name="numberOfBands">The number of bands.</param> /// <param name="numberOfRows">The number of rows.</param> /// <param name="numberOfColumns">The number of columns.</param> /// <param name="radiometricResolution">The radiometric resolution.</param> /// <param name="mapper">The mapper.</param> /// <param name="presentation">The raster presentation.</param> /// <param name="imaging">The raster imaging.</param> protected void SetResultProperties(RasterFormat format, Int32 numberOfBands, Int32 numberOfRows, Int32 numberOfColumns, Int32 radiometricResolution, RasterMapper mapper, RasterPresentation presentation, RasterImaging imaging) { if (_resultPropertiesSet) { return; } _resultFormat = format; _resultDimensions = new RasterDimensions(numberOfBands, numberOfRows, numberOfColumns, radiometricResolution); _resultMapper = mapper; _resultPresentation = presentation; _resultImaging = imaging; _resultPropertiesSet = true; }
/// <summary> /// Sets the properties of the result. /// </summary> /// <param name="numberOfBands">The number of bands.</param> /// <param name="numberOfRows">The number of rows.</param> /// <param name="numberOfColumns">The number of columns.</param> /// <param name="radiometricResolution">The radiometric resolution.</param> protected void SetResultProperties(Int32 numberOfBands, Int32 numberOfRows, Int32 numberOfColumns, Int32 radiometricResolution) { if (_resultPropertiesSet) { return; } _resultFormat = Source.Raster.Format; _resultDimensions = new RasterDimensions(numberOfBands, numberOfRows, numberOfColumns, radiometricResolution); _resultMapper = Source.Raster.Mapper; _resultPresentation = Source.Presentation; _resultImaging = Source.Imaging; _resultPropertiesSet = true; }
/// <summary> /// Sets the properties of the result. /// </summary> /// <param name="format">The raster format.</param> /// <param name="dimensions">The raster dimensions.</param> /// <param name="mapper">The mapper.</param> /// <param name="presentation">The raster presentation.</param> /// <param name="imaging">The raster imaging.</param> protected void SetResultProperties(RasterFormat format, RasterDimensions dimensions, RasterMapper mapper, RasterPresentation presentation, RasterImaging imaging) { if (_resultPropertiesSet) { return; } _resultFormat = format; _resultDimensions = dimensions ?? Source.Raster.Dimensions; _resultMapper = mapper; _resultPresentation = presentation; _resultImaging = imaging; _resultPropertiesSet = true; }
/// <summary> /// Sets the properties of the result. /// </summary> /// <param name="format">The raster format.</param> /// <param name="dimensions">The raster dimensions.</param> protected void SetResultProperties(RasterFormat format, RasterDimensions dimensions) { if (_resultPropertiesSet) { return; } _resultFormat = format; _resultDimensions = dimensions ?? Source.Raster.Dimensions; _resultMapper = Source.Raster.Mapper; _resultPresentation = Source.Presentation; _resultImaging = Source.Imaging; _resultPropertiesSet = true; }
protected static RenderTexture GetRenderTexture(int width, int height, RasterFormat rasterFormat) { var texture = new RenderTexture(width, height, 0, GetRenderTextureFormat(rasterFormat)) { enableRandomWrite = true, useMipMap = UseMipmaps, autoGenerateMips = false, filterMode = FilterMode.Bilinear, anisoLevel = 16, antiAliasing = 2, wrapMode = TextureWrapMode.Repeat }; texture.Create(); return(texture); }
/// <summary> /// Sets the properties of the result. /// </summary> /// <param name="geometry">The geometry.</param> /// <param name="format">The raster format.</param> /// <param name="numberOfBands">The number of bands.</param> /// <param name="radiometricResolution">The radiometric resolution.</param> /// <param name="presentation">The raster presentation.</param> protected void SetResultProperties(ISpectralGeometry geometry, RasterFormat format, Int32 numberOfBands, Int32 radiometricResolution, RasterPresentation presentation) { if (_resultPropertiesSet) { return; } _resultGeometry = geometry; _resultFormat = format; _resultDimensions = new RasterDimensions(numberOfBands, Source.Raster.NumberOfRows, Source.Raster.NumberOfColumns, radiometricResolution); _resultMapper = Source.Raster.Mapper; _resultPresentation = presentation; _resultImaging = Source.Imaging; _resultPropertiesSet = true; }
protected static TextureFormat GetFormat(RasterFormat format) { var result = TextureFormat.RGBA32; switch (format) { case RasterFormat.Format_555: case RasterFormat.Format_565: result = TextureFormat.RGB565; break; case RasterFormat.Format_1555: case RasterFormat.Format_8888: result = TextureFormat.RGBA32; break; case RasterFormat.Format_4444: result = TextureFormat.RGBA4444; break; case RasterFormat.Format_888: result = TextureFormat.RGB24; break; case RasterFormat.Format_LUM8: result = TextureFormat.Alpha8; break; default: Log.Warning("Could not find a matching format for raster {0}", format); break; } if (!SystemInfo.SupportsTextureFormat(result)) { Log.Warning("Texture format {0} is unsupported on current platform, using {1} instead", result, result = TextureFormat.ARGB32); } return(result); }
protected static RenderTextureFormat GetRenderTextureFormat(RasterFormat format) { var result = RenderTextureFormat.Default; switch (format) { case RasterFormat.Format_555: case RasterFormat.Format_565: //result = RenderTextureFormat.RGB565; //break; case RasterFormat.Format_1555: //result = RenderTextureFormat.ARGB1555; //break; case RasterFormat.Format_4444: //result = RenderTextureFormat.ARGB4444; //break; case RasterFormat.Format_888: case RasterFormat.Format_8888: result = RenderTextureFormat.ARGB32; break; case RasterFormat.Format_LUM8: result = RenderTextureFormat.R8; break; default: Log.Warning("Could not find a matching render format for raster {0}", format); break; } if (!SystemInfo.SupportsRenderTextureFormat(result)) { Log.Warning("Render texture format {0} is unsupported on current platform, using {1} instead", result, result = RenderTextureFormat.Default); } return(result); }
protected static Texture2D GetTexture2D(int width, int height, RasterFormat rasterFormat) { return(new Texture2D(width, height, GetFormat(rasterFormat), UseMipmaps)); }
/// <summary> /// Sets the properties of the result. /// </summary> /// <param name="format">The raster format.</param> /// <param name="numberOfBands">The number of bands.</param> /// <param name="radiometricResolution">The radiometric resolution.</param> /// <param name="presentation">The raster presentation.</param> protected void SetResultProperties(RasterFormat format, Int32 numberOfBands, Int32 radiometricResolution, RasterPresentation presentation) { SetResultProperties(format, numberOfBands, Source.Raster.NumberOfRows, Source.Raster.NumberOfColumns, radiometricResolution, presentation); }
public TextureNative(SectionHeader header, Stream stream) : base(header, stream) { SectionHeader.Read(stream); var reader = new BinaryReader(stream); PlatformID = reader.ReadUInt32(); FilterFlags = (Filter)reader.ReadUInt16(); WrapV = (WrapMode)reader.ReadByte(); WrapU = (WrapMode)reader.ReadByte(); DiffuseName = reader.ReadString(32); AlphaName = reader.ReadString(32); Format = (RasterFormat)reader.ReadUInt32(); if (PlatformID == 9) { var dxt = reader.ReadString(4); switch (dxt) { case "DXT1": Compression = CompressionMode.DXT1; break; case "DXT3": Compression = CompressionMode.DXT3; break; default: Compression = CompressionMode.None; break; } } else { Alpha = reader.ReadUInt32() == 0x1; } Width = reader.ReadUInt16(); Height = reader.ReadUInt16(); BPP = (byte)(reader.ReadByte() >> 3); MipMapCount = reader.ReadByte(); RasterType = reader.ReadByte(); if (RasterType != 0x4) { throw new Exception("Unexpected RasterType, expected 0x04."); } if (PlatformID == 9) { Alpha = (reader.ReadByte() & 0x1) == 0x1; } else { Compression = (CompressionMode)reader.ReadByte(); } ImageDataSize = reader.ReadInt32(); ImageData = reader.ReadBytes(ImageDataSize); if ((Format & RasterFormat.ExtMipMap) != 0) { var tot = ImageDataSize; for (var i = 0; i < MipMapCount; ++i) { tot += ImageDataSize >> (2 * i); } ImageLevelData = reader.ReadBytes(tot); } else { ImageLevelData = ImageData; } }
/// <summary> /// Creates a raster image. /// </summary> /// <param name="format">The format of the raster.</param> /// <param name="numberOfBands">The number of bands.</param> /// <param name="numberOfRows">The number of rows.</param> /// <param name="numberOfColumns">The number of columns.</param> /// <param name="mapper">The mapper.</param> /// <returns>The produced raster image.</returns> /// <exception cref="System.ArgumentOutOfRangeException"> /// The number of bands is less than 1. /// or /// The number of rows is less than 0. /// or /// The number of columns is less than 0. /// </exception> public IRaster CreateRaster(RasterFormat format, Int32 numberOfBands, Int32 numberOfRows, Int32 numberOfColumns, RasterMapper mapper) { return(CreateRaster(format, numberOfBands, numberOfRows, numberOfColumns, format == RasterFormat.Floating ? DefaultFloatRadiometricResolution : DefaultRadiometricResolution, mapper)); }
/// <summary> /// Extracts the raster format values. /// </summary> /// <param name="models">The raster format values.</param> /// <returns>The array of extracted enumeration values.</returns> protected static RasterFormat[] ExtractRasterFormats(RasterFormat values) { Array enumValues = Enum.GetValues(typeof(RasterFormat)); return(Enumerable.Range(0, enumValues.Length).Where(value => (Convert.ToInt32(values) & Calculator.Pow(2, value)) != 0).Select(value => (RasterFormat)Calculator.Pow(2, value)).ToArray()); }
private Texture2D ParseTexture(byte[] data, uint width, uint height, uint bpp, uint textureDataSize, uint paletteDataSize, FilterMode filterMode, AddressingMode addressingMode, RasterFormat rasterFormat) { Texture2D tex = new Texture2D((int)width, (int)height, TextureFormat.RGBA32, false); Color[] pixels = new Color[width * height]; if (!rasterFormat.HasFlag(RasterFormat.FORMAT_EXT_PAL8)) { // No palette if (rasterFormat.HasFlag(RasterFormat.FORMAT_8888)) { // Just RGBA 32bit for (int i = 0; i < data.Length / 4; i++) { pixels[i] = new Color(data[i * 4] / 255f, data[i * 4 + 1] / 255f, data[i * 4 + 2] / 255f, data[i * 4 + 3] / 255f); } } else if (rasterFormat.HasFlag(RasterFormat.FORMAT_1555)) { // Just RGBA 5551 for (int i = 0; i < data.Length / 2; i++) { ushort pixel = Util.ToUInt16(new byte[] { data[i * 2], data[i * 2 + 1] }, 0, Settings.s.IsLittleEndian); uint alpha = extractBits(pixel, 1, 15); uint blue = extractBits(pixel, 5, 10); uint green = extractBits(pixel, 5, 5); uint red = extractBits(pixel, 5, 0); pixels[i] = new Color(red / 31.0f, green / 31.0f, blue / 31.0f, alpha); } } else { MapLoader.Loader.print("(RenderWare) Unknown Texture Format: " + rasterFormat); } } else { // Paletted PAL8 mode (2^8 = 256 palette colors) Color[] palette = new Color[256]; if (rasterFormat.HasFlag(RasterFormat.FORMAT_8888)) { // Palette's colors are RGBA 32bit for (int i = 0; i < 256; i++) { palette[i] = new Color( data[textureDataSize + i * 4 + 0] / 255f, data[textureDataSize + i * 4 + 1] / 255f, data[textureDataSize + i * 4 + 2] / 255f, data[textureDataSize + i * 4 + 3] / 128f); } for (int i = 0; i < textureDataSize; i++) { uint paletteIndex = data[i]; if (paletteIndex >= 8 && paletteIndex < 256 - 8 && ((paletteIndex - 8) % 32 < 16)) { uint paletteMod = (paletteIndex - 8) % 16; if (paletteMod < 8) { paletteIndex += 8; } else { paletteIndex -= 8; } } pixels[i] = palette[paletteIndex]; } } else { MapLoader.Loader.print("(RenderWare) Unknown Texture Format: " + rasterFormat); } } tex.SetPixels(pixels); switch (filterMode) { case FilterMode.FILTER_LINEAR: case FilterMode.FILTER_LINEAR_MIP_LINEAR: case FilterMode.FILTER_LINEAR_MIP_NEAREST: case FilterMode.FILTER_MIP_LINEAR: tex.filterMode = UnityEngine.FilterMode.Bilinear; break; case FilterMode.FILTER_NONE: case FilterMode.FILTER_NEAREST: case FilterMode.FILTER_MIP_NEAREST: tex.filterMode = UnityEngine.FilterMode.Point; break; } switch (addressingMode) { case AddressingMode.WRAP_NONE: case AddressingMode.WRAP_WRAP: tex.wrapMode = TextureWrapMode.Repeat; break; case AddressingMode.WRAP_MIRROR: tex.wrapMode = TextureWrapMode.Mirror; break; case AddressingMode.WRAP_CLAMP: tex.wrapMode = TextureWrapMode.Clamp; break; } tex.Apply(); return(tex); }
public abstract UnityTexture DecodeTextureWithProcessor(BufferReader reader, int width, int height, RasterFormat rasterFormat);
public override UnityTexture DecodeTextureWithProcessor(BufferReader reader, int width, int height, RasterFormat rasterFormat) { using (new Timing("DXT3 Decoding")) { uint r, g, b; var texture = GetTexture2D(width, height, rasterFormat); var color = new Color32(); var colors = new Color32[width * height]; var c0 = new Color32(); var c1 = new Color32(); var c2 = new Color32(); var c3 = new Color32(); reader.PrewarmBuffer((width / 4) * (height / 4) * 16); for (var y = 0; y < height; y += 4) { for (var x = 0; x < width; x += 4) { var alphaBlock = reader.ReadUInt64(); var code = reader.ReadUInt32(); var indices = reader.ReadUInt32(); b = (code & 0x1F); //0000 0000 0000 0000 0000 0000 0001 1111 g = (code & 0x7E0) >> 5; //0000 0000 0000 0000 0000 0111 1110 0000 r = (code & 0xF800) >> 11; //0000 0000 0000 0000 1111 1000 0000 0000 c0.r = (byte)(r << 3 | r >> 2); c0.g = (byte)(g << 2 | g >> 3); c0.b = (byte)(b << 3 | r >> 2); b = (code & 0x1F0000) >> 16; //0000 0000 0001 1111 0000 0000 0000 0000 g = (code & 0x7E00000) >> 21; //0000 0111 1110 0000 0000 0000 0000 0000 r = (code & 0xF8000000) >> 27; //1111 1000 0000 0000 0000 0000 0000 0000 c1.r = (byte)(r << 3 | r >> 2); c1.g = (byte)(g << 2 | g >> 3); c1.b = (byte)(b << 3 | r >> 2); c2 = SumColor(MultiplyColor(c0, 0.66666666f), MultiplyColor(c1, 0.33333333f)); c3 = SumColor(MultiplyColor(c0, 0.33333333f), MultiplyColor(c1, 0.66666666f)); for (var yy = 0; yy < 4; yy++) { for (var xx = 0; xx < 4; xx++) { switch (indices % 4) { case 0: color = c0; break; case 1: color = c1; break; case 2: color = c2; break; case 3: color = c3; break; default: throw new Exception("Invalid color index for DXT3"); } color.a = (byte)(alphaBlock % 16 * 255f / 16f); colors[(height - 1 - y - yy) * width + (x + xx)] = color; indices >>= 2; alphaBlock >>= 4; } } } } texture.SetPixels32(colors); texture.Apply(UseMipmaps, !Settings.Instance.compressTextures); return(texture); } }
public UnityTexture DecodeTexture(BufferReader reader, int width, int height, RasterFormat rasterFormat) { if (GPUDecoding) { return(DecodeTextureWithComputeShader(reader, width, height, rasterFormat)); } else { return(DecodeTextureWithProcessor(reader, width, height, rasterFormat)); } }
public override UnityTexture DecodeTextureWithProcessor(BufferReader reader, int width, int height, RasterFormat rasterFormat) { using (new Timing("Color Block Decoding")) { var texture = GetTexture2D(width, height, rasterFormat); var pixelCount = width * height; var colors = new Color32[pixelCount]; var buffer = reader.ReadBytes(pixelCount * 4); for (int x = 0, i = 0; x < width; x++) { for (var y = 0; y < height; y++, i++) { colors[x + width * (height - y - 1)] = new Color32() { b = buffer[i * 4 + 0], g = buffer[i * 4 + 1], r = buffer[i * 4 + 2], a = buffer[i * 4 + 3] } } } ; texture.SetPixels32(colors); texture.Apply(UseMipmaps, !Settings.Instance.compressTextures); return(texture); } }
public abstract UnityTexture DecodeTextureWithComputeShader(BufferReader reader, int width, int height, RasterFormat rasterFormat);
public override UnityTexture DecodeTextureWithProcessor(BufferReader reader, int width, int height, RasterFormat rasterFormat) { using (new Timing("Palette Decoding")) { var texture = GetTexture2D(width, height, rasterFormat); var pixelCount = width * height; var colors = new Color32[pixelCount]; var buffer = reader.ReadBytes(1024 + 4 + pixelCount); // 1024 bytes for palette, 4 bytes for data size for (var x = 0; x < width; x++) { for (var y = 0; y < height; y++) { var palIndex = buffer[1028 + x + width * y] * 4; var colorIndex = x + width * (height - y - 1); // Palette textures are iverted colors[colorIndex] = new Color32() { r = buffer[palIndex + 0], g = buffer[palIndex + 1], b = buffer[palIndex + 2], a = buffer[palIndex + 3] }; } } ; texture.SetPixels32(colors); texture.Apply(UseMipmaps, !Settings.Instance.compressTextures); return(texture); } }
public override UnityTexture DecodeTextureWithComputeShader(BufferReader reader, int width, int height, RasterFormat rasterFormat) { using (new Timing("DXT3 Decoding (Compute Shader)")) using (var buffer = new ComputeBuffer((width / 4) * (height / 4), 16)) { var texture = GetRenderTexture(width, height, rasterFormat); buffer.SetData(reader.ReadBytes((width / 4) * (height / 4) * 16)); shader.SetInt("Width", width); shader.SetInt("Height", height); shader.SetTexture(kernel, "Result", texture); shader.SetBuffer(kernel, "Chunks", buffer); shader.Dispatch(kernel, width / (int)threadsX / 4, height / (int)threadsY / 4, (int)threadsZ); if (UseMipmaps) { texture.GenerateMips(); } return(texture); } }
public override UnityTexture DecodeTextureWithComputeShader(BufferReader reader, int width, int height, RasterFormat rasterFormat) { using (new Timing("Palette Decoding (Compute Shader)")) using (var paletteBuffer = new ComputeBuffer(256, 4)) using (var indicesBuffer = new ComputeBuffer(width * height / 4, 4)) { var texture = GetRenderTexture(width, height, rasterFormat); paletteBuffer.SetData(reader.ReadBytes(1024)); reader.SkipStream(4); //Data size indicesBuffer.SetData(reader.ReadBytes(width * height)); shader.SetInt("Width", width); shader.SetInt("Height", height); shader.SetTexture(kernel, "Result", texture); shader.SetBuffer(kernel, "Palette", paletteBuffer); shader.SetBuffer(kernel, "Indices", indicesBuffer); shader.Dispatch(kernel, width / (int)threadsX, height / (int)threadsY, (int)threadsZ); if (UseMipmaps) { texture.GenerateMips(); } return(texture); } }