Ejemplo n.º 1
0
 public FreeImageAPI.FIBITMAP GetBitmap(ImageType type, ImageColorType colorType)
 {
     FreeImageAPI.FIBITMAP result = new FreeImageAPI.FIBITMAP();
     string filename = GetBitmapPath(type, colorType);
     if (!String.IsNullOrEmpty(filename) && File.Exists(filename))
         result = FreeImageAPI.FreeImage.LoadEx(filename);
     return result;
 }
Ejemplo n.º 2
0
        public FreeImageAPI.FIBITMAP GetBitmap(ImageType type, ImageColorType colorType)
        {
            FreeImageAPI.FIBITMAP result = new FreeImageAPI.FIBITMAP();
            string filename = GetBitmapPath(type, colorType);

            if (!String.IsNullOrEmpty(filename) && File.Exists(filename))
            {
                result = FreeImageAPI.FreeImage.LoadEx(filename);
            }
            return(result);
        }
Ejemplo n.º 3
0
        public MgImageSource DetermineSource(Stream fs)
        {
            FreeImageAPI.FIBITMAP dib = FreeImageAPI.FIBITMAP.Zero;
            try
            {
                var format = FreeImageAPI.FREE_IMAGE_FORMAT.FIF_UNKNOWN;
                dib = FreeImageAPI.FreeImage.LoadFromStream(fs, ref format);

                if (dib.IsNull)
                {
                    throw new InvalidOperationException("Image data invalid");
                }

                var imageType = FreeImageAPI.FreeImage.GetImageType(dib);
                var colorType = FreeImageAPI.FreeImage.GetColorType(dib);
                var redMask   = FreeImageAPI.FreeImage.GetRedMask(dib);
                var greenMask = FreeImageAPI.FreeImage.GetGreenMask(dib);
                var blueMask  = FreeImageAPI.FreeImage.GetRedMask(dib);
                var bpp       = FreeImageAPI.FreeImage.GetBPP(dib);
                var width     = FreeImageAPI.FreeImage.GetWidth(dib);
                var height    = FreeImageAPI.FreeImage.GetHeight(dib);
                var imageSize = FreeImageAPI.FreeImage.GetDIBSize(dib);

                var uncompressedSize = bpp * width * height;

                var zeroMipmap = new MgImageMipmap
                {
                    Offset = 0,
                    Width  = width,
                    Height = height,
                    Size   = uncompressedSize,
                };

                var imgSource = new MgImageSource
                {
                    Format  = DetermineFormat(imageType, colorType, bpp, redMask, greenMask, blueMask),
                    Width   = width,
                    Height  = height,
                    Mipmaps = new[] { zeroMipmap },
                    Size    = uncompressedSize,
                };
                return(imgSource);
            }
            finally
            {
                if (!dib.IsNull)
                {
                    FreeImageAPI.FreeImage.UnloadEx(ref dib);
                }
            }
        }
Ejemplo n.º 4
0
        public static Bitmap LoadDDJ(byte[] buffer)
        {
            if (buffer == null)
            {
                return(new Bitmap(256, 256, PixelFormat.Format16bppRgb555));
            }
            Bitmap bitmap;

            using (Stream stream = new MemoryStream(buffer, 20, buffer.GetUpperBound(0) - 0x13))
            {
                FreeImageAPI.FREE_IMAGE_FORMAT format = FreeImageAPI.FREE_IMAGE_FORMAT.FIF_DDS;
                FreeImageAPI.FIBITMAP          dib    = FreeImageAPI.FreeImage.LoadFromStream(stream, FreeImageAPI.FREE_IMAGE_LOAD_FLAGS.DEFAULT, ref format);
                bitmap = FreeImageAPI.FreeImage.GetBitmap(dib);
                FreeImageAPI.FreeImage.UnloadEx(ref dib);
            }
            return(bitmap);
        }
