fixHdrDecode

Signed-off-by: hw_wyx <wuyinxiao@huawei.com>
Change-Id: I96c76a45dbc60f52b4144111095dc47d5daf4e31
This commit is contained in:
hw_wyx 2024-05-30 19:22:08 +08:00
parent 37d5f8329b
commit 058c0f8323
15 changed files with 55 additions and 23 deletions

View File

@ -81,16 +81,20 @@ std::string ImageSourceOhos::GetProperty(const std::string& key)
return value;
}
RefPtr<PixelMap> ImageSourceOhos::CreatePixelMap(const Size& size, AIImageQuality imageQuality)
RefPtr<PixelMap> ImageSourceOhos::CreatePixelMap(const Size& size, AIImageQuality imageQuality, bool isHdrDecoderNeed)
{
return CreatePixelMap(0, size, imageQuality);
return CreatePixelMap(0, size, imageQuality, isHdrDecoderNeed);
}
RefPtr<PixelMap> ImageSourceOhos::CreatePixelMap(uint32_t index, const Size& size, AIImageQuality imageQuality)
RefPtr<PixelMap> ImageSourceOhos::CreatePixelMap(
uint32_t index, const Size& size, AIImageQuality imageQuality, bool isHdrDecoderNeed)
{
Media::DecodeOptions options;
options.preferDma = true;
options.desiredDynamicRange = Media::DecodeDynamicRange::AUTO;
// only hdr image need to decoder in hdr mode
if (isHdrDecoderNeed) {
options.desiredDynamicRange = Media::DecodeDynamicRange::AUTO;
}
options.resolutionQuality = static_cast<Media::ResolutionQuality>(imageQuality);
// Pass imageQuality to imageFramework
if (size.first > 0 && size.second > 0) {

View File

@ -29,9 +29,12 @@ public:
explicit ImageSourceOhos(std::unique_ptr<Media::ImageSource>&& source) : imageSource_(std::move(source)) {}
std::string GetProperty(const std::string& key) override;
RefPtr<PixelMap> CreatePixelMap(const Size& size, AIImageQuality imageQuality = AIImageQuality::NONE) override;
RefPtr<PixelMap> CreatePixelMap(
uint32_t index, const Size& size, AIImageQuality imageQuality = AIImageQuality::NONE) override;
const Size& size, AIImageQuality imageQuality = AIImageQuality::NONE, bool isHdrDecoderNeed = false) override;
RefPtr<PixelMap> CreatePixelMap(
uint32_t index, const Size& size,
AIImageQuality imageQuality = AIImageQuality::NONE,
bool isHdrDecoderNeed = false) override;
RefPtr<PixelMap> CreatePixelMap() override;
Size GetImageSize() override;
uint32_t GetFrameCount() override;

View File

@ -47,12 +47,14 @@ std::string ImageSourcePreview::GetProperty(const std::string& /* key */)
return "";
}
RefPtr<PixelMap> ImageSourcePreview::CreatePixelMap(const Size& size, AIImageQuality imageQuality)
RefPtr<PixelMap> ImageSourcePreview::CreatePixelMap(
const Size& size, AIImageQuality imageQuality, bool isHdrDecoderNeed)
{
return nullptr;
}
RefPtr<PixelMap> ImageSourcePreview::CreatePixelMap(uint32_t index, const Size& size, AIImageQuality imageQuality)
RefPtr<PixelMap> ImageSourcePreview::CreatePixelMap(
uint32_t index, const Size& size, AIImageQuality imageQuality, bool isHdrDecoderNeed)
{
return nullptr;
}

View File

@ -24,9 +24,10 @@ class ImageSourcePreview : public ImageSource {
public:
std::string GetProperty(const std::string& key) override;
RefPtr<PixelMap> CreatePixelMap(const Size& size, AIImageQuality imageQuality = AIImageQuality::NONE) override;
RefPtr<PixelMap> CreatePixelMap(
uint32_t index, const Size& size, AIImageQuality imageQuality = AIImageQuality::NONE) override;
const Size& size, AIImageQuality imageQuality = AIImageQuality::NONE, bool isHdrDecoderNeed = false) override;
RefPtr<PixelMap> CreatePixelMap(uint32_t index, const Size& size,
AIImageQuality imageQuality = AIImageQuality::NONE, bool isHdrDecoderNeed = false) override;
RefPtr<PixelMap> CreatePixelMap() override;
Size GetImageSize() override;
uint32_t GetFrameCount() override;

