28#include <webp/encode.h>
30static int writerFunction(
const uint8_t* data,
size_t size,
const WebPPicture* picture)
39 return WEBP_PRESET_PICTURE;
41 return WEBP_PRESET_PHOTO;
43 return WEBP_PRESET_DRAWING;
45 return WEBP_PRESET_ICON;
47 return WEBP_PRESET_TEXT;
48 return WEBP_PRESET_DEFAULT;
52 std::u16string_view preset,
int quality)
55 if (!WebPConfigInit(&
config))
57 SAL_WARN(
"vcl.filter.webp",
"WebPConfigInit() failed");
62 if (!WebPConfigLosslessPreset(&
config, 6))
64 SAL_WARN(
"vcl.filter.webp",
"WebPConfigLosslessPreset() failed");
72 SAL_WARN(
"vcl.filter.webp",
"WebPConfigPreset() failed");
77 assert(WebPValidateConfig(&
config));
85 SAL_WARN(
"vcl.filter.webp",
"WebPPictureInit() failed");
90 picture.use_argb = lossless ? 1 : 0;
101 bool dataDone =
false;
110 SAL_WARN(
"vcl.filter.webp",
"WebPPictureImportRGB() failed");
118 SAL_WARN(
"vcl.filter.webp",
"WebPPictureImportBGR() failed");
133 if (!WebPPictureAlloc(&
picture))
135 SAL_WARN(
"vcl.filter.webp",
"WebPPictureAlloc() failed");
138 std::vector<uint8_t> data;
140 data.resize(width * height * bpp);
145 unsigned char* dst = data.data() + width * bpp *
y;
147 const sal_uInt8* srcA = accessAlpha->GetScanline(
y);
151 BitmapColor transparency = accessAlpha->GetPixelFromData(srcA,
x);
153 dst[0] =
color.GetRed();
154 dst[1] =
color.GetGreen();
155 dst[2] =
color.GetBlue();
156 dst[3] =
color.GetAlpha();
165 unsigned char* dst = data.data() + width * bpp *
y;
170 dst[0] =
color.GetRed();
171 dst[1] =
color.GetGreen();
172 dst[2] =
color.GetBlue();
173 dst[3] =
color.GetAlpha();
181 if (!WebPPictureImportRGBA(&
picture, data.data(), width * bpp))
183 SAL_WARN(
"vcl.filter.webp",
"WebPPictureImportRGBA() failed");
198 bool lossless = pFilterConfigItem->
ReadBool(
"Lossless",
true);
200 const OUString preset = pFilterConfigItem->
ReadString(
"Preset",
"");
201 int quality = pFilterConfigItem->
ReadInt32(
"Quality", 75);
202 return writeWebp(rStream, bitmap, lossless, preset, quality);
sal_uInt8 GetIndex() const
const AlphaMask & GetAlphaMask() const
Bitmap GetBitmap(Color aTransparentReplaceColor) const
const Size & GetSizePixel() const
tools::Long Height() const
tools::Long Width() const
ScanlineFormat GetScanlineFormat() const
sal_uInt32 GetScanlineSize() const
Scanline GetBuffer() const
BitmapColor GetPixelFromData(const sal_uInt8 *pData, tools::Long nX) const
Scanline GetScanline(tools::Long nY) const
OUString ReadString(const OUString &rKey, const OUString &rDefault)
bool ReadBool(const OUString &rKey, bool bDefault)
sal_Int32 ReadInt32(const OUString &rKey, sal_Int32 nDefault)
BitmapEx GetBitmapEx(const GraphicConversionParameters &rParameters=GraphicConversionParameters()) const
constexpr tools::Long Height() const
constexpr tools::Long Width() const
Reference< XOutputStream > stream
#define SAL_WARN(area, stream)
bool equalsIgnoreAsciiCase(std::u16string_view s1, std::u16string_view s2)
static int writerFunction(const uint8_t *data, size_t size, const WebPPicture *picture)
bool ExportWebpGraphic(SvStream &rStream, const Graphic &rGraphic, FilterConfigItem *pFilterConfigItem)
static WebPPreset presetToValue(std::u16string_view preset)
static bool writeWebp(SvStream &rStream, const BitmapEx &bitmapEx, bool lossless, std::u16string_view preset, int quality)