Пример #1
0
 public void DrawImage(FreeImageAlgorithmsBitmap dst, FreeImageAlgorithmsMatrix matrix,
                       int dstLeft, int dstTop, int dstWidth, int dstHeight,
                       int srcLeft, int srcTop, int srcWidth, int srcHeight,
                       RGBQUAD colour)
 {
     FreeImage.DrawImageFromSrcToDst(dst.Dib, this.Dib, matrix.Data,
                                     dstLeft, dstTop, dstWidth, dstHeight,
                                     srcLeft, srcTop, srcWidth, srcHeight,
                                     colour, 1);
 }
 public static extern uint ApplyColorMapping(FIBITMAP dib, RGBQUAD[] srccolors, RGBQUAD[] dstcolors, uint count, bool ignore_alpha, bool swap);
 public static extern uint SwapColors(FIBITMAP dib, ref RGBQUAD color_a, ref RGBQUAD color_b, bool ignore_alpha);
 public static unsafe extern bool SetBackgroundColor(FIBITMAP dib, RGBQUAD[] bkcolor);
Пример #5
0
 public void DrawImage(FreeImageAlgorithmsBitmap dst, Rectangle dstRect, RGBQUAD colour)
 {
     FreeImage.DrawImageToDst(dst.Dib, this.Dib, FIA_Matrix.Zero,
         dstRect.Left, dstRect.Top, dstRect.Width, dstRect.Height, colour, 1);
 }
Пример #6
0
        public bool DrawColourRect(Rectangle rect, RGBQUAD colour, int lineWidth)
        {
            FIARECT fiaRect = new FIARECT(rect);

            return FreeImage.DrawColourRect(this.Dib, fiaRect, colour, lineWidth);
        }
Пример #7
0
 internal static extern bool DrawImageToDst(FIBITMAP dst, FIBITMAP src, FIA_Matrix matrix,
                                            int dstLeft, int dstTop, int dstWidth, int dstHeight, RGBQUAD colour, int retain_background);
Пример #8
0
 public static extern FIBITMAP Composite(FIBITMAP fg, bool useFileBkg,
                                         [In, MarshalAs(UnmanagedType.LPStruct)] RGBQUAD appBkColor, FIBITMAP bg);
Пример #9
0
        public void FreeImage_SwapColors()
        {
            dib = iManager.GetBitmap(ImageType.Odd, ImageColorType.Type_08);
            Assert.IsFalse(dib.IsNull);

            RGBQUAD src = new RGBQUAD(Color.FromArgb(93, 119, 170));
            RGBQUAD dst = new RGBQUAD(Color.FromArgb(90, 130, 148));

            uint count = FreeImage.SwapColors(dib, ref src, ref dst, true);

            FreeImage.UnloadEx(ref dib);
        }
Пример #10
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;
        }
Пример #11
0
 private static extern uint SwapColorsWindows(FIBITMAP dib, ref RGBQUAD color_a, ref RGBQUAD color_b, bool ignore_alpha);
Пример #12
0
 private static extern FIBITMAP CompositeWindows(FIBITMAP fg, bool useFileBkg, ref RGBQUAD appBkColor, FIBITMAP bg);
Пример #13
0
 private static extern bool GetBackgroundColorWindows(FIBITMAP dib, out RGBQUAD bkcolor);
Пример #14
0
 private static extern bool SetPixelColorWindows(FIBITMAP dib, uint x, uint y, ref RGBQUAD value);
Пример #15
0
 private static extern bool GetPixelColorLinux(FIBITMAP dib, uint x, uint y, out RGBQUAD value);
 public static extern FIBITMAP Composite(FIBITMAP fg, bool useFileBkg, RGBQUAD[] appBkColor, FIBITMAP bg);
Пример #17
0
 public static extern bool SetPixelColor(FIBITMAP dib, uint x, uint y,
                                         [In, MarshalAs(UnmanagedType.LPStruct)] RGBQUAD value);
Пример #18
0
        private void FreeImage_ApplyColorMapping2(FIBITMAP dib)
        {
            Assert.IsFalse(dib.IsNull);

            Scanline<RGBQUAD> rgbqa = new Scanline<RGBQUAD>(dib, 0);

            RGBQUAD[] src = new RGBQUAD[1];
            RGBQUAD[] dst = new RGBQUAD[1];
            src[0] = rgbqa[0];
            dst[0].Color = src[0].Color == Color.White ? Color.Thistle : Color.White;

            uint count = FreeImage.ApplyColorMapping(dib, src, dst, 1, true, false); // Memory
            Assert.That(count > 0);

            FreeImage.UnloadEx(ref dib);
        }
Пример #19
0
 internal static extern bool DrawColourRect(FIBITMAP src, FIARECT rect,
                                            RGBQUAD colour, int line_width);
Пример #20
0
        public void RGBQUAD()
        {
            RGBQUAD rgbq = new RGBQUAD();
            Assert.AreEqual(0, rgbq.rgbBlue);
            Assert.AreEqual(0, rgbq.rgbGreen);
            Assert.AreEqual(0, rgbq.rgbRed);
            Assert.AreEqual(0, rgbq.rgbReserved);

            rgbq = new RGBQUAD(Color.Chartreuse);
            Assert.That(EqualColors(Color.Chartreuse, rgbq.Color));

            rgbq = new RGBQUAD(Color.FromArgb(133, 83, 95, 173));
            Assert.AreEqual(173, rgbq.rgbBlue);
            Assert.AreEqual(95, rgbq.rgbGreen);
            Assert.AreEqual(83, rgbq.rgbRed);
            Assert.AreEqual(133, rgbq.rgbReserved);

            rgbq.Color = Color.Crimson;
            Assert.That(EqualColors(Color.Crimson, rgbq.Color));

            rgbq.Color = Color.MidnightBlue;
            Assert.That(EqualColors(Color.MidnightBlue, rgbq.Color));

            rgbq.Color = Color.White;
            Assert.AreEqual(255, rgbq.rgbBlue);
            Assert.AreEqual(255, rgbq.rgbGreen);
            Assert.AreEqual(255, rgbq.rgbRed);
            Assert.AreEqual(255, rgbq.rgbReserved);

            rgbq.Color = Color.Black;
            Assert.AreEqual(0, rgbq.rgbBlue);
            Assert.AreEqual(0, rgbq.rgbGreen);
            Assert.AreEqual(0, rgbq.rgbRed);
            Assert.AreEqual(255, rgbq.rgbReserved);

            rgbq = Color.DarkGoldenrod;
            Color color = rgbq;
            Assert.That(EqualColors(Color.DarkGoldenrod, color));
        }
Пример #21
0
        public void AffineTransform(FreeImageAlgorithmsMatrix matrix, RGBQUAD colour)
        {
            FIBITMAP tmp_dib = FreeImage.AffineTransform(this.Dib, (int) this.Width, (int) this.Height, matrix.Data, colour, 1);

            this.ReplaceDib(tmp_dib);
        }
