Beispiel #1
0
        private static int loadImage(string filename, bool loadAlpha)
        {
            bool exists = File.Exists(filename);
            bool flip   = false;

            if (!exists)
            {
                new Problem(ProblemTypes.WARNING, "Failed to load texture \"" + filename + "\".");
                return(0);
            }

            int img = IL.GenImage();

            IL.BindImage(img);
            IL.LoadImage(filename);

            if (flip)
            {
                ILU.FlipImage();
            }

            IL.ConvertImage(ChannelFormat.RGBA, ChannelType.UnsignedByte);

            int imageWidth  = IL.GetInteger(IntName.ImageWidth);
            int imageHeight = IL.GetInteger(IntName.ImageHeight);

            int texID = RawLoadImage(imageWidth, imageHeight, (PixelFormat)IL.GetInteger(IntName.ImageFormat), PixelType.UnsignedByte, IL.GetData(), loadAlpha);

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

            return(texID);
        }
Beispiel #2
0
        public void ResizeToNearestPowerOfTwo(SamplingFilter filter, bool regenerateMipMaps)
        {
            int width  = Width;
            int height = Height;
            int depth  = Depth;

            width  = MemoryHelper.RoundToNearestPowerOfTwo(width);
            height = MemoryHelper.RoundToNearestPowerOfTwo(height);
            depth  = MemoryHelper.RoundToNearestPowerOfTwo(depth);

            Bind();

            SamplingFilter oldFilter = ILU.GetSamplingFilter();

            ILU.SetSamplingFilter(filter);
            ILU.Scale(width, height, depth);

            if (regenerateMipMaps)
            {
                Bind();
                ILU.BuildMipMaps();
            }

            ILU.SetSamplingFilter(oldFilter);
        }
Beispiel #3
0
 public void Apply()
 {
     if (!ILU.IsInitialized)
     {
         return;
     }
     ILU.SetLanguage(this.m_language);
 }
Beispiel #4
0
 public bool Mirror(Image image)
 {
     if (image == null || !image.IsValid)
     {
         return(false);
     }
     IL.BindImage(image.ImageID);
     return(ILU.Mirror());
 }
Beispiel #5
0
 public bool FlipImage(Image image)
 {
     if (image == null || !image.IsValid)
     {
         return(false);
     }
     IL.BindImage(image.ImageID);
     return(ILU.FlipImage());
 }
Beispiel #6
0
 public bool Noisify(Image image, float tolerance)
 {
     if (image == null || !image.IsValid)
     {
         return(false);
     }
     IL.BindImage(image.ImageID);
     return(ILU.Noisify(tolerance));
 }
Beispiel #7
0
 public bool SwapColors(Image image)
 {
     if (image == null || !image.IsValid)
     {
         return(false);
     }
     IL.BindImage(image.ImageID);
     return(ILU.SwapColors());
 }
Beispiel #8
0
 public bool ScaleColors(Image image, float red, float green, float blue)
 {
     if (image == null || !image.IsValid)
     {
         return(false);
     }
     IL.BindImage(image.ImageID);
     return(ILU.ScaleColors(red, green, blue));
 }
Beispiel #9
0
 public bool Scale(Image image, int width, int height, int depth)
 {
     if (image == null || !image.IsValid)
     {
         return(false);
     }
     IL.BindImage(image.ImageID);
     return(ILU.Scale(width, height, depth));
 }
Beispiel #10
0
 public bool EnlargeCanvas(Image image, int width, int height, int depth)
 {
     if (image == null || !image.IsValid)
     {
         return(false);
     }
     IL.BindImage(image.ImageID);
     return(ILU.EnlargeCanvas(width, height, depth));
 }
Beispiel #11
0
 public bool BlurGaussian(Image image, int iterations)
 {
     if (image == null || !image.IsValid)
     {
         return(false);
     }
     IL.BindImage(image.ImageID);
     return(ILU.BlurGaussian(iterations));
 }
Beispiel #12
0
 public bool Alienify(Image image)
 {
     if (image == null || !image.IsValid)
     {
         return(false);
     }
     IL.BindImage(image.ImageID);
     return(ILU.Alienify());
 }
Beispiel #13
0
 public bool Wave(Image image, float angle)
 {
     if (image == null || !image.IsValid)
     {
         return(false);
     }
     IL.BindImage(image.ImageID);
     return(ILU.Wave(angle));
 }
Beispiel #14
0
 public bool Sharpen(Image image, float factor, int iterations)
 {
     if (image == null || !image.IsValid)
     {
         return(false);
     }
     IL.BindImage(image.ImageID);
     return(ILU.Sharpen(factor, iterations));
 }
Beispiel #15
0
 public bool Saturate(Image image, float red, float green, float blue, float saturation)
 {
     if (image == null || !image.IsValid)
     {
         return(false);
     }
     IL.BindImage(image.ImageID);
     return(ILU.Saturate(red, green, blue, saturation));
 }
Beispiel #16
0
 public bool Saturate(Image image, float saturation)
 {
     if (image == null || !image.IsValid)
     {
         return(false);
     }
     IL.BindImage(image.ImageID);
     return(ILU.Saturate(saturation));
 }
