From 09c2283b3c0c5618e4ee415897884d6646867116 Mon Sep 17 00:00:00 2001 From: renhw001 Date: Mon, 28 Oct 2024 10:48:35 +0800 Subject: [PATCH] =?UTF-8?q?ASTC=E8=A7=A3=E7=A0=81=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=8C=87=E5=AE=9A=E5=86=85=E5=AD=98=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: renhw001 --- .../innerkitsimpl/codec/src/image_source.cpp | 13 +++--- .../test/unittest/pixel_astc_test.cpp | 42 +++++++++++++++++++ interfaces/innerkits/include/image_source.h | 2 +- 3 files changed, 50 insertions(+), 7 deletions(-) diff --git a/frameworks/innerkitsimpl/codec/src/image_source.cpp b/frameworks/innerkitsimpl/codec/src/image_source.cpp index 0b8f03546..15be5a2f3 100644 --- a/frameworks/innerkitsimpl/codec/src/image_source.cpp +++ b/frameworks/innerkitsimpl/codec/src/image_source.cpp @@ -577,7 +577,7 @@ unique_ptr ImageSource::CreatePixelMapEx(uint32_t index, const DecodeO } } if (isAstc_.has_value() && isAstc_.value()) { - return CreatePixelMapForASTC(errorCode, opts.fastAstc); + return CreatePixelMapForASTC(errorCode, opts); } #endif @@ -3171,15 +3171,16 @@ static bool FormatIsSUT(const uint8_t *fileData, size_t fileSize) #endif static bool ReadFileAndResoveAstc(size_t fileSize, size_t astcSize, unique_ptr &pixelAstc, - const uint8_t *sourceFilePtr) + const uint8_t *sourceFilePtr, const DecodeOptions &opts) { #if !(defined(ANDROID_PLATFORM) || defined(IOS_PLATFORM)) Size desiredSize = {astcSize, 1}; MemoryData memoryData = {nullptr, astcSize, "CreatePixelMapForASTC Data", desiredSize, pixelAstc->GetPixelFormat()}; ImageInfo pixelAstcInfo; pixelAstc->GetImageInfo(pixelAstcInfo); - AllocatorType allocatorType = IsSupportAstcZeroCopy(pixelAstcInfo.size) ? - AllocatorType::DMA_ALLOC : AllocatorType::SHARE_MEM_ALLOC; + AllocatorType allocatorType = (opts.allocatorType == AllocatorType::DEFAULT) ? + (IsSupportAstcZeroCopy(pixelAstcInfo.size) ? AllocatorType::DMA_ALLOC : AllocatorType::SHARE_MEM_ALLOC) : + opts.allocatorType; std::unique_ptr dstMemory = MemoryManager::CreateMemory(allocatorType, memoryData); if (dstMemory == nullptr) { IMAGE_LOGE("ReadFileAndResoveAstc CreateMemory failed"); @@ -3212,7 +3213,7 @@ static bool ReadFileAndResoveAstc(size_t fileSize, size_t astcSize, unique_ptr

ImageSource::CreatePixelMapForASTC(uint32_t &errorCode, bool fastAstc) +unique_ptr ImageSource::CreatePixelMapForASTC(uint32_t &errorCode, const DecodeOptions &opts) #if defined(ANDROID_PLATFORM) || defined(IOS_PLATFORM) { errorCode = ERROR; @@ -3246,7 +3247,7 @@ unique_ptr ImageSource::CreatePixelMapForASTC(uint32_t &errorCode, boo #else size_t astcSize = ImageUtils::GetAstcBytesCount(info); #endif - if (!ReadFileAndResoveAstc(fileSize, astcSize, pixelAstc, sourceFilePtr)) { + if (!ReadFileAndResoveAstc(fileSize, astcSize, pixelAstc, sourceFilePtr, opts)) { IMAGE_LOGE("[ImageSource] astc ReadFileAndResoveAstc failed."); return nullptr; } diff --git a/frameworks/innerkitsimpl/test/unittest/pixel_astc_test.cpp b/frameworks/innerkitsimpl/test/unittest/pixel_astc_test.cpp index 43d2b5b0e..be2fb94aa 100644 --- a/frameworks/innerkitsimpl/test/unittest/pixel_astc_test.cpp +++ b/frameworks/innerkitsimpl/test/unittest/pixel_astc_test.cpp @@ -693,5 +693,47 @@ HWTEST_F(PixelAstcTest, PixelAstcTest026, TestSize.Level3) } GTEST_LOG_(INFO) << "PixelAstcTest: PixelAstcTest026 end"; } + +/** + * @tc.name: PixelAstcTest027 + * @tc.desc: PixelAstc + * @tc.type: FUNC + */ +HWTEST_F(PixelAstcTest, PixelAstcTest027, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "PixelAstcTest: PixelAstcTest027 start"; + size_t width = 256; // ASTC width + size_t height = 256; // ASTC height + // 4 means ASTC compression format is 4x4 + size_t blockNum = ((width + 4 - 1) / 4) * ((height + 4 - 1) / 4); + // 16 means ASTC per block bytes and header bytes + size_t size = blockNum * 16 + 16; + uint8_t* data = (uint8_t*)malloc(size); + + // 4 means blockSize + if (!GenAstcHeader(data, 4, width, height)) { + GTEST_LOG_(INFO) << "GenAstcHeader failed"; + } + // 16 means header bytes + if (!ConstructAstcBody(data + 16, blockNum, ASTC_BLOCK4X4_FIT_SUT_ASTC_EXAMPLE0)) { + GTEST_LOG_(INFO) << "ConstructAstcBody failed"; + } + uint32_t errorCode = 0; + SourceOptions opts; + std::unique_ptr imageSource = ImageSource::CreateImageSource(data, size, opts, errorCode); + ASSERT_EQ(errorCode, SUCCESS); + ASSERT_NE(imageSource.get(), nullptr); + + DecodeOptions decodeOpts; + decodeOpts.allocatorType = AllocatorType::DMA_ALLOC; + std::unique_ptr pixelMap = imageSource->CreatePixelMap(decodeOpts, errorCode); + ASSERT_EQ(errorCode, SUCCESS); + + if (data != nullptr) { + free(data); + data = nullptr; + } + GTEST_LOG_(INFO) << "PixelAstcTest: PixelAstcTest027 end"; +} } } \ No newline at end of file diff --git a/interfaces/innerkits/include/image_source.h b/interfaces/innerkits/include/image_source.h index 18060352b..48a86b935 100644 --- a/interfaces/innerkits/include/image_source.h +++ b/interfaces/innerkits/include/image_source.h @@ -302,7 +302,7 @@ private: bool GetImageInfoForASTC(ImageInfo& imageInfo, const uint8_t *sourceFilePtr); bool ConvertYUV420ToRGBA(uint8_t *data, uint32_t size, bool isSupportOdd, bool isAddUV, uint32_t &errorCode); std::unique_ptr CreatePixelMapForYUV(uint32_t &errorCode); - std::unique_ptr CreatePixelMapForASTC(uint32_t &errorCode, bool fastAstc = false); + std::unique_ptr CreatePixelMapForASTC(uint32_t &errorCode, const DecodeOptions &opts); uint32_t GetFormatExtended(std::string &format); static std::unique_ptr DoImageSourceCreate( std::function(void)> stream,