Пример #22
0
        public void FreeImage_GetUniqueColors()
        {
            Palette palette;

            //
            // 1bpp
            //

            dib = FreeImage.Allocate(10, 1, 1, 0, 0, 0);
            Assert.IsFalse(dib.IsNull);

            palette = new Palette(dib);
            palette[0] = Color.FromArgb(43, 255, 255, 255);
            palette[1] = Color.FromArgb(222, 0, 0, 0);

            Scanline<FI1BIT> sl1bit = new Scanline<FI1BIT>(dib, 0);
            for (int x = 0; x < sl1bit.Length; x++)
            {
                sl1bit[x] = 0;
            }

            Assert.AreEqual(1, FreeImage.GetUniqueColors(dib));

            sl1bit[5] = 1;
            Assert.AreEqual(2, FreeImage.GetUniqueColors(dib));

            palette[1] = Color.FromArgb(222, 255, 255, 255);
            Assert.AreEqual(1, FreeImage.GetUniqueColors(dib));

            sl1bit[5] = 0;
            Assert.AreEqual(1, FreeImage.GetUniqueColors(dib));

            FreeImage.UnloadEx(ref dib);

            //
            // 4bpp
            //

            dib = FreeImage.Allocate(10, 1, 4, 0, 0, 0);
            Assert.IsFalse(dib.IsNull);

            palette = new Palette(dib);
            palette[0] = new RGBQUAD(Color.FromArgb(43, 255, 255, 255));
            palette[1] = new RGBQUAD(Color.FromArgb(222, 51, 2, 211));
            palette[2] = new RGBQUAD(Color.FromArgb(29, 25, 31, 52));
            palette[3] = new RGBQUAD(Color.FromArgb(173, 142, 61, 178));
            palette[4] = new RGBQUAD(Color.FromArgb(143, 41, 67, 199));
            palette[5] = new RGBQUAD(Color.FromArgb(2, 0, 2, 221));

            Scanline<FI4BIT> sl4bit = new Scanline<FI4BIT>(dib, 0);

            for (int x = 0; x < sl4bit.Length; x++)
            {
                sl4bit[x] = 0;
            }

            Assert.AreEqual(1, FreeImage.GetUniqueColors(dib));

            sl4bit[1] = 1;
            Assert.AreEqual(2, FreeImage.GetUniqueColors(dib));

            sl4bit[2] = 1;
            Assert.AreEqual(2, FreeImage.GetUniqueColors(dib));

            sl4bit[3] = 2;
            Assert.AreEqual(3, FreeImage.GetUniqueColors(dib));

            sl4bit[4] = 3;
            Assert.AreEqual(4, FreeImage.GetUniqueColors(dib));

            sl4bit[5] = 4;
            Assert.AreEqual(5, FreeImage.GetUniqueColors(dib));

            sl4bit[6] = 5;
            Assert.AreEqual(6, FreeImage.GetUniqueColors(dib));

            sl4bit[7] = 6;
            Assert.AreEqual(7, FreeImage.GetUniqueColors(dib));

            sl4bit[8] = 7;
            Assert.AreEqual(7, FreeImage.GetUniqueColors(dib));

            sl4bit[9] = 7;
            Assert.AreEqual(7, FreeImage.GetUniqueColors(dib));

            FreeImage.UnloadEx(ref dib);

            //
            // 8bpp
            //

            dib = FreeImage.Allocate(10, 1, 8, 0, 0, 0);
            Assert.IsFalse(dib.IsNull);

            palette = new Palette(dib);
            palette[0] = new RGBQUAD(Color.FromArgb(43, 255, 255, 255));
            palette[1] = new RGBQUAD(Color.FromArgb(222, 51, 2, 211));
            palette[2] = new RGBQUAD(Color.FromArgb(29, 25, 31, 52));
            palette[3] = new RGBQUAD(Color.FromArgb(173, 142, 61, 178));
            palette[4] = new RGBQUAD(Color.FromArgb(143, 41, 67, 199));
            palette[5] = new RGBQUAD(Color.FromArgb(2, 0, 2, 221));

            Scanline<byte> sl8bit = new Scanline<byte>(dib, 0);

            for (int x = 0; x < sl8bit.Length; x++)
            {
                sl8bit[x] = 0;
            }

            Assert.AreEqual(1, FreeImage.GetUniqueColors(dib));

            sl8bit[1] = 1;
            Assert.AreEqual(2, FreeImage.GetUniqueColors(dib));

            sl8bit[2] = 2;
            Assert.AreEqual(3, FreeImage.GetUniqueColors(dib));

            sl8bit[3] = 3;
            Assert.AreEqual(4, FreeImage.GetUniqueColors(dib));

            sl8bit[4] = 4;
            Assert.AreEqual(5, FreeImage.GetUniqueColors(dib));

            sl8bit[5] = 6;
            Assert.AreEqual(6, FreeImage.GetUniqueColors(dib));

            sl8bit[5] = 7;
            Assert.AreEqual(6, FreeImage.GetUniqueColors(dib));

            sl8bit[5] = 8;
            Assert.AreEqual(6, FreeImage.GetUniqueColors(dib));

            FreeImage.UnloadEx(ref dib);
        }
Пример #23
0
        public bool DrawColourSolidRect(Rectangle rect, RGBQUAD colour)
        {
            FIARECT fiaRect = new FIARECT(rect);

            return FreeImage.DrawColourSolidRect(this.Dib, fiaRect, colour);
        }
