summaryrefslogtreecommitdiff
path: root/svtools
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@collabora.com>2022-01-13 15:59:49 +0100
committerAndras Timar <andras.timar@collabora.com>2022-02-14 12:09:32 +0100
commit8ad4edf43f7e143967590dac02ca72d843f9ae11 (patch)
tree3ebada26f871c099c7ba6cb1a77d677d021e1d48 /svtools
parentb900907fde6d4507cff7844c5bcd6cc2f7b3821f (diff)
support for the WebP image format (tdf#114532)
This commit implements a WebP reader and writer for both lossless and lossy WebP, export dialog options for selecting lossless/lossy and quality for lossy, and various internal support for the format. Since writing WebP to e.g. ODT documents would make those images unreadable by previous versions with no WebP support, support for that is explicitly disabled in GraphicFilter, to be enabled somewhen later. Change-Id: I9b10f6da6faa78a0bb74415a92e9f163c14685f7 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128920 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'svtools')
-rw-r--r--svtools/inc/bitmaps.hlst2
-rw-r--r--svtools/source/filter/exportdialog.cxx53
-rw-r--r--svtools/source/filter/exportdialog.hxx9
-rw-r--r--svtools/source/misc/imagemgr.cxx5
-rw-r--r--svtools/uiconfig/ui/graphicexport.ui36
5 files changed, 88 insertions, 17 deletions
diff --git a/svtools/inc/bitmaps.hlst b/svtools/inc/bitmaps.hlst
index 35332e05ede0..c9c5bd88dc50 100644
--- a/svtools/inc/bitmaps.hlst
+++ b/svtools/inc/bitmaps.hlst
@@ -39,6 +39,7 @@
#define BMP_MET_SC "res/sx03218.png"
#define BMP_PNG_SC "res/sx03219.png"
#define BMP_SVM_SC "res/sx03222.png"
+#define BMP_WEBP_SC "res/sx03223.png"
#define BMP_GLOBAL_DOC_SC "res/sx03226.png"
#define BMP_DRAW_SC "res/sx03227.png"
#define BMP_DRAWTEMPLATE_SC "res/sx03228.png"
@@ -85,6 +86,7 @@
#define BMP_MET_LC "res/lx03218.png"
#define BMP_PNG_LC "res/lx03219.png"
#define BMP_SVM_LC "res/lx03222.png"
+#define BMP_WEBP_LC "res/lx03223.png"
#define BMP_GLOBAL_DOC_LC "res/lx03226.png"
#define BMP_DRAW_LC "res/lx03227.png"
#define BMP_DRAWTEMPLATE_LC "res/lx03228.png"
diff --git a/svtools/source/filter/exportdialog.cxx b/svtools/source/filter/exportdialog.cxx
index 76d90f7b8e06..2d563e02b274 100644
--- a/svtools/source/filter/exportdialog.cxx
+++ b/svtools/source/filter/exportdialog.cxx
@@ -57,6 +57,7 @@
#define FORMAT_EMF 13
#define FORMAT_EPS 14
#define FORMAT_SVG 16
+#define FORMAT_WEBP 17
#define UNIT_DEFAULT -1
#define UNIT_INCH 0
@@ -89,6 +90,8 @@ static sal_Int16 GetFilterFormat(std::u16string_view rExt)
nFormat = FORMAT_EPS;
else if ( rExt == u"SVG" )
nFormat = FORMAT_SVG;
+ else if ( rExt == u"WEBP" )
+ nFormat = FORMAT_WEBP;
return nFormat;
}
@@ -293,6 +296,15 @@ uno::Sequence< beans::PropertyValue > ExportDialog::GetFilterData( bool bUpdateC
pFilterOptions->WriteInt32("CompressionMode", nCheck);
}
break;
+
+ case FORMAT_WEBP :
+ {
+ assert(mpSbCompression);
+ pFilterOptions->WriteInt32("Quality", static_cast<sal_Int32>(mpSbCompression->get_value()));
+ pFilterOptions->WriteBool("Lossless", mxCbLossless->get_active());
+ }
+ break;
+
}
uno::Sequence< beans::PropertyValue > aRet( pFilterOptions->GetFilterData() );
@@ -582,12 +594,13 @@ ExportDialog::ExportDialog(FltCallDialogParameter& rPara,
, mxLbResolution(m_xBuilder->weld_combo_box("resolutionlb"))
, mxColorDepth(m_xBuilder->weld_widget("colordepth"))
, mxLbColorDepth(m_xBuilder->weld_combo_box("colordepthlb"))
- , mxJPGQuality(m_xBuilder->weld_widget("jpgquality"))
+ , mxJPGWEBPQuality(m_xBuilder->weld_widget("jpgwebpquality"))
, mxPNGCompression(m_xBuilder->weld_widget("pngcompression"))
, mxSbPngCompression(m_xBuilder->weld_scale("compressionpngsb"))
, mxNfPngCompression(m_xBuilder->weld_spin_button("compressionpngnf"))
- , mxSbJpgCompression(m_xBuilder->weld_scale("compressionjpgsb"))
- , mxNfJpgCompression(m_xBuilder->weld_spin_button("compressionjpgnf"))
+ , mxSbJpgWebpCompression(m_xBuilder->weld_scale("compressionjpgwebpsb"))
+ , mxNfJpgWebpCompression(m_xBuilder->weld_spin_button("compressionjpgwebpnf"))
+ , mxCbLossless(m_xBuilder->weld_check_button("losslesscb"))
, mxMode(m_xBuilder->weld_widget("mode"))
, mxCbInterlaced(m_xBuilder->weld_check_button("interlacedcb"))
, mxBMPCompression(m_xBuilder->weld_widget("bmpcompression"))
@@ -681,6 +694,8 @@ ExportDialog::ExportDialog(FltCallDialogParameter& rPara,
mxCbInterlaced->connect_toggled( LINK( this, ExportDialog, UpdateHdl ) );
+ mxCbLossless->connect_toggled( LINK( this, ExportDialog, UpdateHdlLossless ) );
+
mxCbSaveTransparency->connect_toggled( LINK( this, ExportDialog, UpdateHdl ) );
mxModifyDimension->connect_toggled( LINK( this, ExportDialog, UpdateLock ) );
@@ -761,15 +776,16 @@ void ExportDialog::createFilterOptions()
mxColorDepth->show();
// Quality
- mxJPGQuality->show();
+ mxJPGWEBPQuality->show();
sal_Int32 nQuality = mpFilterOptionsItem->ReadInt32("Quality", 75);
if ((nQuality < 1 ) || (nQuality > 100))
nQuality = 75;
- mpSbCompression = mxSbJpgCompression.get();
- mpNfCompression = mxNfJpgCompression.get();
+ mpSbCompression = mxSbJpgWebpCompression.get();
+ mpNfCompression = mxNfJpgWebpCompression.get();
mpSbCompression->set_range(1, 100);
mpNfCompression->set_range(1, 100);
mpNfCompression->set_value(nQuality);
+ mxCbLossless->hide(); // only for WebP
}
break;
case FORMAT_PNG :
@@ -852,6 +868,24 @@ void ExportDialog::createFilterOptions()
mxRbEPSCompressionNone->set_active( nCompr != 1 );
}
break;
+ case FORMAT_WEBP :
+ {
+ // Quality
+ mxJPGWEBPQuality->show();
+ sal_Int32 nQuality = mpFilterOptionsItem->ReadInt32("Quality", 75);
+ if ((nQuality < 1 ) || (nQuality > 100))
+ nQuality = 75;
+ mpSbCompression = mxSbJpgWebpCompression.get();
+ mpNfCompression = mxNfJpgWebpCompression.get();
+ mpSbCompression->set_range(1, 100);
+ mpNfCompression->set_range(1, 100);
+ mpNfCompression->set_value(nQuality);
+
+ // Lossless
+ mxCbLossless->set_active(mpFilterOptionsItem->ReadBool("Lossless", true));
+ UpdateHdlLossless(*mxCbLossless);
+ }
+ break;
}
}
@@ -995,6 +1029,13 @@ IMPL_LINK_NOARG(ExportDialog, UpdateHdl, weld::Toggleable&, void)
updateControls();
}
+IMPL_LINK_NOARG(ExportDialog, UpdateHdlLossless, weld::Toggleable&, void)
+{
+ mpSbCompression->set_sensitive(!mxCbLossless->get_active());
+ mpNfCompression->set_sensitive(!mxCbLossless->get_active());
+ updateControls();
+}
+
IMPL_LINK_NOARG(ExportDialog, UpdateLock, weld::Toggleable&, void)
{
if (mxModifyResolution->get_active())
diff --git a/svtools/source/filter/exportdialog.hxx b/svtools/source/filter/exportdialog.hxx
index 28953ee0224c..1c7c63953a16 100644
--- a/svtools/source/filter/exportdialog.hxx
+++ b/svtools/source/filter/exportdialog.hxx
@@ -104,14 +104,16 @@ private:
std::unique_ptr<weld::Widget> mxColorDepth;
std::unique_ptr<weld::ComboBox> mxLbColorDepth;
- std::unique_ptr<weld::Widget> mxJPGQuality;
+ std::unique_ptr<weld::Widget> mxJPGWEBPQuality;
std::unique_ptr<weld::Widget> mxPNGCompression;
std::unique_ptr<weld::Scale> mxSbPngCompression;
std::unique_ptr<weld::SpinButton> mxNfPngCompression;
- std::unique_ptr<weld::Scale> mxSbJpgCompression;
- std::unique_ptr<weld::SpinButton> mxNfJpgCompression;
+ std::unique_ptr<weld::Scale> mxSbJpgWebpCompression;
+ std::unique_ptr<weld::SpinButton> mxNfJpgWebpCompression;
+
+ std::unique_ptr<weld::CheckButton> mxCbLossless;
std::unique_ptr<weld::Widget> mxMode;
std::unique_ptr<weld::CheckButton> mxCbInterlaced;
@@ -152,6 +154,7 @@ private:
DECL_LINK(UpdateHdlMtfSizeY, weld::SpinButton&, void);
DECL_LINK(UpdateHdlNfResolution, weld::SpinButton&, void);
DECL_LINK(SbCompressionUpdateHdl, weld::Scale&, void);
+ DECL_LINK(UpdateHdlLossless, weld::Toggleable&, void);
DECL_LINK(OK, weld::Button&, void);
diff --git a/svtools/source/misc/imagemgr.cxx b/svtools/source/misc/imagemgr.cxx
index 58cba39f574f..7ac01619162e 100644
--- a/svtools/source/misc/imagemgr.cxx
+++ b/svtools/source/misc/imagemgr.cxx
@@ -153,6 +153,7 @@ SvtExtensionResIdMapping_Impl const ExtensionMap_Impl[] =
{ "url", false, STR_DESCRIPTION_LINK, SvImageId::NONE },
{ "vor", false, STR_DESCRIPTION_SOFFICE_TEMPLATE_DOC, SvImageId::WriterTemplate },
{ "vxd", true, STR_DESCRIPTION_SYSFILE, SvImageId::NONE },
+ { "webp", true, STR_DESCRIPTION_GRAPHIC_DOC, SvImageId::WEBP },
{ "wmf", true, STR_DESCRIPTION_GRAPHIC_DOC, SvImageId::WMF },
{ "xls", false, STR_DESCRIPTION_EXCEL_DOC, SvImageId::Calc },
{ "xlt", false, STR_DESCRIPTION_EXCEL_TEMPLATE_DOC, SvImageId::CalcTemplate },
@@ -568,6 +569,8 @@ static OUString GetImageNameFromList_Impl( SvImageId nImageId, vcl::ImageType eI
return BMP_TEXTFILE_LC;
case SvImageId::TIFF:
return BMP_TIFF_LC;
+ case SvImageId::WEBP:
+ return BMP_WEBP_LC;
case SvImageId::WMF:
return BMP_WMF_LC;
case SvImageId::Writer:
@@ -667,6 +670,8 @@ static OUString GetImageNameFromList_Impl( SvImageId nImageId, vcl::ImageType eI
return BMP_TEXTFILE_SC;
case SvImageId::TIFF:
return BMP_TIFF_SC;
+ case SvImageId::WEBP:
+ return BMP_WEBP_SC;
case SvImageId::WMF:
return BMP_WMF_SC;
case SvImageId::Writer:
diff --git a/svtools/uiconfig/ui/graphicexport.ui b/svtools/uiconfig/ui/graphicexport.ui
index 223dd3dd456c..27cf6d17f04e 100644
--- a/svtools/uiconfig/ui/graphicexport.ui
+++ b/svtools/uiconfig/ui/graphicexport.ui
@@ -368,12 +368,12 @@
</packing>
</child>
<child>
- <object class="GtkFrame" id="jpgquality">
+ <object class="GtkFrame" id="jpgwebpquality">
<property name="can-focus">False</property>
<property name="label-xalign">0</property>
<property name="shadow-type">none</property>
<child>
- <!-- n-columns=2 n-rows=1 -->
+ <!-- n-columns=2 n-rows=2 -->
<object class="GtkGrid" id="grid2">
<property name="visible">True</property>
<property name="can-focus">False</property>
@@ -381,7 +381,27 @@
<property name="margin-top">6</property>
<property name="column-spacing">6</property>
<child>
- <object class="GtkSpinButton" id="compressionjpgnf">
+ <object class="GtkCheckButton" id="losslesscb">
+ <property name="label" translatable="yes" context="graphicexport|losslesscb">Lossless</property>
+ <property name="visible">True</property>
+ <property name="can-focus">True</property>
+ <property name="receives-default">False</property>
+ <property name="use-underline">True</property>
+ <property name="active">True</property>
+ <property name="draw-indicator">True</property>
+ <child internal-child="accessible">
+ <object class="AtkObject" id="losslesscb-atkobject">
+ <property name="AtkObject::accessible-description" translatable="yes" context="graphicexport|extended_tip|losslesscb">Lossless images do not lose quality but result in larger files.</property>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="left-attach">0</property>
+ <property name="top-attach">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkSpinButton" id="compressionjpgwebpnf">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="activates-default">True</property>
@@ -389,18 +409,18 @@
<property name="truncate-multiline">True</property>
<property name="adjustment">adjustment1</property>
<child internal-child="accessible">
- <object class="AtkObject" id="compressionjpgnf-atkobject">
- <property name="AtkObject::accessible-description" translatable="yes" context="graphicexport|extended_tip|compressionjpgnf">Sets the quality for the export. Choose from a low quality with minimal file size, up to a high quality and big file size.</property>
+ <object class="AtkObject" id="compressionjpgwebpnf-atkobject">
+ <property name="AtkObject::accessible-description" translatable="yes" context="graphicexport|extended_tip|compressionjpgwebpnf">Sets the quality for the export. Choose from a low quality with minimal file size, up to a high quality and big file size.</property>
</object>
</child>
</object>
<packing>
<property name="left-attach">1</property>
- <property name="top-attach">0</property>
+ <property name="top-attach">1</property>
</packing>
</child>
<child>
- <object class="GtkScale" id="compressionjpgsb">
+ <object class="GtkScale" id="compressionjpgwebpsb">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="valign">center</property>
@@ -410,7 +430,7 @@
</object>
<packing>
<property name="left-attach">0</property>
- <property name="top-attach">0</property>
+ <property name="top-attach">1</property>
</packing>
</child>
</object>