webp_codec.cc 1010 B

123456789101112131415161718192021222324252627282930313233343536
  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. #include "ui/gfx/codec/webp_codec.h"
  5. #include "third_party/skia/include/encode/SkWebpEncoder.h"
  6. #include "ui/gfx/codec/vector_wstream.h"
  7. namespace gfx {
  8. // Encoder ---------------------------------------------------------------------
  9. bool WebpCodec::Encode(const SkPixmap& input,
  10. int quality,
  11. std::vector<unsigned char>* output) {
  12. output->clear();
  13. VectorWStream dst(output);
  14. SkWebpEncoder::Options options;
  15. options.fQuality = quality;
  16. return SkWebpEncoder::Encode(&dst, input, options);
  17. }
  18. bool WebpCodec::Encode(const SkBitmap& src,
  19. int quality,
  20. std::vector<unsigned char>* output) {
  21. SkPixmap pixmap;
  22. if (!src.peekPixels(&pixmap)) {
  23. return false;
  24. }
  25. return WebpCodec::Encode(pixmap, quality, output);
  26. }
  27. } // namespace gfx