diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt index 2f80f10a3b..1723fa645c 100644 --- a/RELEASE_NOTES.txt +++ b/RELEASE_NOTES.txt @@ -9,8 +9,6 @@ Milestone 88 * - * Add AVIF support to SkHeifCodec. - * Removed SkSurfaceProps::kLegacyFontHost_InitType, SkFontLCDConfig, and related code. The default pixel geometry for SkSurfaceProps is now kUnknown instead of kRGB_H. The removal was guarded by the SK_LEGACY_SURFACE_PROPS build flag which was later removed. diff --git a/include/core/SkEncodedImageFormat.h b/include/core/SkEncodedImageFormat.h index 97add6dea6..d0a9e5e0ca 100644 --- a/include/core/SkEncodedImageFormat.h +++ b/include/core/SkEncodedImageFormat.h @@ -29,7 +29,6 @@ enum class SkEncodedImageFormat { kASTC, kDNG, kHEIF, - kAVIF, }; #endif // SkEncodedImageFormat_DEFINED diff --git a/src/codec/SkAndroidCodec.cpp b/src/codec/SkAndroidCodec.cpp index b7878df6d6..6fe68ab6eb 100644 --- a/src/codec/SkAndroidCodec.cpp +++ b/src/codec/SkAndroidCodec.cpp @@ -96,7 +96,6 @@ std::unique_ptr SkAndroidCodec::MakeFromCodec(std::unique_ptr(codec.release(), orientationBehavior); #ifdef SK_HAS_WUFFS_LIBRARY case SkEncodedImageFormat::kGIF: diff --git a/src/codec/SkCodec.cpp b/src/codec/SkCodec.cpp index c4397b955b..3a9ce20ce2 100644 --- a/src/codec/SkCodec.cpp +++ b/src/codec/SkCodec.cpp @@ -125,9 +125,8 @@ std::unique_ptr SkCodec::MakeFromStream( } #ifdef SK_HAS_HEIF_LIBRARY - if (auto format = SkHeifCodec::IsSupported(buffer, bytesRead)) { - return SkHeifCodec::MakeFromStream(std::move(stream), selectionPolicy, - format.value(), outResult); + if (SkHeifCodec::IsHeif(buffer, bytesRead)) { + return SkHeifCodec::MakeFromStream(std::move(stream), selectionPolicy, outResult); } #endif diff --git a/src/codec/SkHeifCodec.cpp b/src/codec/SkHeifCodec.cpp index 2813c0e441..3627a7b4ee 100644 --- a/src/codec/SkHeifCodec.cpp +++ b/src/codec/SkHeifCodec.cpp @@ -18,11 +18,11 @@ #define FOURCC(c1, c2, c3, c4) \ ((c1) << 24 | (c2) << 16 | (c3) << 8 | (c4)) -std::optional SkHeifCodec::IsSupported(const void* buffer, size_t bytesRead) { - // Parse the ftyp box up to bytesRead to determine if this is HEIF or AVIF. +bool SkHeifCodec::IsHeif(const void* buffer, size_t bytesRead) { + // Parse the ftyp box up to bytesRead to determine if this is HEIF. // Any valid ftyp box should have at least 8 bytes. if (bytesRead < 8) { - return std::nullopt; + return false; } uint32_t* ptr = (uint32_t*)buffer; @@ -30,7 +30,7 @@ std::optional SkHeifCodec::IsSupported(const void* buffer, uint32_t chunkType = SkEndian_SwapBE32(ptr[1]); if (chunkType != FOURCC('f', 't', 'y', 'p')) { - return std::nullopt; + return false; } int64_t offset = 8; @@ -38,18 +38,18 @@ std::optional SkHeifCodec::IsSupported(const void* buffer, // This indicates that the next 8 bytes represent the chunk size, // and chunk data comes after that. if (bytesRead < 16) { - return std::nullopt; + return false; } auto* chunkSizePtr = SkTAddOffset(buffer, offset); chunkSize = SkEndian_SwapBE64(*chunkSizePtr); if (chunkSize < 16) { // The smallest valid chunk is 16 bytes long in this case. - return std::nullopt; + return false; } offset += 8; } else if (chunkSize < 8) { // The smallest valid chunk is 8 bytes long. - return std::nullopt; + return false; } if (chunkSize > bytesRead) { @@ -59,11 +59,10 @@ std::optional SkHeifCodec::IsSupported(const void* buffer, // It should at least have major brand (4-byte) and minor version (4-bytes). // The rest of the chunk (if any) is a list of (4-byte) compatible brands. if (chunkDataSize < 8) { - return std::nullopt; + return false; } uint32_t numCompatibleBrands = (chunkDataSize - 8) / 4; - bool isHeif = false; for (size_t i = 0; i < numCompatibleBrands + 2; ++i) { if (i == 1) { // Skip this index, it refers to the minorVersion, @@ -73,23 +72,11 @@ std::optional SkHeifCodec::IsSupported(const void* buffer, auto* brandPtr = SkTAddOffset(buffer, offset + 4 * i); uint32_t brand = SkEndian_SwapBE32(*brandPtr); if (brand == FOURCC('m', 'i', 'f', '1') || brand == FOURCC('h', 'e', 'i', 'c') - || brand == FOURCC('m', 's', 'f', '1') || brand == FOURCC('h', 'e', 'v', 'c') - || brand == FOURCC('a', 'v', 'i', 'f') || brand == FOURCC('a', 'v', 'i', 's')) { - // AVIF files could have "mif1" as the major brand. So we cannot - // distinguish whether the image is AVIF or HEIC just based on the - // "mif1" brand. So wait until we see a specific avif brand to - // determine whether it is AVIF or HEIC. - isHeif = true; - if (brand == FOURCC('a', 'v', 'i', 'f') - || brand == FOURCC('a', 'v', 'i', 's')) { - return SkEncodedImageFormat::kAVIF; - } + || brand == FOURCC('m', 's', 'f', '1') || brand == FOURCC('h', 'e', 'v', 'c')) { + return true; } } - if (isHeif) { - return SkEncodedImageFormat::kHEIF; - } - return std::nullopt; + return false; } static SkEncodedOrigin get_orientation(const HeifFrameInfo& frameInfo) { @@ -136,7 +123,7 @@ static void releaseProc(const void* ptr, void* context) { } std::unique_ptr SkHeifCodec::MakeFromStream(std::unique_ptr stream, - SkCodec::SelectionPolicy selectionPolicy, SkEncodedImageFormat format, Result* result) { + SkCodec::SelectionPolicy selectionPolicy, Result* result) { std::unique_ptr heifDecoder(createHeifDecoder()); if (heifDecoder == nullptr) { *result = kInternalError; @@ -175,21 +162,19 @@ std::unique_ptr SkHeifCodec::MakeFromStream(std::unique_ptr s *result = kSuccess; return std::unique_ptr(new SkHeifCodec( - std::move(info), heifDecoder.release(), orientation, frameCount > 1, format)); + std::move(info), heifDecoder.release(), orientation, frameCount > 1)); } SkHeifCodec::SkHeifCodec( SkEncodedInfo&& info, HeifDecoder* heifDecoder, SkEncodedOrigin origin, - bool useAnimation, - SkEncodedImageFormat format) + bool useAnimation) : INHERITED(std::move(info), skcms_PixelFormat_RGBA_8888, nullptr, origin) , fHeifDecoder(heifDecoder) , fSwizzleSrcRow(nullptr) , fColorXformSrcRow(nullptr) , fUseAnimation(useAnimation) - , fFormat(format) {} bool SkHeifCodec::conversionSupported(const SkImageInfo& dstInfo, bool srcIsOpaque, diff --git a/src/codec/SkHeifCodec.h b/src/codec/SkHeifCodec.h index fc1dba7ab6..48a7cd66c9 100644 --- a/src/codec/SkHeifCodec.h +++ b/src/codec/SkHeifCodec.h @@ -21,23 +21,15 @@ #include "src/codec/SkStubHeifDecoderAPI.h" #endif -#ifdef SK_HAS_HEIF_LIBRARY -#include - class SkHeifCodec : public SkCodec { public: - /* - * Returns kHEIF or kAVIF if one of those image types were detected. - * Returns nullopt otherwise - */ - static std::optional IsSupported(const void*, size_t); + static bool IsHeif(const void*, size_t); /* - * Assumes IsSupported was called and it returned a non-nullopt value. + * Assumes IsHeif was called and returned true. */ static std::unique_ptr MakeFromStream( - std::unique_ptr, SkCodec::SelectionPolicy selectionPolicy, - SkEncodedImageFormat, Result*); + std::unique_ptr, SkCodec::SelectionPolicy selectionPolicy, Result*); protected: @@ -48,7 +40,7 @@ protected: int* rowsDecoded) override; SkEncodedImageFormat onGetEncodedFormat() const override { - return fFormat; + return SkEncodedImageFormat::kHEIF; } int onGetFrameCount() override; @@ -67,8 +59,7 @@ private: * Creates an instance of the decoder * Called only by NewFromStream */ - SkHeifCodec(SkEncodedInfo&&, HeifDecoder*, SkEncodedOrigin, bool animation, - SkEncodedImageFormat); + SkHeifCodec(SkEncodedInfo&&, HeifDecoder*, SkEncodedOrigin, bool animation); void initializeSwizzler(const SkImageInfo& dstInfo, const Options& options); void allocateStorage(const SkImageInfo& dstInfo); @@ -92,7 +83,6 @@ private: std::unique_ptr fSwizzler; bool fUseAnimation; - const SkEncodedImageFormat fFormat; class Frame : public SkFrame { public: @@ -135,5 +125,4 @@ private: using INHERITED = SkCodec; }; -#endif // SK_HAS_HEIF_LIBRARY #endif // SkHeifCodec_DEFINED