コード例 #1
0
ファイル: FileType.cs プロジェクト: smile-ttxp/Paint.NET
 public void Save(Document input, Stream output, SaveConfigToken token, ProgressEventHandler callback, bool rememberToken)
 {
     using (Surface scratch = new Surface(input.Width, input.Height))
     {
         Save(input, output, token, callback, rememberToken);
     }
 }
コード例 #2
0
ファイル: BmpFileType.cs プロジェクト: leejungho2/xynotecgui
        protected override void OnSave(Document input, Stream output, SaveConfigToken token, Surface scratchSurface, ProgressEventHandler callback)
        {
            ImageCodecInfo    icf   = GdiPlusFileType.GetImageCodecInfo(ImageFormat.Bmp);
            EncoderParameters parms = new EncoderParameters(1);
            EncoderParameter  parm  = new EncoderParameter(System.Drawing.Imaging.Encoder.ColorDepth, 24); // BMP's should always save as 24-bit

            parms.Param[0] = parm;

            scratchSurface.Clear(ColorBgra.White);

            using (RenderArgs ra = new RenderArgs(scratchSurface))
            {
                input.Render(ra, true);
            }

            // In order to save memory, we 'squish' the 32-bit bitmap down to 24-bit in-place
            // instead of allocating a new bitmap and copying it over.
            SquishSurfaceTo24Bpp(scratchSurface);

            using (Bitmap bitmap = CreateAliased24BppBitmap(scratchSurface))
            {
                GdiPlusFileType.LoadProperties(bitmap, input);
                bitmap.Save(output, icf, parms);
            }
        }
コード例 #3
0
        protected override void InitWidgetFromToken(SaveConfigToken token)
        {
            if (token is DdsSaveConfigToken)
            {
                DdsSaveConfigToken ddsToken = (DdsSaveConfigToken)token;
                this.fileFormatList.SelectedIndex	= ( int )ddsToken.m_fileFormat;

                this.clusterFit.Checked				= ( ddsToken.m_compressorType == 0 );
                this.rangeFit.Checked				= ( ddsToken.m_compressorType == 1 );
                this.iterativeFit.Checked			= ( ddsToken.m_compressorType == 2 );

                this.perceptualMetric.Checked		= ( ddsToken.m_errorMetric == 0 );
                this.uniformMetric.Checked			= !this.perceptualMetric.Checked;

                this.weightColourByAlpha.Checked	= ddsToken.m_weightColourByAlpha;

                this.generateMipMaps.Checked		= ddsToken.m_generateMipMaps;
            }
            else
            {
                this.fileFormatList.SelectedIndex	= 0;

                this.clusterFit.Checked				= true;
                this.rangeFit.Checked				= false;
                this.iterativeFit.Checked			= false;

                this.perceptualMetric.Checked		= true;
                this.uniformMetric.Checked			= false;

                this.weightColourByAlpha.Checked	= false;

                this.generateMipMaps.Checked		= false;
            }
        }
コード例 #4
0
ファイル: FileType.cs プロジェクト: smile-ttxp/Paint.NET
        /// <summary>
        /// Because the old OnSave() method is obsolete, we must use reflection to call it.
        /// This is important for legacy FileType plugins. It allows us to ensure that no
        /// new plugins can be compiled using the old OnSave() overload.
        /// </summary>
        private void OldOnSaveTrampoline(Document input, Stream output, SaveConfigToken token, ProgressEventHandler callback)
        {
            MethodInfo onSave = GetType().GetMethod(
                "OnSave",
                BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy,
                Type.DefaultBinder,
                new Type[]
            {
                typeof(Document),
                typeof(Stream),
                typeof(SaveConfigToken),
                typeof(ProgressEventHandler)
            },
                null);

            onSave.Invoke(
                this,
                new object[]
            {
                input,
                output,
                token,
                callback
            });
        }
コード例 #5
0
        protected override void OnSave(Document input, Stream output, SaveConfigToken token, 
            Surface scratchSurface, ProgressEventHandler callback)
        {
            RenderArgs ra = new RenderArgs(new Surface(input.Size));
            input.Render(ra);

            ra.Bitmap.Save(output, ImageFormat.Bmp);
        }
コード例 #6
0
 public void Save(Stream dstStream, Document srcDocument, FileType dstFileType, SaveConfigToken parameters, Surface saveScratchSurface)
 {
     this.document = srcDocument;
     this.fileType = dstFileType;
     this.stream = dstStream;
     this.saveConfigToken = parameters;
     this.scratchSurface = saveScratchSurface;
     DialogResult dr = this.ShowDialog(false, !dstFileType.SavesWithProgress , new ThreadStart(SaveCallback));
 }
コード例 #7
0
 public void Save(Stream dstStream, Document srcDocument, FileType dstFileType, SaveConfigToken parameters, Surface saveScratchSurface)
 {
     this.document        = srcDocument;
     this.fileType        = dstFileType;
     this.stream          = dstStream;
     this.saveConfigToken = parameters;
     this.scratchSurface  = saveScratchSurface;
     DialogResult dr = this.ShowDialog(false, !dstFileType.SavesWithProgress, new ThreadStart(SaveCallback));
 }
コード例 #8
0
 protected override void OnLoad(EventArgs e)
 {
     if (this.scratchSurface == null)
     {
         ExceptionUtil.ThrowInvalidOperationException("ScratchSurface was never set: it is null");
     }
     PaintDotNet.SaveConfigToken saveConfigToken = this.SaveConfigToken;
     this.LoadPositions();
     this.SaveConfigToken = saveConfigToken;
     base.OnLoad(e);
 }
