Exemple #1
0
 private void RegisterProc(ref Plugin plugin, int format_id)
 {
     // Copy the function pointers
     plugin = this.plugin;
     // Retrieve the format if assigned to this plugin by FreeImage.
     format = (FREE_IMAGE_FORMAT)format_id;
 }
Exemple #2
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);
        }
Exemple #3
0
 /// <summary>
 /// Save the image to a file. Simplifies creating a stream, good for debugging.
 /// </summary>
 /// <param name="bitmap">The bitmap.</param>
 /// <param name="fileName">The name of the file to save.</param>
 /// <param name="format">The format to save the file in.</param>
 public static void saveToFile(this FreeImageBitmap bitmap, String fileName, FREE_IMAGE_FORMAT format)
 {
     using (Stream test = File.Open(fileName, FileMode.Create))
     {
         bitmap.Save(test, format);
     }
 }
 static void FreeImageEngine_Message(FREE_IMAGE_FORMAT fif, string message)
 {
     // Display the message
     // FreeImage continues code executing when all
     // addes subscribers of 'Message' finished returned.
     MessageBox.Show(message, "FreeImage-Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
 }
Exemple #5
0
        private void iconBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            string path = Path.Combine(MatPath, iconBox.SelectedItem.ToString());

            if (!path.EndsWith(".dds"))
            {
                path += ".dds";
            }

            // Perform cleanup
            if (engineIcon.Image != null)
            {
                engineIcon.Image.Dispose();
                engineIcon.Image = null;
            }

            // Ensure icon exists before proceeding
            if (!File.Exists(path))
            {
                return;
            }

            // Attempt to load image as a DDS file... or png if its a mod sometimes
            FREE_IMAGE_FORMAT Format   = FREE_IMAGE_FORMAT.FIF_UNKNOWN;
            Bitmap            MapImage = FreeImage.LoadBitmap(path, FREE_IMAGE_LOAD_FLAGS.DEFAULT, ref Format);

            if (MapImage != null)
            {
                engineIcon.Image = new Bitmap(MapImage, 256, 64);
            }
        }
Exemple #6
0
        private Bitmap LoadTexture(string filename)
        {
            FIBITMAP dib = new FIBITMAP();

            if (dib.IsNull == false)
            {
                FreeImage.Unload(dib);
            }

            FREE_IMAGE_FORMAT fif = FreeImage.GetFIFFromFilename(filename);

            dib = FreeImage.Load(fif, filename, FREE_IMAGE_LOAD_FLAGS.DEFAULT);

            FreeImage.FlipVertical(dib);

            if (dib.IsNull)
            {
                // f.FileInfo.error
                return(null);
            }

            Bitmap bitmap = FreeImage.GetBitmap(dib);

            FreeImage.Unload(dib);

            return(bitmap);
        }
Exemple #7
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);
        }
Exemple #8
0
 static void FreeImage_Message(FREE_IMAGE_FORMAT fif, string message)
 {
     // Display the data
     MessageBox.Show(
         String.Format("FreeImage-Message:\n{1}\nFormat:{0}", fif.ToString(), message),
         "FreeImage-Message");
 }
Exemple #9
0
 static void FreeImage_Message(FREE_IMAGE_FORMAT fif, string message)
 {
     // Display the data
     MessageBox.Show(
         String.Format("FreeImage-Message:\n{1}\nFormat:{0}", fif.ToString(), message),
         "FreeImage-Message");
 }
            //---------------------------------------------------------------------------------------------------------
            /// <summary>
            /// Загрузка изображения по полному пути
            /// </summary>
            /// <param name="file_name">Имя файла</param>
            /// <returns>Объект BitmapSource</returns>
            //---------------------------------------------------------------------------------------------------------
            public static BitmapSource LoadFromFile(String file_name)
            {
                // Format is stored in 'format' on successfull load.
                FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_UNKNOWN;

                // Try loading the file
                FIBITMAP dib = FreeImage.LoadEx(file_name, ref format);

                try
                {
                    // Error handling
                    if (dib.IsNull)
                    {
                        return(null);
                    }

                    BitmapSource image = null;                     // CreateFromHBitmap(FreeImage.GetHbitmap(dib, IntPtr.Zero, false));
                    FreeImage.UnloadEx(ref dib);

                    return(image);
                }
                catch (Exception exc)
                {
                    XLogger.LogExceptionModule(MODULE_NAME, exc);
                    return(null);
                }
            }