Пример #24
0
        public void MetadataTag()
        {
            FITAG tag;
            MetadataTag metaTag;

            Random rand = new Random();
            dib = iManager.GetBitmap(ImageType.Metadata, ImageColorType.Type_01_Dither);
            Assert.IsFalse(dib.IsNull);

            Assert.That(FreeImage.GetMetadataCount(FREE_IMAGE_MDMODEL.FIMD_EXIF_MAIN, dib) > 0);

            FIMETADATA mData = FreeImage.FindFirstMetadata(FREE_IMAGE_MDMODEL.FIMD_EXIF_MAIN, dib, out tag);
            Assert.IsFalse(tag.IsNull);
            Assert.IsFalse(mData.IsNull);

            //
            // Constructors
            //

            metaTag = new MetadataTag(tag, dib);
            Assert.That(metaTag.Model == FREE_IMAGE_MDMODEL.FIMD_EXIF_MAIN);

            metaTag = new MetadataTag(tag, FREE_IMAGE_MDMODEL.FIMD_EXIF_MAIN);
            Assert.That(metaTag.Model == FREE_IMAGE_MDMODEL.FIMD_EXIF_MAIN);

            //
            // Properties
            //

            metaTag.ID = ushort.MinValue;
            Assert.That(metaTag.ID == ushort.MinValue);

            metaTag.ID = ushort.MaxValue;
            Assert.That(metaTag.ID == ushort.MaxValue);

            metaTag.ID = ushort.MaxValue / 2;
            Assert.That(metaTag.ID == ushort.MaxValue / 2);

            metaTag.Description = "";
            Assert.That(metaTag.Description == "");

            metaTag.Description = "A";
            Assert.That(metaTag.Description == "A");

            metaTag.Description = "ABCDEFG";
            Assert.That(metaTag.Description == "ABCDEFG");

            metaTag.Key = "";
            Assert.That(metaTag.Key == "");

            metaTag.Key = "A";
            Assert.That(metaTag.Key == "A");

            metaTag.Key = "ABCDEFG";
            Assert.That(metaTag.Key == "ABCDEFG");

            //
            // SetValue
            //

            try
            {
                metaTag.SetValue(null, FREE_IMAGE_MDTYPE.FIDT_ASCII);
                Assert.Fail();
            }
            catch
            {
            }

            //
            // FREE_IMAGE_MDTYPE.FIDT_ASCII
            //

            string testString = "";

            Assert.IsTrue(metaTag.SetValue(testString, FREE_IMAGE_MDTYPE.FIDT_ASCII));
            Assert.IsNotNull(metaTag.Value);
            Assert.That(((string)metaTag.Value).Length == 0);

            testString = "X";

            Assert.IsTrue(metaTag.SetValue(testString, FREE_IMAGE_MDTYPE.FIDT_ASCII));
            Assert.IsNotNull(metaTag.Value);
            Assert.That(((string)metaTag.Value).Length == testString.Length);
            Assert.That(((string)metaTag.Value) == testString);

            testString = "TEST-STRING";

            Assert.IsTrue(metaTag.SetValue(testString, FREE_IMAGE_MDTYPE.FIDT_ASCII));
            Assert.IsNotNull(metaTag.Value);
            Assert.That(((string)metaTag.Value).Length == testString.Length);
            Assert.That(((string)metaTag.Value) == testString);

            //
            // FREE_IMAGE_MDTYPE.FIDT_BYTE
            //

            byte testByte;
            byte[] testByteArray;

            Assert.IsTrue(metaTag.SetValue(byte.MinValue, FREE_IMAGE_MDTYPE.FIDT_BYTE));
            Assert.IsNotNull(metaTag.Value);
            Assert.That(((byte[])metaTag.Value).Length == 1);
            Assert.That(((byte[])metaTag.Value)[0] == byte.MinValue);

            Assert.IsTrue(metaTag.SetValue(byte.MaxValue, FREE_IMAGE_MDTYPE.FIDT_BYTE));
            Assert.IsNotNull(metaTag.Value);
            Assert.That(((byte[])metaTag.Value).Length == 1);
            Assert.That(((byte[])metaTag.Value)[0] == byte.MaxValue);

            for (int i = 0; i < 10; i++)
            {
                testByte = (byte)rand.Next(byte.MinValue, byte.MaxValue);
                testByteArray = new byte[rand.Next(0, 31)];

                for (int j = 0; j < testByteArray.Length; j++)
                    testByteArray[j] = (byte)rand.Next();

                Assert.IsTrue(metaTag.SetValue(testByte, FREE_IMAGE_MDTYPE.FIDT_BYTE));
                Assert.IsNotNull(metaTag.Value);
                Assert.That(((byte[])metaTag.Value).Length == 1);
                Assert.That(metaTag.Count == 1);
                Assert.That(metaTag.Length == 1);
                Assert.That(metaTag.Type == FREE_IMAGE_MDTYPE.FIDT_BYTE);
                Assert.That(((byte[])metaTag.Value)[0] == testByte);

                Assert.IsTrue(metaTag.SetValue(testByteArray, FREE_IMAGE_MDTYPE.FIDT_BYTE));
                Assert.IsNotNull(metaTag.Value);
                Assert.That(((byte[])metaTag.Value).Length == testByteArray.Length);
                Assert.That(metaTag.Count == testByteArray.Length);
                Assert.That(metaTag.Length == testByteArray.Length * 1);

                byte[] value = (byte[])metaTag.Value;

                for (int j = 0; j < value.Length; j++)
                    Assert.That(testByteArray[j] == value[j]);
            }

            //
            // FREE_IMAGE_MDTYPE.FIDT_DOUBLE
            //

            double testDouble;
            double[] testDoubleArray;

            Assert.IsTrue(metaTag.SetValue(double.MinValue, FREE_IMAGE_MDTYPE.FIDT_DOUBLE));
            Assert.IsNotNull(metaTag.Value);
            Assert.That(((double[])metaTag.Value).Length == 1);
            Assert.That(((double[])metaTag.Value)[0] == double.MinValue);

            Assert.IsTrue(metaTag.SetValue(double.MaxValue, FREE_IMAGE_MDTYPE.FIDT_DOUBLE));
            Assert.IsNotNull(metaTag.Value);
            Assert.That(((double[])metaTag.Value).Length == 1);
            Assert.That(((double[])metaTag.Value)[0] == double.MaxValue);

            for (int i = 0; i < 10; i++)
            {
                testDouble = (double)rand.NextDouble();
                testDoubleArray = new double[rand.Next(0, 31)];

                for (int j = 0; j < testDoubleArray.Length; j++)
                    testDoubleArray[j] = rand.NextDouble();

                Assert.IsTrue(metaTag.SetValue(testDouble, FREE_IMAGE_MDTYPE.FIDT_DOUBLE));
                Assert.IsNotNull(metaTag.Value);
                Assert.That(((double[])metaTag.Value).Length == 1);
                Assert.That(metaTag.Count == 1);
                Assert.That(metaTag.Length == 8);
                Assert.That(metaTag.Type == FREE_IMAGE_MDTYPE.FIDT_DOUBLE);
                Assert.That(((double[])metaTag.Value)[0] == testDouble);

                Assert.IsTrue(metaTag.SetValue(testDoubleArray, FREE_IMAGE_MDTYPE.FIDT_DOUBLE));
                Assert.IsNotNull(metaTag.Value);
                Assert.That(((double[])metaTag.Value).Length == testDoubleArray.Length);
                Assert.That(metaTag.Count == testDoubleArray.Length);
                Assert.That(metaTag.Length == testDoubleArray.Length * 8);

                double[] value = (double[])metaTag.Value;

                for (int j = 0; j < value.Length; j++)
                    Assert.That(testDoubleArray[j] == value[j]);
            }

            //
            // FREE_IMAGE_MDTYPE.FIDT_FLOAT
            //

            float testfloat;
            float[] testFloatArray;

            Assert.IsTrue(metaTag.SetValue(float.MinValue, FREE_IMAGE_MDTYPE.FIDT_FLOAT));
            Assert.IsNotNull(metaTag.Value);
            Assert.That(((float[])metaTag.Value).Length == 1);
            Assert.That(((float[])metaTag.Value)[0] == float.MinValue);

            Assert.IsTrue(metaTag.SetValue(float.MaxValue, FREE_IMAGE_MDTYPE.FIDT_FLOAT));
            Assert.IsNotNull(metaTag.Value);
            Assert.That(((float[])metaTag.Value).Length == 1);
            Assert.That(((float[])metaTag.Value)[0] == float.MaxValue);

            for (int i = 0; i < 10; i++)
            {
                testfloat = (float)rand.NextDouble();
                testFloatArray = new float[rand.Next(0, 31)];

                for (int j = 0; j < testFloatArray.Length; j++)
                    testFloatArray[j] = (float)rand.NextDouble();

                Assert.IsTrue(metaTag.SetValue(testfloat, FREE_IMAGE_MDTYPE.FIDT_FLOAT));
                Assert.IsNotNull(metaTag.Value);
                Assert.That(((float[])metaTag.Value).Length == 1);
                Assert.That(metaTag.Count == 1);
                Assert.That(metaTag.Length == 4);
                Assert.That(metaTag.Type == FREE_IMAGE_MDTYPE.FIDT_FLOAT);
                Assert.That(((float[])metaTag.Value)[0] == testfloat);

                Assert.IsTrue(metaTag.SetValue(testFloatArray, FREE_IMAGE_MDTYPE.FIDT_FLOAT));
                Assert.IsNotNull(metaTag.Value);
                Assert.That(((float[])metaTag.Value).Length == testFloatArray.Length);
                Assert.That(metaTag.Count == testFloatArray.Length);
                Assert.That(metaTag.Length == testFloatArray.Length * 4);

                float[] value = (float[])metaTag.Value;

                for (int j = 0; j < value.Length; j++)
                    Assert.That(testFloatArray[j] == value[j]);
            }

            //
            // FREE_IMAGE_MDTYPE.FIDT_IFD
            //

            uint testUint;
            uint[] testUintArray;

            Assert.IsTrue(metaTag.SetValue(uint.MinValue, FREE_IMAGE_MDTYPE.FIDT_IFD));
            Assert.IsNotNull(metaTag.Value);
            Assert.That(((uint[])metaTag.Value).Length == 1);
            Assert.That(((uint[])metaTag.Value)[0] == uint.MinValue);

            Assert.IsTrue(metaTag.SetValue(uint.MaxValue, FREE_IMAGE_MDTYPE.FIDT_IFD));
            Assert.IsNotNull(metaTag.Value);
            Assert.That(((uint[])metaTag.Value).Length == 1);
            Assert.That(((uint[])metaTag.Value)[0] == uint.MaxValue);

            for (int i = 0; i < 10; i++)
            {
                testUint = (uint)rand.NextDouble();
                testUintArray = new uint[rand.Next(0, 31)];

                for (int j = 0; j < testUintArray.Length; j++)
                    testUintArray[j] = (uint)rand.Next();

                Assert.IsTrue(metaTag.SetValue(testUint, FREE_IMAGE_MDTYPE.FIDT_IFD));
                Assert.IsNotNull(metaTag.Value);
                Assert.That(((uint[])metaTag.Value).Length == 1);
                Assert.That(metaTag.Count == 1);
                Assert.That(metaTag.Length == 4);
                Assert.That(metaTag.Type == FREE_IMAGE_MDTYPE.FIDT_IFD);
                Assert.That(((uint[])metaTag.Value)[0] == testUint);

                Assert.IsTrue(metaTag.SetValue(testUintArray, FREE_IMAGE_MDTYPE.FIDT_IFD));
                Assert.IsNotNull(metaTag.Value);
                Assert.That(((uint[])metaTag.Value).Length == testUintArray.Length);
                Assert.That(metaTag.Count == testUintArray.Length);
                Assert.That(metaTag.Length == testUintArray.Length * 4);

                uint[] value = (uint[])metaTag.Value;

                for (int j = 0; j < value.Length; j++)
                    Assert.That(testUintArray[j] == value[j]);
            }

            //
            // FREE_IMAGE_MDTYPE.FIDT_LONG
            //

            Assert.IsTrue(metaTag.SetValue(uint.MinValue, FREE_IMAGE_MDTYPE.FIDT_LONG));
            Assert.IsNotNull(metaTag.Value);
            Assert.That(((uint[])metaTag.Value).Length == 1);
            Assert.That(((uint[])metaTag.Value)[0] == uint.MinValue);

            Assert.IsTrue(metaTag.SetValue(uint.MaxValue, FREE_IMAGE_MDTYPE.FIDT_LONG));
            Assert.IsNotNull(metaTag.Value);
            Assert.That(((uint[])metaTag.Value).Length == 1);
            Assert.That(((uint[])metaTag.Value)[0] == uint.MaxValue);

            for (int i = 0; i < 10; i++)
            {
                testUint = (uint)rand.NextDouble();
                testUintArray = new uint[rand.Next(0, 31)];

                for (int j = 0; j < testUintArray.Length; j++)
                    testUintArray[j] = (uint)rand.Next();

                Assert.IsTrue(metaTag.SetValue(testUint, FREE_IMAGE_MDTYPE.FIDT_LONG));
                Assert.IsNotNull(metaTag.Value);
                Assert.That(((uint[])metaTag.Value).Length == 1);
                Assert.That(metaTag.Count == 1);
                Assert.That(metaTag.Length == 4);
                Assert.That(metaTag.Type == FREE_IMAGE_MDTYPE.FIDT_LONG);
                Assert.That(((uint[])metaTag.Value)[0] == testUint);

                Assert.IsTrue(metaTag.SetValue(testUintArray, FREE_IMAGE_MDTYPE.FIDT_LONG));
                Assert.IsNotNull(metaTag.Value);
                Assert.That(((uint[])metaTag.Value).Length == testUintArray.Length);
                Assert.That(metaTag.Count == testUintArray.Length);
                Assert.That(metaTag.Length == testUintArray.Length * 4);

                uint[] value = (uint[])metaTag.Value;

                for (int j = 0; j < value.Length; j++)
                    Assert.That(testUintArray[j] == value[j]);
            }

            //
            // FREE_IMAGE_MDTYPE.FIDT_NOTYPE
            //

            try
            {
                metaTag.SetValue(new object(), FREE_IMAGE_MDTYPE.FIDT_NOTYPE);
                Assert.Fail();
            }
            catch (NotSupportedException)
            {
            }

            //
            // FREE_IMAGE_MDTYPE.FIDT_PALETTE
            //

            RGBQUAD testRGBQUAD;
            RGBQUAD[] testRGBQUADArray;

            for (int i = 0; i < 10; i++)
            {
                testRGBQUAD = new RGBQUAD(Color.FromArgb(rand.Next()));
                testRGBQUADArray = new RGBQUAD[rand.Next(0, 31)];

                for (int j = 0; j < testRGBQUADArray.Length; j++)
                    testRGBQUADArray[j] = new RGBQUAD(Color.FromArgb(rand.Next()));

                Assert.IsTrue(metaTag.SetValue(testRGBQUAD, FREE_IMAGE_MDTYPE.FIDT_PALETTE));
                Assert.IsNotNull(metaTag.Value);
                Assert.That(((RGBQUAD[])metaTag.Value).Length == 1);
                Assert.That(metaTag.Count == 1);
                Assert.That(metaTag.Length == 4);
                Assert.That(metaTag.Type == FREE_IMAGE_MDTYPE.FIDT_PALETTE);
                Assert.That(((RGBQUAD[])metaTag.Value)[0] == testRGBQUAD);

                Assert.IsTrue(metaTag.SetValue(testRGBQUADArray, FREE_IMAGE_MDTYPE.FIDT_PALETTE));
                Assert.IsNotNull(metaTag.Value);
                Assert.That(((RGBQUAD[])metaTag.Value).Length == testRGBQUADArray.Length);
                Assert.That(metaTag.Count == testRGBQUADArray.Length);
                Assert.That(metaTag.Length == testRGBQUADArray.Length * 4);

                RGBQUAD[] value = (RGBQUAD[])metaTag.Value;

                for (int j = 0; j < value.Length; j++)
                    Assert.That(testRGBQUADArray[j] == value[j]);
            }

            //
            // FREE_IMAGE_MDTYPE.FIDT_RATIONAL
            //

            FIURational testFIURational;
            FIURational[] testFIURationalArray;

            for (int i = 0; i < 10; i++)
            {
                testFIURational = new FIURational((uint)rand.Next(), (uint)rand.Next());
                testFIURationalArray = new FIURational[rand.Next(0, 31)];

                for (int j = 0; j < testFIURationalArray.Length; j++)
                    testFIURationalArray[j] = new FIURational((uint)rand.Next(), (uint)rand.Next());

                Assert.IsTrue(metaTag.SetValue(testFIURational, FREE_IMAGE_MDTYPE.FIDT_RATIONAL));
                Assert.IsNotNull(metaTag.Value);
                Assert.That(((FIURational[])metaTag.Value).Length == 1);
                Assert.That(metaTag.Count == 1);
                Assert.That(metaTag.Length == 8);
                Assert.That(metaTag.Type == FREE_IMAGE_MDTYPE.FIDT_RATIONAL);
                Assert.That(((FIURational[])metaTag.Value)[0] == testFIURational);

                Assert.IsTrue(metaTag.SetValue(testFIURationalArray, FREE_IMAGE_MDTYPE.FIDT_RATIONAL));
                Assert.IsNotNull(metaTag.Value);
                Assert.That(((FIURational[])metaTag.Value).Length == testFIURationalArray.Length);
                Assert.That(metaTag.Count == testFIURationalArray.Length);
                Assert.That(metaTag.Length == testFIURationalArray.Length * 8);

                FIURational[] value = (FIURational[])metaTag.Value;

                for (int j = 0; j < value.Length; j++)
                    Assert.That(testFIURationalArray[j] == value[j]);
            }

            //
            // FREE_IMAGE_MDTYPE.FIDT_SBYTE
            //

            sbyte testSByte;
            sbyte[] testSByteArray;

            Assert.IsTrue(metaTag.SetValue(sbyte.MinValue, FREE_IMAGE_MDTYPE.FIDT_SBYTE));
            Assert.IsNotNull(metaTag.Value);
            Assert.That(((sbyte[])metaTag.Value).Length == 1);
            Assert.That(((sbyte[])metaTag.Value)[0] == sbyte.MinValue);

            Assert.IsTrue(metaTag.SetValue(sbyte.MaxValue, FREE_IMAGE_MDTYPE.FIDT_SBYTE));
            Assert.IsNotNull(metaTag.Value);
            Assert.That(((sbyte[])metaTag.Value).Length == 1);
            Assert.That(((sbyte[])metaTag.Value)[0] == sbyte.MaxValue);

            for (int i = 0; i < 10; i++)
            {
                testSByte = (sbyte)rand.Next(sbyte.MinValue, sbyte.MaxValue);
                testSByteArray = new sbyte[rand.Next(0, 31)];

                for (int j = 0; j < testSByteArray.Length; j++)
                    testSByteArray[j] = (sbyte)rand.Next();

                Assert.IsTrue(metaTag.SetValue(testSByte, FREE_IMAGE_MDTYPE.FIDT_SBYTE));
                Assert.IsNotNull(metaTag.Value);
                Assert.That(((sbyte[])metaTag.Value).Length == 1);
                Assert.That(metaTag.Count == 1);
                Assert.That(metaTag.Length == 1);
                Assert.That(metaTag.Type == FREE_IMAGE_MDTYPE.FIDT_SBYTE);
                Assert.That(((sbyte[])metaTag.Value)[0] == testSByte);

                Assert.IsTrue(metaTag.SetValue(testSByteArray, FREE_IMAGE_MDTYPE.FIDT_SBYTE));
                Assert.IsNotNull(metaTag.Value);
                Assert.That(((sbyte[])metaTag.Value).Length == testSByteArray.Length);
                Assert.That(metaTag.Count == testSByteArray.Length);
                Assert.That(metaTag.Length == testSByteArray.Length * 1);

                sbyte[] value = (sbyte[])metaTag.Value;

                for (int j = 0; j < value.Length; j++)
                    Assert.That(testSByteArray[j] == value[j]);
            }

            //
            // FREE_IMAGE_MDTYPE.FIDT_SHORT
            //

            ushort testUShort;
            ushort[] testUShortArray;

            Assert.IsTrue(metaTag.SetValue(ushort.MinValue, FREE_IMAGE_MDTYPE.FIDT_SHORT));
            Assert.IsNotNull(metaTag.Value);
            Assert.That(((ushort[])metaTag.Value).Length == 1);
            Assert.That(((ushort[])metaTag.Value)[0] == ushort.MinValue);

            Assert.IsTrue(metaTag.SetValue(ushort.MaxValue, FREE_IMAGE_MDTYPE.FIDT_SHORT));
            Assert.IsNotNull(metaTag.Value);
            Assert.That(((ushort[])metaTag.Value).Length == 1);
            Assert.That(((ushort[])metaTag.Value)[0] == ushort.MaxValue);

            for (int i = 0; i < 10; i++)
            {
                testUShort = (ushort)rand.Next(ushort.MinValue, sbyte.MaxValue);
                testUShortArray = new ushort[rand.Next(0, 31)];

                for (int j = 0; j < testUShortArray.Length; j++)
                    testUShortArray[j] = (ushort)rand.Next();

                Assert.IsTrue(metaTag.SetValue(testUShort, FREE_IMAGE_MDTYPE.FIDT_SHORT));
                Assert.IsNotNull(metaTag.Value);
                Assert.That(((ushort[])metaTag.Value).Length == 1);
                Assert.That(metaTag.Count == 1);
                Assert.That(metaTag.Length == 2);
                Assert.That(metaTag.Type == FREE_IMAGE_MDTYPE.FIDT_SHORT);
                Assert.That(((ushort[])metaTag.Value)[0] == testUShort);

                Assert.IsTrue(metaTag.SetValue(testUShortArray, FREE_IMAGE_MDTYPE.FIDT_SHORT));
                Assert.IsNotNull(metaTag.Value);
                Assert.That(((ushort[])metaTag.Value).Length == testUShortArray.Length);
                Assert.That(metaTag.Count == testUShortArray.Length);
                Assert.That(metaTag.Length == testUShortArray.Length * 2);

                ushort[] value = (ushort[])metaTag.Value;

                for (int j = 0; j < value.Length; j++)
                    Assert.That(testUShortArray[j] == value[j]);
            }

            //
            // FREE_IMAGE_MDTYPE.FIDT_SLONG
            //

            int testInt;
            int[] testIntArray;

            Assert.IsTrue(metaTag.SetValue(int.MinValue, FREE_IMAGE_MDTYPE.FIDT_SLONG));
            Assert.IsNotNull(metaTag.Value);
            Assert.That(((int[])metaTag.Value).Length == 1);
            Assert.That(((int[])metaTag.Value)[0] == int.MinValue);

            Assert.IsTrue(metaTag.SetValue(int.MaxValue, FREE_IMAGE_MDTYPE.FIDT_SLONG));
            Assert.IsNotNull(metaTag.Value);
            Assert.That(((int[])metaTag.Value).Length == 1);
            Assert.That(((int[])metaTag.Value)[0] == int.MaxValue);

            for (int i = 0; i < 10; i++)
            {
                testInt = (int)rand.NextDouble();
                testIntArray = new int[rand.Next(0, 31)];

                for (int j = 0; j < testIntArray.Length; j++)
                    testIntArray[j] = rand.Next();

                Assert.IsTrue(metaTag.SetValue(testInt, FREE_IMAGE_MDTYPE.FIDT_SLONG));
                Assert.IsNotNull(metaTag.Value);
                Assert.That(((int[])metaTag.Value).Length == 1);
                Assert.That(metaTag.Count == 1);
                Assert.That(metaTag.Length == 4);
                Assert.That(metaTag.Type == FREE_IMAGE_MDTYPE.FIDT_SLONG);
                Assert.That(((int[])metaTag.Value)[0] == testInt);

                Assert.IsTrue(metaTag.SetValue(testIntArray, FREE_IMAGE_MDTYPE.FIDT_SLONG));
                Assert.IsNotNull(metaTag.Value);
                Assert.That(((int[])metaTag.Value).Length == testIntArray.Length);
                Assert.That(metaTag.Count == testIntArray.Length);
                Assert.That(metaTag.Length == testIntArray.Length * 4);

                int[] value = (int[])metaTag.Value;

                for (int j = 0; j < value.Length; j++)
                    Assert.That(testIntArray[j] == value[j]);
            }

            //
            // FREE_IMAGE_MDTYPE.FIDT_SRATIONAL
            //

            FIRational testFIRational;
            FIRational[] testFIRationalArray;

            for (int i = 0; i < 10; i++)
            {
                testFIRational = new FIRational(rand.Next(), rand.Next());
                testFIRationalArray = new FIRational[rand.Next(0, 31)];

                for (int j = 0; j < testFIRationalArray.Length; j++)
                    testFIRationalArray[j] = new FIRational(rand.Next(), rand.Next());

                Assert.IsTrue(metaTag.SetValue(testFIRational, FREE_IMAGE_MDTYPE.FIDT_SRATIONAL));
                Assert.IsNotNull(metaTag.Value);
                Assert.That(((FIRational[])metaTag.Value).Length == 1);
                Assert.That(metaTag.Count == 1);
                Assert.That(metaTag.Length == 8);
                Assert.That(metaTag.Type == FREE_IMAGE_MDTYPE.FIDT_SRATIONAL);
                Assert.That(((FIRational[])metaTag.Value)[0] == testFIRational);

                Assert.IsTrue(metaTag.SetValue(testFIRationalArray, FREE_IMAGE_MDTYPE.FIDT_SRATIONAL));
                Assert.IsNotNull(metaTag.Value);
                Assert.That(((FIRational[])metaTag.Value).Length == testFIRationalArray.Length);
                Assert.That(metaTag.Count == testFIRationalArray.Length);
                Assert.That(metaTag.Length == testFIRationalArray.Length * 8);

                FIRational[] value = (FIRational[])metaTag.Value;

                for (int j = 0; j < value.Length; j++)
                    Assert.That(testFIRationalArray[j] == value[j]);
            }

            //
            // FREE_IMAGE_MDTYPE.FIDT_SSHORT
            //

            short testShort;
            short[] testShortArray;

            Assert.IsTrue(metaTag.SetValue(short.MinValue, FREE_IMAGE_MDTYPE.FIDT_SSHORT));
            Assert.IsNotNull(metaTag.Value);
            Assert.That(((short[])metaTag.Value).Length == 1);
            Assert.That(((short[])metaTag.Value)[0] == short.MinValue);

            Assert.IsTrue(metaTag.SetValue(short.MaxValue, FREE_IMAGE_MDTYPE.FIDT_SSHORT));
            Assert.IsNotNull(metaTag.Value);
            Assert.That(((short[])metaTag.Value).Length == 1);
            Assert.That(((short[])metaTag.Value)[0] == short.MaxValue);

            for (int i = 0; i < 10; i++)
            {
                testShort = (short)rand.Next(short.MinValue, short.MaxValue);
                testShortArray = new short[rand.Next(0, 31)];

                for (int j = 0; j < testShortArray.Length; j++)
                    testShortArray[j] = (short)rand.Next();

                Assert.IsTrue(metaTag.SetValue(testShort, FREE_IMAGE_MDTYPE.FIDT_SSHORT));
                Assert.IsNotNull(metaTag.Value);
                Assert.That(((short[])metaTag.Value).Length == 1);
                Assert.That(metaTag.Count == 1);
                Assert.That(metaTag.Length == 2);
                Assert.That(metaTag.Type == FREE_IMAGE_MDTYPE.FIDT_SSHORT);
                Assert.That(((short[])metaTag.Value)[0] == testShort);

                Assert.IsTrue(metaTag.SetValue(testShortArray, FREE_IMAGE_MDTYPE.FIDT_SSHORT));
                Assert.IsNotNull(metaTag.Value);
                Assert.That(((short[])metaTag.Value).Length == testShortArray.Length);
                Assert.That(metaTag.Count == testShortArray.Length);
                Assert.That(metaTag.Length == testShortArray.Length * 2);

                short[] value = (short[])metaTag.Value;

                for (int j = 0; j < value.Length; j++)
                    Assert.That(testShortArray[j] == value[j]);
            }

            //
            // FREE_IMAGE_MDTYPE.FIDT_UNDEFINED
            //

            Assert.IsTrue(metaTag.SetValue(byte.MinValue, FREE_IMAGE_MDTYPE.FIDT_UNDEFINED));
            Assert.IsNotNull(metaTag.Value);
            Assert.That(((byte[])metaTag.Value).Length == 1);
            Assert.That(((byte[])metaTag.Value)[0] == byte.MinValue);

            Assert.IsTrue(metaTag.SetValue(byte.MaxValue, FREE_IMAGE_MDTYPE.FIDT_UNDEFINED));
            Assert.IsNotNull(metaTag.Value);
            Assert.That(((byte[])metaTag.Value).Length == 1);
            Assert.That(((byte[])metaTag.Value)[0] == byte.MaxValue);

            for (int i = 0; i < 10; i++)
            {
                testByte = (byte)rand.Next(byte.MinValue, byte.MaxValue);
                testByteArray = new byte[rand.Next(0, 31)];

                for (int j = 0; j < testByteArray.Length; j++)
                    testByteArray[j] = (byte)rand.Next();

                Assert.IsTrue(metaTag.SetValue(testByte, FREE_IMAGE_MDTYPE.FIDT_UNDEFINED));
                Assert.IsNotNull(metaTag.Value);
                Assert.That(((byte[])metaTag.Value).Length == 1);
                Assert.That(metaTag.Count == 1);
                Assert.That(metaTag.Length == 1);
                Assert.That(metaTag.Type == FREE_IMAGE_MDTYPE.FIDT_UNDEFINED);
                Assert.That(((byte[])metaTag.Value)[0] == testByte);

                Assert.IsTrue(metaTag.SetValue(testByteArray, FREE_IMAGE_MDTYPE.FIDT_UNDEFINED));
                Assert.IsNotNull(metaTag.Value);
                Assert.That(((byte[])metaTag.Value).Length == testByteArray.Length);
                Assert.That(metaTag.Count == testByteArray.Length);
                Assert.That(metaTag.Length == testByteArray.Length * 1);

                byte[] value = (byte[])metaTag.Value;

                for (int j = 0; j < value.Length; j++)
                    Assert.That(testByteArray[j] == value[j]);
            }

            FreeImage.UnloadEx(ref dib);
        }