コード例 #9
0
ファイル: PdnFileType.cs プロジェクト: leejungho2/xynotecgui
 protected override void OnSave(Document input, Stream output, SaveConfigToken token, Surface scratchSurface, ProgressEventHandler callback)
 {
     if (callback == null)
     {
         input.SaveToStream(output);
     }
     else
     {
         UpdateProgressTranslator upt = new UpdateProgressTranslator(ApproximateMaxOutputOffset(input), callback);
         input.SaveToStream(output, new IOEventHandler(upt.IOEventHandler));
     }
 }
コード例 #10
0
 protected override void OnSave(Document input, Stream output, SaveConfigToken token, Surface scratchSurface, ProgressEventHandler callback)
 {
     if (callback == null)
     {
         input.SaveToStream(output);
     }
     else
     {
         UpdateProgressTranslator upt = new UpdateProgressTranslator(ApproximateMaxOutputOffset(input), callback);
         input.SaveToStream(output, new IOEventHandler(upt.IOEventHandler));
     }
 }
コード例 #11
0
ファイル: GifFileType.cs プロジェクト: nkaligin/paint-mono
        protected override void OnSave(Document input, Stream output, SaveConfigToken token, Surface scratchSurface, ProgressEventHandler progressCallback)
        {
            GifSaveConfigToken gsct = (GifSaveConfigToken)token;

            // Flatten and pre-process the image
            scratchSurface.Clear(ColorBgra.FromBgra(255, 255, 255, 0));

            using (RenderArgs ra = new RenderArgs(scratchSurface))
            {
                input.Render(ra, true);
            }

            for (int y = 0; y < scratchSurface.Height; ++y)
            {
                unsafe
                {
                    ColorBgra* ptr = scratchSurface.GetRowAddressUnchecked(y);

                    for (int x = 0; x < scratchSurface.Width; ++x)
                    {
                        if (ptr->A < gsct.Threshold)
                        {
                            ptr->Bgra = 0;
                        }
                        else
                        {
                            if (gsct.PreMultiplyAlpha)
                            {
                                int r = ((ptr->R * ptr->A) + (255 * (255 - ptr->A))) / 255;
                                int g = ((ptr->G * ptr->A) + (255 * (255 - ptr->A))) / 255;
                                int b = ((ptr->B * ptr->A) + (255 * (255 - ptr->A))) / 255;
                                int a = 255;

                                *ptr = ColorBgra.FromBgra((byte)b, (byte)g, (byte)r, (byte)a);
                            }
                            else
                            {
                                ptr->Bgra |= 0xff000000;
                            }
                        }

                        ++ptr;
                    }
                }
            }

            using (Bitmap quantized = Quantize(scratchSurface, gsct.DitherLevel, 255, progressCallback))
            {
                quantized.Save(output, ImageFormat.Gif);
            }
        }
コード例 #12
0
ファイル: GifFileType.cs プロジェクト: leejungho2/xynotecgui
        protected override void OnSave(Document input, Stream output, SaveConfigToken token, Surface scratchSurface, ProgressEventHandler progressCallback)
        {
            GifSaveConfigToken gsct = (GifSaveConfigToken)token;

            // Flatten and pre-process the image
            scratchSurface.Clear(ColorBgra.FromBgra(255, 255, 255, 0));

            using (RenderArgs ra = new RenderArgs(scratchSurface))
            {
                input.Render(ra, true);
            }

            for (int y = 0; y < scratchSurface.Height; ++y)
            {
                unsafe
                {
                    ColorBgra *ptr = scratchSurface.GetRowAddressUnchecked(y);

                    for (int x = 0; x < scratchSurface.Width; ++x)
                    {
                        if (ptr->A < gsct.Threshold)
                        {
                            ptr->Bgra = 0;
                        }
                        else
                        {
                            if (gsct.PreMultiplyAlpha)
                            {
                                int r = ((ptr->R * ptr->A) + (255 * (255 - ptr->A))) / 255;
                                int g = ((ptr->G * ptr->A) + (255 * (255 - ptr->A))) / 255;
                                int b = ((ptr->B * ptr->A) + (255 * (255 - ptr->A))) / 255;
                                int a = 255;

                                *ptr = ColorBgra.FromBgra((byte)b, (byte)g, (byte)r, (byte)a);
                            }
                            else
                            {
                                ptr->Bgra |= 0xff000000;
                            }
                        }

                        ++ptr;
                    }
                }
            }

            using (Bitmap quantized = Quantize(scratchSurface, gsct.DitherLevel, 255, progressCallback))
            {
                quantized.Save(output, ImageFormat.Gif);
            }
        }