Exemple #11
0
        private void saveToStream(DibMd dibMd, string dstSuffix, Stream stream)
        {
            if (dibMd == null)
            {
                return;
            }

            //string dstSuffix = Path.GetExtension(dstPath).ToLower();
            FREE_IMAGE_FORMAT     format = FREE_IMAGE_FORMAT.FIF_ICO;
            FREE_IMAGE_SAVE_FLAGS flag   = FREE_IMAGE_SAVE_FLAGS.BMP_SAVE_RLE;

            switch (dstSuffix)
            {
            case ".png": format = FREE_IMAGE_FORMAT.FIF_PNG; flag = FREE_IMAGE_SAVE_FLAGS.PNG_Z_DEFAULT_COMPRESSION; break;

            case ".jpg": format = FREE_IMAGE_FORMAT.FIF_JPEG; flag = FREE_IMAGE_SAVE_FLAGS.JPEG_QUALITYGOOD; break;

            case ".bmp": format = FREE_IMAGE_FORMAT.FIF_BMP; flag = FREE_IMAGE_SAVE_FLAGS.BMP_SAVE_RLE; break;

            case ".ico":
            default: break;
            }

            FreeImage.SaveToStream(dibMd.dib, stream, format, flag);
        }
Exemple #12
0
        private void save(DibMd dibMd, string dstPath)
        {
            if (dibMd == null)
            {
                return;
            }

            string                dstSuffix = Path.GetExtension(dstPath).ToLower();
            FREE_IMAGE_FORMAT     format    = FREE_IMAGE_FORMAT.FIF_ICO;
            FREE_IMAGE_SAVE_FLAGS flag      = FREE_IMAGE_SAVE_FLAGS.BMP_SAVE_RLE;

            switch (dstSuffix)
            {
            case ".png": format = FREE_IMAGE_FORMAT.FIF_PNG; flag = FREE_IMAGE_SAVE_FLAGS.PNG_Z_DEFAULT_COMPRESSION; break;

            case ".jpg": format = FREE_IMAGE_FORMAT.FIF_JPEG; flag = FREE_IMAGE_SAVE_FLAGS.JPEG_QUALITYGOOD; break;

            case ".bmp": format = FREE_IMAGE_FORMAT.FIF_BMP; flag = FREE_IMAGE_SAVE_FLAGS.BMP_SAVE_RLE; break;

            case ".ico":
            default: break;
            }
            FreeImage.Save(format, dibMd.dib, dstPath, flag);
            //bool isOk = FreeImage.Save(FREE_IMAGE_FORMAT.FIF_PNG, dibOut, dstPath + ".png", FREE_IMAGE_SAVE_FLAGS.PNG_INTERLACED);
            //FreeImage.Unload(dibMd.dib);
            //FreeImage.Unload(dib);
        }
 static void FreeImageEngine_Message(FREE_IMAGE_FORMAT fif, string message)
 {
     // Display the message
     // FreeImage continues code executing when all
     // addes subscribers of 'Message' finished returned.
     MessageBox.Show(message, "FreeImage-Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
 }
        private void OpenFile(UniFile file)
        {
            m_file = file;
            try
            {
                if (file.FileExtension.ToLowerInvariant() == "dds")
                {
                    m_image  = new FreeImageBitmap(file.Stream, FREE_IMAGE_FORMAT.FIF_DDS);
                    m_format = FREE_IMAGE_FORMAT.FIF_DDS;
                }
                else if (file.FileExtension.ToLowerInvariant() == "tga")
                {
                    m_image  = new FreeImageBitmap(file.Stream, FREE_IMAGE_FORMAT.FIF_TARGA);
                    m_format = FREE_IMAGE_FORMAT.FIF_TARGA;
                }
                m_picbxImage.Image = (Bitmap)m_image;

                m_binary             = new MemoryStream();
                file.Stream.Position = 0;
                file.Stream.CopyTo(m_binary);
            }
            catch (Exception e)
            {
                UIHelper.ShowError("Failed to open image! Error: " + e.Message);
                ModTool.Core.LoggingManager.SendMessage("Failed to open image " + file.FilePath);
                ModTool.Core.LoggingManager.HandleException(e);
            }
            finally
            {
                file.Close();
            }
        }
Exemple #15
0
        public bool CanHandleRequest(TexImage image, IRequest request)
        {
            switch (request.Type)
            {
            case RequestType.Loading:
            {
                LoadingRequest    loader = (LoadingRequest)request;
                FREE_IMAGE_FORMAT format = FreeImage.GetFIFFromFilename(loader.FilePath);
                return(format != FREE_IMAGE_FORMAT.FIF_UNKNOWN && format != FREE_IMAGE_FORMAT.FIF_DDS);        // FreeImage can load DDS texture, but can't handle their mipmaps..
            }

            case RequestType.Export:
            {
                ExportRequest     export = (ExportRequest)request;
                FREE_IMAGE_FORMAT format = FreeImage.GetFIFFromFilename(export.FilePath);
                return(format != FREE_IMAGE_FORMAT.FIF_UNKNOWN && format != FREE_IMAGE_FORMAT.FIF_DDS);
            }

            case RequestType.Rescaling:
                RescalingRequest rescale = (RescalingRequest)request;
                return(rescale.Filter != Filter.Rescaling.Nearest);

            case RequestType.SwitchingChannels:
            case RequestType.GammaCorrection:
            case RequestType.Flipping:
            case RequestType.FlippingSub:
            case RequestType.Swapping:
                return(true);

            default:
                return(false);
            }
        }
Exemple #16
0
        private Bitmap LoadTexture(string filename)
        {
            FIBITMAP dib = new FIBITMAP();

            if (!dib.IsNull)
            {
                FreeImage.Unload(dib);
            }


            FREE_IMAGE_FORMAT fif = FreeImage.GetFIFFromFilename(filename);

            dib = FreeImage.Load(fif, filename, FREE_IMAGE_LOAD_FLAGS.DEFAULT);

            FreeImage.FlipVertical(dib);

            if (dib.IsNull)
            {
                //MessageBox.Show("로딩 실패" + file);
                return(null);
            }

            Bitmap bitmap = FreeImage.GetBitmap(dib);

            FreeImage.Unload(dib);

            return(bitmap);
        }
Exemple #17
0
        public FreeImageEncoderPlugin(ResizeSettings settings, object original)
        {
            ImageFormat originalFormat = DefaultEncoder.GetOriginalFormat(original);
            if (!IsValidOutputFormat(originalFormat)) originalFormat = ImageFormat.Jpeg;//No valid info available about the original format. Use Jpeg.

            //What format was specified?
            ImageFormat requestedFormat = DefaultEncoder.GetRequestedFormat(settings.Format, originalFormat); //fallback to originalFormat if not specified.
            if (!IsValidOutputFormat(requestedFormat))
                throw new ArgumentException("An unrecognized or unsupported output format (" + (settings.Format != null ? settings.Format : "(null)") + ") was specified in 'settings'.");
            this.format =  FreeImage.GetFormat(requestedFormat);

            //Parse JPEG settings.
            int quality = 90;
            if (string.IsNullOrEmpty(settings["quality"]) || !int.TryParse(settings["quality"], NumberStyles.Number, NumberFormatInfo.InvariantInfo, out quality)) quality = 90;
            if (format == FREE_IMAGE_FORMAT.FIF_JPEG) {
                if (quality >= 100) encodingOptions |= FREE_IMAGE_SAVE_FLAGS.JPEG_QUALITYSUPERB;
                else if (quality >= 75)
                    encodingOptions |= FREE_IMAGE_SAVE_FLAGS.JPEG_QUALITYGOOD;
                else if (quality >= 50) encodingOptions |= FREE_IMAGE_SAVE_FLAGS.JPEG_QUALITYNORMAL;
                else if (quality >= 25) encodingOptions |= FREE_IMAGE_SAVE_FLAGS.JPEG_QUALITYAVERAGE;
                else encodingOptions |= FREE_IMAGE_SAVE_FLAGS.JPEG_QUALITYBAD;

                if ("true".Equals(settings["progressive"])) encodingOptions |= FREE_IMAGE_SAVE_FLAGS.JPEG_PROGRESSIVE;

                if ("411".Equals(settings["subsampling"])) encodingOptions |= FREE_IMAGE_SAVE_FLAGS.JPEG_SUBSAMPLING_411;
                if ("420".Equals(settings["subsampling"])) encodingOptions |= FREE_IMAGE_SAVE_FLAGS.JPEG_SUBSAMPLING_420;
                if ("422".Equals(settings["subsampling"])) encodingOptions |= FREE_IMAGE_SAVE_FLAGS.JPEG_SUBSAMPLING_422;
                if ("444".Equals(settings["subsampling"])) encodingOptions |= FREE_IMAGE_SAVE_FLAGS.JPEG_SUBSAMPLING_444;
            }
            if (string.IsNullOrEmpty(settings["colors"]) || !int.TryParse(settings["colors"], NumberStyles.Number, NumberFormatInfo.InvariantInfo, out colors)) colors = -1;

            if (format == FREE_IMAGE_FORMAT.FIF_GIF) {
                //encodingOptions = FREE_IMAGE_SAVE_FLAGS.
            }
        }
 private void saveImage(FreeImageBitmap source, String destFile, FREE_IMAGE_FORMAT format)
 {
     using (Stream outStream = File.Open(destFile, FileMode.Create, FileAccess.ReadWrite, FileShare.None))
     {
         source.Save(outStream, format);
     }
     Log.Info("Wrote {0}", destFile);
 }
Exemple #19
0
        /// <summary>
        /// Loads the specified image.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <param name="loader">The loader.</param>
        /// <exception cref="TextureToolsException">If loading failed : mostly not supported format or path error (FileNotFound).</exception>
        private void Load(TexImage image, LoadingRequest loader)
        {
            Log.Verbose("Loading " + loader.FilePath + " ...");

            FIBITMAP          temp;
            FREE_IMAGE_FORMAT fileFormat = FREE_IMAGE_FORMAT.FIF_UNKNOWN;

            try
            {
                temp = FreeImage.LoadEx(loader.FilePath, ref fileFormat);
                FreeImage.FlipVertical(temp);

                if (temp.IsNull)
                {
                    throw new Exception("FreeImage's image data is null");
                }
            }
            catch (Exception e)
            {
                Log.Error("Loading file " + loader.FilePath + " failed: " + e.Message);
                throw new TextureToolsException("Loading file " + loader.FilePath + " failed: " + e.Message);
            }

            // Converting the image into BGRA_8888 format
            var libraryData = new FreeImageTextureLibraryData {
                Bitmaps = new [] { FreeImage.ConvertTo32Bits(temp) }
            };

            image.LibraryData[this] = libraryData;
            int alphaSize = GetAlphaDepth(fileFormat, temp);

            FreeImage.Unload(temp);

            image.Data               = FreeImage.GetBits(libraryData.Bitmaps[0]);
            image.Width              = (int)FreeImage.GetWidth(libraryData.Bitmaps[0]);
            image.Height             = (int)FreeImage.GetHeight(libraryData.Bitmaps[0]);
            image.Depth              = 1;
            image.Dimension          = image.Height == 1 ? TexImage.TextureDimension.Texture1D : TexImage.TextureDimension.Texture2D;
            image.Format             = loader.LoadAsSRgb? PixelFormat.B8G8R8A8_UNorm_SRgb : PixelFormat.B8G8R8A8_UNorm;
            image.OriginalAlphaDepth = alphaSize;

            int rowPitch, slicePitch;

            Tools.ComputePitch(image.Format, image.Width, image.Height, out rowPitch, out slicePitch);
            image.RowPitch   = rowPitch;
            image.SlicePitch = slicePitch;

            //Only one image in the SubImageArray, FreeImage is only used to load images, not textures.
            image.SubImageArray[0].Data       = image.Data;
            image.SubImageArray[0].DataSize   = image.DataSize;
            image.SubImageArray[0].Width      = image.Width;
            image.SubImageArray[0].Height     = image.Height;
            image.SubImageArray[0].RowPitch   = rowPitch;
            image.SubImageArray[0].SlicePitch = slicePitch;
            image.DataSize         = (int)(FreeImage.GetDIBSize(libraryData.Bitmaps[0]) - GetHeaderSize()); // header size of a bitmap is included in their size calculus
            libraryData.Data       = IntPtr.Zero;
            image.DisposingLibrary = this;
        }
Exemple #20
0
        public bool Save(string filename, FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_UNKNOWN, FREE_IMAGE_SAVE_FLAGS flags = FREE_IMAGE_SAVE_FLAGS.DEFAULT)
        {
            if (dib.IsNull)
            {
                return(false);
            }

            return(FreeImage.SaveEx(dib, filename, format, flags));
        }
Exemple #21
0
        public Bitmap Open(string fileName)
        {
            FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_BMP;
            var ext = Path.GetExtension(fileName);

            switch (ext)
            {
            case ".bmp":
                format = FREE_IMAGE_FORMAT.FIF_BMP;
                break;

            case ".ico":
                format = FREE_IMAGE_FORMAT.FIF_ICO;
                break;

            case ".jpg":
            case ".jif":
            case ".jpeg":
            case ".jpe":
                format = FREE_IMAGE_FORMAT.FIF_JPEG;
                break;

            case ".mng":
                format = FREE_IMAGE_FORMAT.FIF_MNG;
                break;

            case ".pcx":
                format = FREE_IMAGE_FORMAT.FIF_PCX;
                break;

            case ".png":
                format = FREE_IMAGE_FORMAT.FIF_PNG;
                break;

            case ".tga":
            case ".targa":
                format = FREE_IMAGE_FORMAT.FIF_TARGA;
                break;

            case ".tif":
            case ".tiff":
                format = FREE_IMAGE_FORMAT.FIF_TIFF;
                break;

            case ".psd":
                format = FREE_IMAGE_FORMAT.FIF_PSD;
                break;

            case ".gif":
                format = FREE_IMAGE_FORMAT.FIF_GIF;
                break;
            }

            var bitmap = FreeImage.LoadBitmap(fileName, FREE_IMAGE_LOAD_FLAGS.DEFAULT, ref format);

            return(bitmap);
        }
        protected FREE_IMAGE_FORMAT ImageFormatTofiImageFormat(ImageFormat format)
        {
            FREE_IMAGE_FORMAT fiFormat = FREE_IMAGE_FORMAT.FIF_UNKNOWN;

            if (format == ImageFormat.Jpeg)
            {
                fiFormat = FREE_IMAGE_FORMAT.FIF_JPEG;
            }
            return(fiFormat);
        }
Exemple #23
0
        /// <summary>
        /// 图片缩放
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public static Bitmap Rescale(string fileName, float scale)
        {
            FREE_IMAGE_FORMAT format = FreeImage.GetFileType(fileName, 0);
            FIBITMAP          f      = FreeImage.LoadEx(fileName, ref format);
            int      width           = (int)(FreeImage.GetWidth(f) * scale);
            int      height          = (int)(FreeImage.GetHeight(f) * scale);
            FIBITMAP fi = FreeImage.Rescale(f, width, height, FREE_IMAGE_FILTER.FILTER_BILINEAR);

            return(FreeImage.GetBitmap(fi));
        }
Exemple #24
0
        private void seriesModelBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            // Unlock all other controls
            if (!transNameBox.Enabled)
            {
                unitNameBox.Enabled        = true;
                transNameBox.Enabled       = true;
                unlockBox.Enabled          = true;
                priceBox.Enabled           = true;
                filenameTextBox.Enabled    = true;
                hasRetarder.Enabled        = true;
                hasTorqueConverter.Enabled = true;
                diffRatio.Enabled          = true;
                stallRatio.Enabled         = true;
                retardPositions.Enabled    = true;
                confirmButton.Enabled      = true;
            }

            // Perform cleanup
            if (seriesIcon.Image != null)
            {
                seriesIcon.Image.Dispose();
                seriesIcon.Image = null;
            }

            var series = seriesModelBox.SelectedItem as TransmissionSeries;

            if (series == null)
            {
                return;
            }

            // Load image
            string path = Path.Combine(MatPath, series.Icon);

            if (!path.EndsWith(".dds"))
            {
                path += ".dds";
            }

            // Ensure icon exists before proceeding
            if (!File.Exists(path))
            {
                return;
            }

            // Attempt to load image as a DDS file... or png if its a mod sometimes
            FREE_IMAGE_FORMAT Format   = FREE_IMAGE_FORMAT.FIF_UNKNOWN;
            Bitmap            MapImage = FreeImage.LoadBitmap(path, FREE_IMAGE_LOAD_FLAGS.DEFAULT, ref Format);

            if (MapImage != null)
            {
                seriesIcon.Image = new Bitmap(MapImage, 256, 64);
            }
        }
 //---------------------------------------------------------------------------------------------------------
 /// <summary>
 /// Обработка сообщений библиотеки FreeImage
 /// </summary>
 /// <param name="format_image">Формат изображения</param>
 /// <param name="message">Строка сообщения</param>
 //---------------------------------------------------------------------------------------------------------
 private void OnFreeImageMessage(FREE_IMAGE_FORMAT format_image, String message)
 {
     if (this.mCurrentMessage == null)
     {
         this.mCurrentMessage = message;
     }
     else
     {
         this.mCurrentMessage += "\n" + message;
     }
 }