Пример #25
0
        public void ApplyFilters(List<Schema.SkinFile.Attachment.Filter> filters)
        {
            if (dib.IsNull) return;

            foreach (Schema.SkinFile.Attachment.Filter filter in filters)
            {
                switch (filter.name)
                {
                    case "invert":
                        {
                            ///
                            /// TODO: Variable invertion using amount property
                            ///
                            FreeImage.AdjustColors(dib, 0, 0, 0, true);
                            break;
                        }
                    case "colorOverlay":
                        {
                            try
                            {
                                ///
                                /// TODO: Variable overlay using amount property
                                ///
                                RGBQUAD overlayColor = new RGBQUAD(), oldColor;
                                overlayColor.uintValue = Convert.ToUInt32(filter.color, 16);
                                //Console.WriteLine((double)filter.amount / 100);
                                for (uint y = 0; y < FreeImage.GetHeight(dib); y++)
                                {
                                    for (uint x = 0; x < FreeImage.GetWidth(dib); x++)
                                    {
                                        FreeImage.GetPixelColor(dib, x, y, out oldColor);
                                        overlayColor.rgbReserved = oldColor.rgbReserved;
                                        FreeImage.SetPixelColor(dib, x, y, ref overlayColor);
                                    }
                                }
                            }
                            catch { }
                            break;
                        }
                }
            }
        }