コード例 #13
0
ファイル: FileType.cs プロジェクト: smile-ttxp/Paint.NET
        public SaveConfigToken GetLastSaveConfigToken()
        {
            Type            ourType         = this.GetType();
            string          savedTokenName  = "SaveConfigToken." + ourType.Namespace + "." + ourType.Name + ".BinaryFormatter";
            string          savedToken      = Settings.CurrentUser.GetString(savedTokenName, null);
            SaveConfigToken saveConfigToken = null;

            if (savedToken != null)
            {
                try
                {
                    byte[] bytes = Convert.FromBase64String(savedToken);

                    MemoryStream ms = new MemoryStream(bytes);

                    BinaryFormatter   formatter        = new BinaryFormatter();
                    DeferredFormatter deferred         = new DeferredFormatter();
                    StreamingContext  streamingContext = new StreamingContext(formatter.Context.State, deferred);
                    formatter.Context = streamingContext;

                    SerializationFallbackBinder sfb = new SerializationFallbackBinder();
                    sfb.AddAssembly(this.GetType().Assembly);
                    sfb.AddAssembly(typeof(FileType).Assembly);
                    formatter.Binder = sfb;

                    object obj = formatter.Deserialize(ms);
                    deferred.FinishDeserialization(ms);

                    ms.Close();
                    ms = null;

                    //SaveConfigToken sct = new SaveConfigToken();
                    //saveConfigToken = (SaveConfigToken)obj;
                    saveConfigToken = GetSaveConfigTokenFromSerializablePortion(obj);
                }

                catch (Exception)
                {
                    // Ignore erros and revert to default
                    saveConfigToken = null;
                }
            }

            if (saveConfigToken == null)
            {
                saveConfigToken = CreateDefaultSaveConfigToken();
            }

            return(saveConfigToken);
        }
コード例 #14
0
ファイル: DdsFileType.cs プロジェクト: herbqiao/paint.net
        protected override unsafe void OnSave( Document input, Stream output, SaveConfigToken token, Surface scratchSurface, ProgressEventHandler callback )
		{
			DdsSaveConfigToken ddsToken = ( DdsSaveConfigToken )token;

			// We need to be able to feast on the goo inside..
			scratchSurface.Clear( ColorBgra.Transparent );

			using ( RenderArgs ra = new RenderArgs( scratchSurface ) )
			{
				input.Render( ra, true );
			}

			// Create the DDS file, and save it..
			DdsFile ddsFile = new DdsFile();
			ddsFile.Save( output, scratchSurface, ddsToken, callback );
		}
コード例 #15
0
ファイル: JpegFileType.cs プロジェクト: nkaligin/paint-mono
        protected override void OnSave(Document input, Stream output, SaveConfigToken token, Surface scratchSurface, ProgressEventHandler callback)
        {
            JpegSaveConfigToken jsct = (JpegSaveConfigToken)token;

            ImageCodecInfo icf = GdiPlusFileType.GetImageCodecInfo(ImageFormat.Jpeg);
            EncoderParameters parms = new EncoderParameters(1);
            EncoderParameter parm = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, jsct.Quality); // force '95% quality'
            parms.Param[0] = parm;

            scratchSurface.Clear(ColorBgra.White);

            using (RenderArgs ra = new RenderArgs(scratchSurface))
            {
                input.Render(ra, true);
            }

            using (Bitmap bitmap = scratchSurface.CreateAliasedBitmap())
            {
                GdiPlusFileType.LoadProperties(bitmap, input);
                bitmap.Save(output, icf, parms);
            }
        }
コード例 #16
0
ファイル: FileType.cs プロジェクト: leejungho2/xynotecgui
        public SaveConfigToken GetLastSaveConfigToken()
        {
            Type            ourType         = this.GetType();
            string          savedTokenName  = ourType.Namespace + "." + ourType.Name;
            string          savedToken      = Settings.CurrentUser.GetString(savedTokenName, null);
            SaveConfigToken saveConfigToken = null;

            if (savedToken != null)
            {
                try
                {
                    SoapFormatter soap              = new SoapFormatter();
                    byte[]        bytes             = Encoding.UTF8.GetBytes(savedToken);
                    MemoryStream  ms                = new MemoryStream(bytes);
                    SerializationFallbackBinder sfb = new SerializationFallbackBinder();
                    sfb.AddAssembly(this.GetType().Assembly);
                    sfb.AddAssembly(typeof(FileType).Assembly);
                    soap.Binder = sfb;
                    object obj = soap.Deserialize(ms);
                    ms.Close();
                    SaveConfigToken sct = new SaveConfigToken();
                    saveConfigToken = (SaveConfigToken)obj;
                }

                catch
                {
                    // Ignore erros and revert to default
                    saveConfigToken = null;
                }
            }

            if (saveConfigToken == null)
            {
                saveConfigToken = CreateDefaultSaveConfigToken();
            }

            return(saveConfigToken);
        }
コード例 #17
0
ファイル: JpegFileType.cs プロジェクト: vip57884381/Paint.Net
        protected override void OnSave(Document input, Stream output, SaveConfigToken token, Surface scratchSurface, ProgressEventHandler callback)
        {
            JpegSaveConfigToken jsct = (JpegSaveConfigToken)token;

            ImageCodecInfo    icf   = GdiPlusFileType.GetImageCodecInfo(ImageFormat.Jpeg);
            EncoderParameters parms = new EncoderParameters(1);
            EncoderParameter  parm  = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, jsct.Quality); // force '95% quality'

            parms.Param[0] = parm;

            scratchSurface.Clear(ColorBgra.White);

            using (RenderArgs ra = new RenderArgs(scratchSurface))
            {
                input.Render(ra, true);
            }

            using (Bitmap bitmap = scratchSurface.CreateAliasedBitmap())
            {
                GdiPlusFileType.LoadProperties(bitmap, input);
                bitmap.Save(output, icf, parms);
            }
        }
