Пример #1
0
        private FreeImageBitmap CreateFreeImageViaDIB()
        {
            if (!CopySelection())
            {
                return(null);
            }
            FreeImageBitmap fi;
            MemoryStream    stream = null;

            Bovender.WpfHelpers.MainDispatcher.Invoke((Action)(
                                                          () =>
            {
                Logger.Info("CreateFreeImageViaDIB: Copy to clipboard and get data from it");
                stream = Clipboard.GetData(System.Windows.DataFormats.Dib) as MemoryStream;
            })
                                                      );
            using (DibBitmap dibBitmap = new DibBitmap(stream))
            {
                Logger.Info("CreateFreeImageViaDIB: Create FreeImage bitmap");
                fi = new FreeImageBitmap(dibBitmap.Bitmap);
                bool convertType = fi.ConvertType(FREE_IMAGE_TYPE.FIT_BITMAP, true);
                Logger.Debug("CreateFreeImageViaDIB: FreeImageBitmap.ConvertType returned {0}", convertType);
                bool convertColorDepth = fi.ConvertColorDepth(FREE_IMAGE_COLOR_DEPTH.FICD_24_BPP); // won't work with 32 bpp!
                Logger.Debug("CreateFreeImageViaDIB: FreeImageBitmap.ConvertColorDepth returned {0}", convertColorDepth);
                fi.RotateFlip(System.Drawing.RotateFlipType.RotateNoneFlipY);
            }
            stream.Dispose();
            return(fi);
        }
Пример #2
0
        private FreeImageBitmap CreateFreeImageViaDIB()
        {
            FreeImageBitmap fi;

            using (DllManager dllManager = new DllManager())
            {
                dllManager.LoadDll("FreeImage.DLL");
                Logger.Info("CreateFreeImageViaDIB: Copy to clipboard and get data from it");
                if (!CopySelection())
                {
                    return(null);
                }

                MemoryStream stream = Clipboard.GetData(System.Windows.DataFormats.Dib) as MemoryStream;
                using (DibBitmap dibBitmap = new DibBitmap(stream))
                {
                    Logger.Info("CreateFreeImageViaDIB: Create FreeImage bitmap");
                    fi = new FreeImageBitmap(dibBitmap.Bitmap);
                    bool convertType = fi.ConvertType(FREE_IMAGE_TYPE.FIT_BITMAP, true);
                    Logger.Debug("CreateFreeImageViaDIB: FreeImageBitmap.ConvertType returned {0}", convertType);
                    bool convertColorDepth = fi.ConvertColorDepth(FREE_IMAGE_COLOR_DEPTH.FICD_24_BPP); // won't work with 32 bpp!
                    Logger.Debug("CreateFreeImageViaDIB: FreeImageBitmap.ConvertColorDepth returned {0}", convertColorDepth);
                    fi.RotateFlip(System.Drawing.RotateFlipType.RotateNoneFlipY);
                }
            }
            return(fi);
        }
Пример #3
0
        /**
         * Outputs displayable image of image channel to be corrected.
         * @param layer the channel corrected
         * @return true if successful
         **/
        private void outputDisplayableBase(int layer)
        {
            float[] array;
            int     width = base_dimensions[0];
            int     height = base_dimensions[1];
            float   value, value16bpp;

            string image_name = (string)dropdown_imageLayer.Items[layer];

            array = new float[width * height];
            Array.Copy(base_data, width * height * layer, array, 0, width * height);

            FREE_IMAGE_FORMAT     format     = FREE_IMAGE_FORMAT.FIF_TIFF;
            FREE_IMAGE_TYPE       type       = FREE_IMAGE_TYPE.FIT_FLOAT;
            FREE_IMAGE_SAVE_FLAGS save_flags = FREE_IMAGE_SAVE_FLAGS.TIFF_NONE;
            FreeImageBitmap       image      = new FreeImageBitmap(width, height, type);

            float maxValue = Enumerable.Range(0, array.Length).Max(m => array[m]);
            float minValue = Enumerable.Range(0, array.Length).Min(m => array[m]);

            for (int j = 0; j < height; ++j)
            {
                Scanline <float> scanline = image.GetScanline <float>(j);
                for (int k = 0; k < width; ++k)
                {
                    value      = array[width * j + k];
                    value16bpp = (1.0f / (maxValue - minValue) * (value - minValue));
                    scanline.SetValue(value16bpp, k);
                }
            }
            image.RotateFlip(base_orientation);
            image.Save("./Workspace/" + image_name + "_base_displayable.tiff", format, save_flags);
        }
