1 /* 2 * Copyright 2016 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 8 #ifndef SkRawCodec_DEFINED 9 #define SkRawCodec_DEFINED 10 11 #include "include/codec/SkCodec.h" 12 #include "include/codec/SkEncodedImageFormat.h" 13 #include "include/core/SkSize.h" 14 #include "include/core/SkTypes.h" 15 16 #include <cstddef> 17 #include <memory> 18 19 class SkDngImage; 20 class SkStream; 21 struct SkImageInfo; 22 23 /* 24 * 25 * This class implements the decoding for RAW images 26 * 27 */ 28 class SkRawCodec : public SkCodec { 29 public: 30 31 /* 32 * Creates a RAW decoder 33 * Takes ownership of the stream 34 */ 35 static std::unique_ptr<SkCodec> MakeFromStream(std::unique_ptr<SkStream>, Result*); 36 37 ~SkRawCodec() override; 38 39 protected: 40 41 Result onGetPixels(const SkImageInfo& dstInfo, void* dst, size_t dstRowBytes, const Options&, 42 int*) override; 43 onGetEncodedFormat()44 SkEncodedImageFormat onGetEncodedFormat() const override { 45 return SkEncodedImageFormat::kDNG; 46 } 47 48 SkISize onGetScaledDimensions(float desiredScale) const override; 49 50 bool onDimensionsSupported(const SkISize&) override; 51 52 // SkCodec only applies the colorXform if it's necessary for color space 53 // conversion. SkRawCodec will always convert, so tell SkCodec not to. usesColorXform()54 bool usesColorXform() const override { return false; } 55 56 private: 57 58 /* 59 * Creates an instance of the decoder 60 * Called only by NewFromStream, takes ownership of dngImage. 61 */ 62 SkRawCodec(SkDngImage* dngImage); 63 64 std::unique_ptr<SkDngImage> fDngImage; 65 66 using INHERITED = SkCodec; 67 }; 68 69 #endif 70