コード例 #1
0
ファイル: IO.cs プロジェクト: Monkeybin11/ImageViewer-1
 public static void SaveImage(DllImageData image, string filename, string extension, GliFormat format, int quality = 0)
 {
     if (!Dll.image_save(image.Resource.Id, filename, extension, (uint)format, quality))
     {
         throw new Exception(Dll.GetError());
     }
 }
コード例 #2
0
ファイル: IO.cs プロジェクト: Monkeybin11/ImageViewer-1
        /// <summary>
        /// tries to load the image file and returns a list with loaded images
        /// (one image file can contain multiple images with multiple faces with multiple mipmaps)
        /// </summary>
        /// <param name="file">filename</param>
        /// <returns></returns>
        public static DllImageData LoadImage(string file)
        {
            var res = new Resource(file);

            Dll.image_info(res.Id, out var gliFormat, out var originalFormat, out var nLayer, out var nMipmaps);

            return(new DllImageData(res, file, new LayerMipmapCount(nLayer, nMipmaps), new ImageFormat((GliFormat)gliFormat), (GliFormat)originalFormat));
        }
コード例 #3
0
ファイル: Resource.cs プロジェクト: Monkeybin11/ImageViewer-1
 public void Dispose()
 {
     if (Id != 0)
     {
         Dll.image_release(Id);
         Id = 0;
     }
 }
コード例 #4
0
ファイル: Resource.cs プロジェクト: Monkeybin11/ImageViewer-1
 public Resource(uint format, Size3 size, LayerMipmapCount lm)
 {
     Id = Dll.image_allocate(format, size.Width, size.Height, size.Depth, lm.Layers, lm.Mipmaps);
     if (Id == 0)
     {
         throw new Exception("error allocating image: " + Dll.GetError());
     }
 }
コード例 #5
0
ファイル: Resource.cs プロジェクト: Monkeybin11/ImageViewer-1
 public Resource(string file)
 {
     Id = Dll.image_open(file);
     if (Id == 0)
     {
         throw new Exception("error in " + file + ": " + Dll.GetError());
     }
 }
コード例 #6
0
ファイル: Mipmap.cs プロジェクト: mate1983/ImageViewer
 public Mipmap(Resource resource, int layerId, int mipmapId)
 {
     Dll.image_info_mipmap(resource.Id, mipmapId, out var width, out var height, out var depth);
     Depth  = depth;
     Width  = width;
     Height = height;
     Bytes  = Dll.image_get_mipmap(resource.Id, layerId, mipmapId, out var size);
     Size   = size;
 }
コード例 #7
0
        public override MipInfo GetMipmap(LayerMipmapSlice lm)
        {
            var res = new MipInfo();

            Dll.image_info_mipmap(Resource.Id, lm.Mipmap, out res.Size.X, out res.Size.Y, out res.Size.Z);
#if DEBUG
            var expected = Size.GetMip(lm.Mipmap);
            Debug.Assert(expected.Width == res.Size.Width);
            Debug.Assert(expected.Height == res.Size.Height);
            Debug.Assert(expected.Depth == res.Size.Depth);
#endif

            res.Bytes = Dll.image_get_mipmap(Resource.Id, lm.Layer, lm.Mipmap, out res.ByteSize);

            return(res);
        }
コード例 #8
0
ファイル: IO.cs プロジェクト: Monkeybin11/ImageViewer-1
        public static List <GliFormat> GetExportFormats(string extension)
        {
            var ptr = Dll.get_export_formats(extension, out var nFormats);

            if (ptr == IntPtr.Zero)
            {
                throw new Exception(Dll.GetError());
            }

            var rawArray = new int[nFormats];

            Marshal.Copy(ptr, rawArray, 0, nFormats);

            var res = new List <GliFormat>(nFormats);

            res.AddRange(rawArray.Select(i => (GliFormat)i));

            return(res);
        }
コード例 #9
0
 private static Size3 GetSize(Resource res)
 {
     Dll.image_info_mipmap(res.Id, 0, out var width, out var height, out var depth);
     return(new Size3(width, height, depth));
 }