예제 #1
0
        public unsafe void analyzeBuffer()
        {
            float u, v;
            byte  m, t;

            for (int slId = 0; slId < fullBitmap.Height; ++slId)
            {
                var       scanline = fullBitmap.GetScanline <RGBQUAD>(slId);
                RGBQUAD[] slData   = scanline.Data;
                for (int pxId = 0; pxId < scanline.Count; ++pxId)
                {
                    var px = slData[pxId];
                    t = px.rgbReserved; //There is a change of this changing to the wrong texture id, but who knows if would happen (precision issues)

                    IndirectionTexture indirectionTexture;
                    if (t != 255 && virtualTextureManager.getIndirectionTexture(t, out indirectionTexture))
                    {
                        //Here the uvs are crushed to 8 bit, but should be ok since we are just detecting pages
                        //with this number this allows 255 pages to be decenly processsed above that data might be lost.
                        u = px.rgbRed / 255.0f;
                        v = px.rgbGreen / 255.0f;
                        m = px.rgbBlue;
                        indirectionTexture.processPage(u, v, m);
                    }
                }
            }
        }
예제 #2
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);
        }
예제 #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
        public void GetScanline()
        {
            FreeImageBitmap fib;

            fib = new FreeImageBitmap(10, 10, PixelFormat.Format1bppIndexed);
            Scanline <FI1BIT> scanline1 = (Scanline <FI1BIT>)fib.GetScanline(0);

            fib.Dispose();

            fib = new FreeImageBitmap(10, 10, PixelFormat.Format4bppIndexed);
            Scanline <FI4BIT> scanline2 = (Scanline <FI4BIT>)fib.GetScanline(0);

            fib.Dispose();

            fib = new FreeImageBitmap(10, 10, PixelFormat.Format8bppIndexed);
            Scanline <Byte> scanline3 = (Scanline <Byte>)fib.GetScanline(0);

            fib.Dispose();

            fib = new FreeImageBitmap(10, 10, PixelFormat.Format16bppRgb555);
            Scanline <FI16RGB555> scanline4 = (Scanline <FI16RGB555>)fib.GetScanline(0);

            fib.Dispose();

            fib = new FreeImageBitmap(10, 10, PixelFormat.Format16bppRgb565);
            Scanline <FI16RGB565> scanline5 = (Scanline <FI16RGB565>)fib.GetScanline(0);

            fib.Dispose();

            fib = new FreeImageBitmap(10, 10, PixelFormat.Format24bppRgb);
            Scanline <RGBTRIPLE> scanline6 = (Scanline <RGBTRIPLE>)fib.GetScanline(0);

            fib.Dispose();

            fib = new FreeImageBitmap(10, 10, PixelFormat.Format32bppArgb);
            Scanline <RGBQUAD> scanline7 = (Scanline <RGBQUAD>)fib.GetScanline(0);

            fib.Dispose();
        }
예제 #5
0
        public static RgbSpectrumTexture FreeImageLoadExrBitmap(string fileName)
        {

            Console.WriteLine("..Loading hdr bitmap {0}", fileName);
            using (var bmp = new FreeImageBitmap(fileName))
            {
                //bmp.AdjustGamma(2.2);
                var pdata = new RgbSpectrumInfo[bmp.Width * bmp.Height];
                for (int i = 0; i < bmp.Height; i++)
                {
                    Scanline<FIRGBF> s = bmp.GetScanline<FIRGBF>(i);
                    for (int j = 0; j < bmp.Width; j++)
                    {
                        pdata[j + i * bmp.Width] = new RgbSpectrumInfo(s[j].red, s[j].green, s[j].blue);
                        //pdata[j + i * bmp.Width] .DeGamma();
                    }
                }
                Console.WriteLine("... Converted size {0:F5} MBytes", (bmp.Width * bmp.Height * 12.0f) / (1024f * 1024f));
                MemoryOccupied += (ulong)(bmp.Width * bmp.Height * 12u);
                var tex = new RgbSpectrumTexture(fileName, pdata, bmp.Width, bmp.Height);
                return tex;
            }
        }
예제 #6
0
 public static Scanline <byte> GetScanlineFromTop8Bit(this FreeImageBitmap bitmap, int y)
 {
     return(bitmap.GetScanline <byte>(bitmap.Height - 1 - y));
 }
예제 #7
0
        public static RgbSpectrumTexture FreeImageLoadBitmap(string fileName)
        {
            Console.WriteLine("..Loading ldr bitmap {0}", fileName);
            using (var bmp = new FreeImageBitmap(fileName))
            {
                //bmp.AdjustGamma(2.2);

                var pdata = new RgbSpectrumInfo[bmp.Width * bmp.Height];
                for (int i = 0; i < bmp.Height; i++)
                {

                    if (bmp.ColorDepth == 24)
                    {
                        Scanline<RGBTRIPLE> s = bmp.GetScanline<RGBTRIPLE>(i);
                        for (int j = 0; j < bmp.Width; j++)
                        {
                            pdata[j + i * bmp.Width] =
                                RgbSpectrumInfo.Create(s[j].rgbtRed, s[j].rgbtGreen, s[j].rgbtBlue, false).Abs();
                        }
                    }

                    if (bmp.ColorDepth == 32)
                    {
                        Scanline<RGBQUAD> s = bmp.GetScanline<RGBQUAD>(i);
                        for (int j = 0; j < bmp.Width; j++)
                        {
                            pdata[j + i * bmp.Width] =
                                RgbSpectrumInfo.Create(s[j].rgbRed, s[j].rgbGreen, s[j].rgbBlue, false).Abs();
                        }
                    }

                    if (bmp.ColorDepth == 8)
                    {

                        Scanline<byte> s = bmp.GetScanline<byte>(i);
                        for (int j = 0; j < bmp.Width; j++)
                        {
                            pdata[j + i * bmp.Width] =
                                RgbSpectrumInfo.Create(bmp.Palette[s[j]].rgbRed, bmp.Palette[s[j]].rgbGreen, bmp.Palette[s[j]].rgbBlue, false).Abs();
                        }
                    }

                }
                Console.WriteLine("... Converted size {0:F5} MBytes", (bmp.Width * bmp.Height * 12.0f) / (1024f * 1024f));
                MemoryOccupied += (ulong)(bmp.Width * bmp.Height * 12u);

                var tex = new RgbSpectrumTexture(fileName, pdata, bmp.Width, bmp.Height);
                return tex;
            }
        }
