private static int ShrinkSizeForRenderingMethod(int size, RenderingMethod method, int vectorElements, out bool isDivisible) { int divisor = 1; // ReSharper disable once ConvertIfStatementToSwitchStatement if (method == RenderingMethod.RGB) { divisor = 3; } else if (method == RenderingMethod.Vector) { if (vectorElements < 1) { throw new ArgumentException("Vector element count must be greater then zero.", "vectorElements"); } divisor = vectorElements; } int result = size / divisor; isDivisible = (result * divisor == size); return(result); }
private void InitVideoRenderingMethod() { _videoElement?.UnsubscribeEvents(); switch (_optionsService.RenderingMethod) { case RenderingMethod.Ffmpeg: _videoElement = new MediaElementUnoSquare(VideoElementFfmpeg); break; case RenderingMethod.MediaFoundation: _videoElement = new MediaElementMediaFoundation(VideoElementMediaFoundation, _optionsService); break; default: throw new NotImplementedException(); } _currentRenderingMethod = _optionsService.RenderingMethod; if (_videoDisplayManager != null) { UnsubscribeVideoEvents(); _videoDisplayManager.Dispose(); } _videoDisplayManager = new VideoDisplayManager(_videoElement, SubtitleBlock, _optionsService); SubscribeVideoEvents(); }
public CustomDimsTestCase(TensorDimensions dims, CustomDimensionsHint customDims, RenderingMethod method, int vectorElements, Size expectedSize) { Dims = dims; CustomDims = customDims; Method = method; VectorElements = vectorElements; ExpectedSize = expectedSize; }
public CustomDimsTestCase(TensorDimensions dims, CustomDimensionsHint customDims, RenderingMethod method, int vectorElements, Size expectedSize) { Dims = dims; CustomDims = customDims; Method = method; VectorElements = vectorElements; ExpectedSize = expectedSize; }
// TODO(Premek): Report warnings using a logger interface. internal static Size ComputeCustomTextureSize(TensorDimensions dims, CustomDimensionsHint customDims, RenderingMethod method, int vectorElements, out string warning) { warning = ""; if (dims.IsEmpty) { return(Size.Empty); } bool isDivisible; string divisorName = (method == RenderingMethod.RGB) ? "3 (RGB channel count)" : "vector element count"; bool isRowVector = (dims.Rank == 1) || (dims.Rank == 2 && dims[1] == 1); bool isColumnVector = !isRowVector && (dims.Rank == 2) && (dims[0] == 1); TensorDimensions adjustedDims; bool didApplyCustomDims = customDims.TryToApply(dims, out adjustedDims); if (!customDims.IsEmpty && !didApplyCustomDims) { warning = "Could not apply custom dimensions (the element count must match the original)."; } if (!didApplyCustomDims && (isRowVector || isColumnVector)) { return(ComputeTextureSizeForVector(dims.ElementCount, isRowVector, method, vectorElements, divisorName, ref warning)); } int shrinkedLastDim = ShrinkSizeForRenderingMethod(adjustedDims[adjustedDims.Rank - 1], method, vectorElements, out isDivisible); if (!isDivisible || (shrinkedLastDim == 0)) { if (string.IsNullOrEmpty(warning)) { warning = string.Format("The last dimension is {0} {1}. Ignoring dimensions.", (!isDivisible) ? "not divisible by" : "smaller than", divisorName); } return(ComputeTextureSize( ShrinkSizeForRenderingMethod(dims.ElementCount, method, vectorElements, out isDivisible))); } // Squash all dimensions except the first one together. // TODO(Premek): Decide according to actual sizes of the dimensions. int squashedOtherDims = shrinkedLastDim; for (int i = 1; i < adjustedDims.Rank - 1; i++) { squashedOtherDims *= adjustedDims[i]; } return(new Size(adjustedDims[0], squashedOtherDims)); }
private static Size ComputeTextureSizeForVector(int elementCount, bool isRowVector, RenderingMethod method, int vectorElements, string divisorName, ref string warning) { bool isDivisible; int shrinkedSize = ShrinkSizeForRenderingMethod(elementCount, method, vectorElements, out isDivisible); if (!isDivisible && string.IsNullOrEmpty(warning)) { warning = string.Format("Total count is not divisible by {0}.", divisorName); } return(elementCount <= SmallVectorLimit // Don't wrap small vectors. ? new Size(isRowVector ? shrinkedSize : 1, !isRowVector ? shrinkedSize : 1) : ComputeTextureSize(elementCount)); }
private static int ShrinkSizeForRenderingMethod(int size, RenderingMethod method, int vectorElements, out bool isDivisible) { int divisor = 1; // ReSharper disable once ConvertIfStatementToSwitchStatement if (method == RenderingMethod.RGB) { divisor = 3; } else if (method == RenderingMethod.Vector) { if (vectorElements < 1) throw new ArgumentException("Vector element count must be greater then zero.", "vectorElements"); divisor = vectorElements; } int result = size / divisor; isDivisible = (result * divisor == size); return result; }
private static Size ComputeTextureSizeForVector(int elementCount, bool isRowVector, RenderingMethod method, int vectorElements, string divisorName, ref string warning) { bool isDivisible; int shrinkedSize = ShrinkSizeForRenderingMethod(elementCount, method, vectorElements, out isDivisible); if (!isDivisible && string.IsNullOrEmpty(warning)) warning = string.Format("Total count is not divisible by {0}.", divisorName); return elementCount <= SmallVectorLimit // Don't wrap small vectors. ? new Size(isRowVector ? shrinkedSize : 1, !isRowVector ? shrinkedSize : 1) : ComputeTextureSize(elementCount); }
// TODO(Premek): Report warnings using a logger interface. internal static Size ComputeCustomTextureSize(TensorDimensions dims, CustomDimensionsHint customDims, RenderingMethod method, int vectorElements, out string warning) { warning = ""; if (dims.IsEmpty) return Size.Empty; bool isDivisible; string divisorName = (method == RenderingMethod.RGB) ? "3 (RGB channel count)" : "vector element count"; bool isRowVector = (dims.Rank == 1) || (dims.Rank == 2 && dims[1] == 1); bool isColumnVector = !isRowVector && (dims.Rank == 2) && (dims[0] == 1); TensorDimensions adjustedDims; bool didApplyCustomDims = customDims.TryToApply(dims, out adjustedDims); if (!customDims.IsEmpty && !didApplyCustomDims) warning = "Could not apply custom dimensions (the element count must match the original)."; if (!didApplyCustomDims && (isRowVector || isColumnVector)) { return ComputeTextureSizeForVector(dims.ElementCount, isRowVector, method, vectorElements, divisorName, ref warning); } int shrinkedLastDim = ShrinkSizeForRenderingMethod(adjustedDims[adjustedDims.Rank - 1], method, vectorElements, out isDivisible); if (!isDivisible || (shrinkedLastDim == 0)) { if (string.IsNullOrEmpty(warning)) warning = string.Format("The last dimension is {0} {1}. Ignoring dimensions.", (!isDivisible) ? "not divisible by" : "smaller than", divisorName); return ComputeTextureSize( ShrinkSizeForRenderingMethod(dims.ElementCount, method, vectorElements, out isDivisible)); } // Squash all dimensions except the first one together. // TODO(Premek): Decide according to actual sizes of the dimensions. int squashedOtherDims = shrinkedLastDim; for (int i = 1; i < adjustedDims.Rank - 1; i++) squashedOtherDims *= adjustedDims[i]; return new Size(adjustedDims[0], squashedOtherDims); }