SkSampledCodec.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 SkSampledCodec_DEFINED
  8. #define SkSampledCodec_DEFINED
  9. #include "include/codec/SkAndroidCodec.h"
  10. #include "include/codec/SkCodec.h"
  11. /**
  12. * This class implements the functionality of SkAndroidCodec. Scaling will
  13. * be provided by sampling if it cannot be provided by fCodec.
  14. */
  15. class SkSampledCodec : public SkAndroidCodec {
  16. public:
  17. explicit SkSampledCodec(SkCodec*, ExifOrientationBehavior);
  18. ~SkSampledCodec() override {}
  19. protected:
  20. SkISize onGetSampledDimensions(int sampleSize) const override;
  21. bool onGetSupportedSubset(SkIRect* desiredSubset) const override { return true; }
  22. SkCodec::Result onGetAndroidPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
  23. const AndroidOptions& options) override;
  24. private:
  25. /**
  26. * Find the best way to account for native scaling.
  27. *
  28. * Return a size that fCodec can scale to, and adjust sampleSize to finish scaling.
  29. *
  30. * @param sampleSize As an input, the requested sample size.
  31. * As an output, sampling needed after letting fCodec
  32. * scale to the returned dimensions.
  33. * @param nativeSampleSize Optional output parameter. Will be set to the
  34. * effective sample size done by fCodec.
  35. * @return SkISize The size that fCodec should scale to.
  36. */
  37. SkISize accountForNativeScaling(int* sampleSize, int* nativeSampleSize = nullptr) const;
  38. /**
  39. * This fulfills the same contract as onGetAndroidPixels().
  40. *
  41. * We call this function from onGetAndroidPixels() if we have determined
  42. * that fCodec does not support the requested scale, and we need to
  43. * provide the scale by sampling.
  44. */
  45. SkCodec::Result sampledDecode(const SkImageInfo& info, void* pixels, size_t rowBytes,
  46. const AndroidOptions& options);
  47. typedef SkAndroidCodec INHERITED;
  48. };
  49. #endif // SkSampledCodec_DEFINED