コード例 #1
0
ファイル: ImagesModel.cs プロジェクト: mate1983/ImageViewer
        /// <summary>
        /// tests if the image properties match with the current image configuration
        /// </summary>
        private void TestCompability(ITexture image, string name)
        {
            Debug.Assert(NumImages > 0);
            if (image.GetType() != ImageType)
            {
                throw new Exception($"{name}: Incompatible with internal texture types. Expected {ImageType.Name} but got {image.GetType().Name}");
            }

            if (image.NumLayers != NumLayers)
            {
                throw new Exception(
                          $"{name}: Inconsistent amount of layers. Expected {NumLayers} got {image.NumLayers}");
            }

            if (image.Size != Size)
            {
                if (Size.Depth > 1)
                {
                    throw new Exception(
                              $"{name}: Image resolution mismatch. Expected {Size.X}x{Size.Y}x{Size.Z} but got {image.Size.X}x{image.Size.Y}x{image.Size.Z}");
                }

                throw new Exception(
                          $"{name}: Image resolution mismatch. Expected {Size.X}x{Size.Y} but got {image.Size.X}x{image.Size.Y}");
            }


            if (image.NumMipmaps != NumMipmaps)
            {
                throw new ImagesModel.MipmapMismatch(
                          $"{name}: Inconsistent amount of mipmaps. Expected {NumMipmaps} got {image.NumMipmaps}");
            }
        }
コード例 #2
0
        /// <summary>
        /// tries to add the image to the current collection.
        /// </summary>
        /// <exception cref="ImagesModel.MipmapMismatch">will be thrown if everything except the number of mipmaps matches</exception>
        /// <exception cref="Exception">will be thrown if the images does not match with the current set of images</exception>
        public void AddImage(ITexture image, string name, GliFormat originalFormat)
        {
            if (Images.Count == 0) // first image
            {
                InitDimensions(image);
                images.Add(new ImageData(image, name, originalFormat));
                PrevNumImages = 0;
                OnPropertyChanged(nameof(NumImages));
                OnPropertyChanged(nameof(NumLayers));
                OnPropertyChanged(nameof(NumMipmaps));
                OnPropertyChanged(nameof(IsHdr));
                OnPropertyChanged(nameof(Size));
                OnPropertyChanged(nameof(ImageType));
            }
            else // test if compatible with previous images
            {
                if (image.GetType() != ImageType)
                {
                    throw new Exception($"{name}: Incompatible with internal texture types. Expected {ImageType.Name} but got {image.GetType().Name}");
                }

                if (image.NumLayers != NumLayers)
                {
                    throw new Exception(
                              $"{name}: Inconsistent amount of layers. Expected {NumLayers} got {image.NumLayers}");
                }

                if (image.Size != Size)
                {
                    if (Size.Depth > 1)
                    {
                        throw new Exception(
                                  $"{name}: Image resolution mismatch. Expected {Size.X}x{Size.Y}x{Size.Z} but got {image.Size.X}x{image.Size.Y}x{image.Size.Z}");
                    }

                    throw new Exception(
                              $"{name}: Image resolution mismatch. Expected {Size.X}x{Size.Y} but got {image.Size.X}x{image.Size.Y}");
                }


                if (image.NumMipmaps != NumMipmaps)
                {
                    throw new ImagesModel.MipmapMismatch(
                              $"{name}: Inconsistent amount of mipmaps. Expected {NumMipmaps} got {image.NumMipmaps}");
                }

                // remember old properties
                var isHdr = IsHdr;

                images.Add(new ImageData(image, name, originalFormat));
                PrevNumImages = NumImages - 1;
                OnPropertyChanged(nameof(NumImages));

                if (isHdr != IsHdr)
                {
                    OnPropertyChanged(nameof(IsHdr));
                }
            }
        }
コード例 #3
0
ファイル: SpriteSheet.cs プロジェクト: rmckirby/XogoEngine
 private void ValidateArguments(ITexture texture, string dataFilePath, TexturePackerParser parser)
 {
     if (texture == null)
     {
         throw new ArgumentNullException(nameof(texture));
     }
     if (texture.IsDisposed)
     {
         throw new ObjectDisposedException(texture.GetType().FullName);
     }
     if (!File.Exists(dataFilePath))
     {
         throw new FileNotFoundException(nameof(dataFilePath));
     }
 }
コード例 #4
0
 public bool HasSameDimensions(ITexture other)
 {
     if (LayerMipmap != other.LayerMipmap)
     {
         return(false);
     }
     if (Size != other.Size)
     {
         return(false);
     }
     if (GetType() != other.GetType())
     {
         return(false);
     }
     return(true);
 }
コード例 #5
0
ファイル: ImagesModel.cs プロジェクト: mate1983/ImageViewer
 /// returns true if the dimension match with the internal images
 public bool HasMatchingProperties(ITexture tex)
 {
     if (tex.NumLayers != NumLayers)
     {
         return(false);
     }
     if (tex.NumMipmaps != NumMipmaps)
     {
         return(false);
     }
     if (tex.Size != Size)
     {
         return(false);
     }
     if (tex.GetType() != ImageType)
     {
         return(false);
     }
     return(true);
 }