Пример #26
0
        public void FreeImage_Composite()
        {
            dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_08_Greyscale_MinIsBlack);
            Assert.That(!dib.IsNull);
            RGBQUAD rgbq = new RGBQUAD();

            FIBITMAP temp = FreeImage.Composite(dib, false, ref rgbq, new FIBITMAP());
            Assert.AreNotEqual(0, temp);

            FreeImage.UnloadEx(ref temp);
            FreeImage.UnloadEx(ref dib);
        }
 public static extern bool SetPixelColor(FIBITMAP dib, uint x, uint y, ref RGBQUAD value);
Пример #28
0
 protected override object LoadBitmap(Stream s)
 {
     // init FreeImage
     FreeImage.Initialize(true);
     // copy data to FreeImage memory
     byte[] buf = new byte[s.Length];
     s.Read(buf, 0, (int)s.Length);
     GCHandle gch = GCHandle.Alloc(buf, GCHandleType.Pinned);
     IntPtr bufPtr = Marshal.UnsafeAddrOfPinnedArrayElement(buf, 0);
     uint hmem = FreeImage.OpenMemory(bufPtr, buf.Length);
     gch.Free();
     // copy FreeImage pixels to cairo image surface
     FREE_IMAGE_FORMAT fif = FreeImage.GetFileTypeFromMemory(hmem, buf.Length);
     uint fiBitmap = FreeImage.LoadFromMemory(fif, hmem, 0);
     uint width = FreeImage.GetWidth(fiBitmap);
     uint height = FreeImage.GetHeight(fiBitmap);
     uint bpp = FreeImage.GetBPP(fiBitmap);
     if (bpp != 32)
     {
         uint fiBitmap2 = FreeImage.ConvertTo32Bits(fiBitmap);
         FreeImage.Unload(fiBitmap);
         fiBitmap = fiBitmap2;
     }
     Int32[] imgSurfData = new Int32[width * height];
     for (int y = (int)height - 1; y >= 0; y--)
         for (int x = 0; x < width; x++)
         {
             // get pixel color
             RGBQUAD rgb = new RGBQUAD();
             FreeImage.GetPixelColor(fiBitmap, (uint)x, (uint)(height - 1 - y), rgb);
             byte[] pixColor = new byte[4];
             pixColor[0] = rgb.rgbReserved;
             pixColor[1] = rgb.rgbRed;
             pixColor[2] = rgb.rgbGreen;
             pixColor[3] = rgb.rgbBlue;
             // premultiply alpha -> http://cairographics.org/manual/cairo-Image-Surfaces.html#cairo-format-t
             if (pixColor[0] != 255)
             {
                 double a = pixColor[0] / 255.0;
                 pixColor[1] = (byte)(pixColor[1] * a);
                 pixColor[2] = (byte)(pixColor[2] * a);
                 pixColor[3] = (byte)(pixColor[3] * a);
             }
             // convert pixColor to Int32 and put in data array
             if (BitConverter.IsLittleEndian)
             {
                 byte[] pixColor2 = new byte[4];
                 pixColor2[0] = pixColor[3];
                 pixColor2[1] = pixColor[2];
                 pixColor2[2] = pixColor[1];
                 pixColor2[3] = pixColor[0];
                 imgSurfData[x + y * width] = BitConverter.ToInt32(pixColor2, 0);
             }
             else
                 imgSurfData[x + y * width] = BitConverter.ToInt32(pixColor, 0);
         }
     // free FreeImage memory
     FreeImage.CloseMemory(hmem);
     // DeInit FreeImage
     FreeImage.DeInitialize();
     // pin databuffer until imgSurf is destroyed
     _gc_h_surface_data_buffer = GCHandle.Alloc(imgSurfData, GCHandleType.Pinned);
     // create ImageSurface from image data
     IntPtr dataPtr = Marshal.UnsafeAddrOfPinnedArrayElement(imgSurfData, 0);
     ImageSurface imgSurf = new ImageSurface(dataPtr, Format.Argb32, (int)width, (int)height, (int)width * 32 / 8);
     // return surface
     return imgSurf;
 }
        internal static extern FIBITMAP AllocateExT(FREE_IMAGE_TYPE type, int width, int height, int bpp,
			IntPtr color, FREE_IMAGE_COLOR_OPTIONS options, RGBQUAD[] palette,
			uint red_mask, uint green_mask, uint blue_mask);
