web_image.h 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * Copyright (C) 2009 Google Inc. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are
  6. * met:
  7. *
  8. * * Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * * Redistributions in binary form must reproduce the above
  11. * copyright notice, this list of conditions and the following disclaimer
  12. * in the documentation and/or other materials provided with the
  13. * distribution.
  14. * * Neither the name of Google Inc. nor the names of its
  15. * contributors may be used to endorse or promote products derived from
  16. * this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #ifndef THIRD_PARTY_BLINK_PUBLIC_WEB_WEB_IMAGE_H_
  31. #define THIRD_PARTY_BLINK_PUBLIC_WEB_WEB_IMAGE_H_
  32. #include "base/time/time.h"
  33. #include "third_party/blink/public/platform/web_common.h"
  34. #include "third_party/blink/public/platform/web_vector.h"
  35. #include "third_party/skia/include/core/SkBitmap.h"
  36. namespace blink {
  37. class WebData;
  38. struct WebSize;
  39. // APIs to decode an image from a string of data.
  40. class WebImage {
  41. public:
  42. // An image with a duration associated. An animation is a sequence of
  43. // AnimationFrames played in succession.
  44. struct AnimationFrame {
  45. SkBitmap bitmap;
  46. base::TimeDelta duration;
  47. };
  48. // Decodes the given image data. If the image has multiple frames,
  49. // then the frame whose size is desired_size is returned. Otherwise,
  50. // the first frame is returned.
  51. BLINK_EXPORT static SkBitmap FromData(const WebData&,
  52. const WebSize& desired_size);
  53. // Decodes the given data as an SVG image. If the SVG is well-formed, an
  54. // image of the first frame is returned. If an error is encountered an empty
  55. // SkBitmap is returned.
  56. // The |desired_size| will, if non-empty, determine the size of the returned
  57. // image - matching the sizing behavior of an <img> with 'width' and 'height'
  58. // specified to |desired_size| pixels. If empty, the intrinsic size (if any)
  59. // of the image will be used.
  60. BLINK_EXPORT static SkBitmap DecodeSVG(const WebData&,
  61. const WebSize& desired_size);
  62. // Returns a list of all frames in the image. Only the first frame at each
  63. // pixel size will be returned.
  64. BLINK_EXPORT static WebVector<SkBitmap> FramesFromData(const WebData&);
  65. // Returns a list of all animation frames in the image.
  66. BLINK_EXPORT static WebVector<AnimationFrame> AnimationFromData(
  67. const WebData&);
  68. WebImage() = delete;
  69. };
  70. } // namespace blink
  71. #endif // THIRD_PARTY_BLINK_PUBLIC_WEB_WEB_IMAGE_H_