mirror of
https://gitee.com/openharmony/multimedia_image_framework
synced 2024-11-23 15:10:26 +00:00
commit
a7b8b5fb0a
@ -319,7 +319,7 @@ static inline int32_t GetScalePropByDensity(int32_t prop, int32_t srcDensity, in
|
||||
return prop;
|
||||
}
|
||||
|
||||
static void TransformSizeWithDensity(Size &srcSize, int32_t srcDensity, Size &wantSize,
|
||||
static void TransformSizeWithDensity(const Size &srcSize, int32_t srcDensity, const Size &wantSize,
|
||||
int32_t wantDensity, Size &dstSize)
|
||||
{
|
||||
if (IsSizeVailed(wantSize)) {
|
||||
@ -413,7 +413,7 @@ static void ContextToAddrInfos(DecodeContext &context, PixelMapAddrInfos &addrIn
|
||||
addrInfos.func =context.freeFunc;
|
||||
}
|
||||
|
||||
static bool IsSupportDma(PlImageInfo &plInfo)
|
||||
static bool IsSupportDma(const PlImageInfo &plInfo)
|
||||
{
|
||||
#if defined(_WIN32) || defined(_APPLE) || defined(A_PLATFORM) || defined(IOS_PLATFORM)
|
||||
IMAGE_LOGE("Unsupport dma mem alloc");
|
||||
|
@ -169,7 +169,7 @@ void PixelMap::SetPixelsAddr(void *addr, void *context, uint32_t size, Allocator
|
||||
custFreePixelMap_ = func;
|
||||
}
|
||||
|
||||
bool CheckConvertParmas(ImageInfo &src, ImageInfo &dst)
|
||||
bool CheckConvertParmas(const ImageInfo &src, const ImageInfo &dst)
|
||||
{
|
||||
return src.pixelFormat == dst.pixelFormat &&
|
||||
src.size.width == dst.size.width &&
|
||||
|
@ -31,7 +31,7 @@ public:
|
||||
|
||||
Parcelable();
|
||||
explicit Parcelable(bool asRemote);
|
||||
}
|
||||
};
|
||||
|
||||
class Parcel {
|
||||
public:
|
||||
|
@ -176,20 +176,9 @@ static uint32_t DmaMemAlloc(uint64_t count, DecodeContext &context, SkImageInfo
|
||||
#endif
|
||||
}
|
||||
|
||||
uint32_t BmpDecoder::SetContextPixelsBuffer(uint64_t byteCount, DecodeContext &context, SkImageInfo &dstInfo)
|
||||
uint32_t SetBuffer(uint64_t byteCount, DecodeContext &context)
|
||||
{
|
||||
#if !defined(_WIN32) && !defined(_APPLE) && !defined(A_PLATFORM) && !defined(IOS_PLATFORM)
|
||||
if (context.allocatorType == Media::AllocatorType::SHARE_MEM_ALLOC) {
|
||||
uint32_t res = SetShareMemBuffer(byteCount, context);
|
||||
if (res != SUCCESS) {
|
||||
return res;
|
||||
}
|
||||
} else if (context.allocatorType == Media::AllocatorType::DMA_ALLOC) {
|
||||
uint32_t res = DmaMemAlloc(byteCount, context, dstInfo);
|
||||
if (res != SUCCESS) {
|
||||
return res;
|
||||
}
|
||||
} else {
|
||||
if (byteCount <= 0) {
|
||||
HiLog::Error(LABEL, "Decode failed, byteCount is invalid value");
|
||||
return ERR_MEDIA_INVALID_VALUE;
|
||||
@ -200,7 +189,7 @@ uint32_t BmpDecoder::SetContextPixelsBuffer(uint64_t byteCount, DecodeContext &c
|
||||
static_cast<unsigned long long>(byteCount));
|
||||
return ERR_IMAGE_MALLOC_ABNORMAL;
|
||||
}
|
||||
#ifdef _WIN32
|
||||
#ifdef _WIN32
|
||||
if (memset_s(outputBuffer, 0, byteCount) != EOK) {
|
||||
HiLog::Error(LABEL, "Decode failed, memset buffer failed", backRet);
|
||||
free(outputBuffer);
|
||||
@ -220,8 +209,13 @@ uint32_t BmpDecoder::SetContextPixelsBuffer(uint64_t byteCount, DecodeContext &c
|
||||
context.pixelsBuffer.context = nullptr;
|
||||
context.allocatorType = AllocatorType::HEAP_ALLOC;
|
||||
context.freeFunc = nullptr;
|
||||
}
|
||||
#else
|
||||
context.freeFunc = nullptr;
|
||||
#endif
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
uint32_t SetBufferForPlatform(uint64_t byteCount, DecodeContext &context)
|
||||
{
|
||||
if (byteCount <= 0) {
|
||||
HiLog::Error(LABEL, "Decode failed, byteCount is invalid value");
|
||||
return ERR_MEDIA_INVALID_VALUE;
|
||||
@ -252,6 +246,33 @@ uint32_t BmpDecoder::SetContextPixelsBuffer(uint64_t byteCount, DecodeContext &c
|
||||
context.pixelsBuffer.context = nullptr;
|
||||
context.allocatorType = AllocatorType::HEAP_ALLOC;
|
||||
context.freeFunc = nullptr;
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
uint32_t BmpDecoder::SetContextPixelsBuffer(uint64_t byteCount, DecodeContext &context, SkImageInfo &dstInfo)
|
||||
{
|
||||
#if !defined(_WIN32) && !defined(_APPLE) && !defined(A_PLATFORM) && !defined(IOS_PLATFORM)
|
||||
if (context.allocatorType == Media::AllocatorType::SHARE_MEM_ALLOC) {
|
||||
uint32_t res = SetShareMemBuffer(byteCount, context);
|
||||
if (res != SUCCESS) {
|
||||
return res;
|
||||
}
|
||||
} else if (context.allocatorType == Media::AllocatorType::DMA_ALLOC) {
|
||||
uint32_t res = DmaMemAlloc(byteCount, context, dstInfo);
|
||||
if (res != SUCCESS) {
|
||||
return res;
|
||||
}
|
||||
} else {
|
||||
uint32_t res = SetBuffer(byteCount, context);
|
||||
if (res != SUCCESS) {
|
||||
return res;
|
||||
}
|
||||
}
|
||||
#else
|
||||
uint32_t res = SetBufferForPlatform(byteCount, context);
|
||||
if (res != SUCCESS) {
|
||||
return res;
|
||||
}
|
||||
#endif
|
||||
return SUCCESS;
|
||||
}
|
||||
|
@ -176,6 +176,7 @@ static uint32_t HeapMemAlloc(DecodeContext &context, uint64_t count)
|
||||
if (memset_s(out, count, ZERO, count) != EOK) {
|
||||
#endif
|
||||
HiLog::Error(LABEL, "Decode failed, memset buffer failed");
|
||||
free(out);
|
||||
return ERR_IMAGE_DECODE_FAILED;
|
||||
}
|
||||
SetDecodeContextBuffer(context, AllocatorType::HEAP_ALLOC, out, count, nullptr);
|
||||
|
@ -1745,7 +1745,7 @@ static void NumSplit(std::string &src, std::vector<std::string> &out)
|
||||
}
|
||||
}
|
||||
|
||||
static std::string JoinStr(std::vector<std::string> &in, const std::string delim)
|
||||
static std::string JoinStr(std::vector<std::string> &in, const std::string &delim)
|
||||
{
|
||||
std::string res = "";
|
||||
for (size_t i = 0; i < (in.size() - SIZE_ONE); i++) {
|
||||
@ -1772,7 +1772,7 @@ static void FormatTimeStamp(std::string &src, std::string &value)
|
||||
value = JoinStr(dateVector, "-") + " " + JoinStr(timeVector, ":");
|
||||
}
|
||||
|
||||
static uint32_t SpecialExifData(EXIFInfo* info, const std::string name, std::string &value)
|
||||
static uint32_t SpecialExifData(EXIFInfo* info, const std::string &name, std::string &value)
|
||||
{
|
||||
if (IsSameTextStr(DATE_TIME_ORIGINAL_MEDIA, name)) {
|
||||
std::string orgValue;
|
||||
@ -1798,7 +1798,7 @@ static uint32_t SpecialExifData(EXIFInfo* info, const std::string name, std::str
|
||||
return Media::ERR_MEDIA_STATUS_ABNORMAL;
|
||||
}
|
||||
|
||||
static bool GetExifTagByName(const std::string name, ExifTag &tag)
|
||||
static bool GetExifTagByName(const std::string &name, ExifTag &tag)
|
||||
{
|
||||
auto find_item = std::find_if(TAG_MAP.begin(), TAG_MAP.end(),
|
||||
[name](const std::map<ExifTag, std::string>::value_type item) {
|
||||
|
@ -207,6 +207,10 @@ uint32_t PngDecoder::Decode(uint32_t index, DecodeContext &context)
|
||||
#if !defined(_WIN32) && !defined(_APPLE) && !defined(A_PLATFORM) && !defined(IOS_PLATFORM)
|
||||
bool AllocBufferForShareType(DecodeContext &context, uint64_t byteCount)
|
||||
{
|
||||
if (byteCount == 0) {
|
||||
HiLog::Error(LABEL, "alloc output buffer size: 0 error.");
|
||||
return false;
|
||||
}
|
||||
uint32_t id = context.pixelmapUniqueId_;
|
||||
std::string name = "PNG RawData, uniqueId: " + std::to_string(getpid()) + '_' + std::to_string(id);
|
||||
int fd = AshmemCreate(name.c_str(), byteCount);
|
||||
@ -239,7 +243,112 @@ bool AllocBufferForShareType(DecodeContext &context, uint64_t byteCount)
|
||||
context.freeFunc = nullptr;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AllocBufferForDmaType(DecodeContext &context, uint64_t byteCount, PngImageInfo pngImageInfo)
|
||||
{
|
||||
sptr<SurfaceBuffer> sb = SurfaceBuffer::Create();
|
||||
BufferRequestConfig requestConfig = {
|
||||
.width = pngImageInfo.width,
|
||||
.height = pngImageInfo.height,
|
||||
.strideAlignment = 0x8, // set 0x8 as default value to alloc SurfaceBufferImpl
|
||||
.format = GRAPHIC_PIXEL_FMT_RGBA_8888, // PixelFormat
|
||||
.usage = BUFFER_USAGE_CPU_READ || BUFFER_USAGE_CPU_WRITE || BUFFER_USAGE_MEM_DMA,
|
||||
.timeout = 0,
|
||||
.colorGamut = GraphicColorGamut::GRAPHIC_COLOR_GAMUT_SRGB,
|
||||
.transform = GraphicTransformType::GRAPHIC_ROTATE_NONE,
|
||||
};
|
||||
GSError ret = sb->Alloc(requestConfig);
|
||||
if (ret != GSERROR_OK) {
|
||||
HiLog::Error(LABEL, "SurfaceBuffer Alloc failed, %{public}s", GSErrorStr(ret).c_str());
|
||||
return false;
|
||||
}
|
||||
void* nativeBuffer = sb.GetRefPtr();
|
||||
int32_t err = ImageUtils::SurfaceBuffer_Reference(nativeBuffer);
|
||||
if (err != OHOS::GSERROR_OK) {
|
||||
HiLog::Error(LABEL, "NativeBufferReference failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
context.pixelsBuffer.buffer = sb->GetVirAddr();
|
||||
context.pixelsBuffer.context = nativeBuffer;
|
||||
context.pixelsBuffer.bufferSize = byteCount;
|
||||
context.allocatorType = AllocatorType::DMA_ALLOC;
|
||||
context.freeFunc = nullptr;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AllocOutBuffer(DecodeContext &context, uint64_t byteCount)
|
||||
{
|
||||
if (byteCount == 0) {
|
||||
HiLog::Error(LABEL, "alloc output buffer size: 0 error.");
|
||||
return false;
|
||||
}
|
||||
void *outputBuffer = malloc(byteCount);
|
||||
if (outputBuffer == nullptr) {
|
||||
HiLog::Error(LABEL, "alloc output buffer size:[%{public}llu] error.",
|
||||
static_cast<unsigned long long>(byteCount));
|
||||
return false;
|
||||
}
|
||||
#ifdef _WIN32
|
||||
errno_t backRet = memset_s(outputBuffer, 0, byteCount);
|
||||
if (backRet != EOK) {
|
||||
HiLog::Error(LABEL, "init output buffer fail.", backRet);
|
||||
free(outputBuffer);
|
||||
outputBuffer = nullptr;
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
if (memset_s(outputBuffer, byteCount, 0, byteCount) != EOK) {
|
||||
HiLog::Error(LABEL, "init output buffer fail.");
|
||||
free(outputBuffer);
|
||||
outputBuffer = nullptr;
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
context.pixelsBuffer.buffer = outputBuffer;
|
||||
context.pixelsBuffer.bufferSize = byteCount;
|
||||
context.pixelsBuffer.context = nullptr;
|
||||
context.allocatorType = AllocatorType::HEAP_ALLOC;
|
||||
context.freeFunc = nullptr;
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool AllocBufferForPlatform(DecodeContext &context, uint64_t byteCount)
|
||||
{
|
||||
if (byteCount == 0) {
|
||||
HiLog::Error(LABEL, "alloc output buffer size: 0 error.");
|
||||
return false;
|
||||
}
|
||||
void *outputBuffer = malloc(byteCount);
|
||||
if (outputBuffer == nullptr) {
|
||||
HiLog::Error(LABEL, "alloc output buffer size:[%{public}llu] error.",
|
||||
static_cast<unsigned long long>(byteCount));
|
||||
return false;
|
||||
}
|
||||
#ifdef _WIN32
|
||||
errno_t backRet = memset_s(outputBuffer, 0, byteCount);
|
||||
if (backRet != EOK) {
|
||||
HiLog::Error(LABEL, "init output buffer fail.", backRet);
|
||||
free(outputBuffer);
|
||||
outputBuffer = nullptr;
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
if (memset_s(outputBuffer, byteCount, 0, byteCount) != EOK) {
|
||||
HiLog::Error(LABEL, "init output buffer fail.");
|
||||
free(outputBuffer);
|
||||
outputBuffer = nullptr;
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
context.pixelsBuffer.buffer = outputBuffer;
|
||||
context.pixelsBuffer.bufferSize = byteCount;
|
||||
context.pixelsBuffer.context = nullptr;
|
||||
context.allocatorType = AllocatorType::HEAP_ALLOC;
|
||||
context.freeFunc = nullptr;
|
||||
return true;
|
||||
}
|
||||
|
||||
uint8_t *PngDecoder::AllocOutputBuffer(DecodeContext &context)
|
||||
{
|
||||
@ -252,91 +361,21 @@ uint8_t *PngDecoder::AllocOutputBuffer(DecodeContext &context)
|
||||
return nullptr;
|
||||
}
|
||||
} else if (context.allocatorType == Media::AllocatorType::DMA_ALLOC) {
|
||||
sptr<SurfaceBuffer> sb = SurfaceBuffer::Create();
|
||||
BufferRequestConfig requestConfig = {
|
||||
.width = pngImageInfo_.width,
|
||||
.height = pngImageInfo_.height,
|
||||
.strideAlignment = 0x8, // set 0x8 as default value to alloc SurfaceBufferImpl
|
||||
.format = GRAPHIC_PIXEL_FMT_RGBA_8888, // PixelFormat
|
||||
.usage = BUFFER_USAGE_CPU_READ || BUFFER_USAGE_CPU_WRITE || BUFFER_USAGE_MEM_DMA,
|
||||
.timeout = 0,
|
||||
.colorGamut = GraphicColorGamut::GRAPHIC_COLOR_GAMUT_SRGB,
|
||||
.transform = GraphicTransformType::GRAPHIC_ROTATE_NONE,
|
||||
};
|
||||
GSError ret = sb->Alloc(requestConfig);
|
||||
if (ret != GSERROR_OK) {
|
||||
HiLog::Error(LABEL, "SurfaceBuffer Alloc failed, %{public}s", GSErrorStr(ret).c_str());
|
||||
if (!AllocBufferForDmaType(context, byteCount, pngImageInfo_)) {
|
||||
HiLog::Error(LABEL, "alloc output buffer for DMA_ALLOC error.");
|
||||
return nullptr;
|
||||
}
|
||||
void* nativeBuffer = sb.GetRefPtr();
|
||||
int32_t err = ImageUtils::SurfaceBuffer_Reference(nativeBuffer);
|
||||
if (err != OHOS::GSERROR_OK) {
|
||||
HiLog::Error(LABEL, "NativeBufferReference failed");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
context.pixelsBuffer.buffer = sb->GetVirAddr();
|
||||
context.pixelsBuffer.context = nativeBuffer;
|
||||
context.pixelsBuffer.bufferSize = byteCount;
|
||||
context.allocatorType = AllocatorType::DMA_ALLOC;
|
||||
context.freeFunc = nullptr;
|
||||
} else {
|
||||
void *outputBuffer = malloc(byteCount);
|
||||
if (outputBuffer == nullptr) {
|
||||
HiLog::Error(LABEL, "alloc output buffer size:[%{public}llu] error.",
|
||||
static_cast<unsigned long long>(byteCount));
|
||||
if (!AllocOutBuffer(context, byteCount)) {
|
||||
HiLog::Error(LABEL, "alloc output buffer for DMA_ALLOC error.");
|
||||
return nullptr;
|
||||
}
|
||||
#ifdef _WIN32
|
||||
errno_t backRet = memset_s(outputBuffer, 0, byteCount);
|
||||
if (backRet != EOK) {
|
||||
HiLog::Error(LABEL, "init output buffer fail.", backRet);
|
||||
free(outputBuffer);
|
||||
outputBuffer = nullptr;
|
||||
return nullptr;
|
||||
}
|
||||
#else
|
||||
if (memset_s(outputBuffer, byteCount, 0, byteCount) != EOK) {
|
||||
HiLog::Error(LABEL, "init output buffer fail.");
|
||||
free(outputBuffer);
|
||||
outputBuffer = nullptr;
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
context.pixelsBuffer.buffer = outputBuffer;
|
||||
context.pixelsBuffer.bufferSize = byteCount;
|
||||
context.pixelsBuffer.context = nullptr;
|
||||
context.allocatorType = AllocatorType::HEAP_ALLOC;
|
||||
context.freeFunc = nullptr;
|
||||
}
|
||||
#else
|
||||
void *outputBuffer = malloc(byteCount);
|
||||
if (outputBuffer == nullptr) {
|
||||
HiLog::Error(LABEL, "alloc output buffer size:[%{public}llu] error.",
|
||||
static_cast<unsigned long long>(byteCount));
|
||||
return nullptr;
|
||||
}
|
||||
#ifdef _WIN32
|
||||
errno_t backRet = memset_s(outputBuffer, 0, byteCount);
|
||||
if (backRet != EOK) {
|
||||
HiLog::Error(LABEL, "init output buffer fail.", backRet);
|
||||
free(outputBuffer);
|
||||
outputBuffer = nullptr;
|
||||
if (!AllocBufferForPlatform(context, byteCount)) {
|
||||
HiLog::Error(LABEL, "alloc output buffer for SHARE_MEM_ALLOC error.");
|
||||
return nullptr;
|
||||
}
|
||||
#else
|
||||
if (memset_s(outputBuffer, byteCount, 0, byteCount) != EOK) {
|
||||
HiLog::Error(LABEL, "init output buffer fail.");
|
||||
free(outputBuffer);
|
||||
outputBuffer = nullptr;
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
context.pixelsBuffer.buffer = outputBuffer;
|
||||
context.pixelsBuffer.bufferSize = byteCount;
|
||||
context.pixelsBuffer.context = nullptr;
|
||||
context.allocatorType = AllocatorType::HEAP_ALLOC;
|
||||
context.freeFunc = nullptr;
|
||||
#endif
|
||||
}
|
||||
return static_cast<uint8_t *>(context.pixelsBuffer.buffer);
|
||||
|
Loading…
Reference in New Issue
Block a user