SkIcoCodec.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 SkIcoCodec_DEFINED
  8. #define SkIcoCodec_DEFINED
  9. #include "include/codec/SkCodec.h"
  10. #include "include/core/SkImageInfo.h"
  11. #include "include/core/SkStream.h"
  12. #include "include/core/SkTypes.h"
  13. #include "include/private/SkTArray.h"
  14. /*
  15. * This class implements the decoding for bmp images
  16. */
  17. class SkIcoCodec : public SkCodec {
  18. public:
  19. static bool IsIco(const void*, size_t);
  20. /*
  21. * Assumes IsIco was called and returned true
  22. * Creates an Ico decoder
  23. * Reads enough of the stream to determine the image format
  24. */
  25. static std::unique_ptr<SkCodec> MakeFromStream(std::unique_ptr<SkStream>, Result*);
  26. protected:
  27. /*
  28. * Chooses the best dimensions given the desired scale
  29. */
  30. SkISize onGetScaledDimensions(float desiredScale) const override;
  31. bool onDimensionsSupported(const SkISize&) override;
  32. /*
  33. * Initiates the Ico decode
  34. */
  35. Result onGetPixels(const SkImageInfo& dstInfo, void* dst, size_t dstRowBytes, const Options&,
  36. int*) override;
  37. SkEncodedImageFormat onGetEncodedFormat() const override {
  38. return SkEncodedImageFormat::kICO;
  39. }
  40. SkScanlineOrder onGetScanlineOrder() const override;
  41. bool conversionSupported(const SkImageInfo&, bool, bool) override {
  42. // This will be checked by the embedded codec.
  43. return true;
  44. }
  45. // Handled by the embedded codec.
  46. bool usesColorXform() const override { return false; }
  47. private:
  48. Result onStartScanlineDecode(const SkImageInfo& dstInfo,
  49. const SkCodec::Options& options) override;
  50. int onGetScanlines(void* dst, int count, size_t rowBytes) override;
  51. bool onSkipScanlines(int count) override;
  52. Result onStartIncrementalDecode(const SkImageInfo& dstInfo, void* pixels, size_t rowBytes,
  53. const SkCodec::Options&) override;
  54. Result onIncrementalDecode(int* rowsDecoded) override;
  55. SkSampler* getSampler(bool createIfNecessary) override;
  56. /*
  57. * Searches fEmbeddedCodecs for a codec that matches requestedSize.
  58. * The search starts at startIndex and ends when an appropriate codec
  59. * is found, or we have reached the end of the array.
  60. *
  61. * @return the index of the matching codec or -1 if there is no
  62. * matching codec between startIndex and the end of
  63. * the array.
  64. */
  65. int chooseCodec(const SkISize& requestedSize, int startIndex);
  66. /*
  67. * Constructor called by NewFromStream
  68. * @param embeddedCodecs codecs for the embedded images, takes ownership
  69. */
  70. SkIcoCodec(SkEncodedInfo&& info, SkTArray<std::unique_ptr<SkCodec>, true>* embeddedCodecs);
  71. std::unique_ptr<SkTArray<std::unique_ptr<SkCodec>, true>> fEmbeddedCodecs;
  72. // fCurrCodec is owned by this class, but should not be an
  73. // std::unique_ptr. It will be deleted by the destructor of fEmbeddedCodecs.
  74. SkCodec* fCurrCodec;
  75. typedef SkCodec INHERITED;
  76. };
  77. #endif // SkIcoCodec_DEFINED