Example #1
0
 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());
     }
 }
Example #2
0
        /// <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));
        }
Example #3
0
 public void Dispose()
 {
     if (Id != 0)
     {
         Dll.image_release(Id);
         Id = 0;
     }
 }
Example #4
0
 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());
     }
 }
Example #5
0
 public Resource(string file)
 {
     Id = Dll.image_open(file);
     if (Id == 0)
     {
         throw new Exception("error in " + file + ": " + Dll.GetError());
     }
 }
Example #6
0
 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;
 }
Example #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);
        }
Example #8
0
        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);
        }
Example #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));
 }