Beispiel #17
0
 public bool Pixelize(Image image, int pixelSize)
 {
     if (image == null || !image.IsValid)
     {
         return(false);
     }
     IL.BindImage(image.ImageID);
     return(ILU.Pixelize(pixelSize));
 }
Beispiel #18
0
 public bool Rotate3D(Image image, float x, float y, float z, float angle)
 {
     if (image == null || !image.IsValid)
     {
         return(false);
     }
     IL.BindImage(image.ImageID);
     return(ILU.Rotate3D(x, y, z, angle));
 }
Beispiel #19
0
 public bool Crop(Image image, int offsetX, int offsetY, int offsetZ, int width, int height, int depth)
 {
     if (image == null || !image.IsValid)
     {
         return(false);
     }
     IL.BindImage(image.ImageID);
     return(ILU.Crop(offsetX, offsetY, offsetZ, width, height, depth));
 }
Beispiel #20
0
 public bool BuildMipMaps(Image image)
 {
     if (image == null || !image.IsValid)
     {
         return(false);
     }
     IL.BindImage(image.ImageID);
     return(ILU.BuildMipMaps());
 }
Beispiel #21
0
 public bool EnlargeImage(Image image, int xDim, int yDim, int zDim)
 {
     if (image == null || !image.IsValid)
     {
         return(false);
     }
     IL.BindImage(image.ImageID);
     return(ILU.EnlargeImage(xDim, yDim, zDim));
 }
Beispiel #22
0
 public bool Contrast(Image image, float contrast)
 {
     if (image == null || !image.IsValid)
     {
         return(false);
     }
     IL.BindImage(image.ImageID);
     return(ILU.Contrast(contrast));
 }
Beispiel #23
0
 public bool ScaleAlpha(Image image, float scale)
 {
     if (image == null || !image.IsValid)
     {
         return(false);
     }
     IL.BindImage(image.ImageID);
     return(ILU.ScaleAlpha(scale));
 }
Beispiel #24
0
 public bool Convolution(Image image, int[] matrix, int scale, int bias)
 {
     if (image == null || !image.IsValid)
     {
         return(false);
     }
     IL.BindImage(image.ImageID);
     return(ILU.Convolution(matrix, scale, bias));
 }
Beispiel #25
0
 public bool ReplaceColor(Image image, byte red, byte green, byte blue, float tolerance)
 {
     if (image == null || !image.IsValid)
     {
         return(false);
     }
     IL.BindImage(image.ImageID);
     return(ILU.ReplaceColor(red, green, blue, tolerance));
 }
Beispiel #26
0
 public bool GammaCorrect(Image image, float gamma)
 {
     if (image == null || !image.IsValid)
     {
         return(false);
     }
     IL.BindImage(image.ImageID);
     return(ILU.GammaCorrect(gamma));
 }
Beispiel #27
0
 public bool EdgeDetectP(Image image)
 {
     if (image == null || !image.IsValid)
     {
         return(false);
     }
     IL.BindImage(image.ImageID);
     return(ILU.EdgeDetectP());
 }
Beispiel #28
0
 public bool InvertAlpha(Image image)
 {
     if (image == null || !image.IsValid)
     {
         return(false);
     }
     IL.BindImage(image.ImageID);
     return(ILU.InvertAlpha());
 }
Beispiel #29
0
 public bool Emboss(Image image)
 {
     if (image == null || !image.IsValid)
     {
         return(false);
     }
     IL.BindImage(image.ImageID);
     return(ILU.Emboss());
 }
Beispiel #30
0
        private static PixImage LoadImage(int img)
        {
            var  size     = new V2i(IL.GetInteger(IntName.ImageWidth), IL.GetInteger(IntName.ImageHeight));
            var  dataType = IL.GetDataType();
            var  format   = IL.GetFormat();
            var  channels = IL.GetInteger(IntName.ImageChannels);
            Type type;

            Col.Format fmt;

            // try to get format information
            if (!s_pixDataTypes.TryGetValue(dataType, out type))
            {
                return(null);
            }
            if (!s_pixColorFormats.TryGetValue(format, out fmt))
            {
                return(null);
            }

            // if the image has a lower-left origin flip it
            var mode = (OriginMode)IL.GetInteger((IntName)0x0603);

            if (mode == OriginMode.LowerLeft && !ILU.FlipImage())
            {
                return(null);
            }


            // create an appropriate PixImage instance
            var imageType = typeof(PixImage <>).MakeGenericType(type);
            var pix       = (PixImage)Activator.CreateInstance(imageType, fmt, size, channels);

            // copy the data to the PixImage
            var gc = GCHandle.Alloc(pix.Data, GCHandleType.Pinned);

            try
            {
                var ptr = IL.GetData();
                ptr.CopyTo(pix.Data, 0, pix.Data.Length);
            }
            finally
            {
                gc.Free();
            }

            // unbind and delete the DevIL image
            IL.BindImage(0);
            IL.DeleteImage(img);

            return(pix);
        }