image_util.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Copyright 2014 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 EXTENSIONS_COMMON_IMAGE_UTIL_H_
  5. #define EXTENSIONS_COMMON_IMAGE_UTIL_H_
  6. class SkBitmap;
  7. typedef unsigned int SkColor;
  8. namespace base {
  9. class FilePath;
  10. }
  11. // This file contains various utility functions for extension images and colors.
  12. namespace extensions {
  13. namespace image_util {
  14. // Returns whether an icon image is considered to be visible in its display
  15. // context.
  16. bool IsIconSufficientlyVisible(const SkBitmap& bitmap);
  17. // Returns whether an icon image is considered to be visible in its display
  18. // context.
  19. bool IsIconAtPathSufficientlyVisible(const base::FilePath& path);
  20. // This is the color of the toolbar in the default scheme. There is a unit test
  21. // to catch any changes to this value.
  22. extern const SkColor kDefaultToolbarColor;
  23. // Renders the icon bitmap onto another bitmap, combining it with the specified
  24. // background color, then determines whether the rendered icon is sufficiently
  25. // visible against the background.
  26. bool IsRenderedIconSufficientlyVisible(const SkBitmap& bitmap,
  27. SkColor background_color);
  28. // Returns whether an icon image is considered to be visible in its display
  29. // context, according to the previous function.
  30. bool IsRenderedIconAtPathSufficientlyVisible(const base::FilePath& path,
  31. SkColor background_color);
  32. // Icons should be a reasonable size for analysis. There have been crash
  33. // reports due to memory allocation issues with calls to
  34. // SkBitmap::allocN32Pixels. See crbug.com/1155746.
  35. constexpr int kMaxAllowedPixels = 2048 * 2048;
  36. // Renders the icon bitmap onto another bitmap, combining it with the specified
  37. // background color. The output bitmap must be empty.
  38. [[nodiscard]] bool RenderIconForVisibilityAnalysis(const SkBitmap& icon,
  39. SkColor background_color,
  40. SkBitmap* rendered_icon);
  41. // Load a PNG image from a file into the destination bitmap.
  42. bool LoadPngFromFile(const base::FilePath& path, SkBitmap* dst);
  43. } // namespace image_util
  44. } // namespace extensions
  45. #endif // EXTENSIONS_COMMON_IMAGE_UTIL_H_