コード例 #1
0
        /// <summary>
        /// Loads a <see cref="FieldImage"/> from a <see cref="LightFieldPackage"/>.
        /// </summary>
        /// <param name="package">The package to load the field image from.</param>
        /// <returns>a new instance of the <see cref="FieldImage"/> class.</returns>
        public static FieldImage From(LightFieldPackage package)
        {
            if (package == null)
            {
                throw new ArgumentNullException("package");
            }

            LightFieldComponent metadataComponent = package.GetMetadata().FirstOrDefault();

            if (metadataComponent == null)
            {
                throw new ArgumentException("The package does not contain any metadata.", "package");
            }

            Json.Master master = new Json.Master();
            try { master.LoadFromJson(metadataComponent.GetDataAsString()); }
            catch (FormatException e) { throw new ArgumentException("The package contains invalid metadata.", e); }
            if (master.Picture == null)
            {
                throw new ArgumentException("The package does not contain required metadata.", "package");
            }

            PictureMetadata pictureMetadata = new PictureMetadata(master.Picture);

            LightFieldComponent frameMetadataComponent = package.GetComponent(pictureMetadata.Frame.MetadataReference).FirstOrDefault();

            if (frameMetadataComponent == null)
            {
                throw new ArgumentException("The package does not contain any frame metadata.", "package");
            }

            Json.FrameMetadata frameMetadata = new Json.FrameMetadata();
            try { frameMetadata.LoadFromJson(frameMetadataComponent.GetDataAsString()); }
            catch (FormatException e) { throw new ArgumentException("The package contains invalid metadata.", e); }


            Json.FrameMetadata  privateMetadata          = new Json.FrameMetadata();
            LightFieldComponent privateMetadataComponent = package.GetComponent(pictureMetadata.Frame.PrivateMetadataReference).FirstOrDefault();

            if (privateMetadataComponent != null)
            {
                try { privateMetadata.LoadFromJson(frameMetadataComponent.GetDataAsString()); }
                catch (FormatException) { }
            }

            LightFieldComponent frameComponent = package.GetComponent(pictureMetadata.Frame.ImageReference).FirstOrDefault();

            if (frameComponent == null)
            {
                throw new ArgumentException("The package does not contain the frame data.", "package");
            }

            return(new FieldImage(frameComponent, frameMetadata, privateMetadata));
        }
コード例 #2
0
        private void LoadFrame(Json.FrameItem frameItem)
        {
            if (frameItem == null || frameItem.Frame == null)
            {
                return;
            }

            Json.FrameReferences frameReferences = frameItem.Frame;

            if (frameReferences.Metadata == null && frameReferences.MetadataRef != null)
            {
                LightFieldComponent frameMetadataComponent = Package.GetComponent(frameReferences.MetadataRef).FirstOrDefault();
                if (frameMetadataComponent != null)
                {
                    try
                    {
                        Json.FrameMetadata frameMetadata = new Json.FrameMetadata();
                        frameMetadata.LoadFromJson(frameMetadataComponent.GetDataAsString());
                        frameReferences.Metadata = frameMetadata;
                    }
                    catch (FormatException e) { OnException(e); }
                }
            }

            if (frameReferences.PrivateMetadata == null && frameReferences.PrivateMetadataRef != null)
            {
                LightFieldComponent privateMetadataComponent = Package.GetComponent(frameReferences.PrivateMetadataRef).FirstOrDefault();
                if (privateMetadataComponent != null)
                {
                    try
                    {
                        Json.FrameMetadata privateMetadata = new Json.FrameMetadata();
                        privateMetadata.LoadFromJson(privateMetadataComponent.GetDataAsString());
                        frameReferences.PrivateMetadata = privateMetadata;
                    }
                    catch (FormatException e) { OnException(e); }
                }
            }

            _frames.Add(frameReferences);
        }