/// <summary> /// Constructs a <see cref="ResourceAccessorTextureImageSource"/> for the given data. /// </summary> /// <param name="resourceAccessor">The resource accessor to load the texture data from.</param> /// <param name="rotation">Desired rotation for the given image.</param> public ResourceAccessorTextureImageSource(IFileSystemResourceAccessor resourceAccessor, RightAngledRotation rotation) { _key = resourceAccessor.CanonicalLocalResourcePath.Serialize(); _resourceAccessor = resourceAccessor; _stream = _resourceAccessor.OpenRead(); _rotation = rotation; }
protected static Matrix TranslateRotation(RightAngledRotation rar) { if (rar == RightAngledRotation.Zero) { return(Matrix.Identity); } float rotation = 0; switch (rar) { case RightAngledRotation.HalfPi: rotation = (float)Math.PI / 2; break; case RightAngledRotation.Pi: rotation = (float)Math.PI; break; case RightAngledRotation.ThreeHalfPi: rotation = (float)Math.PI * 3 / 2; break; } Matrix matrix = Matrix.Translation(-0.5f, -0.5f, 0); matrix *= Matrix.RotationZ(rotation); matrix *= Matrix.Translation(0.5f, 0.5f, 0); return(matrix); }
/// <summary> /// Constructs a <see cref="BinaryTextureImageSource"/> for thumbnails of the given size from MediaItems. /// </summary> public static ImageSource CreateMediaItemThumbnailAspectSource(object source, int width, int height) { MediaItem mediaItem = source as MediaItem; if (mediaItem == null) { return(null); } Guid id = mediaItem.MediaItemId; // Local media items don't have an item id string key = (id == Guid.Empty ? Guid.NewGuid() : id).ToString(); byte[] textureData = null; // Each resolution is cached separately. If we read cache only and our favourite resolution is not yet in cache, // we try to find any other existing. if (mediaItem.Aspects.ContainsKey(ThumbnailLargeAspect.ASPECT_ID)) { textureData = (byte[])mediaItem.Aspects[ThumbnailLargeAspect.ASPECT_ID].GetAttributeValue(ThumbnailLargeAspect.ATTR_THUMBNAIL); } ImageRotation miRotation; bool flipX; bool flipY; ImageAspect.GetOrientationMetadata(mediaItem, out miRotation, out flipX, out flipY); RightAngledRotation rotation = RotationTranslator.TranslateToRightAngledRotation(miRotation); return(new BinaryTextureImageSource(textureData, rotation, key)); }
protected void CycleTextures(TextureAsset nextTexture, RightAngledRotation rotation) { // Current -> Last _lastTexture = _currentTexture; _lastImageContext = _imageContext; // Next -> Current _currentTexture = nextTexture; _imageContext = new ImageContext { FrameSize = _frameSize, ShaderEffect = Effect, Rotation = rotation }; if (_lastTexture != _currentTexture) { StartTransition(); FireChanged(); } }
protected void CycleTextures(RightAngledRotation rotation) { // Current -> Last _lastTexture = _currentTexture; _lastImageContext = _imageContext; // Next -> Current _currentTexture = _nextTexture; _imageContext = new ImageContext { FrameSize = _frameSize, ShaderEffect = Effect, Rotation = rotation, HorizontalTextureAlignment = HorizontalTextureAlignment, VerticalTextureAlignment = VerticalTextureAlignment }; // Clear next _nextTexture = null; if (_lastTexture != _currentTexture) { StartTransition(); FireChanged(); } }
/// <summary> /// Constructs a <see cref="BinaryTextureImageSource"/> for the given data. /// </summary> /// <param name="textureData">Binary data to create the texture for.</param> /// <param name="rotation">Desired rotation for the given image.</param> public BinaryTextureImageSource(byte[] textureData, RightAngledRotation rotation) : this(textureData, rotation, BitConverter.ToString(sha1.ComputeHash(textureData))) { }
/// <summary> /// Constructs a <see cref="BinaryTextureImageSource"/> for the given data. /// </summary> /// <param name="textureData">Binary data to create the texture for.</param> /// <param name="rotation">Desired rotation for the given image.</param> /// <param name="key">Unique key for storing the generated texture in the <see cref="ContentManager"/>.</param> public BinaryTextureImageSource(byte[] textureData, RightAngledRotation rotation, string key) { _key = key; _textureData = textureData; _rotation = rotation; }
protected void CycleTextures(RightAngledRotation rotation) { // Current -> Last _lastTexture = _currentTexture; _lastImageContext = _imageContext; // Next -> Current _currentTexture = _nextTexture; _imageContext = new ImageContext { FrameSize = _frameSize, ShaderEffect = Effect, Rotation = rotation }; // Clear next _nextTexture = null; if (_lastTexture != _currentTexture) { StartTransition(); FireChanged(); } }
/// <summary> /// Constructs a <see cref="BinaryTextureImageSource"/> for the given data. /// </summary> /// <param name="textureData">Binary data to create the texture for.</param> /// <param name="rotation">Desired rotation for the given image.</param> public BinaryTextureImageSource(byte[] textureData, RightAngledRotation rotation) : this(textureData, rotation, BitConverter.ToString(sha1.ComputeHash(textureData))) {}
protected static Matrix TranslateRotation(RightAngledRotation rar) { if (rar == RightAngledRotation.Zero) return Matrix.Identity; float rotation = 0; switch (rar) { case RightAngledRotation.HalfPi: rotation = (float) Math.PI / 2; break; case RightAngledRotation.Pi: rotation = (float) Math.PI; break; case RightAngledRotation.ThreeHalfPi: rotation = (float) Math.PI * 3 / 2; break; } Matrix matrix = Matrix.Translation(-0.5f, -0.5f, 0); matrix *= Matrix.RotationZ(rotation); matrix *= Matrix.Translation(0.5f, 0.5f, 0); return matrix; }