private void ProcessColorImage(Surface fullSurface) { CICPColorData?colorConversionInfo = null; if (this.colorInfoBox is NclxColorInformation nclxColorInformation) { colorConversionInfo = new CICPColorData { colorPrimaries = nclxColorInformation.ColorPrimaries, transferCharacteristics = nclxColorInformation.TransferCharacteristics, matrixCoefficients = nclxColorInformation.MatrixCoefficients, fullRange = nclxColorInformation.FullRange }; } if (this.colorGridInfo != null) { FillColorImageGrid(colorConversionInfo, fullSurface); } else { DecodeInfo decodeInfo = new DecodeInfo { tileColumnIndex = 0, tileRowIndex = 0, expectedWidth = (uint)fullSurface.Width, expectedHeight = (uint)fullSurface.Height }; DecodeColorImage(this.primaryItemId, decodeInfo, colorConversionInfo, fullSurface); SetImageColorData(colorConversionInfo, decodeInfo); } }
private void DecodeAlphaImage(uint itemId, DecodeInfo decodeInfo, Surface fullSurface) { using (AvifItemData alpha = ReadAlphaImage(itemId)) { AvifNative.DecompressAlpha(alpha, decodeInfo, fullSurface); } }
private void DecodeColorImage(uint itemId, DecodeInfo decodeInfo, CICPColorData?colorConversionInfo, Surface fullSurface) { using (AvifItemData color = ReadColorImage(itemId)) { AvifNative.DecompressColor(color, colorConversionInfo, decodeInfo, fullSurface); } }
public static void DecompressAlpha(AvifItemData alphaImage, DecodeInfo decodeInfo, Surface fullSurface) { if (alphaImage is null) { ExceptionUtil.ThrowArgumentNullException(nameof(alphaImage)); } if (decodeInfo is null) { ExceptionUtil.ThrowArgumentNullException(nameof(decodeInfo)); } if (fullSurface is null) { ExceptionUtil.ThrowArgumentNullException(nameof(fullSurface)); } DecoderStatus status = DecoderStatus.Ok; unsafe { alphaImage.UseBufferPointer((ptr, length) => { BitmapData bitmapData = new BitmapData { scan0 = fullSurface.Scan0.Pointer, width = (uint)fullSurface.Width, height = (uint)fullSurface.Height, stride = (uint)fullSurface.Stride }; UIntPtr alphaImageSize = new UIntPtr(length); if (IntPtr.Size == 8) { status = AvifNative_64.DecompressAlphaImage(ptr, alphaImageSize, decodeInfo, ref bitmapData); } else { status = AvifNative_86.DecompressAlphaImage(ptr, alphaImageSize, decodeInfo, ref bitmapData); } }); } if (status != DecoderStatus.Ok) { HandleError(status); } }
private void SetImageColorData(CICPColorData?containerColorData, DecodeInfo decodeInfo) { if (containerColorData.HasValue) { this.ImageColorData = containerColorData; } else { this.ImageColorData = new CICPColorData { colorPrimaries = decodeInfo.firstTileColorData.colorPrimaries, transferCharacteristics = decodeInfo.firstTileColorData.transferCharacteristics, matrixCoefficients = decodeInfo.firstTileColorData.matrixCoefficients, fullRange = decodeInfo.firstTileColorData.fullRange }; } }
private void ProcessAlphaImage(Surface fullSurface) { if (this.alphaGridInfo != null) { FillAlphaImageGrid(fullSurface); } else { DecodeInfo decodeInfo = new DecodeInfo { tileColumnIndex = 0, tileRowIndex = 0, expectedWidth = (uint)fullSurface.Width, expectedHeight = (uint)fullSurface.Height }; DecodeAlphaImage(this.alphaItemId, decodeInfo, fullSurface); } }
internal void ProcessByteStream(byte[] buffer) { DecodeInfo info = decoder.Transform(buffer, output); if (writeableBitmap == null || writeableBitmap.PixelWidth != info.Width || writeableBitmap.PixelHeight != info.Height) { writeableBitmap = CreateDefaultBitmap(info.Width, info.Height); } var area = new Int32Rect(0, 0, info.Width, info.Height); writeableBitmap.Lock(); writeableBitmap.WritePixels(area, output, info.Width * info.BytesPerPixel, 0); writeableBitmap.AddDirtyRect(area); writeableBitmap.Unlock(); if (ImageComplete != null) { ImageComplete(this, new DroneImageCompleteEventArgs(ImageSource)); } }
private void FillColorImageGrid(CICPColorData?colorInfo, Surface fullSurface) { this.colorGridInfo.CheckAvailableTileCount(); DecodeInfo decodeInfo = new DecodeInfo { expectedWidth = 0, expectedHeight = 0 }; IReadOnlyList <uint> childImageIds = this.colorGridInfo.ChildImageIds; bool firstTile = true; // The tiles are encoded from top to bottom then left to right. for (int row = 0; row < this.colorGridInfo.TileRowCount; row++) { decodeInfo.tileRowIndex = (uint)row; int startIndex = row * this.colorGridInfo.TileColumnCount; for (int col = 0; col < this.colorGridInfo.TileColumnCount; col++) { decodeInfo.tileColumnIndex = (uint)col; DecodeColorImage(childImageIds[startIndex + col], decodeInfo, colorInfo, fullSurface); if (firstTile) { firstTile = false; CheckImageGridAndTileBounds(decodeInfo.expectedWidth, decodeInfo.expectedHeight, decodeInfo.chromaSubsampling, this.colorGridInfo); } } } this.ImageGridMetadata = new ImageGridMetadata(this.colorGridInfo, decodeInfo.expectedHeight, decodeInfo.expectedWidth); SetImageColorData(colorInfo, decodeInfo); }
public static void DecompressColor(AvifItemData colorImage, CICPColorData?colorConversionInfo, DecodeInfo decodeInfo, Surface fullSurface) { if (colorImage is null) { ExceptionUtil.ThrowArgumentNullException(nameof(colorImage)); } if (decodeInfo is null) { ExceptionUtil.ThrowArgumentNullException(nameof(decodeInfo)); } if (fullSurface is null) { ExceptionUtil.ThrowArgumentNullException(nameof(fullSurface)); } DecoderStatus status = DecoderStatus.Ok; unsafe { colorImage.UseBufferPointer((ptr, length) => { BitmapData bitmapData = new BitmapData { scan0 = fullSurface.Scan0.Pointer, width = (uint)fullSurface.Width, height = (uint)fullSurface.Height, stride = (uint)fullSurface.Stride }; UIntPtr colorImageSize = new UIntPtr(length); if (colorConversionInfo.HasValue) { CICPColorData colorData = colorConversionInfo.Value; if (IntPtr.Size == 8) { status = AvifNative_64.DecompressColorImage(ptr, colorImageSize, ref colorData, decodeInfo, ref bitmapData); } else { status = AvifNative_86.DecompressColorImage(ptr, colorImageSize, ref colorData, decodeInfo, ref bitmapData); } } else { if (IntPtr.Size == 8) { status = AvifNative_64.DecompressColorImage(ptr, colorImageSize, IntPtr.Zero, decodeInfo, ref bitmapData); } else { status = AvifNative_86.DecompressColorImage(ptr, colorImageSize, IntPtr.Zero, decodeInfo, ref bitmapData); } } }); } if (status != DecoderStatus.Ok) { HandleError(status); } }