Exemple #26
0
 public static byte[] ImageToByteArray(string path, FREE_IMAGE_FORMAT format)
 {
     using (var image = FreeImageBitmap.FromFile(path))
     {
         using (var m = new MemoryStream())
         {
             image.Save(m, format);
             return(m.ToArray());
         }
     }
 }
Exemple #27
0
 void FreeImage_Message(FREE_IMAGE_FORMAT fif, string message)
 {
     if (this.message == null)
     {
         this.message = message;
     }
     else
     {
         this.message += "\n" + message;
     }
 }
 public static IntPtr Load(FREE_IMAGE_FORMAT fif, string filename, int flags)
 {
     if (CurrentPlatform.OS == OS.Windows)
     {
         return(LoadU(fif, filename, flags));
     }
     else
     {
         return(LoadS(fif, filename, flags));
     }
 }
        private static IcnsImage LoadWithFreeImage(IcnsImageParser.IcnsElement element, IcnsType imageType)
        {
            using (MemoryStream ms = new MemoryStream(element.data))
            {
                FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_JP2;
                FIBITMAP          fib    = FreeImage.LoadFromStream(ms, ref format);
                Bitmap            bmp    = FreeImage.GetBitmap(fib);
                FreeImage.Unload(fib);

                return(new IcnsImage(bmp, imageType));
            }
        }