예제 #8
0
        public static void FreeImageSaveExrBitmap(string fileName, int width, int height, RgbSpectrum[] data, string[] watermark = null)
        {
            using (var bmp = new FreeImageBitmap(width, height, FREE_IMAGE_TYPE.FIT_RGBF))
            {
                for (int i = 0; i < bmp.Height; i++)
                {
                    Scanline<FIRGBF> s = bmp.GetScanline<FIRGBF>(i);
                    for (int j = 0; j < bmp.Width; j++)
                    {
                        try
                        {
                            var spectra = data[j + i * bmp.Width];
                            s[j] = new FIRGBF()
                            {
                                blue = spectra.c3,
                                green = spectra.c2,
                                red = spectra.c1
                            };
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                    }
                }
                if (watermark != null)
                {
                    ApplyWaterMark(10, 400, bmp.ToBitmap(), watermark);
                }

                bmp.Save(fileName, FREE_IMAGE_FORMAT.FIF_EXR, FREE_IMAGE_SAVE_FLAGS.EXR_NONE);
                bmp.TmoReinhard05(1, 0.4);
                bmp.Save(fileName, FREE_IMAGE_FORMAT.FIF_PNG);
            }
        }
예제 #9
0
        public unsafe void Properties()
        {
            string filename = iManager.GetBitmapPath(ImageType.Even, ImageColorType.Type_32);

            Assert.IsNotNull(filename);
            Assert.IsTrue(File.Exists(filename));

            FreeImageBitmap fib = new FreeImageBitmap(filename);

            Assert.IsFalse(fib.HasPalette);

            try
            {
                Palette palette = fib.Palette;
                Assert.Fail();
            }
            catch
            {
            }

            Assert.IsFalse(fib.HasBackgroundColor);
            fib.BackgroundColor = Color.LightSeaGreen;
            Assert.IsTrue(fib.HasBackgroundColor);
            Assert.That(
                Color.LightSeaGreen.B == fib.BackgroundColor.Value.B &&
                Color.LightSeaGreen.G == fib.BackgroundColor.Value.G &&
                Color.LightSeaGreen.R == fib.BackgroundColor.Value.R);
            fib.BackgroundColor = null;
            Assert.IsFalse(fib.HasBackgroundColor);
            fib.Dispose();

            fib = new FreeImageBitmap(100, 100, PixelFormat.Format1bppIndexed);
            ImageFlags flags = (ImageFlags)fib.Flags;

            Assert.That((flags & ImageFlags.ColorSpaceRgb) == ImageFlags.ColorSpaceRgb);
            Assert.That((flags & ImageFlags.HasAlpha) != ImageFlags.HasAlpha);
            Assert.That((flags & ImageFlags.HasRealDpi) != ImageFlags.HasRealDpi);
            Assert.That((flags & ImageFlags.HasTranslucent) != ImageFlags.HasTranslucent);
            fib.Dispose();

            dib = FreeImage.Allocate(100, 100, 32, 0xFF0000, 0xFF00, 0xFF);
            FIICCPROFILE *prof = (FIICCPROFILE *)FreeImage.CreateICCProfile(dib, new byte[] { 0, 1, 2, 3 }, 4);

            fib = new FreeImageBitmap(dib);
            Scanline <RGBQUAD> sc   = (Scanline <RGBQUAD>)fib.GetScanline(0);
            RGBQUAD            rgbq = sc[0];

            rgbq.rgbReserved = 127;
            sc[0]            = rgbq;
            flags            = (ImageFlags)fib.Flags;
            Assert.That((flags & ImageFlags.HasAlpha) == ImageFlags.HasAlpha);
            Assert.That((flags & ImageFlags.HasRealDpi) != ImageFlags.HasRealDpi);
            Assert.That((flags & ImageFlags.HasTranslucent) == ImageFlags.HasTranslucent);
            fib.Dispose();
            fib = null;
            GC.Collect(2, GCCollectionMode.Forced);
            GC.WaitForPendingFinalizers();

            fib = new FreeImageBitmap(iManager.GetBitmapPath(ImageType.Metadata, ImageColorType.Type_01_Dither));
            int[] propList = fib.PropertyIdList;
            Assert.IsNotNull(propList);
            Assert.Greater(propList.Length, 0);
            PropertyItem[] propItemList = fib.PropertyItems;
            Assert.IsNotNull(propItemList);
            Assert.Greater(propItemList.Length, 0);
            Assert.IsNotNull(fib.RawFormat);
            fib.Dispose();

            fib = new FreeImageBitmap(iManager.GetBitmapPath(ImageType.Multipaged, ImageColorType.Type_01_Dither));
            Assert.Greater(fib.FrameCount, 1);
            fib.Dispose();
        }
예제 #10
0
        public void GetScanline()
        {
            FreeImageBitmap fib;

            fib = new FreeImageBitmap(10, 10, PixelFormat.Format1bppIndexed);
            Scanline<FI1BIT> scanline1 = (Scanline<FI1BIT>)fib.GetScanline(0);
            fib.Dispose();

            fib = new FreeImageBitmap(10, 10, PixelFormat.Format4bppIndexed);
            Scanline<FI4BIT> scanline2 = (Scanline<FI4BIT>)fib.GetScanline(0);
            fib.Dispose();

            fib = new FreeImageBitmap(10, 10, PixelFormat.Format8bppIndexed);
            Scanline<Byte> scanline3 = (Scanline<Byte>)fib.GetScanline(0);
            fib.Dispose();

            fib = new FreeImageBitmap(10, 10, PixelFormat.Format16bppRgb555);
            Scanline<FI16RGB555> scanline4 = (Scanline<FI16RGB555>)fib.GetScanline(0);
            fib.Dispose();

            fib = new FreeImageBitmap(10, 10, PixelFormat.Format16bppRgb565);
            Scanline<FI16RGB565> scanline5 = (Scanline<FI16RGB565>)fib.GetScanline(0);
            fib.Dispose();

            fib = new FreeImageBitmap(10, 10, PixelFormat.Format24bppRgb);
            Scanline<RGBTRIPLE> scanline6 = (Scanline<RGBTRIPLE>)fib.GetScanline(0);
            fib.Dispose();

            fib = new FreeImageBitmap(10, 10, PixelFormat.Format32bppArgb);
            Scanline<RGBQUAD> scanline7 = (Scanline<RGBQUAD>)fib.GetScanline(0);
            fib.Dispose();
        }
예제 #11
0
        private bool MergeImages(string fileNameFormat, string outputDir, string prefix, int frameNum, string ext)
        {
            FreeImageBitmap combined = null;
            string fname = "";
            bool supported = false;
            bool mergeSuccessful = true;
            FREE_IMAGE_TYPE type = FREE_IMAGE_TYPE.FIT_UNKNOWN;
            FreeImageBitmap source = null;

            string mergedFile = string.Format(fileNameFormat, outputDir, prefix, frameNum, ext);
            string tempFile = string.Format(fileNameFormat, outputDir, prefix, frameNum, "_tmp" + ext);

            // Allocate a bitmap to store the final image
            fname = string.Format(fileNameFormat, outputDir, "slice_0_" + prefix, frameNum, ext);

            try
            {
                source = new FreeImageBitmap(fname);

                if (source != null)
                {
                    type = source.ImageType;
                    switch (type)
                    {
                        case FREE_IMAGE_TYPE.FIT_BITMAP:
                            if (source.ColorDepth == 32 || source.ColorDepth == 24)
                                supported = true;
                            break;
                        case FREE_IMAGE_TYPE.FIT_RGB16:
                        case FREE_IMAGE_TYPE.FIT_RGBA16:
                        case FREE_IMAGE_TYPE.FIT_RGBAF:
                        case FREE_IMAGE_TYPE.FIT_RGBF:
                            supported = true;
                            break;
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Error opening slice file");
            }

            if (supported == false)
            {
                Console.WriteLine("Image format not supported");
                return false;
            }

            try
            {
                // Create a new image of the input file type and the correct size
                FIBITMAP newImage = FreeImage.AllocateT(type, Width, Height, source.ColorDepth, source.RedMask, source.BlueMask, source.GreenMask);

                FreeImage.SaveEx(newImage, tempFile);
                FreeImage.UnloadEx(ref newImage);
                source.Dispose();
                source = null;
                GC.Collect();
                GC.WaitForPendingFinalizers();
                combined = new FreeImageBitmap(tempFile);
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Error creating output file");
                mergeSuccessful = false;
            }

            for (int i = 0; i < SlicesAcross * SlicesDown; i++)
            {
                // Load the image slice
                fname = string.Format(fileNameFormat, outputDir, "slice_" + i + "_" + prefix, frameNum, ext);
                FreeImageBitmap slice = new FreeImageBitmap(fname);

                int posX;
                int posY;

                if (SlicesDown > 1 && SlicesAcross > 1)
                {
                    posX = i % SlicesAcross;
                    posY = i / SlicesAcross;
                }
                else if (SlicesDown == 1)
                {
                    posX = i;
                    posY = 0;
                }
                else
                {
                    posX = 0;
                    posY = i;
                }

                // Calculate the image slice sizes and the row/column position
                double sizeV = (1.0 / SlicesDown) * Height;
                double sizeH = (1.0 / SlicesAcross) * Width;
                double overlapV = sizeV * (Overlap / 100.0);
                double overlapH = sizeH * (Overlap / 100.0);

                double realLeft = sizeH * posX;
                double left = realLeft - overlapH;

                double realTop = sizeV * posY;
                double top = realTop - overlapV;

                // Check the sizes are within limits and adjust
                left = Math.Max(0.0, left);
                top = Math.Max(0.0, top);

                try
                {
                    switch (type)
                    {
                        case FREE_IMAGE_TYPE.FIT_BITMAP:
                            if (slice.ColorDepth == 24)
                            {
                                for (int y = 0; y < slice.Height; y++)
                                {
                                    int srcY = (slice.Height - 1) - y;
                                    int destY = (combined.Height - 1) - (srcY + (int)top);
                                    int topY = y + (int)top;
                                    Scanline<RGBTRIPLE> srcLine = (Scanline<RGBTRIPLE>)slice.GetScanline(y);
                                    Scanline<RGBTRIPLE> destLine = (Scanline<RGBTRIPLE>)combined.GetScanline(destY);

                                    for (int x = 0; x < slice.Width; x++)
                                    {
                                        int destX = x + (int)left;

                                        // Make sure it's not out of bounds
                                        if (destY >= Height || destY >= Width)
                                            continue;
                                        // Is the pixel in an overlapping Area
                                        if (topY < realTop || destX < realLeft)
                                        {
                                            MergePixel srcPixel = new MergePixel(srcLine[x].rgbtRed, srcLine[x].rgbtGreen, srcLine[x].rgbtBlue, 0);
                                            MergePixel destPixel = new MergePixel(destLine[destX].rgbtRed, destLine[destX].rgbtGreen, destLine[destX].rgbtBlue, 0);

                                            destPixel = CalculatePixelWeight(overlapV, overlapH, realLeft, left, realTop, top, y, topY, x, srcPixel, destPixel);

                                            RGBTRIPLE dest;
                                            dest.rgbtRed = destPixel.red > 255.0 ? (byte)255 : (byte)destPixel.red;
                                            dest.rgbtGreen = destPixel.green > 255.0 ? (byte)255 : (byte)destPixel.green;
                                            dest.rgbtBlue = destPixel.blue > 255.0 ? (byte)255 : (byte)destPixel.blue;
                                            destLine[destX] = dest;
                                        }
                                        else
                                            destLine[destX] = srcLine[x];
                                    }
                                }
                            }
                            else
                            {
                                for (int y = 0; y < slice.Height; y++)
                                {
                                    int srcY = (slice.Height - 1) - y;
                                    int destY = (combined.Height - 1) - (srcY + (int)top);
                                    int topY = y + (int)top;
                                    Scanline<RGBQUAD> srcLine = (Scanline<RGBQUAD>)slice.GetScanline(y);
                                    Scanline<RGBQUAD> destLine = (Scanline<RGBQUAD>)combined.GetScanline(destY);

                                    for (int x = 0; x < slice.Width; x++)
                                    {
                                        int destX = x + (int)left;

                                        // Make sure it's not out of bounds
                                        if (destY >= Height || destY >= Width)
                                            continue;
                                        // Is the pixel in an overlapping Area
                                        if (topY < realTop || destX < realLeft)
                                        {
                                            MergePixel srcPixel = new MergePixel(srcLine[x].rgbRed, srcLine[x].rgbGreen, srcLine[x].rgbBlue, destLine[destX].rgbReserved);
                                            MergePixel destPixel = new MergePixel(destLine[destX].rgbRed, destLine[destX].rgbGreen, destLine[destX].rgbBlue, destLine[destX].rgbReserved);

                                            destPixel = CalculatePixelWeight(overlapV, overlapH, realLeft, left, realTop, top, y, topY, x, srcPixel, destPixel);

                                            RGBQUAD dest = new RGBQUAD();
                                            dest.rgbRed = destPixel.red > 255.0 ? (byte)255 : (byte)destPixel.red;
                                            dest.rgbGreen = destPixel.green > 255.0 ? (byte)255 : (byte)destPixel.green;
                                            dest.rgbBlue = destPixel.blue > 255.0 ? (byte)255 : (byte)destPixel.blue;
                                            dest.rgbReserved = destPixel.alpha > 255.0 ? (byte)255 : (byte)destPixel.alpha;
                                            destLine[destX] = dest;
                                        }
                                        else
                                            destLine[destX] = srcLine[x];
                                    }
                                }
                            }
                            break;
                        case FREE_IMAGE_TYPE.FIT_RGB16:
                            for (int y = 0; y < slice.Height; y++)
                            {
                                int srcY = (slice.Height - 1) - y;
                                int destY = (combined.Height - 1) - (srcY + (int)top);
                                int topY = y + (int)top;
                                Scanline<FIRGB16> srcLine = (Scanline<FIRGB16>)slice.GetScanline(y);
                                Scanline<FIRGB16> destLine = (Scanline<FIRGB16>)combined.GetScanline(destY);

                                for (int x = 0; x < slice.Width; x++)
                                {
                                    int destX = x + (int)left;

                                    // Make sure it's not out of bounds
                                    if (destY >= Height || destY >= Width)
                                        continue;
                                    // Is the pixel in an overlapping Area
                                    if (topY < realTop || destX < realLeft)
                                    {
                                        MergePixel srcPixel = new MergePixel(srcLine[x].red, srcLine[x].green, srcLine[x].blue, 0);
                                        MergePixel destPixel = new MergePixel(destLine[destX].red, destLine[destX].green, destLine[destX].blue, 0);

                                        destPixel = CalculatePixelWeight(overlapV, overlapH, realLeft, left, realTop, top, y, topY, x, srcPixel, destPixel);

                                        FIRGB16 dest = new FIRGB16();
                                        dest.red = (ushort)destPixel.red;
                                        dest.green = (ushort)destPixel.green;
                                        dest.blue = (ushort)destPixel.blue;
                                        destLine[destX] = dest;
                                    }
                                    else
                                        destLine[destX] = srcLine[x];
                                }
                            }
                            break;
                        case FREE_IMAGE_TYPE.FIT_RGBA16:
                            for (int y = 0; y < slice.Height; y++)
                            {
                                int srcY = (slice.Height - 1) - y;
                                int destY = (combined.Height - 1) - (srcY + (int)top);
                                int topY = y + (int)top;
                                Scanline<FIRGBA16> srcLine = (Scanline<FIRGBA16>)slice.GetScanline(y);
                                Scanline<FIRGBA16> destLine = (Scanline<FIRGBA16>)combined.GetScanline(destY);

                                for (int x = 0; x < slice.Width; x++)
                                {
                                    int destX = x + (int)left;

                                    // Make sure it's not out of bounds
                                    if (destY >= Height || destY >= Width)
                                        continue;
                                    // Is the pixel in an overlapping Area
                                    if (topY < realTop || destX < realLeft)
                                    {
                                        MergePixel srcPixel = new MergePixel(srcLine[x].red, srcLine[x].green, srcLine[x].blue, srcLine[x].alpha);
                                        MergePixel destPixel = new MergePixel(destLine[destX].red, destLine[destX].green, destLine[destX].blue, destLine[destX].alpha);

                                        destPixel = CalculatePixelWeight(overlapV, overlapH, realLeft, left, realTop, top, y, topY, x, srcPixel, destPixel);

                                        FIRGBA16 dest = new FIRGBA16();
                                        dest.red = (ushort)destPixel.red;
                                        dest.green = (ushort)destPixel.green;
                                        dest.blue = (ushort)destPixel.blue;
                                        dest.alpha = (ushort)destPixel.alpha;
                                        destLine[destX] = dest;
                                    }
                                    else
                                        destLine[destX] = srcLine[x];
                                }
                            }
                            break;
                        case FREE_IMAGE_TYPE.FIT_RGBAF:
                            for (int y = 0; y < slice.Height; y++)
                            {
                                int srcY = (slice.Height - 1) - y;
                                int destY = (combined.Height - 1) - (srcY + (int)top);
                                int topY = y + (int)top;
                                Scanline<FIRGBAF> srcLine = (Scanline<FIRGBAF>)slice.GetScanline(y);
                                Scanline<FIRGBAF> destLine = (Scanline<FIRGBAF>)combined.GetScanline(destY);

                                for (int x = 0; x < slice.Width; x++)
                                {
                                    int destX = x + (int)left;

                                    // Make sure it's not out of bounds
                                    if (destY >= Height || destY >= Width)
                                        continue;
                                    // Is the pixel in an overlapping Area
                                    if (topY < realTop || destX < realLeft)
                                    {
                                        MergePixel srcPixel = new MergePixel(srcLine[x].red, srcLine[x].green, srcLine[x].blue, destLine[destX].alpha);
                                        MergePixel destPixel = new MergePixel(destLine[destX].red, destLine[destX].green, destLine[destX].blue, destLine[destX].alpha);

                                        destPixel = CalculatePixelWeight(overlapV, overlapH, realLeft, left, realTop, top, y, topY, x, srcPixel, destPixel);

                                        FIRGBAF dest = new FIRGBAF();
                                        dest.red = (float)destPixel.red;
                                        dest.green = (float)destPixel.green;
                                        dest.blue = (float)destPixel.blue;
                                        dest.alpha = (float)destPixel.alpha;
                                        destLine[destX] = dest;
                                    }
                                    else
                                        destLine[destX] = srcLine[x];
                                }
                            }
                            break;
                        case FREE_IMAGE_TYPE.FIT_RGBF:
                            for (int y = 0; y < slice.Height; y++)
                            {
                                int srcY = (slice.Height - 1) - y;
                                int destY = (combined.Height - 1) - (srcY + (int)top);
                                int topY = y + (int)top;
                                Scanline<FIRGBF> srcLine = (Scanline<FIRGBF>)slice.GetScanline(y);
                                Scanline<FIRGBF> destLine = (Scanline<FIRGBF>)combined.GetScanline(destY);

                                for (int x = 0; x < slice.Width; x++)
                                {
                                    int destX = x + (int)left;

                                    // Make sure it's not out of bounds
                                    if (destY >= Height || destY >= Width)
                                        continue;
                                    // Is the pixel in an overlapping Area
                                    if (topY < realTop || destX < realLeft)
                                    {
                                        MergePixel srcPixel = new MergePixel(srcLine[x].red, srcLine[x].green, srcLine[x].blue, 0);
                                        MergePixel destPixel = new MergePixel(destLine[destX].red, destLine[destX].green, destLine[destX].blue, 0);

                                        destPixel = CalculatePixelWeight(overlapV, overlapH, realLeft, left, realTop, top, y, topY, x, srcPixel, destPixel);

                                        FIRGBF dest = new FIRGBF();
                                        dest.red = (float)destPixel.red;
                                        dest.green = (float)destPixel.green;
                                        dest.blue = (float)destPixel.blue;
                                        destLine[destX] = dest;
                                    }
                                    else
                                        destLine[destX] = srcLine[x];
                                }
                            }
                            break;
                    }
                    slice.Dispose();
                }
                catch (Exception ex)
                {
                    logger.Error(ex, "Error merging image files");
                    mergeSuccessful = false;
                }
            }
            try
            {
                if (mergeSuccessful)
                {
                    combined.Save(mergedFile);
                    combined.Dispose();
                    combined = null;
                    GC.Collect();
                    GC.WaitForPendingFinalizers();
                    File.Delete(tempFile);
                }
                else
                {
                    Log += DateTime.Now.ToLongTimeString() + " Merging frame " + frameNum + " failed.\n";
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Error writing combined file");
                mergeSuccessful = false;
            }

            return mergeSuccessful;
        }
예제 #12
0
 protected void SavePBOhdr(string fileName) {
     OGLBuffer buffer = OutputBuffer as OGLBuffer;
     if (buffer == null)
         return;
     Vector4[] data = new Vector4[buffer.Width * buffer.Height];
     buffer.GetDataNoAlloc<Vector4>(data);
     using (var bmp = new FreeImageBitmap(this.Width, this.Height, FREE_IMAGE_TYPE.FIT_RGBF)) {
         for (var j = 0ul; j < buffer.Height; j++) {
             var scanLine = bmp.GetScanline<FIRGBF>((int)buffer.Height - (int)j - 1);
             for (var i = 0ul; i < buffer.Width; i++) {
                 var px = data[(int)i + (int)(buffer.Height - j - 1) * bmp.Width];
                 scanLine[(int)i] = new FIRGBF() { red = px.X, green = px.Y, blue = px.Z};
             }
         }
         bmp.Save(fileName, FREE_IMAGE_FORMAT.FIF_EXR);
     }
 }
예제 #13
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();
                }
            }
        }
예제 #14
0
 public static Scanline <RGBTRIPLE> GetScanlineFromTop24Bit(this FreeImageBitmap bitmap, int y)
 {
     return(bitmap.GetScanline <RGBTRIPLE>(bitmap.Height - 1 - y));
 }
예제 #15
0
        public unsafe void Properties()
        {
            string filename = iManager.GetBitmapPath(ImageType.Even, ImageColorType.Type_32);
            Assert.IsNotNull(filename);
            Assert.IsTrue(File.Exists(filename));

            FreeImageBitmap fib = new FreeImageBitmap(filename);
            Assert.IsFalse(fib.HasPalette);

            try
            {
                Palette palette = fib.Palette;
                Assert.Fail();
            }
            catch
            {
            }

            Assert.IsFalse(fib.HasBackgroundColor);
            fib.BackgroundColor = Color.LightSeaGreen;
            Assert.IsTrue(fib.HasBackgroundColor);
            Assert.That(
                Color.LightSeaGreen.B == fib.BackgroundColor.Value.B &&
                Color.LightSeaGreen.G == fib.BackgroundColor.Value.G &&
                Color.LightSeaGreen.R == fib.BackgroundColor.Value.R);
            fib.BackgroundColor = null;
            Assert.IsFalse(fib.HasBackgroundColor);
            fib.Dispose();

            fib = new FreeImageBitmap(100, 100, PixelFormat.Format1bppIndexed);
            ImageFlags flags = (ImageFlags)fib.Flags;
            Assert.That((flags & ImageFlags.ColorSpaceRgb) == ImageFlags.ColorSpaceRgb);
            Assert.That((flags & ImageFlags.HasAlpha) != ImageFlags.HasAlpha);
            Assert.That((flags & ImageFlags.HasRealDpi) != ImageFlags.HasRealDpi);
            Assert.That((flags & ImageFlags.HasTranslucent) != ImageFlags.HasTranslucent);
            fib.Dispose();

            dib = FreeImage.Allocate(100, 100, 32, 0xFF0000, 0xFF00, 0xFF);
            FIICCPROFILE* prof = (FIICCPROFILE*)FreeImage.CreateICCProfile(dib, new byte[] { 0, 1, 2, 3 }, 4);
            fib = new FreeImageBitmap(dib);
            Scanline<RGBQUAD> sc = (Scanline<RGBQUAD>)fib.GetScanline(0);
            RGBQUAD rgbq = sc[0];
            rgbq.rgbReserved = 127;
            sc[0] = rgbq;
            flags = (ImageFlags)fib.Flags;
            Assert.That((flags & ImageFlags.HasAlpha) == ImageFlags.HasAlpha);
            Assert.That((flags & ImageFlags.HasRealDpi) != ImageFlags.HasRealDpi);
            Assert.That((flags & ImageFlags.HasTranslucent) == ImageFlags.HasTranslucent);
            fib.Dispose();
            fib = null;
            GC.Collect(2, GCCollectionMode.Forced);
            GC.WaitForPendingFinalizers();

            fib = new FreeImageBitmap(iManager.GetBitmapPath(ImageType.Metadata, ImageColorType.Type_01_Dither));
            int[] propList = fib.PropertyIdList;
            Assert.IsNotNull(propList);
            Assert.Greater(propList.Length, 0);
            PropertyItem[] propItemList = fib.PropertyItems;
            Assert.IsNotNull(propItemList);
            Assert.Greater(propItemList.Length, 0);
            Assert.IsNotNull(fib.RawFormat);
            fib.Dispose();

            fib = new FreeImageBitmap(iManager.GetBitmapPath(ImageType.Multipaged, ImageColorType.Type_01_Dither));
            Assert.Greater(fib.FrameCount, 1);
            fib.Dispose();
        }
예제 #16
0
 public static Scanline <FI4BIT> GetScanlineFromTop4Bit(this FreeImageBitmap bitmap, int y)
 {
     return(bitmap.GetScanline <FI4BIT>(bitmap.Height - 1 - y));
 }
예제 #17
0
        private bool MergeImages(string fileNameFormat, string outputDir, string prefix, int frameNum, string ext)
        {
            FreeImageBitmap combined        = null;
            string          fname           = "";
            bool            supported       = false;
            bool            mergeSuccessful = true;
            FREE_IMAGE_TYPE type            = FREE_IMAGE_TYPE.FIT_UNKNOWN;
            FreeImageBitmap source          = null;

            string mergedFile = string.Format(fileNameFormat, outputDir, prefix, frameNum, ext);
            string tempFile   = string.Format(fileNameFormat, outputDir, prefix, frameNum, "_tmp" + ext);

            // Allocate a bitmap to store the final image
            fname = string.Format(fileNameFormat, outputDir, "slice_0_" + prefix, frameNum, ext);

            try
            {
                source = new FreeImageBitmap(fname);

                if (source != null)
                {
                    type = source.ImageType;
                    switch (type)
                    {
                    case FREE_IMAGE_TYPE.FIT_BITMAP:
                        if (source.ColorDepth == 32 || source.ColorDepth == 24)
                        {
                            supported = true;
                        }
                        break;

                    case FREE_IMAGE_TYPE.FIT_RGB16:
                    case FREE_IMAGE_TYPE.FIT_RGBA16:
                    case FREE_IMAGE_TYPE.FIT_RGBAF:
                    case FREE_IMAGE_TYPE.FIT_RGBF:
                        supported = true;
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Error opening slice file");
            }

            if (supported == false)
            {
                Console.WriteLine("Image format not supported");
                return(false);
            }

            try
            {
                // Create a new image of the input file type and the correct size
                FIBITMAP newImage = FreeImage.AllocateT(type, Width, Height, source.ColorDepth, source.RedMask, source.BlueMask, source.GreenMask);

                FreeImage.SaveEx(newImage, tempFile);
                FreeImage.UnloadEx(ref newImage);
                source.Dispose();
                source = null;
                GC.Collect();
                GC.WaitForPendingFinalizers();
                combined = new FreeImageBitmap(tempFile);
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Error creating output file");
                mergeSuccessful = false;
            }

            for (int i = 0; i < SlicesAcross * SlicesDown; i++)
            {
                // Load the image slice
                fname = string.Format(fileNameFormat, outputDir, "slice_" + i + "_" + prefix, frameNum, ext);
                FreeImageBitmap slice = new FreeImageBitmap(fname);

                int posX;
                int posY;

                if (SlicesDown > 1 && SlicesAcross > 1)
                {
                    posX = i % SlicesAcross;
                    posY = i / SlicesAcross;
                }
                else if (SlicesDown == 1)
                {
                    posX = i;
                    posY = 0;
                }
                else
                {
                    posX = 0;
                    posY = i;
                }

                // Calculate the image slice sizes and the row/column position
                double sizeV    = (1.0 / SlicesDown) * Height;
                double sizeH    = (1.0 / SlicesAcross) * Width;
                double overlapV = sizeV * (Overlap / 100.0);
                double overlapH = sizeH * (Overlap / 100.0);

                double realLeft = sizeH * posX;
                double left     = realLeft - overlapH;

                double realTop = sizeV * posY;
                double top     = realTop - overlapV;

                // Check the sizes are within limits and adjust
                left = Math.Max(0.0, left);
                top  = Math.Max(0.0, top);

                try
                {
                    switch (type)
                    {
                    case FREE_IMAGE_TYPE.FIT_BITMAP:
                        if (slice.ColorDepth == 24)
                        {
                            for (int y = 0; y < slice.Height; y++)
                            {
                                int srcY  = (slice.Height - 1) - y;
                                int destY = (combined.Height - 1) - (srcY + (int)top);
                                int topY  = y + (int)top;
                                Scanline <RGBTRIPLE> srcLine  = (Scanline <RGBTRIPLE>)slice.GetScanline(y);
                                Scanline <RGBTRIPLE> destLine = (Scanline <RGBTRIPLE>)combined.GetScanline(destY);

                                for (int x = 0; x < slice.Width; x++)
                                {
                                    int destX = x + (int)left;

                                    // Make sure it's not out of bounds
                                    if (destY >= Height || destY >= Width)
                                    {
                                        continue;
                                    }
                                    // Is the pixel in an overlapping Area
                                    if (topY < realTop || destX < realLeft)
                                    {
                                        MergePixel srcPixel  = new MergePixel(srcLine[x].rgbtRed, srcLine[x].rgbtGreen, srcLine[x].rgbtBlue, 0);
                                        MergePixel destPixel = new MergePixel(destLine[destX].rgbtRed, destLine[destX].rgbtGreen, destLine[destX].rgbtBlue, 0);

                                        destPixel = CalculatePixelWeight(overlapV, overlapH, realLeft, left, realTop, top, y, topY, x, srcPixel, destPixel);

                                        RGBTRIPLE dest;
                                        dest.rgbtRed    = destPixel.red > 255.0 ? (byte)255 : (byte)destPixel.red;
                                        dest.rgbtGreen  = destPixel.green > 255.0 ? (byte)255 : (byte)destPixel.green;
                                        dest.rgbtBlue   = destPixel.blue > 255.0 ? (byte)255 : (byte)destPixel.blue;
                                        destLine[destX] = dest;
                                    }
                                    else
                                    {
                                        destLine[destX] = srcLine[x];
                                    }
                                }
                            }
                        }
                        else
                        {
                            for (int y = 0; y < slice.Height; y++)
                            {
                                int srcY  = (slice.Height - 1) - y;
                                int destY = (combined.Height - 1) - (srcY + (int)top);
                                int topY  = y + (int)top;
                                Scanline <RGBQUAD> srcLine  = (Scanline <RGBQUAD>)slice.GetScanline(y);
                                Scanline <RGBQUAD> destLine = (Scanline <RGBQUAD>)combined.GetScanline(destY);

                                for (int x = 0; x < slice.Width; x++)
                                {
                                    int destX = x + (int)left;

                                    // Make sure it's not out of bounds
                                    if (destY >= Height || destY >= Width)
                                    {
                                        continue;
                                    }
                                    // Is the pixel in an overlapping Area
                                    if (topY < realTop || destX < realLeft)
                                    {
                                        MergePixel srcPixel  = new MergePixel(srcLine[x].rgbRed, srcLine[x].rgbGreen, srcLine[x].rgbBlue, destLine[destX].rgbReserved);
                                        MergePixel destPixel = new MergePixel(destLine[destX].rgbRed, destLine[destX].rgbGreen, destLine[destX].rgbBlue, destLine[destX].rgbReserved);

                                        destPixel = CalculatePixelWeight(overlapV, overlapH, realLeft, left, realTop, top, y, topY, x, srcPixel, destPixel);

                                        RGBQUAD dest = new RGBQUAD();
                                        dest.rgbRed      = destPixel.red > 255.0 ? (byte)255 : (byte)destPixel.red;
                                        dest.rgbGreen    = destPixel.green > 255.0 ? (byte)255 : (byte)destPixel.green;
                                        dest.rgbBlue     = destPixel.blue > 255.0 ? (byte)255 : (byte)destPixel.blue;
                                        dest.rgbReserved = destPixel.alpha > 255.0 ? (byte)255 : (byte)destPixel.alpha;
                                        destLine[destX]  = dest;
                                    }
                                    else
                                    {
                                        destLine[destX] = srcLine[x];
                                    }
                                }
                            }
                        }
                        break;

                    case FREE_IMAGE_TYPE.FIT_RGB16:
                        for (int y = 0; y < slice.Height; y++)
                        {
                            int srcY  = (slice.Height - 1) - y;
                            int destY = (combined.Height - 1) - (srcY + (int)top);
                            int topY  = y + (int)top;
                            Scanline <FIRGB16> srcLine  = (Scanline <FIRGB16>)slice.GetScanline(y);
                            Scanline <FIRGB16> destLine = (Scanline <FIRGB16>)combined.GetScanline(destY);

                            for (int x = 0; x < slice.Width; x++)
                            {
                                int destX = x + (int)left;

                                // Make sure it's not out of bounds
                                if (destY >= Height || destY >= Width)
                                {
                                    continue;
                                }
                                // Is the pixel in an overlapping Area
                                if (topY < realTop || destX < realLeft)
                                {
                                    MergePixel srcPixel  = new MergePixel(srcLine[x].red, srcLine[x].green, srcLine[x].blue, 0);
                                    MergePixel destPixel = new MergePixel(destLine[destX].red, destLine[destX].green, destLine[destX].blue, 0);

                                    destPixel = CalculatePixelWeight(overlapV, overlapH, realLeft, left, realTop, top, y, topY, x, srcPixel, destPixel);

                                    FIRGB16 dest = new FIRGB16();
                                    dest.red        = (ushort)destPixel.red;
                                    dest.green      = (ushort)destPixel.green;
                                    dest.blue       = (ushort)destPixel.blue;
                                    destLine[destX] = dest;
                                }
                                else
                                {
                                    destLine[destX] = srcLine[x];
                                }
                            }
                        }
                        break;

                    case FREE_IMAGE_TYPE.FIT_RGBA16:
                        for (int y = 0; y < slice.Height; y++)
                        {
                            int srcY  = (slice.Height - 1) - y;
                            int destY = (combined.Height - 1) - (srcY + (int)top);
                            int topY  = y + (int)top;
                            Scanline <FIRGBA16> srcLine  = (Scanline <FIRGBA16>)slice.GetScanline(y);
                            Scanline <FIRGBA16> destLine = (Scanline <FIRGBA16>)combined.GetScanline(destY);

                            for (int x = 0; x < slice.Width; x++)
                            {
                                int destX = x + (int)left;

                                // Make sure it's not out of bounds
                                if (destY >= Height || destY >= Width)
                                {
                                    continue;
                                }
                                // Is the pixel in an overlapping Area
                                if (topY < realTop || destX < realLeft)
                                {
                                    MergePixel srcPixel  = new MergePixel(srcLine[x].red, srcLine[x].green, srcLine[x].blue, srcLine[x].alpha);
                                    MergePixel destPixel = new MergePixel(destLine[destX].red, destLine[destX].green, destLine[destX].blue, destLine[destX].alpha);

                                    destPixel = CalculatePixelWeight(overlapV, overlapH, realLeft, left, realTop, top, y, topY, x, srcPixel, destPixel);

                                    FIRGBA16 dest = new FIRGBA16();
                                    dest.red        = (ushort)destPixel.red;
                                    dest.green      = (ushort)destPixel.green;
                                    dest.blue       = (ushort)destPixel.blue;
                                    dest.alpha      = (ushort)destPixel.alpha;
                                    destLine[destX] = dest;
                                }
                                else
                                {
                                    destLine[destX] = srcLine[x];
                                }
                            }
                        }
                        break;

                    case FREE_IMAGE_TYPE.FIT_RGBAF:
                        for (int y = 0; y < slice.Height; y++)
                        {
                            int srcY  = (slice.Height - 1) - y;
                            int destY = (combined.Height - 1) - (srcY + (int)top);
                            int topY  = y + (int)top;
                            Scanline <FIRGBAF> srcLine  = (Scanline <FIRGBAF>)slice.GetScanline(y);
                            Scanline <FIRGBAF> destLine = (Scanline <FIRGBAF>)combined.GetScanline(destY);

                            for (int x = 0; x < slice.Width; x++)
                            {
                                int destX = x + (int)left;

                                // Make sure it's not out of bounds
                                if (destY >= Height || destY >= Width)
                                {
                                    continue;
                                }
                                // Is the pixel in an overlapping Area
                                if (topY < realTop || destX < realLeft)
                                {
                                    MergePixel srcPixel  = new MergePixel(srcLine[x].red, srcLine[x].green, srcLine[x].blue, destLine[destX].alpha);
                                    MergePixel destPixel = new MergePixel(destLine[destX].red, destLine[destX].green, destLine[destX].blue, destLine[destX].alpha);

                                    destPixel = CalculatePixelWeight(overlapV, overlapH, realLeft, left, realTop, top, y, topY, x, srcPixel, destPixel);

                                    FIRGBAF dest = new FIRGBAF();
                                    dest.red        = (float)destPixel.red;
                                    dest.green      = (float)destPixel.green;
                                    dest.blue       = (float)destPixel.blue;
                                    dest.alpha      = (float)destPixel.alpha;
                                    destLine[destX] = dest;
                                }
                                else
                                {
                                    destLine[destX] = srcLine[x];
                                }
                            }
                        }
                        break;

                    case FREE_IMAGE_TYPE.FIT_RGBF:
                        for (int y = 0; y < slice.Height; y++)
                        {
                            int srcY  = (slice.Height - 1) - y;
                            int destY = (combined.Height - 1) - (srcY + (int)top);
                            int topY  = y + (int)top;
                            Scanline <FIRGBF> srcLine  = (Scanline <FIRGBF>)slice.GetScanline(y);
                            Scanline <FIRGBF> destLine = (Scanline <FIRGBF>)combined.GetScanline(destY);

                            for (int x = 0; x < slice.Width; x++)
                            {
                                int destX = x + (int)left;

                                // Make sure it's not out of bounds
                                if (destY >= Height || destY >= Width)
                                {
                                    continue;
                                }
                                // Is the pixel in an overlapping Area
                                if (topY < realTop || destX < realLeft)
                                {
                                    MergePixel srcPixel  = new MergePixel(srcLine[x].red, srcLine[x].green, srcLine[x].blue, 0);
                                    MergePixel destPixel = new MergePixel(destLine[destX].red, destLine[destX].green, destLine[destX].blue, 0);

                                    destPixel = CalculatePixelWeight(overlapV, overlapH, realLeft, left, realTop, top, y, topY, x, srcPixel, destPixel);

                                    FIRGBF dest = new FIRGBF();
                                    dest.red        = (float)destPixel.red;
                                    dest.green      = (float)destPixel.green;
                                    dest.blue       = (float)destPixel.blue;
                                    destLine[destX] = dest;
                                }
                                else
                                {
                                    destLine[destX] = srcLine[x];
                                }
                            }
                        }
                        break;
                    }
                    slice.Dispose();
                }
                catch (Exception ex)
                {
                    logger.Error(ex, "Error merging image files");
                    mergeSuccessful = false;
                }
            }
            try
            {
                if (mergeSuccessful)
                {
                    combined.Save(mergedFile);
                    combined.Dispose();
                    combined = null;
                    GC.Collect();
                    GC.WaitForPendingFinalizers();
                    File.Delete(tempFile);
                }
                else
                {
                    Log += DateTime.Now.ToLongTimeString() + " Merging frame " + frameNum + " failed.\n";
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Error writing combined file");
                mergeSuccessful = false;
            }

            return(mergeSuccessful);
        }