Ejemplo n.º 5
0
        public ITexture2D GetIBLTexture(string path)
        {
            FreeImageAPI.FREE_IMAGE_FORMAT type   = FreeImageAPI.FreeImage.GetFileType(path, 0);
            FreeImageAPI.FIBITMAP          bitmap = FreeImageAPI.FreeImage.Load(type, path, FreeImageAPI.FREE_IMAGE_LOAD_FLAGS.DEFAULT);
            //FreeImageAPI.FIBITMAP convert = FreeImageAPI.FreeImage.ToneMapping(bitmap, FreeImageAPI.FREE_IMAGE_TMO.FITMO_DRAGO03, 0, 0);
            FreeImageAPI.FIBITMAP convert = FreeImageAPI.FreeImage.ToneMapping(bitmap, FreeImageAPI.FREE_IMAGE_TMO.FITMO_REINHARD05, 0, 0);

            if (bitmap.IsNull)
            {
                return(null);
            }
            uint width     = FreeImageAPI.FreeImage.GetWidth(convert);
            uint height    = FreeImageAPI.FreeImage.GetHeight(convert);
            int  channelNo = 3;

            byte[] imgData = new byte[width * height * channelNo];
            for (int i = 0; i < height; i++)
            {
                for (int j = 0; j < width; j++)
                {
                    int idx = i * (int)width + j;
                    FreeImageAPI.RGBQUAD color = new FreeImageAPI.RGBQUAD();
                    int byteIdx = idx * channelNo;
                    byteIdx -= 1;
                    bool  pSuccess = FreeImageAPI.FreeImage.GetPixelColor(convert, (uint)j, (uint)i, out color);
                    Color nColor   = color.Color;

                    imgData[byteIdx + 1] = color.rgbRed;
                    imgData[byteIdx + 2] = color.rgbGreen;
                    imgData[byteIdx + 3] = color.rgbBlue;

                    if (!pSuccess)
                    {
                        return(null);
                    }
                }
            }
            Texture2dGL text = Texture2dGL.Create((int)width, (int)height);
            IntPtr      ptr  = Marshal.UnsafeAddrOfPinnedArrayElement(imgData, 0);

            text.LoadPixels(ptr, (int)width, (int)height, OpenTK.Graphics.OpenGL4.PixelInternalFormat.Rgb8, OpenTK.Graphics.OpenGL4.PixelFormat.Rgb, OpenTK.Graphics.OpenGL4.PixelType.UnsignedByte);
            return(text);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Converts an array of sprite filenames into a sprite sheet object.
        /// </summary>
        public override BackgroundContent Process(BackgroundXMLData aInput, ContentProcessorContext aContext)
        {
            BackgroundContent output = new BackgroundContent();


            FreeImageAPI.FIBITMAP b = FreeImageAPI.FreeImage.LoadEx(aInput.file);

            FreeImageAPI.BITMAPINFO info = FreeImageAPI.FreeImage.GetInfoEx(b);


            //Resize to power of two
            int newWidth  = RoundUpPowerOf2(info.bmiHeader.biWidth);
            int newHeight = RoundUpPowerOf2(info.bmiHeader.biHeight);

            b = FreeImageAPI.FreeImage.Rescale(b, newWidth, newHeight, FreeImageAPI.FREE_IMAGE_FILTER.FILTER_BICUBIC);
            b = FreeImageAPI.FreeImage.RotateClassic(b, 180);
            FreeImageAPI.FreeImage.FlipHorizontal(b);

            int nbW = 1, nbH = 1;

            if (newWidth > TILE_SIZE)
            {
                nbW = newWidth / TILE_SIZE;
            }
            if (newHeight > TILE_SIZE)
            {
                nbH = newHeight / TILE_SIZE;
            }

            output.Width  = newWidth;
            output.Height = newHeight;

            BackgroundTileContent[][] tilesContent = new BackgroundTileContent[nbW][];
            for (int i = 0; i < nbW; i++)
            {
                tilesContent[i] = new BackgroundTileContent[nbH];
                for (int j = 0; j < nbH; j++)
                {
                    BackgroundTileContent tileContent = new BackgroundTileContent();
                    tileContent.X   = i * 512;
                    tileContent.Y   = j * 512;
                    tileContent.Tex = new Texture2DContent();
                    BitmapContent tile = new PixelBitmapContent <Color>(Math.Min(TILE_SIZE, newWidth), Math.Min(TILE_SIZE, newHeight));

                    Rectangle source = new Rectangle(i * TILE_SIZE, j * TILE_SIZE, Math.Min(TILE_SIZE, newWidth), Math.Min(TILE_SIZE, newHeight));
                    Rectangle dest   = new Rectangle(0, 0, Math.Min(TILE_SIZE, newWidth), Math.Min(TILE_SIZE, newHeight));


                    for (int k = 0; k < Math.Min(512, newWidth); k++)
                    {
                        for (int l = 0; l < Math.Min(512, newHeight); l++)
                        {
                            FreeImageAPI.RGBQUAD rgb;
                            FreeImageAPI.FreeImage.GetPixelColor(b, (uint)(tileContent.X + k), (uint)(tileContent.Y + l), out rgb);
                            ((PixelBitmapContent <Color>)tile).SetPixel(k, l, new Color(rgb.rgbRed, rgb.rgbGreen, rgb.rgbBlue));
                        }
                    }
                    tileContent.Tex.Mipmaps.Add(tile);

                    tilesContent[i][j] = tileContent;
                }
            }
            output.TilesContent = tilesContent;
            output.Speed        = aInput.speed;

            return(output);
        }