Exemple #30
0
        private static FIBITMAP complexedLoad(FileInfo inputFileInfo)
        {
            FIBITMAP              fibitmap           = FIBITMAP.Zero;
            FREE_IMAGE_FORMAT     freeImageFormat    = getComplexedFormat(FileUtil.getSuffix(inputFileInfo.Name));
            FREE_IMAGE_LOAD_FLAGS freeImageLoadFlags = FREE_IMAGE_LOAD_FLAGS.DEFAULT;

            if (FREE_IMAGE_FORMAT.FIF_UNKNOWN != freeImageFormat)
            {
                fibitmap = FreeImage.Load(freeImageFormat, inputFileInfo.FullName, freeImageLoadFlags);
            }
            return(fibitmap);
        }
Exemple #31
0
 public static byte[] ThumbNailByteArray(string path, FREE_IMAGE_FORMAT format)
 {
     using (var image = FreeImageBitmap.FromFile(path))
     {
         var newImage = image.GetThumbnailImage(1000, true);
         using (var m = new MemoryStream())
         {
             newImage.Save(m, format);
             return(m.ToArray());
         }
     }
 }
Exemple #32
0
		/// <summary>
		/// Internal callback
		/// </summary>
		private static void OnMessage(FREE_IMAGE_FORMAT fif, string message)
		{
			// Get a local copy of the multicast-delegate
			OutputMessageFunction m = Message;

			// Check the local copy instead of the static instance
			// to prevent a second thread from setting the delegate
			// to null, which would cause a nullreference exception
			if (m != null)
			{
				// Invoke the multicast-delegate
				m.Invoke(fif, message);
			}
		}