Пример #4
0
        /**
         * Outputs .tiff file to be read into Argo Solution as input parameter
         * @param layer the channel corrected
         * @return true if successful
         **/
        private bool outputBase(int layer)
        {
            float[] array;
            int     width  = base_dimensions[0];
            int     height = base_dimensions[1];
            float   value;

            if (layer == -1)
            {
                return(false);
            }

            string image_name = (string)dropdown_imageLayer.Items[layer];

            array = new float[width * height];
            Array.Copy(base_data, width * height * layer, array, 0, width * height);

            FREE_IMAGE_FORMAT     format     = FREE_IMAGE_FORMAT.FIF_TIFF;
            FREE_IMAGE_TYPE       type       = FREE_IMAGE_TYPE.FIT_FLOAT;
            FREE_IMAGE_SAVE_FLAGS save_flags = FREE_IMAGE_SAVE_FLAGS.TIFF_NONE;
            FreeImageBitmap       image      = new FreeImageBitmap(width, height, type);

            for (int j = 0; j < height; ++j)
            {
                Scanline <float> scanline = image.GetScanline <float>(j);
                for (int k = 0; k < width; ++k)
                {
                    value = array[width * j + k];
                    scanline.SetValue(value, k);
                }
            }
            image.RotateFlip(base_orientation);
            image.Save("./Workspace/" + image_name + "_base.tiff", format, save_flags);
            return(true);
        }
Пример #5
0
 /// <summary>
 /// Copy the given RenderTarget with the specified format.
 /// </summary>
 /// <param name="bitmap"></param>
 /// <param name="renderTarget"></param>
 /// <param name="format"></param>
 public static void copyFromRenderTarget(this FreeImageBitmap bitmap, RenderTarget renderTarget, OgrePlugin.PixelFormat format)
 {
     using (PixelBox pixelBox = bitmap.createPixelBox(format))
     {
         renderTarget.copyContentsToMemory(pixelBox, RenderTarget.FrameBuffer.FB_AUTO);
     }
     bitmap.RotateFlip(RotateFlipType.RotateNoneFlipY);
 }