View File

@ -36,9 +36,10 @@ public:
virtual std::string GetProperty(const std::string& key) = 0;
virtual RefPtr<PixelMap> CreatePixelMap(const Size& size, AIImageQuality imageQuality = AIImageQuality::NONE) = 0;
virtual RefPtr<PixelMap> CreatePixelMap(
uint32_t index, const Size& size, AIImageQuality imageQuality = AIImageQuality::NONE) = 0;
const Size& size, AIImageQuality imageQuality = AIImageQuality::NONE, bool isHdrDecoderNeed = false) = 0;
virtual RefPtr<PixelMap> CreatePixelMap(uint32_t index, const Size& size,
AIImageQuality imageQuality = AIImageQuality::NONE, bool isHdrDecoderNeed = false) = 0;
virtual RefPtr<PixelMap> CreatePixelMap() = 0;
virtual Size GetImageSize() = 0;
virtual uint32_t GetFrameCount() = 0;

View File

@ -101,7 +101,7 @@ RefPtr<CanvasImage> ImageDecoder::MakeDrawingImage()
return canvasImage;
}
RefPtr<CanvasImage> ImageDecoder::MakePixmapImage(AIImageQuality imageQuality)
RefPtr<CanvasImage> ImageDecoder::MakePixmapImage(AIImageQuality imageQuality, bool isHdrDecoderNeed)
{
CHECK_NULL_RETURN(obj_ && data_, nullptr);
#ifndef USE_ROSEN_DRAWING
@ -118,7 +118,7 @@ RefPtr<CanvasImage> ImageDecoder::MakePixmapImage(AIImageQuality imageQuality)
auto srcStr = src.GetSrcType() == SrcType::BASE64 ? src.GetKey() : src.ToString();
ACE_SCOPED_TRACE("CreateImagePixelMap %s, sourceSize: [ %d, %d ], targetSize: [ %d, %d ]", srcStr.c_str(),
sourceSize.first, sourceSize.second, static_cast<int32_t>(width), static_cast<int32_t>(height));
auto pixmap = source->CreatePixelMap({ width, height }, imageQuality);
auto pixmap = source->CreatePixelMap({ width, height }, imageQuality, isHdrDecoderNeed);
CHECK_NULL_RETURN(pixmap, nullptr);
auto image = PixelMapImage::Create(pixmap);

View File

@ -37,7 +37,8 @@ public:
#endif
// decode image using ImageFramework, return true if process is successful.
RefPtr<CanvasImage> MakePixmapImage(AIImageQuality imageQuality = AIImageQuality::NONE);
RefPtr<CanvasImage> MakePixmapImage(
AIImageQuality imageQuality = AIImageQuality::NONE, bool isHdrDecoderNeed = false);
private:
#ifndef USE_ROSEN_DRAWING

View File

@ -102,6 +102,16 @@ public:
dynamicMode_ = dynamicMode;
}
void SetIsHdrDecoderNeed(bool isHdrDecoderNeed)
{
isHdrDecoderNeed_ = isHdrDecoderNeed;
}
bool GetIsHdrDecoderNeed()
{
return isHdrDecoderNeed_;
}
DynamicRangeMode GetDynamicRangeMode()
{
return dynamicMode_;
@ -181,6 +191,7 @@ private:
// the container of the creator thread of this image loading context
const int32_t containerId_ {0};
bool isHdrDecoderNeed_ = false;
bool autoResize_ = true;
bool syncLoad_ = false;
bool loadInVipChannel_ = false;

View File

@ -337,7 +337,7 @@ void ImageProvider::MakeCanvasImageHelper(const RefPtr<ImageObject>& obj, const
ImageDecoder decoder(obj, size, imageDecoderOptions.forceResize);
RefPtr<CanvasImage> image;
if (SystemProperties::GetImageFrameworkEnabled()) {
image = decoder.MakePixmapImage(imageDecoderOptions.imageQuality);
image = decoder.MakePixmapImage(imageDecoderOptions.imageQuality, imageDecoderOptions.isHdrDecoderNeed);
} else {
#ifndef USE_ROSEN_DRAWING
image = decoder.MakeSkiaImage();

View File

@ -52,6 +52,7 @@ struct ImageDecoderOptions {
bool loadInVipChannel = false;
DynamicRangeMode dynamicMode = DynamicRangeMode::STANDARD;
AIImageQuality imageQuality = AIImageQuality::NONE;
bool isHdrDecoderNeed = false;
};
class ImageObject;

View File

@ -49,7 +49,8 @@ void StaticImageObject::MakeCanvasImage(const RefPtr<ImageLoadingContext>& ctx,
.sync = syncLoad,
.loadInVipChannel = loadInVipChannel,
.dynamicMode = ctx->GetDynamicRangeMode(),
.imageQuality = ctx->GetImageQuality()
.imageQuality = ctx->GetImageQuality(),
.isHdrDecoderNeed = ctx->GetIsHdrDecoderNeed()
});
}

View File

@ -433,7 +433,10 @@ void ImagePattern::StartDecoding(const SizeF& dstSize)
bool hasValidSlice = renderProp && renderProp->HasImageResizableSlice();
DynamicRangeMode dynamicMode = DynamicRangeMode::STANDARD;
if (renderProp && renderProp->HasDynamicMode()) {
loadingCtx_->SetIsHdrDecoderNeed(true);
dynamicMode = renderProp->GetDynamicMode().value_or(DynamicRangeMode::STANDARD);
} else {
loadingCtx_->SetIsHdrDecoderNeed(false);
}
if (loadingCtx_) {

View File

@ -25,9 +25,12 @@ class MockImageSource : public ImageSource {
public:
MOCK_METHOD1(GetProperty, std::string(const std::string& key));
MOCK_METHOD2(CreatePixelMap, RefPtr<PixelMap>(const ImageSource::Size& size, AIImageQuality imageQuality));
MOCK_METHOD3(
CreatePixelMap, RefPtr<PixelMap>(uint32_t index, const ImageSource::Size& size, AIImageQuality imageQuality));
CreatePixelMap,
RefPtr<PixelMap>(const ImageSource::Size& size, AIImageQuality imageQuality, bool isHdrDecoderNeed));
MOCK_METHOD4(
CreatePixelMap, RefPtr<PixelMap>(uint32_t index,
const ImageSource::Size& size, AIImageQuality imageQuality, bool isHdrDecoderNeed));
MOCK_METHOD0(CreatePixelMap, RefPtr<PixelMap>());
MOCK_METHOD0(GetImageSize, ImageSource::Size());
MOCK_METHOD0(GetFrameCount, uint32_t());

View File

@ -29,7 +29,7 @@ RefPtr<CanvasImage> ImageDecoder::MakeDrawingImage()
}
#endif
RefPtr<CanvasImage> ImageDecoder::MakePixmapImage(AIImageQuality imageQuality)
RefPtr<CanvasImage> ImageDecoder::MakePixmapImage(AIImageQuality imageQuality, bool isHdrDecoderNeed)
{
return MakeRefPtr<PixelMapImage>(nullptr);
}

View File

@ -113,9 +113,10 @@ HWTEST_F(ImageFileCacheTestNg, WriteCacheFileFunc001, TestSize.Level1)
bool convertToAstc = accessCount == convertAstcThreshold;
if (convertToAstc) {
EXPECT_CALL(*mockImageSource, GetFrameCount()).WillOnce(Return(1));
EXPECT_CALL(*mockImageSource, CreatePixelMap(_, AIImageQuality::NONE)).WillOnce(Return(mockPixelMap));
EXPECT_CALL(*mockImagePacker,
FinalizePacking(_)).WillOnce(DoAll(SetArgReferee<0>(imageData.size()), Return(0)));
EXPECT_CALL(*mockImageSource, CreatePixelMap(_, AIImageQuality::NONE, false))
.WillOnce(Return(mockPixelMap));
EXPECT_CALL(*mockImagePacker, FinalizePacking(_))
.WillOnce(DoAll(SetArgReferee<0>(imageData.size()), Return(0)));
}
filePath = ImageFileCache::GetInstance().GetCacheFilePathInner(url, "");
ASSERT_EQ(filePath, ImageFileCache::GetInstance().ConstructCacheFilePath(fileCacheKey));