SkSampler.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 SkSampler_DEFINED
  8. #define SkSampler_DEFINED
  9. #include "include/codec/SkCodec.h"
  10. #include "include/core/SkTypes.h"
  11. #include "src/codec/SkCodecPriv.h"
  12. class SkSampler : public SkNoncopyable {
  13. public:
  14. /**
  15. * Update the sampler to sample every sampleX'th pixel. Returns the
  16. * width after sampling.
  17. */
  18. int setSampleX(int sampleX) {
  19. return this->onSetSampleX(sampleX);
  20. }
  21. /**
  22. * Update the sampler to sample every sampleY'th row.
  23. */
  24. void setSampleY(int sampleY) {
  25. fSampleY = sampleY;
  26. }
  27. /**
  28. * Retrieve the value set for sampleY.
  29. */
  30. int sampleY() const {
  31. return fSampleY;
  32. }
  33. /**
  34. * Based on fSampleY, return whether this row belongs in the output.
  35. *
  36. * @param row Row of the image, starting with the first row in the subset.
  37. */
  38. bool rowNeeded(int row) const {
  39. return (row - get_start_coord(fSampleY)) % fSampleY == 0;
  40. }
  41. /**
  42. * Fill the remainder of the destination with 0.
  43. *
  44. * 0 has a different meaning depending on the SkColorType. For color types
  45. * with transparency, this means transparent. For k565 and kGray, 0 is
  46. * black.
  47. *
  48. * @param info
  49. * Contains the color type of the rows to fill.
  50. * Contains the pixel width of the destination rows to fill
  51. * Contains the number of rows that we need to fill.
  52. *
  53. * @param dst
  54. * The destination row to fill.
  55. *
  56. * @param rowBytes
  57. * Stride in bytes of the destination.
  58. *
  59. * @param zeroInit
  60. * Indicates whether memory is already zero initialized.
  61. */
  62. static void Fill(const SkImageInfo& info, void* dst, size_t rowBytes,
  63. SkCodec::ZeroInitialized zeroInit);
  64. virtual int fillWidth() const = 0;
  65. SkSampler()
  66. : fSampleY(1)
  67. {}
  68. virtual ~SkSampler() {}
  69. private:
  70. int fSampleY;
  71. virtual int onSetSampleX(int) = 0;
  72. };
  73. #endif // SkSampler_DEFINED