/// <inheritdoc cref="Load"/> public IEnumerable <Color> Load(byte[] tex, EncodingLoadContext loadContext) { // Initialize PVR Texture var pvrTexture = PvrTexture.Create(tex, (uint)loadContext.Size.Width, (uint)loadContext.Size.Height, 1, (PixelFormat)_format, ChannelType.UnsignedByte, ColorSpace.Linear); // Transcode texture to RGBA8888 var successful = pvrTexture.Transcode(PixelFormat.RGBA8888, ChannelType.UnsignedByteNorm, ColorSpace.Linear, CompressionQuality.PVRTCHigh); if (!successful) { throw new InvalidOperationException("Transcoding with PVRTexLib was not successful."); } // Yield colors // Get colors in unswizzled order, so the framework applies the swizzle correctly var paddedWidth = GetPaddedWidth(loadContext.Size.Width); var swizzle = GetSwizzle(loadContext.Size.Width); var textureData = pvrTexture.GetData(); for (var y = 0; y < loadContext.Size.Height; y++) { for (var x = 0; x < loadContext.Size.Width; x++) { var sourcePoint = swizzle.Get(y * paddedWidth + x); var textureIndex = (sourcePoint.Y * paddedWidth + sourcePoint.X) * 4; yield return(Color.FromArgb(textureData[textureIndex + 3], textureData[textureIndex], textureData[textureIndex + 1], textureData[textureIndex + 2])); } } }
/// <inheritdoc cref="Load"/> public IEnumerable <Color> Load(byte[] input, EncodingLoadContext loadContext) { var blockSize = BitsPerValue / 8; var compressionFormat = GetCompressionFormat(); var decoder = GetDecoder(); return(Enumerable.Range(0, input.Length / blockSize).AsParallel() .AsOrdered() .WithDegreeOfParallelism(loadContext.TaskCount) .SelectMany(x => { var span = input.AsSpan(x * blockSize, blockSize); // Filter out null blocks with error color for BC7 and BC6H if (_format == BcFormat.Bc7 || _format == BcFormat.Bc6H) { if (input.Skip(x * blockSize).Take(blockSize).All(b => b == 0)) { return Enumerable.Repeat(Color.Magenta, blockSize); } } var decodedBlock = decoder.DecodeBlock(span, compressionFormat); decodedBlock.TryGetMemory(out var memory); return memory.ToArray().Select(y => Color.FromArgb(y.a, y.r, y.g, y.b)); })); }
/// <inheritdoc cref="Load"/> public IEnumerable <Color> Load(byte[] input, IList <Color> palette, EncodingLoadContext loadContext) { var br = new BinaryReaderX(new MemoryStream(input), _byteOrder, _bitOrder, 1); return(ReadValues(br).AsParallel().AsOrdered() .WithDegreeOfParallelism(loadContext.TaskCount) .Select(c => _descriptor.GetColor(c, palette))); }
/// <inheritdoc cref="Load"/> public IEnumerable <Color> Load(byte[] input, EncodingLoadContext loadContext) { var br = new BinaryReaderX(new MemoryStream(input), _byteOrder); return(ReadBlocks(br).AsParallel().AsOrdered() .WithDegreeOfParallelism(loadContext.TaskCount) .SelectMany(DecodeNextBlock)); }
/// <inheritdoc cref="Load"/> public IEnumerable <Color> Load(byte[] input, EncodingLoadContext loadContext) { var bits = loadContext.Size.Width * loadContext.Size.Height * BitsPerValue; var length = bits / 8 + (bits % 8 > 0 ? 1 : 0); return(_readValuesDelegate(input, length).AsParallel().AsOrdered() .WithDegreeOfParallelism(loadContext.TaskCount) .Select(v => _descriptor.GetColor(v))); }
public IEnumerable <Color> Load(byte[] input, EncodingLoadContext loadContext) { for (var i = 0; i < input.Length; i += 64) { for (var j = 0; j < 32; j += 2) { yield return(Color.FromArgb(input[i + j], input[i + j + 1], input[i + 32 + j], input[i + 32 + j + 1])); } } }
public IEnumerable <Color> Load(byte[] input, EncodingLoadContext loadContext) { for (var i = 0; i < input.Length; i += 2) { var value = ReadValue(input, i); if ((value & 0x80000000) == 0) { yield return(_desc1.GetColor(value)); } else { yield return(_desc2.GetColor(value)); } } }
/// <inheritdoc cref="Load"/> public IEnumerable <Color> Load(byte[] input, EncodingLoadContext loadContext) { var compressionFormat = GetCompressionFormat(); var decoder = GetDecoder(); var blockSize = BitsPerValue / 8; return(Enumerable.Range(0, input.Length / blockSize).AsParallel() .AsOrdered() .WithDegreeOfParallelism(loadContext.TaskCount) .SelectMany(x => { var decodedBlock = decoder.DecodeBlock(input.AsSpan(x * blockSize, blockSize), compressionFormat); decodedBlock.TryGetMemory(out var memory); return memory.ToArray().Select(y => Color.FromArgb(y.a, y.r, y.g, y.b)); })); }
/// <inheritdoc cref="Load"/> public IEnumerable <Color> Load(byte[] tex, EncodingLoadContext loadContext) { // Initialize PVR Texture var pvrTexture = PvrTexture.Create(tex, (uint)loadContext.Size.Width, (uint)loadContext.Size.Height, 1, (PixelFormat)_format, ChannelType.UnsignedByte, ColorSpace.Linear); // Transcode texture to RGBA8888 var successful = pvrTexture.Transcode(PixelFormat.RGBA8888, ChannelType.UnsignedByteNorm, ColorSpace.Linear, CompressionQuality.PVRTCHigh); if (!successful) { throw new InvalidOperationException("Transcoding with PVRTexLib was not successful."); } // Yield colors var textureData = pvrTexture.GetData(); for (var i = 0L; i < textureData.Length; i += 4) { yield return(Color.FromArgb(textureData[i + 3], textureData[i], textureData[i + 1], textureData[i + 2])); } }
/// <inheritdoc cref="Load"/> public IEnumerable <Color> Load(byte[] input, EncodingLoadContext loadContext) { throw new System.NotImplementedException(); }