Exemple #1
0
        protected static PixImage CreateRawSystem(Stream stream, PixLoadOptions options)
        {
            var decoder = BitmapDecoder.Create(stream,
                                               BitmapCreateOptions.None, BitmapCacheOption.Default);

            return(CreateRaw((BitmapSource)decoder.Frames[0]));
        }
Exemple #2
0
        /// <summary>
        /// Creates a new image from the file. Note that in this raw image the channel
        /// count of the volume and the channel count of the format may be different.
        /// </summary>
        protected static PixImage CreateRawSystem(string filename, PixLoadOptions options = PixLoadOptions.Default)
        {
            var bitmapImage = new BitmapImage();

            bitmapImage.BeginInit();
            bitmapImage.UriSource     = new Uri(filename, UriKind.RelativeOrAbsolute);
            bitmapImage.CacheOption   = BitmapCacheOption.OnLoad;
            bitmapImage.CreateOptions = BitmapCreateOptions.None
                                        | BitmapCreateOptions.PreservePixelFormat;
            bitmapImage.EndInit();
            return(CreateRaw((BitmapSource)bitmapImage));
        }
        private static PixImage CreateRawFreeImage(
            Stream stream,
            PixLoadOptions loadFlags = PixLoadOptions.Default)
        {
            var dib = FreeImage.LoadFromStream(stream);
            var pi  = CreateFromFiBitMap(dib);

            if (pi == null)
            {
                return(null);
            }
            FreeImage.Unload(dib);
            return(pi);
        }
Exemple #4
0
        /// <summary>
        /// Load image from stream via devil.
        /// </summary>
        /// <returns>If file could not be read, returns null, otherwise a Piximage.</returns>
        private static PixImage CreateRawDevil(
            string fileName,
            PixLoadOptions loadFlags = PixLoadOptions.Default)
        {
            lock (s_devilLock)
            {
                var img = IL.GenImage();

                IL.BindImage(img);
                if (!IL.LoadImage(fileName))
                {
                    throw new ImageLoadException(string.Format("Could not load image: {0}", fileName));
                }

                return(LoadImage(img));
            }
        }
Exemple #5
0
        /// <summary>
        /// Load image from stream via devil.
        /// </summary>
        /// <returns>If file could not be read, returns null, otherwise a Piximage.</returns>
        private static PixImage CreateRawDevil(
            Stream stream,
            PixLoadOptions loadFlags = PixLoadOptions.Default)
        {
            lock (s_devilLock)
            {
                var img = IL.GenImage();

                IL.BindImage(img);
                if (!IL.LoadStream(stream))
                {
                    throw new ImageLoadException("stream");
                }

                return(LoadImage(img));
            }
        }
Exemple #6
0
        /// <summary>
        /// Gets info about a PixImage without loading the entire image into memory.
        /// </summary>
        /// <returns>null if the file info could not be loaded.</returns>
        public static PixImageInfo InfoFromFileNameDevil(
            string fileName, PixLoadOptions options)
        {
            lock (s_devilLock)
            {
                try
                {
                    var img = IL.GenImage();
                    IL.BindImage(img);

                    if (!IL.LoadImage(fileName))
                    {
                        throw new ArgumentException("fileName");
                    }

                    var dataType = IL.GetDataType();
                    var format   = IL.GetFormat();
                    var width    = IL.GetInteger(IntName.ImageWidth);
                    var height   = IL.GetInteger(IntName.ImageHeight);
                    //var channels = IL.GetInteger(IntName.ImageChannels);

                    IL.BindImage(0);
                    IL.DeleteImage(img);


                    Type       type;
                    Col.Format fmt;

                    if (!s_pixDataTypes.TryGetValue(dataType, out type))
                    {
                        return(null);
                    }
                    if (!s_pixColorFormats.TryGetValue(format, out fmt))
                    {
                        return(null);
                    }

                    var size = new V2i(width, height);
                    return(new PixImageInfo(new PixFormat(type, fmt), size));
                }
                catch (Exception)
                {
                    return(null);
                }
            }
        }
 /// <summary>
 /// Load image from stream via System.Drawing.
 /// </summary>
 /// <returns>If file could not be read, returns null, otherwise a Piximage.</returns>
 private static PixImage CreateRawBitmap(
     Stream stream,
     PixLoadOptions loadFlags = PixLoadOptions.Default)
 {
     try
     {
         using (var bmp = (Bitmap)Bitmap.FromStream(stream))
         {
             var result = CreateRawBitmap(bmp);
             return(result);
         }
     }
     catch (Exception)
     {
         return(null);
     }
 }
Exemple #8
0
 /// <summary>
 /// Gets info about a PixImage without loading the entire image into
 /// memory.
 /// </summary>
 protected static PixImageInfo InfoFromFileNameSystem(
     string fileName, PixLoadOptions options)
 {
     try
     {
         var src0 = new BitmapImage();
         src0.BeginInit();
         src0.UriSource     = new Uri(fileName, UriKind.RelativeOrAbsolute);
         src0.CacheOption   = BitmapCacheOption.None;
         src0.CreateOptions = BitmapCreateOptions.DelayCreation;
         src0.EndInit();
         var pixFormat = s_pixFormatAndCountOfPixelFormat[src0.Format].E0;
         return(new PixImageInfo(pixFormat, new V2i(src0.PixelWidth, src0.PixelHeight)));
     }
     catch
     {
         return(null);
     }
 }
Exemple #9
0
 public static PixImageMipMap Create(string filename, PixLoadOptions options)
 {
     return(new PixImageMipMap(PixImage.Create(filename, options)));
 }
 private static PixImageInfo InfoFromFileNameFreeImage(
     string fileName, PixLoadOptions options)
 {
     // TODO: return something if its possible
     return(null);
 }
Exemple #11
0
 /// <summary>
 /// Gets info about a PixImage without loading the entire image into memory.
 /// </summary>
 /// <returns>null if the file info could not be loaded.</returns>
 public static PixImageInfo InfoFromFileNameBitmap(
     string fileName, PixLoadOptions options)
 {
     // TODO: implement
     return(null);
 }