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); } }
private long CalculateExtentOffset(ulong baseOffset, ConstructionMethod constructionMethod, ItemLocationExtent extent) { if (extent is null) { ExceptionUtil.ThrowArgumentNullException(nameof(extent)); } ulong offset; try { if (constructionMethod == ConstructionMethod.FileOffset) { checked { offset = baseOffset + extent.Offset; if ((offset + extent.Length) > this.fileLength) { throw new FormatException("The item has an invalid file offset."); } } } else if (constructionMethod == ConstructionMethod.IDatBoxOffset) { ItemDataBox dataBox = this.metaBox.ItemData; if (dataBox is null) { throw new FormatException("The file does not have an item data box."); } checked { if ((extent.Offset + extent.Length) > (ulong)dataBox.Length) { throw new FormatException("The item has an invalid data box offset."); } offset = (ulong)dataBox.Offset + extent.Offset; if ((offset + extent.Length) > this.fileLength) { throw new FormatException("The item has an invalid file offset."); } } } else { throw new FormatException($"ItemLocationEntry construction method { constructionMethod } is not supported."); } } catch (OverflowException ex) { throw new FormatException("Overflow when attempting to calculate the item file offset.", ex); } if (offset > long.MaxValue) { throw new FormatException($"The item file offset exceeds {long.MaxValue:F0} bytes."); } return((long)offset); }