コード例 #18
0
ファイル: BmpFileType.cs プロジェクト: nkaligin/paint-mono
        protected override void OnSave(Document input, Stream output, SaveConfigToken token, Surface scratchSurface, ProgressEventHandler callback)
        {
            ImageCodecInfo icf = GdiPlusFileType.GetImageCodecInfo(ImageFormat.Bmp);
            EncoderParameters parms = new EncoderParameters(1);
            EncoderParameter parm = new EncoderParameter(System.Drawing.Imaging.Encoder.ColorDepth, 24); // BMP's should always save as 24-bit
            parms.Param[0] = parm;

            scratchSurface.Clear(ColorBgra.White);

            using (RenderArgs ra = new RenderArgs(scratchSurface))
            {
                input.Render(ra, true);
            }

            // In order to save memory, we 'squish' the 32-bit bitmap down to 24-bit in-place
            // instead of allocating a new bitmap and copying it over.
            SquishSurfaceTo24Bpp(scratchSurface);

            using (Bitmap bitmap = CreateAliased24BppBitmap(scratchSurface))
            {
                GdiPlusFileType.LoadProperties(bitmap, input);
                bitmap.Save(output, icf, parms);
            }
        }
コード例 #19
0
ファイル: FileType.cs プロジェクト: leejungho2/xynotecgui
 protected virtual void OnSave(Document input, Stream output, SaveConfigToken token, Surface scratchSurface, ProgressEventHandler callback)
 {
     throw new OnSaveNotImplementedException("Derived classes must implement this method. It is virtual instead of abstract in order to maintain compatibility with legacy plugins.");
 }
コード例 #20
0
ファイル: FileType.cs プロジェクト: metadeta96/openpdn
 protected virtual object GetSerializablePortionOfSaveConfigToken(SaveConfigToken token)
 {
     return token;
 }
コード例 #21
0
ファイル: FileType.cs プロジェクト: leejungho2/xynotecgui
 /// <summary>
 /// Determines if saving with a given SaveConfigToken would alter the image
 /// in any way. Put another way, if the document is saved with these settings
 /// and then immediately loaded, would it have exactly the same pixel values?
 /// Any lossy codec should return 'false'.
 /// This value is used to optimizing preview rendering memory usage, and as such
 /// flattening should not be taken in to consideration. For example, the codec
 /// for PNG returns true, even though it flattens the image.
 /// </summary>
 /// <param name="token">The SaveConfigToken to determine reflexiveness for.</param>
 /// <returns>true if the save would be reflexive, false if not</returns>
 /// <remarks>If the SaveConfigToken is for another FileType, the result is undefined.</remarks>
 public virtual bool IsReflexive(SaveConfigToken token)
 {
     return false;
 }
コード例 #22
0
ファイル: FileType.cs プロジェクト: leejungho2/xynotecgui
        public void Save(
            Document input,
            Stream output,
            SaveConfigToken token,
            Surface scratchSurface,
            ProgressEventHandler callback,
            bool rememberToken)
        {
            if (!this.SupportsSaving)
            {
                throw new NotImplementedException("Saving is not supported by this FileType");
            }
            else
            {
                Surface disposeMe = null;

                if (scratchSurface == null)
                {
                    disposeMe = new Surface(input.Size);
                    scratchSurface = disposeMe;
                }
                else if (scratchSurface.Size != input.Size)
                {
                    throw new ArgumentException("scratchSurface.Size must equal input.Size");
                }

                if (rememberToken)
                {
                    Type ourType = this.GetType();
                    string savedTokenName = ourType.Namespace + "." + ourType.Name;
                    SoapFormatter soap = new SoapFormatter();
                    MemoryStream ms = new MemoryStream();
                    soap.Serialize(ms, token);
                    byte[] bytes = ms.GetBuffer();
                    string utf8 = Encoding.UTF8.GetString(bytes);
                    Settings.CurrentUser.SetString(savedTokenName, utf8);
                }

                if (!this.SavesWithProgress)
                {
                    try
                    {
                        OnSave(input, output, token, scratchSurface, null);
                    }

                    catch (OnSaveNotImplementedException)
                    {
                        OldOnSaveTrampoline(input, output, token, null);
                    }
                }
                else
                {
                    try
                    {
                        OnSave(input, output, token, scratchSurface, callback);
                    }

                    catch (OnSaveNotImplementedException)
                    {
                        OldOnSaveTrampoline(input, output, token, callback);
                    }
                }

                if (disposeMe != null)
                {
                    disposeMe.Dispose();
                    disposeMe = null;
                }
            }
        }
コード例 #23
0
        protected override void InitWidgetFromToken(SaveConfigToken token)
        {
            TgaSaveConfigToken tgaToken = (TgaSaveConfigToken)token;

            if (tgaToken.BitDepth == 24)
            {
                this.bpp24Radio.Checked = true;
                this.bpp32Radio.Checked = false;
            }
            else
            {
                this.bpp24Radio.Checked = false;
                this.bpp32Radio.Checked = true;
            }

            this.rleCompressCheckBox.Checked = tgaToken.RleCompress;
        }
コード例 #24
0
 protected override void OnSave(Document input, Stream output, SaveConfigToken token, Surface scratchSurface, ProgressEventHandler callback)
 {
     GdiPlusFileType.Save(input, output, scratchSurface, this.ImageFormat, callback);
 }