Exemple #33
0
        /// <summary>
        /// Internal callback
        /// </summary>
        private static void OnMessage(FREE_IMAGE_FORMAT fif, string message)
        {
            // Get a local copy of the multicast-delegate
            OutputMessageFunction m = Message;

            // Check the local copy instead of the static instance
            // to prevent a second thread from setting the delegate
            // to null, which would cause a null reference exception
            if (m != null)
            {
                // Invoke the multicast-delegate
                m.Invoke(fif, message);
            }
        }
Exemple #34
0
        private static FREE_IMAGE_FORMAT getComplexedFormat(string suffix)
        {
            FREE_IMAGE_FORMAT freeImageFormat = FREE_IMAGE_FORMAT.FIF_UNKNOWN;

            if (conplexedFormatDict.ContainsKey(suffix))
            {
                freeImageFormat = conplexedFormatDict[suffix];
            }
            else if (formatDict.ContainsKey(suffix))
            {
                freeImageFormat = FreeImage.GetFormat(formatDict[suffix]);
            }
            return(freeImageFormat);
        }
        private void OpenFile(UniFile file)
        {
            m_file = file;
            try
            {
                if (file.FileExtension.ToLowerInvariant() == "dds")
                {
                    m_image = new FreeImageBitmap(file.Stream, FREE_IMAGE_FORMAT.FIF_DDS);
                    m_format = FREE_IMAGE_FORMAT.FIF_DDS;
                }
                else if (file.FileExtension.ToLowerInvariant() == "tga")
                {
                    m_image = new FreeImageBitmap(file.Stream, FREE_IMAGE_FORMAT.FIF_TARGA);
                    m_format = FREE_IMAGE_FORMAT.FIF_TARGA;
                }
                m_picbxImage.Image = (Bitmap)m_image;

                m_binary = new MemoryStream();
                file.Stream.Position = 0;
                file.Stream.CopyTo(m_binary);
            }
            catch (Exception e)
            {
                 UIHelper.ShowError("Failed to open image! Error: " + e.Message);
                ModTool.Core.LoggingManager.SendMessage("Failed to open image " + file.FilePath);
                ModTool.Core.LoggingManager.HandleException(e);
            }
            finally
            {
                file.Close();
            }
        }
 /// <summary>
 /// Returns a comma-delimited file extension list describing the bitmap formats the given plugin can read and/or write.
 /// </summary>
 /// <param name="fif">The desired <see cref="FREE_IMAGE_FORMAT"/>.</param>
 /// <returns>A comma-delimited file extension list.</returns>
 public static unsafe string GetFIFExtensionList(FREE_IMAGE_FORMAT fif)
 {
     return PtrToStr(GetFIFExtensionList_(fif));
 }
 /// <summary>
 /// Returns a descriptive string that describes the bitmap formats the given plugin can read and/or write.
 /// </summary>
 /// <param name="fif">The desired <see cref="FREE_IMAGE_FORMAT"/>.</param>
 /// <returns>A descriptive string that describes the bitmap formats.</returns>
 public static unsafe string GetFIFDescription(FREE_IMAGE_FORMAT fif)
 {
     return PtrToStr(GetFIFDescription_(fif));
 }
 public static extern int SetPluginEnabled(FREE_IMAGE_FORMAT fif, bool enable);
 public static extern FIBITMAP LoadFromHandle(FREE_IMAGE_FORMAT fif, ref FreeImageIO io, fi_handle handle, FREE_IMAGE_LOAD_FLAGS flags);
 public FreeImageAlgorithmsBitmap(Stream stream, FREE_IMAGE_FORMAT format)
     : base(stream, format)
 {
 }
 private static extern FIBITMAP LoadU(FREE_IMAGE_FORMAT fif, string filename, FREE_IMAGE_LOAD_FLAGS flags);
 private static unsafe extern byte* GetFIFRegExpr_(FREE_IMAGE_FORMAT fif);
 private static unsafe extern byte* GetFormatFromFIF_(FREE_IMAGE_FORMAT fif);
 private static unsafe extern byte* GetFIFMimeType_(FREE_IMAGE_FORMAT fif);
 private static unsafe extern byte* GetFIFExtensionList_(FREE_IMAGE_FORMAT fif);
 private static unsafe extern byte* GetFIFDescription_(FREE_IMAGE_FORMAT fif);
 void FreeImage_Message(FREE_IMAGE_FORMAT fif, string message)
 {
     if (this.message == null)
     {
         this.message = message;
     }
     else
     {
         this.message += "\n" + message;
     }
 }
 public static extern int IsPluginEnabled(FREE_IMAGE_FORMAT fif);
        public static extern bool SaveToHandle(FREE_IMAGE_FORMAT fif, FIBITMAP dib, ref FreeImageIO io, fi_handle handle,
			FREE_IMAGE_SAVE_FLAGS flags);
 public static extern bool FIFSupportsExportType(FREE_IMAGE_FORMAT fif, FREE_IMAGE_TYPE type);
        public static extern FIMULTIBITMAP OpenMultiBitmap(FREE_IMAGE_FORMAT fif, string filename, bool create_new,
			bool read_only, bool keep_cache_in_memory, FREE_IMAGE_LOAD_FLAGS flags);
 public static extern bool FIFSupportsICCProfiles(FREE_IMAGE_FORMAT fif);
 public static extern FIMULTIBITMAP LoadMultiBitmapFromMemory(FREE_IMAGE_FORMAT fif, FIMEMORY stream, FREE_IMAGE_LOAD_FLAGS flags);
 public static extern bool FIFSupportsWriting(FREE_IMAGE_FORMAT fif);
 private static extern bool SaveU(FREE_IMAGE_FORMAT fif, FIBITMAP dib, string filename, FREE_IMAGE_SAVE_FLAGS flags);
 public static extern bool SaveToMemory(FREE_IMAGE_FORMAT fif, FIBITMAP dib, FIMEMORY stream, FREE_IMAGE_SAVE_FLAGS flags);
        public static extern FIMULTIBITMAP OpenMultiBitmapFromHandle(FREE_IMAGE_FORMAT fif, ref FreeImageIO io,
			fi_handle handle, FREE_IMAGE_LOAD_FLAGS flags);
 public static extern bool FIFSupportsExportBPP(FREE_IMAGE_FORMAT fif, int bpp);
 private static void FreeImageErrorOccurred(FREE_IMAGE_FORMAT format, string msg)
 {
     throw new FreeImageException(msg);
 }
 public static extern void OutputMessageProc(FREE_IMAGE_FORMAT fif, string message);