webp_codec.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Copyright 2021 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef UI_GFX_CODEC_WEBP_CODEC_H_
  5. #define UI_GFX_CODEC_WEBP_CODEC_H_
  6. #include <vector>
  7. #include "third_party/skia/include/core/SkBitmap.h"
  8. #include "third_party/skia/include/core/SkPixmap.h"
  9. #include "ui/gfx/codec/codec_export.h"
  10. class SkBitmap;
  11. namespace gfx {
  12. class Size;
  13. // Interface for encoding WebP data. This is currently only used
  14. // in the devtools protocol to encode screenshots, so currently only minimally
  15. // supports lossy encoding.
  16. class CODEC_EXPORT WebpCodec {
  17. public:
  18. WebpCodec(const WebpCodec&) = delete;
  19. WebpCodec& operator=(const WebpCodec&) = delete;
  20. // Encodes (lossy) the given raw 'input' pixmap, which includes a pointer to
  21. // pixels as well as information describing the pixel format. The encoded WebP
  22. // data will be written into the supplied vector and true will be returned on
  23. // success. On failure (false), the contents of the output buffer are
  24. // undefined.
  25. //
  26. // quality: an integer in the range 0-100, where 100 is the highest quality.
  27. // Since this currently only supports lossy encoding, a higher
  28. // quality means a higher visual quality.
  29. static bool Encode(const SkPixmap& input,
  30. int quality,
  31. std::vector<unsigned char>* output);
  32. // Encodes (lossy) the 'input' bitmap. The encoded WebP data will be written
  33. // into the supplied vector and true will be returned on success. On failure
  34. // (false), the contents of the output buffer are undefined.
  35. //
  36. // quality: an integer in the range 0-100, where 100 is the highest quality.
  37. // Since this currently only supports lossy encoding, a higher
  38. // quality means a higher visual quality.
  39. static bool Encode(const SkBitmap& input,
  40. int quality,
  41. std::vector<unsigned char>* output);
  42. };
  43. } // namespace gfx
  44. #endif // UI_GFX_CODEC_WEBP_CODEC_H_