Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions Pinta.Core/ImageFormats/WebPFormat.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;

using GdkPixbuf;

namespace Pinta.Core;

public sealed class WebPFormat : GdkPixbufFormat
{
private const int DefaultQuality = 80;

public WebPFormat ()
: base ("webp")
{
}

protected override void DoSave (Pixbuf pb, Gio.File file, string fileType, Gtk.Window parent)
{
int level = PintaCore.Settings.GetSetting<int> (SettingNames.WEBP_QUALITY, DefaultQuality);

if (!PintaCore.Workspace.ActiveDocument.HasBeenSavedInSession) {
level = PintaCore.Actions.File.RaiseModifyCompression (level, parent);

if (level == -1)
throw new OperationCanceledException ();
}

PintaCore.Settings.PutSetting (SettingNames.WEBP_QUALITY, level);

using var stream = file.Replace ();
try {
pb.SaveToStreamv (stream, fileType, ["quality"], [level.ToString ()], null);
} finally {
stream.Close (null);
}
}
}
2 changes: 2 additions & 0 deletions Pinta.Core/Managers/ImageConverterManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ private static FormatDescriptor CreateFormatDescriptor (PixbufFormat format)
IImageExporter? exporter;
if (formatName == "jpeg")
exporter = importer = new JpegFormat ();
else if (formatName == "webp")
exporter = importer = new WebPFormat ();
else if (formatName == "tga")
exporter = new TgaExporter ();
else if (format.IsWritable ())
Expand Down
2 changes: 2 additions & 0 deletions Pinta.Core/SettingNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ internal static class SettingNames

internal const string JPG_QUALITY = "jpg-quality";

internal const string WEBP_QUALITY = "webp-quality";

internal const string SELECTION_COMBINE_MODE = "selection-combine-mode";

internal const string SHOW_CANVAS_GRID = "show-canvas-grid";
Expand Down
2 changes: 1 addition & 1 deletion Pinta/Actions/File/ModifyCompressionAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void IActionHandler.Uninitialize ()

private void Activated (object? sender, ModifyCompressionEventArgs e)
{
JpegCompressionDialog dlg = new (e.Quality, e.ParentWindow);
QualityDialog dlg = new (e.Quality, e.ParentWindow);

if (dlg.RunBlocking () == Gtk.ResponseType.Ok)
e.Quality = dlg.CompressionLevel;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// JpegCompressionDialog.cs
//
//
// QualityDialog.cs
//
// Author:
// Maia Kozheva <sikon@ubuntu.com>
//
Expand Down Expand Up @@ -28,11 +28,11 @@

namespace Pinta;

public sealed class JpegCompressionDialog : Gtk.Dialog
public sealed class QualityDialog : Gtk.Dialog
{
private readonly Gtk.Scale compression_level;

public JpegCompressionDialog (int defaultQuality, Gtk.Window parent)
public QualityDialog (int defaultQuality, Gtk.Window parent)
{
Gtk.Label qualityLabel = Gtk.Label.New (Translations.GetString ("Quality: "));
qualityLabel.Xalign = 0;
Expand All @@ -43,7 +43,7 @@ public JpegCompressionDialog (int defaultQuality, Gtk.Window parent)

// --- Initialization (Gtk.Window)

Title = Translations.GetString ("JPEG Quality");
Title = Translations.GetString ("Image Quality");
TransientFor = parent;
Modal = true;

Expand Down
Loading