コード例 #25
0
ファイル: FileType`2.cs プロジェクト: onelifeonelover/cstd
 protected override sealed void OnSave(Document input, Stream output, SaveConfigToken token, Surface scratchSurface, ProgressEventHandler callback)
 {
     OnSaveT(input, output, (TToken)token, scratchSurface, callback);
 }
コード例 #26
0
ファイル: FileType.cs プロジェクト: smile-ttxp/Paint.NET
 /// <summary>
 /// Determines if saving with a given SaveConfigToken would alter the image
 /// in any way. Put another way, if the document is saved with these settings
 /// and then immediately loaded, would it have exactly the same pixel values?
 /// Any lossy codec should return 'false'.
 /// This value is used to optimizing preview rendering memory usage, and as such
 /// flattening should not be taken in to consideration. For example, the codec
 /// for PNG returns true, even though it flattens the image.
 /// </summary>
 /// <param name="token">The SaveConfigToken to determine reflexiveness for.</param>
 /// <returns>true if the save would be reflexive, false if not</returns>
 /// <remarks>If the SaveConfigToken is for another FileType, the result is undefined.</remarks>
 public virtual bool IsReflexive(SaveConfigToken token)
 {
     return(false);
 }
コード例 #27
0
ファイル: FileType`2.cs プロジェクト: onelifeonelover/cstd
 protected override sealed object GetSerializablePortionOfSaveConfigToken(SaveConfigToken token)
 {
     return(GetSerializablePortionOfSaveConfigToken((TToken)token));
 }
コード例 #28
0
 /// <summary>
 /// This method must be overridden in derived classes.
 /// In this method you must take the values from the given EffectToken
 /// and use them to properly initialize the dialog's user interface elements.
 /// </summary>
 protected virtual void InitWidgetFromToken(SaveConfigToken sourceToken)
 {
     //throw new InvalidOperationException("InitWidgetFromToken was not implemented, or the derived method called the base method");
 }
コード例 #29
0
ファイル: TgaFileType.cs プロジェクト: leejungho2/xynotecgui
 public override bool IsReflexive(SaveConfigToken token)
 {
     if (((TgaSaveConfigToken)token).BitDepth == 32)
     {
         return true;
     }
     else
     {
         return base.IsReflexive(token);
     }
 }
コード例 #30
0
 protected override void OnSave(Document input, Stream output, SaveConfigToken token, Surface scratchSurface, ProgressEventHandler callback)
 {
     GdiPlusFileType.Save(input, output, scratchSurface, this.ImageFormat, callback);
 }
コード例 #31
0
 protected override void InitWidgetFromToken(SaveConfigToken token)
 {
     this.thresholdSlider.Value            = ((GifSaveConfigToken)token).Threshold;
     this.ditherSlider.Value               = ((GifSaveConfigToken)token).DitherLevel;
     this.preMultiplyAlphaCheckBox.Checked = ((GifSaveConfigToken)token).PreMultiplyAlpha;
 }
コード例 #32
0
ファイル: FileType.cs プロジェクト: smile-ttxp/Paint.NET
 protected virtual object GetSerializablePortionOfSaveConfigToken(SaveConfigToken token)
 {
     return(token);
 }
コード例 #33
0
        /// <summary>
        /// Sets the FileType and SaveConfigToken parameters that are used if the
        /// user chooses "Save" from the File menu. These are not used by the
        /// DocumentControl class and should be used by whoever actually goes
        /// to save the Document instance.
        /// </summary>
        /// <param name="fileType"></param>
        /// <param name="saveParameters"></param>
        public void SetDocumentSaveOptions(string newFilePath, FileType newFileType, SaveConfigToken newSaveConfigToken)
        {
            this.filePath = newFilePath;
            OnFilePathChanged();

            this.fileType = newFileType;

            if (newSaveConfigToken == null)
            {
                this.saveConfigToken = null;
            }
            else
            {
                this.saveConfigToken = (SaveConfigToken)newSaveConfigToken.Clone();
            }

            OnSaveOptionsChanged();
        }
コード例 #34
0
ファイル: FileType.cs プロジェクト: smile-ttxp/Paint.NET
 protected virtual void OnSave(Document input, Stream output, SaveConfigToken token, ProgressEventHandler callback)
 {
 }
コード例 #35
0
ファイル: BmpFileType.cs プロジェクト: nkaligin/paint-mono
 public override bool IsReflexive(SaveConfigToken token)
 {
     return false;
 }
コード例 #36
0
ファイル: TgaFileType.cs プロジェクト: leejungho2/xynotecgui
        private void SaveTga(Surface input, Stream output, SaveConfigToken token, ProgressEventHandler progressCallback)
        {
            TgaSaveConfigToken tgaToken = (TgaSaveConfigToken)token;

            TgaHeader header = new TgaHeader();

            header.idLength = 0;
            header.cmapType = 0;
            header.imageType = tgaToken.RleCompress ? TgaType.RleRgb : TgaType.Rgb;
            header.cmapIndex = 0;
            header.cmapLength = 0;
            header.cmapEntrySize = 0; // if bpp=8, set this to 24
            header.xOrigin = 0;
            header.yOrigin = 0;
            header.imageWidth = (ushort)input.Width;
            header.imageHeight = (ushort)input.Height;
            header.pixelDepth = (byte)tgaToken.BitDepth;
            header.imageDesc = 0;

            header.Write(output);

            // write palette if doing 8-bit
            // ... todo?

            for (int y = input.Height - 1; y >= 0; --y)
            {
                // non-rle output
                if (tgaToken.RleCompress)
                {
                    SaveTgaRowRle(output, input, ref header, y);
                }
                else
                {
                    SaveTgaRowRaw(output, input, ref header, y);
                }

                if (progressCallback != null)
                {
                    progressCallback(this, new ProgressEventArgs(100.0 * ((double)(input.Height - y) / (double)input.Height)));
                }
            }
        }
