image_util.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 ASH_PUBLIC_CPP_IMAGE_UTIL_H_
  5. #define ASH_PUBLIC_CPP_IMAGE_UTIL_H_
  6. #include <string>
  7. #include "ash/public/cpp/ash_public_export.h"
  8. #include "base/callback_forward.h"
  9. namespace base {
  10. class FilePath;
  11. } // namespace base
  12. namespace gfx {
  13. class ImageSkia;
  14. class Size;
  15. } // namespace gfx
  16. namespace ash {
  17. namespace image_util {
  18. // Returns a `gfx::ImageSkia` of the specified `size` which draws nothing.
  19. ASH_PUBLIC_EXPORT gfx::ImageSkia CreateEmptyImage(const gfx::Size& size);
  20. using DecodeImageCallback = base::OnceCallback<void(const gfx::ImageSkia&)>;
  21. // Reads contents at |file_path| and calls |callback| with a decoded image.
  22. // Calls |callback| with an empty image on failure to read the file or decode
  23. // the image.
  24. // If the image is too large, it will be repeatedly halved until it fits in
  25. // |IPC::Channel::kMaximumMessageSize| bytes.
  26. ASH_PUBLIC_EXPORT void DecodeImageFile(DecodeImageCallback callback,
  27. const base::FilePath& file_path);
  28. // Reads contents of |data| and calls |callback| with a decoded image.
  29. // Calls |callback| with an empty image on failure to decode the image.
  30. // If the image is too large, it will be repeatedly halved until it fits in
  31. // |IPC::Channel::kMaximumMessageSize| bytes.
  32. ASH_PUBLIC_EXPORT void DecodeImageData(DecodeImageCallback callback,
  33. const std::string& data);
  34. } // namespace image_util
  35. } // namespace ash
  36. #endif // ASH_PUBLIC_CPP_IMAGE_UTIL_H_