SkBitmapRegionDecoder.h 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * Copyright 2015 Google Inc.
  3. *
  4. * Use of this source code is governed by a BSD-style license that can be
  5. * found in the LICENSE file.
  6. */
  7. #ifndef SkBitmapRegionDecoder_DEFINED
  8. #define SkBitmapRegionDecoder_DEFINED
  9. #include "include/android/SkBRDAllocator.h"
  10. #include "include/core/SkBitmap.h"
  11. #include "include/core/SkEncodedImageFormat.h"
  12. #include "include/core/SkStream.h"
  13. /*
  14. * This class aims to provide an interface to test multiple implementations of
  15. * SkBitmapRegionDecoder.
  16. */
  17. class SK_API SkBitmapRegionDecoder {
  18. public:
  19. enum Strategy {
  20. kAndroidCodec_Strategy, // Uses SkAndroidCodec for scaling and subsetting
  21. };
  22. /*
  23. * @param data Refs the data while this object exists, unrefs on destruction
  24. * @param strategy Strategy used for scaling and subsetting
  25. * @return Tries to create an SkBitmapRegionDecoder, returns NULL on failure
  26. */
  27. static SkBitmapRegionDecoder* Create(sk_sp<SkData>, Strategy strategy);
  28. /*
  29. * @param stream Takes ownership of the stream
  30. * @param strategy Strategy used for scaling and subsetting
  31. * @return Tries to create an SkBitmapRegionDecoder, returns NULL on failure
  32. */
  33. static SkBitmapRegionDecoder* Create(
  34. SkStreamRewindable* stream, Strategy strategy);
  35. /*
  36. * Decode a scaled region of the encoded image stream
  37. *
  38. * @param bitmap Container for decoded pixels. It is assumed that the pixels
  39. * are initially unallocated and will be allocated by this function.
  40. * @param allocator Allocator for the pixels. If this is NULL, the default
  41. * allocator (HeapAllocator) will be used.
  42. * @param desiredSubset Subset of the original image to decode.
  43. * @param sampleSize An integer downscaling factor for the decode.
  44. * @param colorType Preferred output colorType.
  45. * New implementations should return NULL if they do not support
  46. * decoding to this color type.
  47. * The old kOriginal_Strategy will decode to a default color type
  48. * if this color type is unsupported.
  49. * @param requireUnpremul If the image is not opaque, we will use this to determine the
  50. * alpha type to use.
  51. * @param prefColorSpace If non-null and supported, this is the color space that we will
  52. * decode into. Otherwise, we will choose a default.
  53. *
  54. */
  55. virtual bool decodeRegion(SkBitmap* bitmap, SkBRDAllocator* allocator,
  56. const SkIRect& desiredSubset, int sampleSize,
  57. SkColorType colorType, bool requireUnpremul,
  58. sk_sp<SkColorSpace> prefColorSpace = nullptr) = 0;
  59. virtual SkEncodedImageFormat getEncodedFormat() = 0;
  60. virtual SkColorType computeOutputColorType(SkColorType requestedColorType) = 0;
  61. virtual sk_sp<SkColorSpace> computeOutputColorSpace(SkColorType outputColorType,
  62. sk_sp<SkColorSpace> prefColorSpace = nullptr) = 0;
  63. int width() const { return fWidth; }
  64. int height() const { return fHeight; }
  65. virtual ~SkBitmapRegionDecoder() {}
  66. protected:
  67. SkBitmapRegionDecoder(int width, int height)
  68. : fWidth(width)
  69. , fHeight(height)
  70. {}
  71. private:
  72. const int fWidth;
  73. const int fHeight;
  74. };
  75. #endif