From 11764c981c24726413b6387cb17bf2897d85cce6 Mon Sep 17 00:00:00 2001 From: y00656910 Date: Sat, 9 Aug 2025 20:09:59 +0800 Subject: [PATCH] modifyPixelMapName Signed-off-by: y00656910 Change-Id: I4dac8274ef479b9cb831b480ab32b329ca87bd23 --- .../innerkitsimpl/codec/src/image_source.cpp | 18 ++++++++++++++---- .../image_source_test/image_source_test.cpp | 2 +- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/frameworks/innerkitsimpl/codec/src/image_source.cpp b/frameworks/innerkitsimpl/codec/src/image_source.cpp index 19a62c35d..2c897a476 100644 --- a/frameworks/innerkitsimpl/codec/src/image_source.cpp +++ b/frameworks/innerkitsimpl/codec/src/image_source.cpp @@ -5317,10 +5317,20 @@ std::string ImageSource::GetPixelMapName(PixelMap* pixelMap) IMAGE_LOGE("%{public}s error, pixelMap is null", __func__); return "undefined_"; } - std::string pixelMapStr = "w" + std::to_string(pixelMap->GetWidth()) + - "_h" + std::to_string(pixelMap->GetHeight()) + - "_streamSize" + std::to_string(sourceStreamPtr_->GetStreamSize()) + - "_mimeType" + sourceInfo_.encodedFormat; + std::string pixelMapStr = std::to_string(pixelMap->GetWidth()) + + "_x" + std::to_string(pixelMap->GetHeight()) + + "-streamsize-" + std::to_string(sourceStreamPtr_->GetStreamSize()) + + "-mimeType-"; + std::string prefix = "image/"; + size_t minFormatLength = 9; + size_t maxFormatLength = 20; + if ((!sourceInfo_.encodedFormat.empty()) && sourceInfo_.encodedFormat.size() >= minFormatLength && + sourceInfo_.encodedFormat.size() <= maxFormatLength && + sourceInfo_.encodedFormat.compare(0, prefix.size(), prefix) == 0) { + pixelMapStr += sourceInfo_.encodedFormat.substr(prefix.size()); + } else { + pixelMapStr += "undefined"; + } IMAGE_LOGD("pixelMapStr is %{public}s", pixelMapStr.c_str()); return pixelMapStr; } 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 579fb4637..7dbdb8c90 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 @@ -1728,7 +1728,7 @@ HWTEST_F(ImageSourceTest, End2EndTest001, TestSize.Level3) ASSERT_EQ(desiredWidth, pixelMap->GetWidth()); ASSERT_EQ(desiredHeight, pixelMap->GetHeight()); ASSERT_EQ("undefined_", imageSource->GetPixelMapName(nullptr)); - ASSERT_EQ("w400_h200_streamSize27897_mimeTypeimage/jpeg", imageSource->GetPixelMapName(pixelMap.get())); + ASSERT_EQ("400x200-streamsize-27897-mimetype-jpeg", imageSource->GetPixelMapName(pixelMap.get())); } /** -- Gitee