From bd570756e3ccc7e3b96715f00a04838cfe9bca77 Mon Sep 17 00:00:00 2001 From: hw_wyx Date: Tue, 20 Aug 2024 17:57:19 +0800 Subject: [PATCH] fixDrawablePixelMap Signed-off-by: hw_wyx Change-Id: I904ceb5e7c5f7ca2782cb812eee05ed38d858856 --- .../drawable_descriptor/image_converter.cpp | 10 ++++++++-- .../drawable_descriptor/image_source_preview.h | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/interfaces/inner_api/drawable_descriptor/image_converter.cpp b/interfaces/inner_api/drawable_descriptor/image_converter.cpp index bafba52f1bd..534c17a0d99 100644 --- a/interfaces/inner_api/drawable_descriptor/image_converter.cpp +++ b/interfaces/inner_api/drawable_descriptor/image_converter.cpp @@ -16,6 +16,7 @@ #include "image_converter.h" #include "drawable_descriptor_log.h" +#include "securec.h" #ifndef PREVIEW #include "image_utils.h" #include "platform/image_native/image_type.h" @@ -139,12 +140,17 @@ std::shared_ptr ImageConverter::BitmapToPixelMap( auto data = bitMap->GetPixels(); opts.size.width = static_cast(bitMap->GetWidth()); opts.size.height = static_cast(bitMap->GetHeight()); - auto pixelMap = Media::PixelMap::Create(reinterpret_cast(data), - opts.size.width * opts.size.height, opts); + opts.editable = false; + auto pixelMap = Media::PixelMap::Create(opts); if (!pixelMap) { HILOGE("PixelMap is null, bitMap's Size = (%{public}d, %{public}d)", bitMap->GetWidth(), bitMap->GetHeight()); return pixelMap; } + auto dstAddr = pixelMap->GetWritablePixels(); + if (memcpy_s(dstAddr, pixelMap->GetByteCount(), data, pixelMap->GetByteCount()) != 0) { + HILOGE("PixelMap write fail"); + return nullptr; + } return pixelMap; } #endif diff --git a/interfaces/inner_api/drawable_descriptor/image_source_preview.h b/interfaces/inner_api/drawable_descriptor/image_source_preview.h index 56e3e7e7009..7598e644275 100644 --- a/interfaces/inner_api/drawable_descriptor/image_source_preview.h +++ b/interfaces/inner_api/drawable_descriptor/image_source_preview.h @@ -113,6 +113,21 @@ public: return 0; } + void* GetWritablePixels() + { + return nullptr; + } + + int32_t GetByteCount() + { + return 0; + } + + static std::unique_ptr Create(const InitializationOptions& opts) + { + return nullptr; + } + static std::unique_ptr Create( const uint32_t* colors, uint32_t colorLength, const InitializationOptions& opts) {