Пример #6
0
        private FreeImageBitmap DrawTiles(Metafile metafile, Transparency transparency)
        {
            // http://stackoverflow.com/a/503201/270712 by rjmunro
            int numTiles             = (OriginalHeight - 1) / Height + 1;
            int percentCompletedStep = 100 / (numTiles * 2 + 1);

            Logger.Info("Preparing to draw {0} tiles...", numTiles);
            FreeImageBitmap f            = new FreeImageBitmap(Width, OriginalHeight, PixelFormat.Format32bppArgb);
            Graphics        g            = CreateGraphics(transparency);
            int             scanLineSize = Width * 4; // must align with 32 bits; with RGBA this is always the case

            Logger.Info("Scan line size: {0:0.0} kB", scanLineSize / 1024);

            int       currentLine     = 0;
            int       metafileHeight  = metafile.Height;
            int       metafileWidth   = metafile.Width;
            Rectangle destinationRect = new Rectangle(
                Width, Height, 0, 0);

            while (currentLine < OriginalHeight && !_cancelled)
            {
                Logger.Info("Drawing tile starting at y={0}...", currentLine);
                PercentCompleted += percentCompletedStep;
                int currentTileHeight = Math.Min(Height, OriginalHeight - currentLine);
                g.Clear(Color.Transparent);
                Rectangle sourceRect = new Rectangle(
                    0, metafileHeight * currentLine / OriginalHeight,
                    metafileWidth, metafileHeight * Height / OriginalHeight);
                Logger.Debug("Source rect: {0}; destination rect: {1}", sourceRect, destinationRect);
                g.DrawImage(metafile, destinationRect, sourceRect, GraphicsUnit.Pixel);
                PercentCompleted += percentCompletedStep;
                IntPtr     scanlinePointer = f.GetScanlinePointer(currentLine);
                BitmapData bitmapData      = _bitmap.LockBits(
                    new Rectangle(0, 0, Width, Height),
                    ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
                CopyMemory(scanlinePointer, bitmapData.Scan0,
                           Convert.ToUInt32(bitmapData.Stride * currentTileHeight));
                _bitmap.UnlockBits(bitmapData);
                currentLine += currentTileHeight;
            }
            g.Dispose();
            if (!_cancelled)
            {
                Logger.Info("Flipping FreeImage vertically.");
                PercentCompleted += percentCompletedStep;
                f.RotateFlip(RotateFlipType.RotateNoneFlipY);
                return(f);
            }
            else
            {
                Logger.Info("Drawing of tiles was cancelled, returning null");
                return(null);
            }
        }
Пример #7
0
 public TestImageAtlas()
     : base("UnitTestPlugin.GUI.TestImageAtlas.TestImageAtlas.layout")
 {
     using (var bitmap = new FreeImageBitmap(Assembly.GetCallingAssembly().GetManifestResourceStream("UnitTestPlugin.Resources.LegacyLogoSmall.jpg")))
     {
         bitmap.RotateFlip(RotateFlipType.RotateNoneFlipY);
         Log.Debug("Adding LegacyLogoSmall to image atlas");
         ImageAtlasPage page      = imageAtlas.addImage("LegacyLogoSmall", bitmap);
         ImageBox       imageBox1 = (ImageBox)window.findWidget("ImageBox1");
         Rectangle      coord;
         if (page.tryGetImageLocation("LegacyLogoSmall", out coord))
         {
             imageBox1.setImageTexture(page.TextureName);
             imageBox1.setImageCoord(new IntCoord(coord.Left, coord.Top, coord.Width, coord.Height));
         }
     }
     using (var bitmap = new FreeImageBitmap(Assembly.GetCallingAssembly().GetManifestResourceStream("UnitTestPlugin.Resources.DownloadIcon.png")))
     {
         bitmap.RotateFlip(RotateFlipType.RotateNoneFlipY);
         for (int i = 0; i < 10; ++i)
         {
             String imageName = "DownloadIcon" + i;
             Log.Debug("Adding DownloadIcon to image atlas");
             ImageAtlasPage page = imageAtlas.addImage(imageName, bitmap);
             Log.Debug("Page is {0}", page.TextureName);
             ImageBox  imageBox1 = (ImageBox)window.findWidget("ImageBox2");
             Rectangle coord;
             if (page.tryGetImageLocation(imageName, out coord))
             {
                 imageBox1.setImageTexture(page.TextureName);
                 imageBox1.setImageCoord(new IntCoord(coord.Left, coord.Top, coord.Width, coord.Height));
             }
         }
     }
     using (var bitmap = new FreeImageBitmap(Assembly.GetCallingAssembly().GetManifestResourceStream("UnitTestPlugin.Resources.LegacyLogoSmall.jpg")))
     {
         bitmap.RotateFlip(RotateFlipType.RotateNoneFlipY);
         Log.Debug("Adding LegacyLogoSmall1 to image atlas");
         ImageAtlasPage page      = imageAtlas.addImage("LegacyLogoSmall1", bitmap);
         ImageBox       imageBox1 = (ImageBox)window.findWidget("ImageBox1");
         Rectangle      coord;
         if (page.tryGetImageLocation("LegacyLogoSmall1", out coord))
         {
             imageBox1.setImageTexture(page.TextureName);
             imageBox1.setImageCoord(new IntCoord(coord.Left, coord.Top, coord.Width, coord.Height));
         }
     }
 }
Пример #8
0
        public unsafe void RotateFlip()
        {
            FreeImageBitmap fib = new FreeImageBitmap(2, 2, PixelFormat.Format32bppArgb);

            ResetRotateBitmap(fib);
            fib.RotateFlip(RotateFlipType.RotateNoneFlipX);
            Assert.AreEqual(0x00000002, ((int *)fib.GetScanlinePointer(0))[0]);
            Assert.AreEqual(0x00000001, ((int *)fib.GetScanlinePointer(0))[1]);
            Assert.AreEqual(0x00000004, ((int *)fib.GetScanlinePointer(1))[0]);
            Assert.AreEqual(0x00000003, ((int *)fib.GetScanlinePointer(1))[1]);

            ResetRotateBitmap(fib);
            fib.RotateFlip(RotateFlipType.RotateNoneFlipY);
            Assert.AreEqual(0x00000003, ((int *)fib.GetScanlinePointer(0))[0]);
            Assert.AreEqual(0x00000004, ((int *)fib.GetScanlinePointer(0))[1]);
            Assert.AreEqual(0x00000001, ((int *)fib.GetScanlinePointer(1))[0]);
            Assert.AreEqual(0x00000002, ((int *)fib.GetScanlinePointer(1))[1]);

            ResetRotateBitmap(fib);
            fib.RotateFlip(RotateFlipType.RotateNoneFlipXY);
            Assert.AreEqual(0x00000004, ((int *)fib.GetScanlinePointer(0))[0]);
            Assert.AreEqual(0x00000003, ((int *)fib.GetScanlinePointer(0))[1]);
            Assert.AreEqual(0x00000002, ((int *)fib.GetScanlinePointer(1))[0]);
            Assert.AreEqual(0x00000001, ((int *)fib.GetScanlinePointer(1))[1]);

            ResetRotateBitmap(fib);
            fib.RotateFlip(RotateFlipType.Rotate90FlipNone);
            Assert.AreEqual(0x00000003, ((int *)fib.GetScanlinePointer(0))[0]);
            Assert.AreEqual(0x00000001, ((int *)fib.GetScanlinePointer(0))[1]);
            Assert.AreEqual(0x00000004, ((int *)fib.GetScanlinePointer(1))[0]);
            Assert.AreEqual(0x00000002, ((int *)fib.GetScanlinePointer(1))[1]);

            ResetRotateBitmap(fib);
            fib.RotateFlip(RotateFlipType.Rotate90FlipX);
            Assert.AreEqual(0x00000001, ((int *)fib.GetScanlinePointer(0))[0]);
            Assert.AreEqual(0x00000003, ((int *)fib.GetScanlinePointer(0))[1]);
            Assert.AreEqual(0x00000002, ((int *)fib.GetScanlinePointer(1))[0]);
            Assert.AreEqual(0x00000004, ((int *)fib.GetScanlinePointer(1))[1]);

            ResetRotateBitmap(fib);
            fib.RotateFlip(RotateFlipType.Rotate90FlipY);
            Assert.AreEqual(0x00000004, ((int *)fib.GetScanlinePointer(0))[0]);
            Assert.AreEqual(0x00000002, ((int *)fib.GetScanlinePointer(0))[1]);
            Assert.AreEqual(0x00000003, ((int *)fib.GetScanlinePointer(1))[0]);
            Assert.AreEqual(0x00000001, ((int *)fib.GetScanlinePointer(1))[1]);

            fib.Dispose();
        }
Пример #9
0
        public unsafe void RotateFlip()
        {
            FreeImageBitmap fib = new FreeImageBitmap(2, 2, PixelFormat.Format32bppArgb);

            ResetRotateBitmap(fib);
            fib.RotateFlip(RotateFlipType.RotateNoneFlipX);
            Assert.AreEqual(0x00000002, ((int*)fib.GetScanlinePointer(0))[0]);
            Assert.AreEqual(0x00000001, ((int*)fib.GetScanlinePointer(0))[1]);
            Assert.AreEqual(0x00000004, ((int*)fib.GetScanlinePointer(1))[0]);
            Assert.AreEqual(0x00000003, ((int*)fib.GetScanlinePointer(1))[1]);

            ResetRotateBitmap(fib);
            fib.RotateFlip(RotateFlipType.RotateNoneFlipY);
            Assert.AreEqual(0x00000003, ((int*)fib.GetScanlinePointer(0))[0]);
            Assert.AreEqual(0x00000004, ((int*)fib.GetScanlinePointer(0))[1]);
            Assert.AreEqual(0x00000001, ((int*)fib.GetScanlinePointer(1))[0]);
            Assert.AreEqual(0x00000002, ((int*)fib.GetScanlinePointer(1))[1]);

            ResetRotateBitmap(fib);
            fib.RotateFlip(RotateFlipType.RotateNoneFlipXY);
            Assert.AreEqual(0x00000004, ((int*)fib.GetScanlinePointer(0))[0]);
            Assert.AreEqual(0x00000003, ((int*)fib.GetScanlinePointer(0))[1]);
            Assert.AreEqual(0x00000002, ((int*)fib.GetScanlinePointer(1))[0]);
            Assert.AreEqual(0x00000001, ((int*)fib.GetScanlinePointer(1))[1]);

            ResetRotateBitmap(fib);
            fib.RotateFlip(RotateFlipType.Rotate90FlipNone);
            Assert.AreEqual(0x00000003, ((int*)fib.GetScanlinePointer(0))[0]);
            Assert.AreEqual(0x00000001, ((int*)fib.GetScanlinePointer(0))[1]);
            Assert.AreEqual(0x00000004, ((int*)fib.GetScanlinePointer(1))[0]);
            Assert.AreEqual(0x00000002, ((int*)fib.GetScanlinePointer(1))[1]);

            ResetRotateBitmap(fib);
            fib.RotateFlip(RotateFlipType.Rotate90FlipX);
            Assert.AreEqual(0x00000001, ((int*)fib.GetScanlinePointer(0))[0]);
            Assert.AreEqual(0x00000003, ((int*)fib.GetScanlinePointer(0))[1]);
            Assert.AreEqual(0x00000002, ((int*)fib.GetScanlinePointer(1))[0]);
            Assert.AreEqual(0x00000004, ((int*)fib.GetScanlinePointer(1))[1]);

            ResetRotateBitmap(fib);
            fib.RotateFlip(RotateFlipType.Rotate90FlipY);
            Assert.AreEqual(0x00000004, ((int*)fib.GetScanlinePointer(0))[0]);
            Assert.AreEqual(0x00000002, ((int*)fib.GetScanlinePointer(0))[1]);
            Assert.AreEqual(0x00000003, ((int*)fib.GetScanlinePointer(1))[0]);
            Assert.AreEqual(0x00000001, ((int*)fib.GetScanlinePointer(1))[1]);

            fib.Dispose();
        }
Пример #10
0
        /// <summary>
        /// Create a paged image from a FreeImageBitmap instance, note that this function is destructive
        /// to the passed in FreeImageBitmap since it will resize it while creating all the mip levels
        /// for the paged image. However, you will still need to dispose the image you pass in, this class
        /// makes a copy while destroying the image, but does not take ownership of the original.
        /// </summary>
        /// <param name="image">The image to extract pages from.</param>
        /// <param name="pageSize">The size of the pages to extract.</param>
        public static void fromBitmap(FreeImageBitmap image, int pageSize, int padding, Stream stream, ImageType imageType, int maxSize, bool lossless, FREE_IMAGE_FILTER filter, ImagePageSizeStrategy pageSizeStrategy, Action <FreeImageBitmap> afterResize = null)
        {
            stream.Seek(HeaderSize, SeekOrigin.Begin); //Leave some space for the header

            if (image.Width > maxSize)
            {
                Logging.Log.Info("Image size {0} was too large, resizing to {1}", image.Width, maxSize);
                pageSizeStrategy.rescaleImage(image, new Size(maxSize, maxSize), filter);
            }

            PagedImage            pagedImage = new PagedImage();
            int                   padding2x  = padding * 2;
            FREE_IMAGE_FORMAT     outputFormat;
            FREE_IMAGE_SAVE_FLAGS saveFlags = FREE_IMAGE_SAVE_FLAGS.DEFAULT;

            switch (imageType)
            {
            default:
            case ImageType.PNG:
                outputFormat = FREE_IMAGE_FORMAT.FIF_PNG;
                break;

            case ImageType.WEBP:
                outputFormat = FREE_IMAGE_FORMAT.FIF_WEBP;
                if (lossless)
                {
                    saveFlags = FREE_IMAGE_SAVE_FLAGS.WEBP_LOSSLESS;
                }
                else
                {
                    saveFlags = (FREE_IMAGE_SAVE_FLAGS)90;
                }
                break;
            }

            //Kind of weird, ogre and freeimage are backwards from one another in terms of scanline 0 being the top or bottom
            //This easily fixes the math below by just flipping the image first. Note that pages must be flipped back over because
            //of this when they are saved.
            image.RotateFlip(RotateFlipType.RotateNoneFlipY);

            pagedImage.numImages  = 0;
            pagedImage.imageType  = (int)imageType;
            pagedImage.imageXSize = image.Width;
            pagedImage.imageYSize = image.Height;
            pagedImage.pageSize   = pageSize;
            if (pagedImage.imageXSize != pagedImage.imageYSize)
            {
                throw new InvalidDataException("Image must be a square");
            }

            int mipLevelCount = 0;
            int numPages      = 0;

            for (int i = pagedImage.imageXSize; i >= pageSize; i >>= 1)
            {
                ++mipLevelCount;
                int pagesForMip = i / pageSize;
                numPages += pagesForMip * pagesForMip;
            }
            pagedImage.pages      = new List <ImageInfo>(numPages);
            pagedImage.mipIndices = new List <MipIndexInfo>(mipLevelCount);

            IntSize2 fullPageSize = new IntSize2(pageSize + padding2x, pageSize + padding2x);

            for (int mip = 0; mip < mipLevelCount; ++mip)
            {
                //Setup mip level
                if (mip != 0)
                {
                    pageSizeStrategy.rescaleImage(image, new Size(image.Width >> 1, image.Height >> 1), filter);
                    if (afterResize != null)
                    {
                        //Flip so external functions aren't confused
                        image.RotateFlip(RotateFlipType.RotateNoneFlipY);
                        afterResize(image);
                        //Flip back for correct math
                        image.RotateFlip(RotateFlipType.RotateNoneFlipY);
                    }
                }
                int size = image.Width / pageSize;
                pagedImage.mipIndices.Add(new MipIndexInfo(pagedImage.numImages, size));
                pageSizeStrategy.extractPage(image, padding, stream, pagedImage, pageSize, fullPageSize, size, outputFormat, saveFlags);
            }

            //Write half size mip
            int      halfPageSize   = pageSize >> 1;
            IntSize2 halfSizePadded = new IntSize2(halfPageSize + padding2x, halfPageSize + padding2x);

            pageSizeStrategy.rescaleImage(image, new Size(image.Width >> 1, image.Height >> 1), filter);
            pageSizeStrategy.extractPage(image, padding, stream, pagedImage, halfPageSize, halfSizePadded, 1, outputFormat, saveFlags);

            pagedImage.indexStart = (int)stream.Position;

            using (BinaryWriter sw = new BinaryWriter(stream, EncodingShim.Default, true))
            {
                foreach (var imageInfo in pagedImage.pages)
                {
                    imageInfo.write(sw);
                }

                //Go back to header reserved space
                sw.BaseStream.Seek(0, SeekOrigin.Begin);
                sw.Write(MagicNumber);
                sw.Write(pagedImage.numImages);
                sw.Write(pagedImage.imageType);
                sw.Write(pagedImage.imageXSize);
                sw.Write(pagedImage.imageYSize);
                sw.Write(pagedImage.pageSize);
                sw.Write(pagedImage.indexStart);
            }
        }
Пример #11
0
        /**
         */
        private void updateImages(int index)
        {
            float[] array;
            float   maxValue, minValue, value;
            int     value16bpp;
            Bitmap  bitmap;
            Color   color;
            Image   old_bitmap;

            if (base_dimensions != null)
            {
                int width  = base_dimensions[0];
                int height = base_dimensions[1];

                array = new float[width * height];
                Array.Copy(base_data, width * height * index, array, 0, width * height);

                FreeImageBitmap image_bitmap = new FreeImageBitmap(new Bitmap(width, height), width, height);
                maxValue = Enumerable.Range(0, array.Length).Max(m => array[m]);
                minValue = Enumerable.Range(0, array.Length).Min(m => array[m]);
                for (int j = 0; j < height; ++j)
                {
                    Scanline <int> scanline = image_bitmap.GetScanline <int>(j);

                    for (int k = 0; k < width; ++k)
                    {
                        value      = array[width * j + k];
                        value16bpp = (int)(255.0f / (maxValue - minValue) * (value - minValue));
                        color      = Color.FromArgb(value16bpp, value16bpp, value16bpp);
                        scanline.SetValue(color.ToArgb(), k);
                    }
                }

                image_bitmap.RotateFlip(base_orientation);
                bitmap = image_bitmap.ToBitmap();
                image_bitmap.Dispose();

                old_bitmap       = image_base.Image;
                image_base.Image = bitmap;
                if (old_bitmap != null)
                {
                    old_bitmap.Dispose();
                }
            }



            if (sliver_dimensions != null)
            {
                int width  = sliver_dimensions[0];
                int height = sliver_dimensions[1];

                array = new float[width * height];
                Array.Copy(sliver_data, width * height * index, array, 0, width * height);
                FreeImageBitmap image_bitmap = new FreeImageBitmap(new Bitmap(width, height), width, height);
                maxValue = Enumerable.Range(0, array.Length).Max(m => array[m]);
                minValue = Enumerable.Range(0, array.Length).Min(m => array[m]);
                for (int j = 0; j < height; ++j)
                {
                    Scanline <int> scanline = image_bitmap.GetScanline <int>(j);

                    for (int k = 0; k < width; ++k)
                    {
                        value      = array[width * j + k];
                        value16bpp = (int)(255.0f / (maxValue - minValue) * (value - minValue));
                        color      = Color.FromArgb(value16bpp, value16bpp, value16bpp);
                        scanline.SetValue(color.ToArgb(), k);
                    }
                }

                image_bitmap.RotateFlip(sliver_orientation);
                bitmap = image_bitmap.ToBitmap();
                image_bitmap.Dispose();

                old_bitmap         = image_sliver.Image;
                image_sliver.Image = bitmap;
                if (old_bitmap != null)
                {
                    old_bitmap.Dispose();
                }
            }
        }