Пример #30
0
        public byte[] GetPngData()
        {
            byte[] data = GetSurfaceData();
            // check data format
            System.Diagnostics.Debug.Assert(surface.Format == Format.Argb32, "ERROR: surface.Format is not \"Argb32\".");
            System.Diagnostics.Debug.Assert(data.Length == Width * Height * 4, "ERROR: data is wrong length.");
            // init FreeImage
            FreeImage.Initialize(true);
            // load data into FreeImage
            uint fiBitmap = FreeImage.Allocate(Width, Height, 32, 0x00FF0000, 0x0000FF00, 0x000000FF);
            for (int y = Height - 1; y >= 0; y--)
                for (int x = 0; x < Width; x++)
                {
                    int idx = y * Width * 4 + x * 4;
                    RGBQUAD rgb = new RGBQUAD();
                    rgb.rgbRed = data[idx + 2];
                    rgb.rgbGreen = data[idx + 1];
                    rgb.rgbBlue = data[idx];
                    rgb.rgbReserved = data[idx + 3];
                    FreeImage.SetPixelColor(fiBitmap, (uint)x, (uint)(Height - y - 1), rgb);
                }
            // copy FreeImage data to byte array
            uint hmem = FreeImage.OpenMemory(IntPtr.Zero, 0);
            FreeImage.SaveToMemory(FREE_IMAGE_FORMAT.FIF_PNG, fiBitmap, hmem, 0);
            FreeImage.Unload(fiBitmap);
            IntPtr ptr = IntPtr.Zero;
            int size_in_bytes = 0;
            FreeImage.AcquireMemory(hmem, ref ptr, ref size_in_bytes);
            byte[] pngData = new byte[size_in_bytes];
            Marshal.Copy(ptr, pngData, 0, size_in_bytes);
            FreeImage.CloseMemory(hmem);
            // DeInit FreeImage
            FreeImage.DeInitialize();

            return pngData;
        }
 public static extern FIBITMAP ColorQuantizeEx(FIBITMAP dib, FREE_IMAGE_QUANTIZE quantize, int PaletteSize, int ReserveSize, RGBQUAD[] ReservePalette);
