SkMaskSwizzler.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 SkMaskSwizzler_DEFINED
  8. #define SkMaskSwizzler_DEFINED
  9. #include "include/core/SkTypes.h"
  10. #include "src/codec/SkMasks.h"
  11. #include "src/codec/SkSampler.h"
  12. #include "src/codec/SkSwizzler.h"
  13. /*
  14. *
  15. * Used to swizzle images whose pixel components are extracted by bit masks
  16. * Currently only used by bmp
  17. *
  18. */
  19. class SkMaskSwizzler : public SkSampler {
  20. public:
  21. /*
  22. * @param masks Unowned pointer to helper class
  23. */
  24. static SkMaskSwizzler* CreateMaskSwizzler(const SkImageInfo& dstInfo,
  25. bool srcIsOpaque,
  26. SkMasks* masks,
  27. uint32_t bitsPerPixel,
  28. const SkCodec::Options& options);
  29. /*
  30. * Swizzle a row
  31. */
  32. void swizzle(void* dst, const uint8_t* SK_RESTRICT src);
  33. int fillWidth() const override {
  34. return fDstWidth;
  35. }
  36. /**
  37. * Returns the byte offset at which we write to destination memory, taking
  38. * scaling, subsetting, and partial frames into account.
  39. * A similar function exists on SkSwizzler.
  40. */
  41. int swizzleWidth() const { return fDstWidth; }
  42. private:
  43. /*
  44. * Row procedure used for swizzle
  45. */
  46. typedef void (*RowProc)(void* dstRow, const uint8_t* srcRow, int width,
  47. SkMasks* masks, uint32_t startX, uint32_t sampleX);
  48. SkMaskSwizzler(SkMasks* masks, RowProc proc, int subsetWidth, int srcOffset);
  49. int onSetSampleX(int) override;
  50. SkMasks* fMasks; // unowned
  51. const RowProc fRowProc;
  52. // FIXME: Can this class share more with SkSwizzler? These variables are all the same.
  53. const int fSubsetWidth; // Width of the subset of source before any sampling.
  54. int fDstWidth; // Width of dst, which may differ with sampling.
  55. int fSampleX;
  56. int fSrcOffset;
  57. int fX0;
  58. };
  59. #endif