/// <summary> /// Decode a shared encoded image to a shared image. /// </summary> /// <param name="sharedEncodedImage">The shared encoded image to decode.</param> /// <returns>The decoded shared image.</returns> internal static Shared <Image> Decode(this Shared <EncodedImage> sharedEncodedImage) { Shared <Image> sharedImage = null; if (sharedEncodedImage.Resource != null) { // The code below maintains back-compatibility with encoded images which did not store the pixel format // on the instance, but only in the stream. If the pixel format is unknown, we call upon the decoder to // retrieve the pixel format. This might be less performant, but enables decoding in the right format // even from older versions of encoded images. var decoder = new ImageFromStreamDecoder(); var pixelFormat = sharedEncodedImage.Resource.PixelFormat == PixelFormat.Undefined ? decoder.GetPixelFormat(sharedEncodedImage.Resource.ToStream()) : sharedEncodedImage.Resource.PixelFormat; // If the decoder does not return a valid pixel format, we throw an exception. if (pixelFormat == PixelFormat.Undefined) { throw new ArgumentException("The encoded image does not contain a supported pixel format."); } sharedImage = ImagePool.GetOrCreate(sharedEncodedImage.Resource.Width, sharedEncodedImage.Resource.Height, pixelFormat); decoder.DecodeFromStream(sharedEncodedImage.Resource.ToStream(), sharedImage.Resource); } return(sharedImage); }
/// <summary> /// Convert encoded image to image. /// </summary> public Shared <Image> EncodedImageToImage(Shared <EncodedImage> encodedImage, Envelope envelope) { var decoder = new ImageFromStreamDecoder();//this is a platform specific decoder var image = encodedImage.Resource.Decode(decoder); var sharedImage = ImagePool.GetOrCreate(encodedImage.Resource.Width, encodedImage.Resource.Height, image.PixelFormat); sharedImage.Resource.CopyFrom(image.ImageData); return(sharedImage); }
/// <summary> /// Exports data based on the specified export command. /// </summary> /// <param name="exportCommand">The export command.</param> /// <returns>An error code or 0 if success.</returns> public static int Run(Verbs.ExportCommand exportCommand) { const string videoStreamName = "VideoImageCameraView"; const string videoEncodedStreamName = "VideoEncodedImageCameraView"; const string audioStreamName = "Audio"; var pngEncoder = new ImageToPngStreamEncoder(); var decoder = new ImageFromStreamDecoder(); // Create a pipeline using var p = Pipeline.Create(deliveryPolicy: DeliveryPolicy.Unlimited); // Open the psi store for reading var store = PsiStore.Open(p, exportCommand.StoreName, exportCommand.StorePath); // Get references to the various streams. If a stream is not present in the store, // the reference will be null. var accelerometer = store.OpenStreamOrDefault <(Vector3D, DateTime)[]>("Accelerometer");