Пример #32
0
 public bool DrawColourSolidRect(FIARECT rect, RGBQUAD colour)
 {
     return(FreeImage.DrawColourSolidRect(this.Dib, rect, colour));
 }
 public static extern bool GetBackgroundColor(FIBITMAP dib, out RGBQUAD bkcolor);
Пример #34
0
        public bool DrawColourSolidRect(Rectangle rect, RGBQUAD colour)
        {
            FIARECT fiaRect = new FIARECT(rect);

            return(FreeImage.DrawColourSolidRect(this.Dib, fiaRect, colour));
        }
Пример #35
0
 public static extern bool SetBackgroundColor(FIBITMAP dib,
                                              [In, MarshalAs(UnmanagedType.LPStruct)] RGBQUAD bkcolor);
Пример #36
0
 public bool DrawColourRect(FIARECT rect, RGBQUAD colour, int lineWidth)
 {
     return(FreeImage.DrawColourRect(this.Dib, rect, colour, lineWidth));
 }
Пример #37
0
 internal static extern bool DrawColourSolidRect(FIBITMAP src, FIARECT rect, RGBQUAD colour);
Пример #38
0
        public bool DrawColourRect(Rectangle rect, RGBQUAD colour, int lineWidth)
        {
            FIARECT fiaRect = new FIARECT(rect);

            return(FreeImage.DrawColourRect(this.Dib, fiaRect, colour, lineWidth));
        }
Пример #39
0
 internal static extern FIBITMAP AffineTransform(FIBITMAP src, int image_dst_width, int image_dst_height,
                                                 FIA_Matrix matrix, RGBQUAD colour, int retain_background);
Пример #40
0
        public FreeImageAlgorithmsBitmap AffineTransform(int image_dst_width, int image_dst_height,
                                                         FreeImageAlgorithmsMatrix matrix, RGBQUAD colour, int retainBackground)
        {
            FIBITMAP tmp_dib = FreeImage.AffineTransform(this.Dib, image_dst_width, image_dst_height, matrix.Data, colour, retainBackground);

            return(new FreeImageAlgorithmsBitmap(tmp_dib));
        }
Пример #41
0
        public FreeImageAlgorithmsBitmap AffineTransform(int image_dst_width, int image_dst_height,
            FreeImageAlgorithmsMatrix matrix, RGBQUAD colour, int retainBackground)
        {
            FIBITMAP tmp_dib = FreeImage.AffineTransform(this.Dib, image_dst_width, image_dst_height, matrix.Data, colour, retainBackground);

            return new FreeImageAlgorithmsBitmap(tmp_dib);
        }
Пример #42
0
        public void AffineTransform(FreeImageAlgorithmsMatrix matrix, RGBQUAD colour)
        {
            FIBITMAP tmp_dib = FreeImage.AffineTransform(this.Dib, (int)this.Width, (int)this.Height, matrix.Data, colour, 1);

            this.ReplaceDib(tmp_dib);
        }
Пример #43
0
 public bool DrawColourRect(FIARECT rect, RGBQUAD colour, int lineWidth)
 {
     return FreeImage.DrawColourRect(this.Dib, rect, colour, lineWidth);
 }
Пример #44
0
 public void DrawImage(FreeImageAlgorithmsBitmap dst, Rectangle dstRect, RGBQUAD colour)
 {
     FreeImage.DrawImageToDst(dst.Dib, this.Dib, FIA_Matrix.Zero,
                              dstRect.Left, dstRect.Top, dstRect.Width, dstRect.Height, colour, 1);
 }
Пример #45
0
 public bool DrawColourSolidRect(FIARECT rect, RGBQUAD colour)
 {
     return FreeImage.DrawColourSolidRect(this.Dib, rect, colour);
 }
Пример #46
0
 public void DrawImage(FreeImageAlgorithmsBitmap dst, Point dstPoint, Size dstSize, RGBQUAD colour)
 {
     FreeImage.DrawImageToDst(dst.Dib, this.Dib, FIA_Matrix.Zero,
                              dstPoint.X, dstPoint.Y, dstSize.Width, dstSize.Height, colour, 1);
 }
Пример #47
0
 public void DrawImage(FreeImageAlgorithmsBitmap dst, FreeImageAlgorithmsMatrix matrix,
     int dstLeft, int dstTop, int dstWidth, int dstHeight, RGBQUAD colour)
 {
     FreeImage.DrawImageToDst(dst.Dib, this.Dib, matrix.Data,
         dstLeft, dstTop, dstWidth, dstHeight, colour, 1);
 }
