diff --git a/frameworks/innerkitsimpl/codec/src/image_source.cpp b/frameworks/innerkitsimpl/codec/src/image_source.cpp index 68f07725470861c7f62984386b3528c7ebafbc0c..815bddc274da79463e3e57b32bc3e192c6d85ab0 100644 --- a/frameworks/innerkitsimpl/codec/src/image_source.cpp +++ b/frameworks/innerkitsimpl/codec/src/image_source.cpp @@ -5386,6 +5386,28 @@ std::string ImageSource::GetPixelMapName(PixelMap* pixelMap) IMAGE_LOGD("pixelMapStr is %{public}s", pixelMapStr.c_str()); return pixelMapStr; } +ImageHdrType ImageSource::CheckHdrType() +{ + IMAGE_LOGD("start CheckHdrType()"); + + if (checkHdrTypeHasSet) { + IMAGE_LOGD("already have checkHdrType_: %{public}d", checkHdrType_); + return checkHdrType_; + } + if (ImageSource::ParseHdrType()) { + IMAGE_LOGD("ParseHdrType checkHdrType_: %{public}d", sourceHdrType_); + checkHdrType_ = sourceHdrType_; + if (checkHdrType_ == ImageHdrType::HDR_LOG_DUAL) { + checkHdrType_ = ImageHdrType::SDR; + } + IMAGE_LOGD("final checkHdrType_: %{public}d", checkHdrType_); + } else { + checkHdrType_ = ImageHdrType::UNKNOWN; + IMAGE_LOGD("fail checkHdrType_: %{public}d", checkHdrType_); + } + checkHdrTypeHasSet = true; + return checkHdrType_; +} } // namespace Media } // namespace OHOS diff --git a/frameworks/innerkitsimpl/test/unittest/image_source_test/image_source_test.cpp b/frameworks/innerkitsimpl/test/unittest/image_source_test/image_source_test.cpp index 29c4828b79b2c9dc515a66f7f23b1c2731732a22..26cf4380993d35fcb049acc5c0e7a5b8cc012255 100644 --- a/frameworks/innerkitsimpl/test/unittest/image_source_test/image_source_test.cpp +++ b/frameworks/innerkitsimpl/test/unittest/image_source_test/image_source_test.cpp @@ -59,6 +59,16 @@ static const std::string IMAGE_JPG_THREE_GAINMAP_HDR_PATH = "/data/local/tmp/ima static const std::string IMAGE_HEIC_THREE_GAINMAP_HDR_PATH = "/data/local/tmp/image/three_gainmap_hdr.heic"; static const std::string IMAGE_GIF_LARGE_SIZE_PATH = "/data/local/tmp/image/fake_large_size_test.gif"; // 50000x50000 static const std::string IMAGE_JPG_LARGE_SIZE_PATH = "/data/local/tmp/image/fake_large_size_test.jpg"; // 30000x30000 +static const std::string IMAGE_HEIC_ISO_HDR_VIVID_SINGLE_PATH = + "/data/local/tmp/image/iso_hdr_vivid_single.heic"; +static const std::string IMAGE_JPG_JPEG_UWA_SINGLE_BASE_COLOR_PATH = + "/data/local/tmp/image/jpeg_uwa_single_base_color.jpg"; +static const std::string IMAGE_JPG_JPEG_UWA_SINGLE_ALTERNATE_COLOR_PATH = + "/data/local/tmp/image/jpeg_uwa_single_alternate_color.jpg"; +static const std::string IMAGE_JPG_JPEG_UWA_MULTI_BASE_COLOR_PATH = + "/data/local/tmp/image/jpeg_uwa_multi_base_color.jpg"; +static const std::string IMAGE_JPG_JPEG_UWA_MULTI_ALTERNATE_COLOR_PATH = + "/data/local/tmp/image/jpeg_uwa_multi_alternate_color.jpg"; static const int32_t DECODE_DESIRED_WIDTH = 7500; static const int32_t DECODE_DESIRED_HEIGHT = 7500; static const int32_t DESIRED_REGION_WIDTH = 4096; @@ -3332,5 +3342,100 @@ HWTEST_F(ImageSourceTest, LargeImageTest005, TestSize.Level3) ASSERT_EQ(pixelMap->GetWidth(), DECODE_DESIRED_WIDTH); ASSERT_EQ(pixelMap->GetHeight(), DECODE_DESIRED_HEIGHT); } + +/** + * @tc.name: CheckHdrType001 + * @tc.desc: test the HdrType ImageHdrType::UNKNOWN + * @tc.type: FUNC + */ +HWTEST_F(ImageSourceTest, CheckHdrType001, TestSize.Level3) +{ + uint32_t errorCode = 0; + SourceOptions opts; + std::unique_ptr imageSource = ImageSource::CreateImageSource(IMAGE_INPUT_HEIF_PATH, opts, errorCode); + ImageHdrType hdrType; + hdrType = imageSource->CheckHdrType(); + ASSERT_EQ(hdrType, ImageHdrType::UNKNOWN); +} + +/** + * @tc.name: CheckHdrType002 + * @tc.desc: test the HdrType ImageHdrType::SDR + * @tc.type: FUNC + */ +HWTEST_F(ImageSourceTest, CheckHdrType002, TestSize.Level3) +{ + uint32_t errorCode = 0; + SourceOptions opts; + std::unique_ptr imageSource = ImageSource::CreateImageSource(IMAGE_INPUT_JPEG_PATH, opts, errorCode); + ImageHdrType hdrType; + hdrType = imageSource->CheckHdrType(); + ASSERT_EQ(hdrType, ImageHdrType::SDR); +} + +/** + * @tc.name: CheckHdrType003 + * @tc.desc: test the HdrType ImageHdrType::SDR + * @tc.type: FUNC + */ +HWTEST_F(ImageSourceTest, CheckHdrType003, TestSize.Level3) +{ + uint32_t errorCode = 0; + SourceOptions opts; + std::unique_ptr imageSource = + ImageSource::CreateImageSource(IMAGE_INPUT_EXIF_JPEG_PATH, opts, errorCode); + ImageHdrType hdrType; + hdrType = imageSource->CheckHdrType(); + ASSERT_EQ(hdrType, ImageHdrType::SDR); +} + +/** + * @tc.name: CheckHdrType005 + * @tc.desc: test the HdrType ImageHdrType::HDR_CUVA + * @tc.type: FUNC + */ +HWTEST_F(ImageSourceTest, CheckHdrType005, TestSize.Level3) +{ + uint32_t errorCode = 0; + SourceOptions opts; + std::unique_ptr imageSource = + ImageSource::CreateImageSource(IMAGE_INPUT_JPEG_HDR_PATH, opts, errorCode); + ImageHdrType hdrType; + hdrType = imageSource->CheckHdrType(); + ASSERT_EQ(hdrType, ImageHdrType::HDR_CUVA); +} + + +/** + * @tc.name: CheckHdrType007 + * @tc.desc: test the HdrType ImageHdrType::HDR_VIVID_DUAL + * @tc.type: FUNC + */ +HWTEST_F(ImageSourceTest, CheckHdrType007, TestSize.Level3) +{ + uint32_t errorCode = 0; + SourceOptions opts; + std::unique_ptr imageSource = + ImageSource::CreateImageSource(IMAGE_JPG_THREE_GAINMAP_HDR_PATH, opts, errorCode); + ImageHdrType hdrType; + hdrType = imageSource->CheckHdrType(); + ASSERT_EQ(hdrType, ImageHdrType::HDR_VIVID_DUAL); +} + +/** + * @tc.name: CheckHdrType008 + * @tc.desc: test the HdrType ImageHdrType::HDR_VIVID_DUAL + * @tc.type: FUNC + */ +HWTEST_F(ImageSourceTest, CheckHdrType008, TestSize.Level3) +{ + uint32_t errorCode = 0; + SourceOptions opts; + std::unique_ptr imageSource = + ImageSource::CreateImageSource(IMAGE_HEIC_THREE_GAINMAP_HDR_PATH, opts, errorCode); + ImageHdrType hdrType; + hdrType = imageSource->CheckHdrType(); + ASSERT_EQ(hdrType, ImageHdrType::HDR_VIVID_DUAL); +} } // namespace Multimedia } // namespace OHOS \ No newline at end of file diff --git a/interfaces/innerkits/include/image_source.h b/interfaces/innerkits/include/image_source.h index 9052f7052b407788bdb30e02d3c1829de4517b3a..c08b2c64082d57bd1e46a0a037f2b2624aca31a6 100644 --- a/interfaces/innerkits/include/image_source.h +++ b/interfaces/innerkits/include/image_source.h @@ -261,6 +261,7 @@ public: NATIVEEXPORT uint64_t GetImageId(); NATIVEEXPORT bool IsSvgUseDma(const DecodeOptions &opts); NATIVEEXPORT bool IsSupportAllocatorType(DecodeOptions& decOps, int32_t allocatorType); + ImageHdrType CheckHdrType(); private: DISALLOW_COPY_AND_MOVE(ImageSource); @@ -427,6 +428,8 @@ private: std::optional isAstc_; uint64_t imageId_; // generated from the last six bits of the current timestamp ImageHdrType sourceHdrType_; // source image hdr type; + ImageHdrType checkHdrType_; + bool checkHdrTypeHasSet = false; std::shared_ptr exifMetadata_ = nullptr; std::string source_; // Image source fd buffer etc bool isExifReadFailed_ = false;