From b65b4fe41ffb81dc4b49bda1183a393e487b374f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B1=91=E5=B1=91=E5=B1=91?= Date: Tue, 31 Dec 2024 10:57:18 +0000 Subject: [PATCH 1/6] update frameworks/innerkitsimpl/utils/src/image_utils.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 屑屑屑 --- .../innerkitsimpl/utils/src/image_utils.cpp | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/frameworks/innerkitsimpl/utils/src/image_utils.cpp b/frameworks/innerkitsimpl/utils/src/image_utils.cpp index f140cc405..a553eb925 100644 --- a/frameworks/innerkitsimpl/utils/src/image_utils.cpp +++ b/frameworks/innerkitsimpl/utils/src/image_utils.cpp @@ -102,6 +102,9 @@ static const uint8_t NUM_6 = 6; static const uint8_t NUM_7 = 7; static const uint8_t INT_255 = 255; static const string FILE_DIR_IN_THE_SANDBOX = "/data/storage/el2/base/files/"; +static constexpr int32_t PLANE_Y = 0; +static constexpr int32_t PLANE_U = 1; +static constexpr int32_t PLANE_V = 2; bool ImageUtils::GetFileSize(const string &pathName, size_t &size) { @@ -983,5 +986,69 @@ int32_t ImageUtils::GetAPIVersion() return FAULT_API_VERSION; #endif } + +static void GetYUVStrideInfo(int32_t pixelFmt, OH_NativeBuffer_Planes *planes, YUVStrideInfo &dstStrides) +{ +#if !defined(_WIN32) && !defined(_APPLE) && !defined(IOS_PLATFORM) && !defined(ANDROID_PLATFORM) + if (pixelFmt == GRAPHIC_PIXEL_FMT_YCBCR_420_SP) { + auto yStride = planes->planes[PLANE_Y].columnStride; + auto uvStride = planes->planes[PLANE_U].columnStride; + auto yOffset = planes->planes[PLANE_Y].offset; + auto uvOffset = planes->planes[PLANE_U].offset; + dstStrides = {yStride, uvStride, yOffset, uvOffset}; + } else if (pixelFmt == GRAPHIC_PIXEL_FMT_YCRCB_420_SP) { + auto yStride = planes->planes[PLANE_Y].columnStride; + auto uvStride = planes->planes[PLANE_V].columnStride; + auto yOffset = planes->planes[PLANE_Y].offset; + auto uvOffset = planes->planes[PLANE_V].offset; + dstStrides = {yStride, uvStride, yOffset, uvOffset}; + } else if (pixelFmt == GRAPHIC_PIXEL_FMT_YCBCR_P010) { + auto yStride = planes->planes[PLANE_Y].columnStride / 2; + auto uvStride = planes->planes[PLANE_U].columnStride / 2; + auto yOffset = planes->planes[PLANE_Y].offset / 2; + auto uvOffset = planes->planes[PLANE_U].offset / 2; + dstStrides = {yStride, uvStride, yOffset, uvOffset}; + } else if (pixelFmt == GRAPHIC_PIXEL_FMT_YCRCB_P010) { + auto yStride = planes->planes[PLANE_Y].columnStride / 2; + auto uvStride = planes->planes[PLANE_V].columnStride / 2; + auto yOffset = planes->planes[PLANE_Y].offset / 2; + auto uvOffset = planes->planes[PLANE_V].offset / 2; + dstStrides = {yStride, uvStride, yOffset, uvOffset}; + } +#endif +} + +void ImageUtils::UpdateSdrYuvStrides(const ImageInfo &imageInfo, YUVStrideInfo &dstStrides, + void *context, AllocatorType dstType) +{ + int32_t dstWidth = imageInfo.size.width; + int32_t dstHeight = imageInfo.size.height; + int32_t dstYStride = dstWidth; + int32_t dstUvStride = (dstWidth + 1) / NUM_2 * NUM_2; + int32_t dstYOffset = 0; + int32_t dstUvOffset = dstYStride * dstHeight; + dstStrides = {dstYStride, dstUvStride, dstYOffset, dstUvOffset}; + +#if !defined(_WIN32) && !defined(_APPLE) && !defined(IOS_PLATFORM) && !defined(ANDROID_PLATFORM) + if (context == nullptr) { + return; + } + if (dstType == AllocatorType::DMA_ALLOC) { + auto sb = static_cast(context); + if (sb == nullptr) { + IMAGE_LOGE("get SurfaceBuffer failed"); + return; + } + OH_NativeBuffer_Planes *planes = nullptr; + GSError retVal = sb->GetPlanesInfo(reinterpret_cast(&planes)); + if (retVal != OHOS::GSERROR_OK || planes == nullptr) { + IMAGE_LOGE("UpdateSdrYuvStrides Get planesInfo failed, retVal:%{public}d", retVal); + } else if (planes->planeCount >= NUM_2) { + int32_t pixelFmt = sb->GetFormat(); + GetYUVStrideInfo(pixelFmt, planes, dstStrides); + } + } +#endif +} } // namespace Media } // namespace OHOS -- Gitee From 397ed2f3b8b8e6a609a0cd091590079b8ec5a04c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B1=91=E5=B1=91=E5=B1=91?= Date: Tue, 31 Dec 2024 10:59:29 +0000 Subject: [PATCH 2/6] update frameworks/innerkitsimpl/utils/include/image_utils.h. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 屑屑屑 --- frameworks/innerkitsimpl/utils/include/image_utils.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/frameworks/innerkitsimpl/utils/include/image_utils.h b/frameworks/innerkitsimpl/utils/include/image_utils.h index 16c1f973d..09c2e61e1 100644 --- a/frameworks/innerkitsimpl/utils/include/image_utils.h +++ b/frameworks/innerkitsimpl/utils/include/image_utils.h @@ -89,6 +89,8 @@ public: static bool HasOverflowed(uint32_t num1, uint32_t num2); static int32_t GetAPIVersion(); static std::string GetEncodedHeifFormat(); + static void UpdateSdrYuvStrides(const ImageInfo &imageInfo, YUVStrideInfo &dstStrides, + void *context, AllocatorType dstType); template static bool CheckMulOverflow(const T& num1, const T& num2) -- Gitee From 38e0d02790f93cf604201ffb38dc7ba61c994948 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B1=91=E5=B1=91=E5=B1=91?= Date: Tue, 31 Dec 2024 11:02:21 +0000 Subject: [PATCH 3/6] update frameworks/innerkitsimpl/common/src/pixel_map.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 屑屑屑 --- .../innerkitsimpl/common/src/pixel_map.cpp | 69 +------------------ 1 file changed, 2 insertions(+), 67 deletions(-) diff --git a/frameworks/innerkitsimpl/common/src/pixel_map.cpp b/frameworks/innerkitsimpl/common/src/pixel_map.cpp index 72fb4e951..a7a311680 100644 --- a/frameworks/innerkitsimpl/common/src/pixel_map.cpp +++ b/frameworks/innerkitsimpl/common/src/pixel_map.cpp @@ -4101,70 +4101,6 @@ bool PixelMap::GetToSdrColorSpaceIsSRGB() return toSdrColorIsSRGB_; } -#if !defined(_WIN32) && !defined(_APPLE) && !defined(IOS_PLATFORM) && !defined(ANDROID_PLATFORM) -static void GetYUVStrideInfo(int32_t pixelFmt, OH_NativeBuffer_Planes *planes, YUVStrideInfo &dstStrides) -{ - if (pixelFmt == GRAPHIC_PIXEL_FMT_YCBCR_420_SP) { - auto yStride = planes->planes[PLANE_Y].columnStride; - auto uvStride = planes->planes[PLANE_U].columnStride; - auto yOffset = planes->planes[PLANE_Y].offset; - auto uvOffset = planes->planes[PLANE_U].offset; - dstStrides = {yStride, uvStride, yOffset, uvOffset}; - } else if (pixelFmt == GRAPHIC_PIXEL_FMT_YCRCB_420_SP) { - auto yStride = planes->planes[PLANE_Y].columnStride; - auto uvStride = planes->planes[PLANE_V].columnStride; - auto yOffset = planes->planes[PLANE_Y].offset; - auto uvOffset = planes->planes[PLANE_V].offset; - dstStrides = {yStride, uvStride, yOffset, uvOffset}; - } else if (pixelFmt == GRAPHIC_PIXEL_FMT_YCBCR_P010) { - auto yStride = planes->planes[PLANE_Y].columnStride / 2; - auto uvStride = planes->planes[PLANE_U].columnStride / 2; - auto yOffset = planes->planes[PLANE_Y].offset / 2; - auto uvOffset = planes->planes[PLANE_U].offset / 2; - dstStrides = {yStride, uvStride, yOffset, uvOffset}; - } else if (pixelFmt == GRAPHIC_PIXEL_FMT_YCRCB_P010) { - auto yStride = planes->planes[PLANE_Y].columnStride / 2; - auto uvStride = planes->planes[PLANE_V].columnStride / 2; - auto yOffset = planes->planes[PLANE_Y].offset / 2; - auto uvOffset = planes->planes[PLANE_V].offset / 2; - dstStrides = {yStride, uvStride, yOffset, uvOffset}; - } -} -#endif - -static void UpdateSdrYuvStrides(const ImageInfo &imageInfo, YUVStrideInfo &dstStrides, - void *context, AllocatorType dstType) -{ - int32_t dstWidth = imageInfo.size.width; - int32_t dstHeight = imageInfo.size.height; - int32_t dstYStride = dstWidth; - int32_t dstUvStride = (dstWidth + 1) / NUM_2 * NUM_2; - int32_t dstYOffset = 0; - int32_t dstUvOffset = dstYStride * dstHeight; - dstStrides = {dstYStride, dstUvStride, dstYOffset, dstUvOffset}; - -#if !defined(_WIN32) && !defined(_APPLE) && !defined(IOS_PLATFORM) && !defined(ANDROID_PLATFORM) - if (context == nullptr) { - return; - } - if (dstType == AllocatorType::DMA_ALLOC) { - auto sb = static_cast(context); - if (sb == nullptr) { - IMAGE_LOGE("get SurfaceBuffer failed"); - return; - } - OH_NativeBuffer_Planes *planes = nullptr; - GSError retVal = sb->GetPlanesInfo(reinterpret_cast(&planes)); - if (retVal != OHOS::GSERROR_OK || planes == nullptr) { - IMAGE_LOGE("UpdateSdrYuvStrides Get planesInfo failed, retVal:%{public}d", retVal); - } else if (planes->planeCount >= NUM_2) { - int32_t pixelFmt = sb->GetFormat(); - GetYUVStrideInfo(pixelFmt, planes, dstStrides); - } - } -#endif -} - std::unique_ptr PixelMap::CreateSdrMemory(ImageInfo &imageInfo, PixelFormat format, AllocatorType dstType, uint32_t &errorCode, bool toSRGB) { @@ -4269,8 +4205,7 @@ uint32_t PixelMap::ToSdr() } else if (imageInfo.pixelFormat == PixelFormat::YCRCB_P010) { outFormat = PixelFormat::NV21; } - bool toSRGB = toSdrColorIsSRGB_; - return ToSdr(outFormat, toSRGB); + return ToSdr(outFormat, toSdrColorIsSRGB_); } uint32_t PixelMap::ToSdr(PixelFormat format, bool toSRGB) @@ -4300,7 +4235,7 @@ uint32_t PixelMap::ToSdr(PixelFormat format, bool toSRGB) imageInfo.pixelFormat = sdrMemory->data.format; SetImageInfo(imageInfo, true); YUVStrideInfo dstStrides; - UpdateSdrYuvStrides(imageInfo, dstStrides, sdrMemory->extend.data, dstType); + ImageUtils::UpdateSdrYuvStrides(imageInfo, dstStrides, sdrMemory->extend.data, dstType); UpdateYUVDataInfo(sdrMemory->data.format, imageInfo.size.width, imageInfo.size.height, dstStrides); #ifdef IMAGE_COLORSPACE_FLAG InnerSetColorSpace(OHOS::ColorManager::ColorSpace(toSRGB ? ColorManager::SRGB : ColorManager::DISPLAY_P3)); -- Gitee From e211c0a1f247168f989f318e265c396d11c6398b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B1=91=E5=B1=91=E5=B1=91?= Date: Tue, 31 Dec 2024 12:36:35 +0000 Subject: [PATCH 4/6] update frameworks/innerkitsimpl/utils/include/image_utils.h. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 屑屑屑 --- frameworks/innerkitsimpl/utils/include/image_utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/innerkitsimpl/utils/include/image_utils.h b/frameworks/innerkitsimpl/utils/include/image_utils.h index 09c2e61e1..76029ff02 100644 --- a/frameworks/innerkitsimpl/utils/include/image_utils.h +++ b/frameworks/innerkitsimpl/utils/include/image_utils.h @@ -90,7 +90,7 @@ public: static int32_t GetAPIVersion(); static std::string GetEncodedHeifFormat(); static void UpdateSdrYuvStrides(const ImageInfo &imageInfo, YUVStrideInfo &dstStrides, - void *context, AllocatorType dstType); + void *context, AllocatorType dstType); template static bool CheckMulOverflow(const T& num1, const T& num2) -- Gitee From 03feb6ad392f236f5d1926d2f5d4f76581e14141 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B1=91=E5=B1=91=E5=B1=91?= Date: Tue, 31 Dec 2024 12:37:21 +0000 Subject: [PATCH 5/6] update frameworks/innerkitsimpl/common/src/pixel_map.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 屑屑屑 --- frameworks/innerkitsimpl/common/src/pixel_map.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/frameworks/innerkitsimpl/common/src/pixel_map.cpp b/frameworks/innerkitsimpl/common/src/pixel_map.cpp index a7a311680..07556c77a 100644 --- a/frameworks/innerkitsimpl/common/src/pixel_map.cpp +++ b/frameworks/innerkitsimpl/common/src/pixel_map.cpp @@ -97,9 +97,6 @@ constexpr uint8_t BGRA_BYTES = 4; constexpr uint8_t RGBA_F16_BYTES = 8; constexpr uint8_t PER_PIXEL_LEN = 1; constexpr uint32_t MAX_READ_COUNT = 2048; -static constexpr int32_t PLANE_Y = 0; -static constexpr int32_t PLANE_U = 1; -static constexpr int32_t PLANE_V = 2; constexpr uint8_t FILL_NUMBER = 3; constexpr uint8_t ALIGN_NUMBER = 4; -- Gitee From 9794964be7a498a2cd17c483a61d6c88c20bd2fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B1=91=E5=B1=91=E5=B1=91?= Date: Wed, 1 Jan 2025 11:20:16 +0000 Subject: [PATCH 6/6] update frameworks/innerkitsimpl/utils/src/image_utils.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 屑屑屑 --- frameworks/innerkitsimpl/utils/src/image_utils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/innerkitsimpl/utils/src/image_utils.cpp b/frameworks/innerkitsimpl/utils/src/image_utils.cpp index a553eb925..735aa0536 100644 --- a/frameworks/innerkitsimpl/utils/src/image_utils.cpp +++ b/frameworks/innerkitsimpl/utils/src/image_utils.cpp @@ -1019,7 +1019,7 @@ static void GetYUVStrideInfo(int32_t pixelFmt, OH_NativeBuffer_Planes *planes, Y } void ImageUtils::UpdateSdrYuvStrides(const ImageInfo &imageInfo, YUVStrideInfo &dstStrides, - void *context, AllocatorType dstType) + void *context, AllocatorType dstType) { int32_t dstWidth = imageInfo.size.width; int32_t dstHeight = imageInfo.size.height; -- Gitee