forked from mirrors/gecko-dev
This patch implements the transparency support for AVIF image files.
To convert the decoded YCbCr and Alpha data to RGBA, a function named
`ConvertYCbCrAToARGB` is created to do this job in the following
procedure:
ConvertYCbCrAToARGB:
If the layout of the YCbCr is I420
Calling libyuv::I420AlphaToARGB
Else
Fill RGB data converted by ConvertYCbCrToRGB in ARGB buffer first
Insert the alpha data to ARGB buffer
On the other hand, this patch refactors the nsAVIFDecoder a bit to make
the lifetime of the parsed data and decoded image data clearer. They
won't live longer than Parser object and {Dav1d, AOM}Decoder object.
This should improve the code readability.
This patch also adds a transparent image test (TransparentAVIFTestCase)
to check the FLAG_HAS_TRANSPARENCY is posted or not. The test image file
`transparent.avif` is from Bug 1654462.
Differential Revision: https://phabricator.services.mozilla.com/D98951
74 lines
2 KiB
C++
74 lines
2 KiB
C++
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
*
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
#ifndef mozilla_image_decoders_nsAVIFDecoder_h
|
|
#define mozilla_image_decoders_nsAVIFDecoder_h
|
|
|
|
#include "Decoder.h"
|
|
#include "mp4parse.h"
|
|
#include "SurfacePipe.h"
|
|
|
|
#include "aom/aom_decoder.h"
|
|
#include "dav1d/dav1d.h"
|
|
|
|
#include "mozilla/Telemetry.h"
|
|
|
|
namespace mozilla {
|
|
namespace image {
|
|
class RasterImage;
|
|
|
|
class nsAVIFDecoder final : public Decoder {
|
|
public:
|
|
virtual ~nsAVIFDecoder();
|
|
|
|
DecoderType GetType() const override { return DecoderType::AVIF; }
|
|
|
|
protected:
|
|
LexerResult DoDecode(SourceBufferIterator& aIterator,
|
|
IResumable* aOnResume) override;
|
|
|
|
private:
|
|
friend class DecoderFactory;
|
|
friend class AVIFDecoderInterface;
|
|
|
|
// Decoders should only be instantiated via DecoderFactory.
|
|
explicit nsAVIFDecoder(RasterImage* aImage);
|
|
|
|
static intptr_t ReadSource(uint8_t* aDestBuf, uintptr_t aDestBufSize,
|
|
void* aUserData);
|
|
|
|
typedef int Dav1dResult;
|
|
enum class NonAOMCodecError { NoFrame, SizeOverflow };
|
|
typedef Variant<aom_codec_err_t, NonAOMCodecError> AOMResult;
|
|
enum class NonDecoderResult {
|
|
NeedMoreData,
|
|
MetadataOk,
|
|
ParseError,
|
|
NoPrimaryItem,
|
|
SizeOverflow,
|
|
OutOfMemory,
|
|
PipeInitError,
|
|
WriteBufferError,
|
|
AlphaYSizeMismatch,
|
|
AlphaYColorDepthMismatch
|
|
};
|
|
using DecodeResult = Variant<NonDecoderResult, Dav1dResult, AOMResult>;
|
|
DecodeResult Decode(SourceBufferIterator& aIterator, IResumable* aOnResume);
|
|
|
|
static bool IsDecodeSuccess(const DecodeResult& aResult);
|
|
|
|
void RecordDecodeResultTelemetry(const DecodeResult& aResult);
|
|
|
|
Vector<uint8_t> mBufferedData;
|
|
|
|
/// Pointer to the next place to read from mBufferedData
|
|
const uint8_t* mReadCursor = nullptr;
|
|
};
|
|
|
|
} // namespace image
|
|
} // namespace mozilla
|
|
|
|
#endif // mozilla_image_decoders_nsAVIFDecoder_h
|