コード例 #37
0
ファイル: FileType`2.cs プロジェクト: onelifeonelover/cstd
 public override sealed bool IsReflexive(SaveConfigToken token)
 {
     return(IsReflexive((TToken)token));
 }
コード例 #38
0
 protected SaveConfigToken(SaveConfigToken copyMe)
 {
 }
コード例 #39
0
        /// <summary>
        /// Used to set the file name, file type, and save config token
        /// </summary>
        /// <param name="newFileName"></param>
        /// <param name="newFileType"></param>
        /// <param name="newSaveConfigToken"></param>
        /// <returns>true if the user clicked through and accepted, or false if they cancelled at any point</returns>
        private bool DoSaveAsDialog(
            out string newFileName, 
            out FileType newFileType, 
            out SaveConfigToken newSaveConfigToken, 
            Surface saveScratchSurface)
        {
            FileTypeCollection fileTypes = FileTypes.GetFileTypes();

            using (IFileSaveDialog sfd = SystemLayer.CommonDialogs.CreateFileSaveDialog())
            {
                sfd.AddExtension = true;
                sfd.CheckPathExists = true;
                sfd.OverwritePrompt = true;
                string filter = fileTypes.ToString(false, null, true, false);
                sfd.Filter = filter;

                string localFileName;
                FileType localFileType;
                SaveConfigToken localSaveConfigToken;
                GetDocumentSaveOptions(out localFileName, out localFileType, out localSaveConfigToken);

                if (Document.Layers.Count > 1 && 
                    localFileType != null && 
                    !localFileType.SupportsLayers)
                {
                    localFileType = null;
                }

                if (localFileType == null)
                {
                    if (Document.Layers.Count == 1)
                    {
                        localFileType = PdnFileTypes.Png;
                    }
                    else
                    {
                        localFileType = PdnFileTypes.Pdn;
                    }

                    localFileName = Path.ChangeExtension(localFileName, localFileType.DefaultExtension);
                }

                if (localFileName == null)
                {
                    string name = GetDefaultSaveName();
                    string newName = Path.ChangeExtension(name, localFileType.DefaultExtension);
                    localFileName = Path.Combine(GetDefaultSavePath(), newName);
                }

                // If the filename is only an extension (i.e. ".lmnop") then we must treat it specially
                string fileNameOnly = Path.GetFileName(localFileName);
                if (fileNameOnly.Length >= 1 && fileNameOnly[0] == '.')
                {
                    sfd.FileName = localFileName;
                }
                else
                {
                    sfd.FileName = Path.ChangeExtension(localFileName, null);
                }

                sfd.FilterIndex = 1 + fileTypes.IndexOfFileType(localFileType);
                sfd.InitialDirectory = Path.GetDirectoryName(localFileName);
                sfd.Title = PdnResources.GetString("SaveAsDialog.Title");

                DialogResult dr1 = ShowFileDialog(this, sfd);
                bool result;

                if (dr1 != DialogResult.OK)
                {
                    result = false;
                }
                else
                {
                    localFileName = sfd.FileName;
                    FileType fileType2 = fileTypes[sfd.FilterIndex - 1];
                    result = GetSaveConfigToken(fileType2, localSaveConfigToken, out localSaveConfigToken, saveScratchSurface);
                    localFileType = fileType2;
                }

                if (result)
                {
                    newFileName = localFileName;
                    newFileType = localFileType;
                    newSaveConfigToken = localSaveConfigToken;
                }
                else
                {
                    newFileName = null;
                    newFileType = null;
                    newSaveConfigToken = null;
                }

                return result;
            }
        }
コード例 #40
0
ファイル: FileType.cs プロジェクト: leejungho2/xynotecgui
        public SaveConfigToken GetLastSaveConfigToken()
        {
            Type ourType = this.GetType();
            string savedTokenName = ourType.Namespace + "." + ourType.Name;
            string savedToken = Settings.CurrentUser.GetString(savedTokenName, null);
            SaveConfigToken saveConfigToken = null;

            if (savedToken != null)
            {
                try
                {
                    SoapFormatter soap = new SoapFormatter();
                    byte[] bytes = Encoding.UTF8.GetBytes(savedToken);
                    MemoryStream ms = new MemoryStream(bytes);
                    SerializationFallbackBinder sfb = new SerializationFallbackBinder();
                    sfb.AddAssembly(this.GetType().Assembly);
                    sfb.AddAssembly(typeof(FileType).Assembly);
                    soap.Binder = sfb;
                    object obj = soap.Deserialize(ms);
                    ms.Close();
                    SaveConfigToken sct = new SaveConfigToken();
                    saveConfigToken = (SaveConfigToken)obj;
                }

                catch
                {
                    // Ignore erros and revert to default
                    saveConfigToken = null;
                }
            }

            if (saveConfigToken == null)
            {
                saveConfigToken = CreateDefaultSaveConfigToken();
            }

            return saveConfigToken;
        }
コード例 #41
0
 /// <summary>
 /// This method must be overridden in derived classes.
 /// In this method you must take the values from the given EffectToken
 /// and use them to properly initialize the dialog's user interface elements.
 /// </summary>
 protected virtual void InitWidgetFromToken(SaveConfigToken sourceToken)
 {
     //throw new InvalidOperationException("InitWidgetFromToken was not implemented, or the derived method called the base method");
 }
コード例 #42
0
ファイル: FileType.cs プロジェクト: leejungho2/xynotecgui
 public void Save(Document input, Stream output, SaveConfigToken token, ProgressEventHandler callback, bool rememberToken)
 {
     using (Surface scratch = new Surface(input.Width, input.Height))
     {
         Save(input, output, token, callback, rememberToken);
     }
 }
コード例 #43
0
 protected SaveConfigToken(SaveConfigToken copyMe)
 {
 }
コード例 #44
0
ファイル: FileType.cs プロジェクト: leejungho2/xynotecgui
 protected virtual void OnSave(Document input, Stream output, SaveConfigToken token, ProgressEventHandler callback)
 {
 }
コード例 #45
0
 protected override void InitWidgetFromToken(SaveConfigToken token)
 {
     this.qualitySlider.Value = ((JpegSaveConfigToken)token).Quality;
 }
コード例 #46
0
ファイル: FileType.cs プロジェクト: leejungho2/xynotecgui
        /// <summary>
        /// Because the old OnSave() method is obsolete, we must use reflection to call it.
        /// This is important for legacy FileType plugins. It allows us to ensure that no
        /// new plugins can be compiled using the old OnSave() overload.
        /// </summary>
        private void OldOnSaveTrampoline(Document input, Stream output, SaveConfigToken token, ProgressEventHandler callback)
        {
            MethodInfo onSave = GetType().GetMethod(
                "OnSave",
                BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy,
                Type.DefaultBinder,
                new Type[]
                {
                    typeof(Document),
                    typeof(Stream),
                    typeof(SaveConfigToken),
                    typeof(ProgressEventHandler)
                },
                null);

            onSave.Invoke(
                this,
                new object[]
                {
                    input,
                    output,
                    token,
                    callback
                });
        }
コード例 #47
0
ファイル: BmpFileType.cs プロジェクト: leejungho2/xynotecgui
 public override bool IsReflexive(SaveConfigToken token)
 {
     return(false);
 }
コード例 #48
0
ファイル: FileType.cs プロジェクト: smile-ttxp/Paint.NET
        public void Save(
            Document input,
            Stream output,
            SaveConfigToken token,
            Surface scratchSurface,
            ProgressEventHandler callback,
            bool rememberToken)
        {
            Tracing.LogFeature("Save(" + GetType().FullName + ")");

            if (!this.SupportsSaving)
            {
                throw new NotImplementedException("Saving is not supported by this FileType");
            }
            else
            {
                Surface disposeMe = null;

                if (scratchSurface == null)
                {
                    disposeMe      = new Surface(input.Size);
                    scratchSurface = disposeMe;
                }
                else if (scratchSurface.Size != input.Size)
                {
                    throw new ArgumentException("scratchSurface.Size must equal input.Size");
                }

                if (rememberToken)
                {
                    Type   ourType        = this.GetType();
                    string savedTokenName = "SaveConfigToken." + ourType.Namespace + "." + ourType.Name + ".BinaryFormatter";

                    MemoryStream ms = new MemoryStream();

                    BinaryFormatter   formatter         = new BinaryFormatter();
                    DeferredFormatter deferredFormatter = new DeferredFormatter(false, null);
                    StreamingContext  streamingContext  = new StreamingContext(formatter.Context.State, deferredFormatter);
                    formatter.Context = streamingContext;

                    object tokenSubset = GetSerializablePortionOfSaveConfigToken(token);

                    formatter.Serialize(ms, tokenSubset);
                    deferredFormatter.FinishSerialization(ms);

                    byte[] bytes       = ms.GetBuffer();
                    string base64Bytes = Convert.ToBase64String(bytes);

                    Settings.CurrentUser.SetString(savedTokenName, base64Bytes);
                }

                try
                {
                    OnSave(input, output, token, scratchSurface, callback);
                }

                catch (OnSaveNotImplementedException)
                {
                    OldOnSaveTrampoline(input, output, token, callback);
                }

                if (disposeMe != null)
                {
                    disposeMe.Dispose();
                    disposeMe = null;
                }
            }
        }
コード例 #49
0
 protected override sealed void InitWidgetFromToken(SaveConfigToken sourceToken)
 {
     InitWidgetFromToken((TToken)sourceToken);
 }
コード例 #50
0
ファイル: FileType.cs プロジェクト: leejungho2/xynotecgui
        public void Save(
            Document input,
            Stream output,
            SaveConfigToken token,
            Surface scratchSurface,
            ProgressEventHandler callback,
            bool rememberToken)
        {
            if (!this.SupportsSaving)
            {
                throw new NotImplementedException("Saving is not supported by this FileType");
            }
            else
            {
                Surface disposeMe = null;

                if (scratchSurface == null)
                {
                    disposeMe      = new Surface(input.Size);
                    scratchSurface = disposeMe;
                }
                else if (scratchSurface.Size != input.Size)
                {
                    throw new ArgumentException("scratchSurface.Size must equal input.Size");
                }

                if (rememberToken)
                {
                    Type          ourType        = this.GetType();
                    string        savedTokenName = ourType.Namespace + "." + ourType.Name;
                    SoapFormatter soap           = new SoapFormatter();
                    MemoryStream  ms             = new MemoryStream();
                    soap.Serialize(ms, token);
                    byte[] bytes = ms.GetBuffer();
                    string utf8  = Encoding.UTF8.GetString(bytes);
                    Settings.CurrentUser.SetString(savedTokenName, utf8);
                }

                if (!this.SavesWithProgress)
                {
                    try
                    {
                        OnSave(input, output, token, scratchSurface, null);
                    }

                    catch (OnSaveNotImplementedException)
                    {
                        OldOnSaveTrampoline(input, output, token, null);
                    }
                }
                else
                {
                    try
                    {
                        OnSave(input, output, token, scratchSurface, callback);
                    }

                    catch (OnSaveNotImplementedException)
                    {
                        OldOnSaveTrampoline(input, output, token, callback);
                    }
                }

                if (disposeMe != null)
                {
                    disposeMe.Dispose();
                    disposeMe = null;
                }
            }
        }
コード例 #51
0
 private void defaultsButton_Click(object sender, System.EventArgs e)
 {
     this.SaveConfigToken = this.FileType.CreateDefaultSaveConfigToken();
 }
コード例 #52
0
ファイル: FileType.cs プロジェクト: smile-ttxp/Paint.NET
 protected virtual void OnSave(Document input, Stream output, SaveConfigToken token, Surface scratchSurface, ProgressEventHandler callback)
 {
     throw new OnSaveNotImplementedException("Derived classes must implement this method. It is virtual instead of abstract in order to maintain compatibility with legacy plugins.");
 }
コード例 #53
0
 private void DefaultsButton_Click(object sender, System.EventArgs e)
 {
     this.SaveConfigToken = this.FileType.CreateDefaultSaveConfigToken();
 }
コード例 #54
0
        public void GetDocumentSaveOptions(out string filePathResult, out FileType fileTypeResult, out SaveConfigToken saveConfigTokenResult)
        {
            filePathResult = this.filePath;
            fileTypeResult = this.fileType;

            if (this.saveConfigToken == null)
            {
                saveConfigTokenResult = null;
            }
            else
            {
                saveConfigTokenResult = (SaveConfigToken)this.saveConfigToken.Clone();
            }
        }
コード例 #55
0
ファイル: TgaFileType.cs プロジェクト: leejungho2/xynotecgui
        protected override void OnSave(Document input, Stream output, SaveConfigToken token, Surface scratchSurface, ProgressEventHandler callback)
        {
            scratchSurface.Clear(ColorBgra.FromBgra(255, 255, 255, 0));

            using (RenderArgs ra = new RenderArgs(scratchSurface))
            {
                input.Render(ra, true);
            }

            SaveTga(scratchSurface, output, token, callback);
        }
コード例 #56
0
        /// <summary>
        /// Use this to get a save config token. You should already know the filename and file type.
        /// An existing save config token is optional and will be used to pre-populate the config dialog.
        /// </summary>
        /// <param name="fileType"></param>
        /// <param name="saveConfigToken"></param>
        /// <param name="newSaveConfigToken"></param>
        /// <returns>false if the user cancelled, otherwise true</returns>
        private bool GetSaveConfigToken(
            FileType currentFileType, 
            SaveConfigToken currentSaveConfigToken, 
            out SaveConfigToken newSaveConfigToken, 
            Surface saveScratchSurface)
        {
            if (currentFileType.SupportsConfiguration)
            {
                using (SaveConfigDialog scd = new SaveConfigDialog())
                {
                    scd.ScratchSurface = saveScratchSurface;

                    ProgressEventHandler peh = delegate(object sender, ProgressEventArgs e)
                    {
                        if (e.Percent < 0 || e.Percent >= 100)
                        {
                            AppWorkspace.Widgets.StatusBarProgress.ResetProgressStatusBar();
                            AppWorkspace.Widgets.StatusBarProgress.EraseProgressStatusBar();
                        }
                        else
                        {
                            AppWorkspace.Widgets.StatusBarProgress.SetProgressStatusBar(e.Percent);
                        }
                    };

                    //if (currentFileType.SavesWithProgress)
                    {
                        scd.Progress += peh;
                    }

                    scd.Document = Document;
                    scd.FileType = currentFileType;

                    SaveConfigToken token = currentFileType.GetLastSaveConfigToken();
                    if (currentSaveConfigToken != null &&
                        token.GetType() == currentSaveConfigToken.GetType())
                    {
                        scd.SaveConfigToken = currentSaveConfigToken;
                    }

                    scd.EnableInstanceOpacity = false;

                    // show configuration/preview dialog
                    DialogResult dr = scd.ShowDialog(this);

                    //if (currentFileType.SavesWithProgress)
                    {
                        scd.Progress -= peh;
                        AppWorkspace.Widgets.StatusBarProgress.ResetProgressStatusBar();
                        AppWorkspace.Widgets.StatusBarProgress.EraseProgressStatusBar();
                    }

                    if (dr == DialogResult.OK)
                    {
                        newSaveConfigToken = scd.SaveConfigToken;
                        return true;
                    }
                    else
                    {
                        newSaveConfigToken = null;
                        return false;
                    }
                }
            }
            else
            {
                newSaveConfigToken = currentFileType.GetLastSaveConfigToken();
                return true;
            }
        }
コード例 #57
0
 protected override void InitWidgetFromToken(SaveConfigToken token)
 {
     this.qualitySlider.Value = ((JpegSaveConfigToken)token).Quality;
 }