internal SaveWidgetDialog(SaveConfigWidget widget, SaveConfigToken defaultToken) { this.SuspendLayout(); SaveConfigWidget configWidget = widget; configWidget.Location = new Point(7, 7); configWidget.Width = 180; Button defaultsButton = new Button(); defaultsButton.AutoSize = true; defaultsButton.FlatStyle = FlatStyle.System; defaultsButton.Text = "Defaults"; defaultsButton.Click += (object sender, EventArgs e) => configWidget.Token = defaultToken; this.IconName = "Save"; this.Text = "Save Configuration"; this.Controls.AddRange(new Control[] { configWidget, defaultsButton }); this.ResumeLayout(false); defaultsButton.Location = new Point((configWidget.Right - configWidget.Left) / 2 + configWidget.Left - defaultsButton.Width / 2, configWidget.Bottom + 16); this.ClientSize = new Size(configWidget.Right + 7, defaultsButton.Bottom + 7); }
protected override void InitWidgetFromToken(SaveConfigToken token) { if (token is DdsSaveConfigToken ddsToken) { 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; } }
protected override void InitWidgetFromToken(SaveConfigToken token) { HDPhotoSaveConfigToken hdToken = (HDPhotoSaveConfigToken)token; this.qualitySlider.Value = hdToken.Quality; this.bpp24RB.Checked = (hdToken.BitDepth == 24); this.bpp32RB.Checked = (hdToken.BitDepth == 32); }
protected override void InitWidgetFromToken(SaveConfigToken token) { HDPhotoSaveConfigToken hdToken = (HDPhotoSaveConfigToken)token; this.qualitySlider.Value = hdToken.Quality; this.bpp24RB.Checked = (hdToken.BitDepth == 24); this.bpp32RB.Checked = (hdToken.BitDepth == 32); }
protected override void OnSave(Document input, Stream output, SaveConfigToken token, Surface surface, ProgressEventHandler callback) { // Do save operation... RenderArgs ra = new RenderArgs(new Surface(input.Size)); input.Render(ra, true); ra.Bitmap.Save(output, System.Drawing.Imaging.ImageFormat.Png); }
protected override void OnSave(Document input, Stream output, SaveConfigToken token, Surface scratchSurface, ProgressEventHandler callback) { using (RenderArgs ra = new RenderArgs(new Surface(input.Size)) { } }
protected override void InitWidgetFromToken(SaveConfigToken token) { if (token is PsdSaveConfigToken psdToken) { this.rleCompressCheckBox.Checked = psdToken.RleCompress; } else { this.rleCompressCheckBox.Checked = true; } }
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); }
public override bool IsReflexive(SaveConfigToken token) { if (((TgaSaveConfigToken)token).BitDepth == 32) { return(true); } else { return(base.IsReflexive(token)); } }
protected override void OnSave(Document input, System.IO.Stream output, SaveConfigToken token, Surface scratchSurface, ProgressEventHandler callback) { // Because the function signature takes in a Stream, we cannot force the // extension to .PSB for large documents. However, Photoshop is happy // to load a PSB file even if it has a .PSD extension. var psdToken = (PsdSaveConfigToken)token; PsdSave.Save(input, output, psdToken, scratchSurface, callback); }
protected override void OnSave(Document input, Stream output, SaveConfigToken token, Surface scratchSurface, ProgressEventHandler callback) { if (callback == null) { input.SaveToStream(output); } else { UpdateProgressTranslator translator = new UpdateProgressTranslator(this.ApproximateMaxOutputOffset(input), callback); input.SaveToStream(output, new IOEventHandler(translator.IOEventHandler)); } }
protected override void OnSave(Document input, System.IO.Stream output, SaveConfigToken token, Surface scratchSurface, ProgressEventHandler callback) { //Here you get the image from Paint.NET and you'll have to convert it //and write the resulting bytes to the output stream (this will save it to the specified file) using (RenderArgs ra = new RenderArgs(new Surface(input.Size))) { //You must call this to prepare the bitmap input.Render(ra); //Now you can access the bitmap and perform some logic on it //In this case I'm converting the bitmap to something else (byte[]) var sampleData = ConvertBitmapToSampleFormat(ra.Bitmap); output.Write(sampleData, 0, sampleData.Length); } }
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); }
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; }
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))); } } }
protected override void OnSave( Document input, Stream output, SaveConfigToken token, Surface scratchSurface, ProgressEventHandler callback) { switch (Thread.CurrentThread.GetApartmentState()) { // WIC does not support MTA, so we must marshal this stuff to another thread that is guaranteed to be STA. case ApartmentState.Unknown: case ApartmentState.MTA: ParameterizedThreadStart pts = new ParameterizedThreadStart(OnSaveThreadProc); OnSaveArgs osa = new OnSaveArgs(); osa.input = input; osa.output = output; osa.token = token; osa.scratchSurface = scratchSurface; osa.callback = callback; Thread staThread = new Thread(pts); staThread.SetApartmentState(ApartmentState.STA); staThread.Start(osa); staThread.Join(); if (osa.exception != null) { throw new ApplicationException("OnSaveImpl() threw an exception", osa.exception); } break; case ApartmentState.STA: OnSaveImpl(input, output, token, scratchSurface, callback); break; default: throw new InvalidOperationException(); } }
protected override void OnSave(Document input, Stream output, SaveConfigToken token, Surface scratchSurface, ProgressEventHandler callback) { input.Flatten(scratchSurface); var pixels = new ColorRgba32[scratchSurface.Width, scratchSurface.Height]; unsafe { for (int y = 0; y < scratchSurface.Height; ++y) { var src = scratchSurface.GetRowPointer(y); for (int x = 0; x < scratchSurface.Width; ++x) { pixels[y, x] = new ColorRgba32((*src).R, (*src).G, (*src).B, (*src).A); src++; } } } using (var writer = new BinaryWriterEx(output, true)) { PaaEncoder.WritePAA(writer, pixels); } }
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, true); // Show dialog and setup engine parameters SaveDialogSettingsState pvrMetaData; if (pvrMetaDataCache != null) { pvrMetaData = ShowSetupDialogBox(pvrMetaDataCache, ra.Bitmap); //load from cache when there } else // no cache make clear instance of settings dialog { switch (LoadEngineMode) { case PvrEngineEnum.None: pvrMetaData = ShowSetupDialogBox(loadedPvrPuyo, ra.Bitmap); //null break; case PvrEngineEnum.ShenmueDK: pvrMetaData = ShowSetupDialogBox(loadedPvr, ra.Bitmap); break; case PvrEngineEnum.PuyoTools: pvrMetaData = ShowSetupDialogBox(loadedPvrPuyo, ra.Bitmap); break; default: pvrMetaData = ShowSetupDialogBox(loadedPvrPuyo, ra.Bitmap); //null break; } } using (var ms = new MemoryStream()) { Image <Bgra32> image = ImageSharpExtensions.ToImageSharpImage(ra.Bitmap); var tmpPvrPuyo = new PvrTextureEncoder(image, pvrMetaData.PuyoPixelFormat, (PvrDataFormat)pvrMetaData.PuyoDataFormat); // optiona global id if (pvrMetaData.GbixId != null) { tmpPvrPuyo.GlobalIndex = pvrMetaData.GbixId; } // dithering tmpPvrPuyo.DitheringMode = pvrMetaData.Dithering; // EyeWeightMode if (pvrMetaData.EyeWeightMode) { tmpPvrPuyo.MetricMode = 1; } else { tmpPvrPuyo.MetricMode = 0; } //GuardedStream workaround (forums.getpaint.net/topic/114912-i-can-not-save-my-work/)? tmpPvrPuyo.Save(ms); byte[] tmpBfr = ms.ToArray(); output.Write(tmpBfr, 0, tmpBfr.Length); pvrMetaDataCache = pvrMetaData; // update settings cache } }
protected override void OnSave(Document input, Stream output, SaveConfigToken token, Surface scratchSurface, ProgressEventHandler callback) { /// Up to date raw data. using (RenderArgs renderArgs = new RenderArgs(scratchSurface)) { input.Render(renderArgs, true); } var bitmap = scratchSurface.CreateAliasedBitmap(); byte[] rawData; using (var memoryStream = new MemoryStream()) { bitmap.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Png); memoryStream.Position = 0; rawData = memoryStream.ToArray(); } SixLabors.ImageSharp.Image <SixLabors.ImageSharp.PixelFormats.Rgba32> fullImage = SixLabors.ImageSharp.Image.Load(rawData); var originalMetaData = input.Metadata.GetUserValue(MetadataNames.DMI_RawData); DMISharp.DMIFile dmi; if (!String.IsNullOrEmpty(originalMetaData)) { //Modyfing loaded DMI - preserve states info, apply frame changes and state name changes byte[] originalRawData = Convert.FromBase64String(originalMetaData); dmi = new DMISharp.DMIFile(new MemoryStream(originalRawData)); /// Update every state image from current document var frameNumber = 0; foreach (var state in dmi.States) { for (int frame = 0; frame < state.Frames; frame++) { for (int dir = 0; dir < state.Dirs; dir++) { var offset = CalculateOffset(frameNumber, input.Width, input.Height, dmi.Metadata.FrameWidth, dmi.Metadata.FrameHeight); Point2Int32 dstOffset = new Point2Int32(offset.X, offset.Y); RectInt32 srcRect = new RectInt32(dstOffset, new SizeInt32(dmi.Metadata.FrameWidth, dmi.Metadata.FrameHeight)); var newFrame = fullImage.Clone(x => x.Crop(new SixLabors.ImageSharp.Rectangle(offset.X, offset.Y, dmi.Metadata.FrameWidth, dmi.Metadata.FrameHeight))); state.SetFrame(newFrame, (DMISharp.StateDirection)dir, frame); frameNumber += 1; } } } ///Update state names if they changed foreach (var layer in input.Layers) { var stateName = layer.Metadata.GetUserValue(MetadataNames.DMI_StateName); if (!String.IsNullOrEmpty(stateName)) { var originalState = dmi.States.Where(state => state.Name == stateName).FirstOrDefault(); originalState.Name = layer.Name; } } } else { //Creating DMI from scratch - generate icon state per layer, assume square frames, single dir and no animations var framesPerLine = (int)Math.Ceiling(Math.Sqrt(input.Layers.Count)); var frameWidth = input.Width / framesPerLine; var frameHeight = input.Height / framesPerLine; dmi = new DMISharp.DMIFile(frameWidth, frameHeight); var stateCounter = 0; foreach (var layer in input.Layers) { var offset = CalculateOffset(stateCounter, input.Width, input.Height, frameWidth, frameHeight); var newFrame = fullImage.Clone(x => x.Crop(new SixLabors.ImageSharp.Rectangle(offset.X, offset.Y, frameWidth, frameHeight))); var newState = new DMISharp.DMIState(layer.Name, DMISharp.DirectionDepth.One, 1, frameWidth, frameHeight); newState.SetFrame(newFrame, 0); dmi.AddState(newState); stateCounter += 1; } } dmi.Save(output); }
protected override void OnSave(Document input, Stream output, SaveConfigToken token, Surface scratchSurface, ProgressEventHandler callback) { Save(input, output, scratchSurface, this.ImageFormat, callback); }
public override bool IsReflexive(SaveConfigToken token) { return(false); }
private void OnSaveImpl( Document input, Stream output, SaveConfigToken token, Surface scratchSurface, ProgressEventHandler callback) { HDPhotoSaveConfigToken hdToken = token as HDPhotoSaveConfigToken; WmpBitmapEncoder wbe = new WmpBitmapEncoder(); using (RenderArgs ra = new RenderArgs(scratchSurface)) { input.Render(ra, true); } MemoryBlock block = scratchSurface.Scan0; IntPtr scan0 = block.Pointer; double dpiX; double dpiY; switch (input.DpuUnit) { case MeasurementUnit.Centimeter: dpiX = Document.DotsPerCmToDotsPerInch(input.DpuX); dpiY = Document.DotsPerCmToDotsPerInch(input.DpuY); break; case MeasurementUnit.Inch: dpiX = input.DpuX; dpiY = input.DpuY; break; case MeasurementUnit.Pixel: dpiX = Document.GetDefaultDpu(MeasurementUnit.Inch); dpiY = Document.GetDefaultDpu(MeasurementUnit.Inch); break; default: throw new InvalidEnumArgumentException(); } BitmapSource bitmapSource = BitmapFrame.Create( scratchSurface.Width, scratchSurface.Height, dpiX, dpiY, System.Windows.Media.PixelFormats.Bgra32, null, scan0, (int)block.Length, // TODO: does not support >2GB images scratchSurface.Stride); FormatConvertedBitmap fcBitmap = new FormatConvertedBitmap( bitmapSource, hdToken.BitDepth == 24 ? PixelFormats.Bgr24 : PixelFormats.Bgra32, null, 0); BitmapFrame outputFrame0 = BitmapFrame.Create(fcBitmap); wbe.Frames.Add(outputFrame0); wbe.ImageQualityLevel = (float)hdToken.Quality / 100.0f; string tempFileName = FileSystem.GetTempFileName(); FileStream tempFileOut = new FileStream(tempFileName, FileMode.Create, FileAccess.Write, FileShare.Read); wbe.Save(tempFileOut); tempFileOut.Close(); tempFileOut = null; FileStream tempFileIn = new FileStream(tempFileName, FileMode.Open, FileAccess.ReadWrite, FileShare.Read); WmpBitmapDecoder wbd = new WmpBitmapDecoder(tempFileIn, BitmapCreateOptions.None, BitmapCacheOption.None); BitmapFrame ioFrame0 = wbd.Frames[0]; InPlaceBitmapMetadataWriter metadata2 = ioFrame0.CreateInPlaceBitmapMetadataWriter(); CopyMetadataTo(metadata2, input.Metadata); tempFileIn.Close(); tempFileIn = null; FileStream tempFileIn2 = new FileStream(tempFileName, FileMode.Open, FileAccess.ReadWrite, FileShare.Read); Utility.CopyStream(tempFileIn2, output); tempFileIn2.Close(); tempFileIn2 = null; try { File.Delete(tempFileName); } catch (Exception) { } // WPF doesn't give us an IDisposable implementation on its types Utility.GCFullCollect(); }
protected override void OnSave(Document input, System.IO.Stream output, SaveConfigToken token, Surface scratchSurface, ProgressEventHandler callback) { PsdSaveConfigToken psdToken = (PsdSaveConfigToken)token; PsdFile psdFile = new PsdFile(); //----------------------------------------------------------------------- psdFile.Rows = input.Height; psdFile.Columns = input.Width; // we have an Alpha channel which will be saved, // we have to add this to our image resources psdFile.Channels = 4; // for now we oly save the images as RGB psdFile.ColorMode = PsdFile.ColorModes.RGB; psdFile.Depth = 8; //----------------------------------------------------------------------- // no color mode Data //----------------------------------------------------------------------- ResolutionInfo resInfo = new ResolutionInfo(); resInfo.HeightUnit = ResolutionInfo.Unit.In; resInfo.WidthUnit = ResolutionInfo.Unit.In; if (input.DpuUnit == MeasurementUnit.Inch) { resInfo.HResUnit = ResolutionInfo.ResUnit.PxPerInch; resInfo.VResUnit = ResolutionInfo.ResUnit.PxPerInch; resInfo.HRes = (short)input.DpuX; resInfo.VRes = (short)input.DpuY; } else { resInfo.HResUnit = ResolutionInfo.ResUnit.PxPerCent; resInfo.VResUnit = ResolutionInfo.ResUnit.PxPerCent; resInfo.HRes = (short)(input.DpuX / 2.54); resInfo.VRes = (short)(input.DpuY / 2.54); } psdFile.Resolution = resInfo; //----------------------------------------------------------------------- psdFile.ImageCompression = psdToken.RleCompress ? ImageCompression.Rle : ImageCompression.Raw; int size = psdFile.Rows * psdFile.Columns; psdFile.ImageData = new byte[psdFile.Channels][]; for (int i = 0; i < psdFile.Channels; i++) { psdFile.ImageData[i] = new byte[size]; } using (RenderArgs ra = new RenderArgs(scratchSurface)) { input.Flatten(scratchSurface); } unsafe { for (int y = 0; y < psdFile.Rows; y++) { int rowIndex = y * psdFile.Columns; ColorBgra *srcRow = scratchSurface.GetRowAddress(y); ColorBgra *srcPixel = srcRow; for (int x = 0; x < psdFile.Columns; x++) { int pos = rowIndex + x; psdFile.ImageData[0][pos] = srcPixel->R; psdFile.ImageData[1][pos] = srcPixel->G; psdFile.ImageData[2][pos] = srcPixel->B; psdFile.ImageData[3][pos] = srcPixel->A; srcPixel++; } } } PaintDotNet.Threading.PrivateThreadPool threadPool = new PaintDotNet.Threading.PrivateThreadPool(); foreach (BitmapLayer layer in input.Layers) { PhotoshopFile.Layer psdLayer = new PhotoshopFile.Layer(psdFile); BlendOpToBlendModeKey(layer.BlendOp, psdLayer); SaveLayerPixelsContext slc = new SaveLayerPixelsContext(layer, psdFile, input, psdLayer, psdToken); WaitCallback waitCallback = new WaitCallback(slc.SaveLayer); threadPool.QueueUserWorkItem(waitCallback); } threadPool.Drain(); psdFile.Save(output); }
protected override void OnSave(Document input, Stream output, SaveConfigToken token, Surface scratchSurface, ProgressEventHandler callback) { MbmSave.Save(input, output, scratchSurface, 24, BitmapColor.Color); }
public override bool IsReflexive(SaveConfigToken token) => true;