Пример #48
0
 public static unsafe RGBQUAD[] GetPaletteCopy(uint dib)
 {
     RGBQUAD[] rgbquadArray = new RGBQUAD[0x100];
     if (GetBPP(dib) <= 8)
     {
         byte* rawPalette = (byte*) GetRawPalette(dib);
         for (int i = 0; i < 0x100; i++)
         {
             rgbquadArray[i] = new RGBQUAD();
             rgbquadArray[i].rgbBlue = rawPalette[0];
             rawPalette++;
             rgbquadArray[i].rgbGreen = rawPalette[0];
             rawPalette++;
             rgbquadArray[i].rgbRed = rawPalette[0];
             rawPalette++;
             rgbquadArray[i].rgbReserved = rawPalette[0];
             rawPalette++;
         }
     }
     return rgbquadArray;
 }
Пример #49
0
 public void DrawImage(FreeImageAlgorithmsBitmap dst, Point dstPoint, Size dstSize, RGBQUAD colour)
 {
     FreeImage.DrawImageToDst(dst.Dib, this.Dib, FIA_Matrix.Zero,
         dstPoint.X, dstPoint.Y, dstSize.Width, dstSize.Height, colour, 1);
 }
Пример #50
0
        public void Transform(Schema.SkinFile.Attachment.Transform trnsfrm)
        {
            if (dib.IsNull) return;

            if (FreeImage.GetWidth(dib) <= 1 || FreeImage.GetHeight(dib) <= 1)
                return;
            FREE_IMAGE_FILTER filter = FREE_IMAGE_FILTER.FILTER_BSPLINE;

            if (trnsfrm.scaleFilter != null)
                switch (trnsfrm.scaleFilter.ToUpper())
                {
                    case "BOX":
                        filter = FREE_IMAGE_FILTER.FILTER_BOX;
                        break;
                    case "BICUBIC":
                        filter = FREE_IMAGE_FILTER.FILTER_BICUBIC;
                        break;
                    case "BILINEAR":
                        filter = FREE_IMAGE_FILTER.FILTER_BILINEAR;
                        break;
                    case "BSPLINE":
                        filter = FREE_IMAGE_FILTER.FILTER_BSPLINE;
                        break;
                    case "CATMULLROM":
                        filter = FREE_IMAGE_FILTER.FILTER_CATMULLROM;
                        break;
                    case "LANCZOS3":
                        filter = FREE_IMAGE_FILTER.FILTER_LANCZOS3;
                        break;
                }
            RectangleF originalDimensions, rotationDimensions;
            GraphicsUnit pageUnit = GraphicsUnit.Pixel;
            dib = FreeImage.Rescale(dib, (int)(FreeImage.GetWidth(dib) * trnsfrm.scaleX), (int)(FreeImage.GetHeight(dib) * trnsfrm.scaleY), filter);
            originalDimensions = FreeImage.GetBitmap(dib).GetBounds(ref pageUnit);

            RGBQUAD bgColor = new RGBQUAD();
            bgColor.rgbRed = 0x00;
            bgColor.rgbGreen = 0x00;
            bgColor.rgbBlue = 0x00;
            bgColor.rgbReserved = 0x00;
            // TODO: вычесть из положения разницу между оригинальными размерами и размерами после поворота (по крайней мере сверху)
            //int size = (int)(trnsfrm.x > 0 ? trnsfrm.x : 0) + (int)(trnsfrm.y > 0 ? trnsfrm.y : 0);
            //trnsfrm.angle = -45;
            /*
            double cos = Math.Cos(-trnsfrm.angle * Math.PI / 180), sin = Math.Sin(-trnsfrm.angle * Math.PI / 180);
            Point[] points = new Point[4] {
                new Point((int)(originalDimensions.Width / 2), (int)(originalDimensions.Height / 2)),  // top left //(int)(originalDimensions.Width / 2 * cos - originalDimensions.Height / 2 * sin), (int)(originalDimensions.Width / 2 * sin + originalDimensions.Height / 2 * cos)),
                new Point((int)(originalDimensions.Width / 2), (int)(-originalDimensions.Height / 2)), // top right
                new Point((int)(-originalDimensions.Width / 2), (int)(originalDimensions.Height / 2)), // bottom left
                new Point((int)(-originalDimensions.Width / 2), (int)(-originalDimensions.Height / 2)) // bottom right
            };
            for (int i = 0; i < points.Length; i++)
            {
                points[i].X = (int)(points[i].X * cos - points[i].Y * sin);
                points[i].Y = (int)(points[i].X * sin + points[i].Y * cos);
            }
            int maxRight = points[0].X, maxBottom = points[0].Y;
            for (int i = 0; i < points.Length; i++)
            {
                if (points[i].X > maxRight) maxRight = points[i].X;
                if (points[i].Y > maxBottom) maxBottom = points[i].Y;
            }

            Console.WriteLine(points[0]);
            Console.WriteLine(points[1]);
            Console.WriteLine(points[2]);
            Console.WriteLine(points[3]);

            Console.WriteLine(maxRight);
            Console.WriteLine(maxBottom);
            int rightOffset = (int)(maxRight - originalDimensions.Width / 2), bottomOffset = (int)(maxBottom - originalDimensions.Height / 2);
            Console.WriteLine(rightOffset);
            Console.WriteLine(bottomOffset);
            */
            /*
            Console.WriteLine(originalDimensions);
            Console.WriteLine(originalDimensions.Width / 2 * Math.Cos(trnsfrm.angle * Math.PI / 180) - originalDimensions.Height / 2 * Math.Sin(trnsfrm.angle * Math.PI / 180));
            Console.WriteLine(originalDimensions.Width / 2 * Math.Sin(trnsfrm.angle * Math.PI / 180) + originalDimensions.Height / 2 * Math.Cos(trnsfrm.angle * Math.PI / 180));
            */
            dib = FreeImage.Rotate<RGBQUAD>(dib, -trnsfrm.angle, bgColor);
            rotationDimensions = FreeImage.GetBitmap(dib).GetBounds(ref pageUnit);
            dib = FreeImage.EnlargeCanvas<RGBQUAD>(dib,
                0,
                0,
                (int)(trnsfrm.x > 0 ? trnsfrm.x : 0),// + rightOffset,//(int)(originalDimensions.Width / 2 * Math.Cos(trnsfrm.angle * Math.PI / 180) - originalDimensions.Height / 2 * Math.Sin(trnsfrm.angle * Math.PI / 180) - originalDimensions.Width / 2) + 2,
                (int)(trnsfrm.y > 0 ? trnsfrm.y : 0),// + bottomOffset,//(int)(originalDimensions.Width / 2 * Math.Sin(trnsfrm.angle * Math.PI / 180) + originalDimensions.Height / 2 * Math.Cos(trnsfrm.angle * Math.PI / 180)),
                bgColor,
                FREE_IMAGE_COLOR_OPTIONS.FICO_RGBA
            );
            //dib = FreeImage.RotateEx(dib, 0, trnsfrm.x, trnsfrm.y, 0, 0, true);
            //dib = FreeImage.Rotate<RGBQUAD>(dib, trnsfrm.angle, bgColor);

            //dib = FreeImage.RotateEx(dib, 0, trnsfrm.x, trnsfrm.y, originalDimensions.Width / 2, originalDimensions.Height / 2, true);
            dib = FreeImage.RotateEx(dib, 0, trnsfrm.x, trnsfrm.y, 0, 0, true);
            dib = FreeImage.EnlargeCanvas<RGBQUAD>(dib,
                (int)(rotationDimensions.Width - originalDimensions.Width) / -2,
                (int)(rotationDimensions.Height - originalDimensions.Height) / -2,
                0,
                0,
                bgColor,
                FREE_IMAGE_COLOR_OPTIONS.FICO_RGBA
            );
            //dib = FreeImage.RotateEx(dib, 0, trnsfrm.x - (rotationDimensions.Width - originalDimensions.Width) / 2, trnsfrm.y - (rotationDimensions.Height - originalDimensions.Height) / 2, 0, 0, true);
            //dib = FreeImage.RotateEx(dib, 0, trnsfrm.x, trnsfrm.y, 0, 0, true);
        }