mirror of
https://gitee.com/openharmony/multimedia_image_framework
synced 2024-11-23 06:59:52 +00:00
change HiLog::xx->HILOG_xx by IMAGE_LOGx
Signed-off-by: y00656910 <yaoxingyu3@huawei.com> Change-Id: Ib937137822f0b43a3d18723c26943bac06ea7bfe
This commit is contained in:
parent
52c591cb91
commit
5b8f6bdb87
@ -17,11 +17,10 @@
|
||||
|
||||
#include "buffer_packer_stream.h"
|
||||
#include "file_packer_stream.h"
|
||||
#include "hilog/log.h"
|
||||
#include "image/abs_image_encoder.h"
|
||||
#include "image_log.h"
|
||||
#include "image_trace.h"
|
||||
#include "image_utils.h"
|
||||
#include "log_tags.h"
|
||||
#include "media_errors.h"
|
||||
#include "ostream_packer_stream.h"
|
||||
#include "plugin_server.h"
|
||||
@ -29,12 +28,16 @@
|
||||
#include "include/jpeg_encoder.h"
|
||||
#endif
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_IMAGE
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "ImagePacker"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
using namespace OHOS::HiviewDFX;
|
||||
using namespace ImagePlugin;
|
||||
using namespace MultimediaPlugin;
|
||||
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_IMAGE, "ImagePacker" };
|
||||
static constexpr uint8_t QUALITY_MAX = 100;
|
||||
const static std::string EXTENDED_ENCODER = "image/extended";
|
||||
static constexpr size_t SIZE_ZERO = 0;
|
||||
@ -48,7 +51,7 @@ uint32_t ImagePacker::GetSupportedFormats(std::set<std::string> &formats)
|
||||
uint32_t ret =
|
||||
pluginServer_.PluginServerGetClassInfo<AbsImageEncoder>(AbsImageEncoder::SERVICE_DEFAULT, classInfos);
|
||||
if (ret != SUCCESS) {
|
||||
HiLog::Error(LABEL, "get class info from plugin server failed, ret:%{public}u.", ret);
|
||||
IMAGE_LOGE("get class info from plugin server failed, ret:%{public}u.", ret);
|
||||
return ret;
|
||||
}
|
||||
for (auto &info : classInfos) {
|
||||
@ -60,7 +63,7 @@ uint32_t ImagePacker::GetSupportedFormats(std::set<std::string> &formats)
|
||||
AttrData &attr = iter->second;
|
||||
std::string format;
|
||||
if (attr.GetValue(format) != SUCCESS) {
|
||||
HiLog::Error(LABEL, "attr data get format failed.");
|
||||
IMAGE_LOGE("attr data get format failed.");
|
||||
continue;
|
||||
}
|
||||
formats.insert(format);
|
||||
@ -71,11 +74,11 @@ uint32_t ImagePacker::GetSupportedFormats(std::set<std::string> &formats)
|
||||
uint32_t ImagePacker::StartPackingImpl(const PackOption &option)
|
||||
{
|
||||
if (packerStream_ == nullptr || packerStream_.get() == nullptr) {
|
||||
HiLog::Error(LABEL, "make buffer packer stream failed.");
|
||||
IMAGE_LOGE("make buffer packer stream failed.");
|
||||
return ERR_IMAGE_DATA_ABNORMAL;
|
||||
}
|
||||
if (!GetEncoderPlugin(option)) {
|
||||
HiLog::Error(LABEL, "StartPackingImpl get encoder plugin failed.");
|
||||
IMAGE_LOGE("StartPackingImpl get encoder plugin failed.");
|
||||
return ERR_IMAGE_MISMATCHED_FORMAT;
|
||||
}
|
||||
PlEncodeOptions plOpts;
|
||||
@ -89,18 +92,18 @@ uint32_t ImagePacker::StartPacking(uint8_t *outputData, uint32_t maxSize, const
|
||||
{
|
||||
ImageTrace imageTrace("ImagePacker::StartPacking by outputData");
|
||||
if (!IsPackOptionValid(option)) {
|
||||
HiLog::Error(LABEL, "array startPacking option invalid %{public}s, %{public}u.", option.format.c_str(),
|
||||
option.quality);
|
||||
IMAGE_LOGE("array startPacking option invalid %{public}s, %{public}u.", option.format.c_str(),
|
||||
option.quality);
|
||||
return ERR_IMAGE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
if (outputData == nullptr) {
|
||||
HiLog::Error(LABEL, "output buffer is null.");
|
||||
IMAGE_LOGE("output buffer is null.");
|
||||
return ERR_IMAGE_INVALID_PARAMETER;
|
||||
}
|
||||
BufferPackerStream *stream = new (std::nothrow) BufferPackerStream(outputData, maxSize);
|
||||
if (stream == nullptr) {
|
||||
HiLog::Error(LABEL, "make buffer packer stream failed.");
|
||||
IMAGE_LOGE("make buffer packer stream failed.");
|
||||
return ERR_IMAGE_DATA_ABNORMAL;
|
||||
}
|
||||
FreeOldPackerStream();
|
||||
@ -112,13 +115,13 @@ uint32_t ImagePacker::StartPacking(const std::string &filePath, const PackOption
|
||||
{
|
||||
ImageTrace imageTrace("ImagePacker::StartPacking by filePath");
|
||||
if (!IsPackOptionValid(option)) {
|
||||
HiLog::Error(LABEL, "filepath startPacking option invalid %{public}s, %{public}u.", option.format.c_str(),
|
||||
option.quality);
|
||||
IMAGE_LOGE("filepath startPacking option invalid %{public}s, %{public}u.", option.format.c_str(),
|
||||
option.quality);
|
||||
return ERR_IMAGE_INVALID_PARAMETER;
|
||||
}
|
||||
FilePackerStream *stream = new (std::nothrow) FilePackerStream(filePath);
|
||||
if (stream == nullptr) {
|
||||
HiLog::Error(LABEL, "make file packer stream failed.");
|
||||
IMAGE_LOGE("make file packer stream failed.");
|
||||
return ERR_IMAGE_DATA_ABNORMAL;
|
||||
}
|
||||
FreeOldPackerStream();
|
||||
@ -130,13 +133,12 @@ uint32_t ImagePacker::StartPacking(const int &fd, const PackOption &option)
|
||||
{
|
||||
ImageTrace imageTrace("ImagePacker::StartPacking by fd");
|
||||
if (!IsPackOptionValid(option)) {
|
||||
HiLog::Error(LABEL, "fd startPacking option invalid %{public}s, %{public}u.", option.format.c_str(),
|
||||
option.quality);
|
||||
IMAGE_LOGE("fd startPacking option invalid %{public}s, %{public}u.", option.format.c_str(), option.quality);
|
||||
return ERR_IMAGE_INVALID_PARAMETER;
|
||||
}
|
||||
FilePackerStream *stream = new (std::nothrow) FilePackerStream(fd);
|
||||
if (stream == nullptr) {
|
||||
HiLog::Error(LABEL, "make file packer stream failed.");
|
||||
IMAGE_LOGE("make file packer stream failed.");
|
||||
return ERR_IMAGE_DATA_ABNORMAL;
|
||||
}
|
||||
FreeOldPackerStream();
|
||||
@ -148,13 +150,13 @@ uint32_t ImagePacker::StartPacking(std::ostream &outputStream, const PackOption
|
||||
{
|
||||
ImageTrace imageTrace("ImagePacker::StartPacking by outputStream");
|
||||
if (!IsPackOptionValid(option)) {
|
||||
HiLog::Error(LABEL, "outputStream startPacking option invalid %{public}s, %{public}u.", option.format.c_str(),
|
||||
option.quality);
|
||||
IMAGE_LOGE("outputStream startPacking option invalid %{public}s, %{public}u.", option.format.c_str(),
|
||||
option.quality);
|
||||
return ERR_IMAGE_INVALID_PARAMETER;
|
||||
}
|
||||
OstreamPackerStream *stream = new (std::nothrow) OstreamPackerStream(outputStream);
|
||||
if (stream == nullptr) {
|
||||
HiLog::Error(LABEL, "make ostream packer stream failed.");
|
||||
IMAGE_LOGE("make ostream packer stream failed.");
|
||||
return ERR_IMAGE_DATA_ABNORMAL;
|
||||
}
|
||||
FreeOldPackerStream();
|
||||
@ -170,8 +172,7 @@ uint32_t ImagePacker::StartPackingAdapter(PackerStream &outputStream, const Pack
|
||||
packerStream_ = std::unique_ptr<PackerStream>(&outputStream);
|
||||
|
||||
if (!IsPackOptionValid(option)) {
|
||||
HiLog::Error(LABEL, "packer stream option invalid %{public}s, %{public}u.", option.format.c_str(),
|
||||
option.quality);
|
||||
IMAGE_LOGE("packer stream option invalid %{public}s, %{public}u.", option.format.c_str(), option.quality);
|
||||
return ERR_IMAGE_INVALID_PARAMETER;
|
||||
}
|
||||
return StartPackingImpl(option);
|
||||
@ -196,11 +197,11 @@ uint32_t ImagePacker::AddImage(ImageSource &source)
|
||||
}
|
||||
pixelMap_ = source.CreatePixelMap(opts, ret);
|
||||
if (ret != SUCCESS) {
|
||||
HiLog::Error(LABEL, "image source create pixel map failed.");
|
||||
IMAGE_LOGE("image source create pixel map failed.");
|
||||
return ret;
|
||||
}
|
||||
if (pixelMap_ == nullptr || pixelMap_.get() == nullptr) {
|
||||
HiLog::Error(LABEL, "create the pixel map unique_ptr fail.");
|
||||
IMAGE_LOGE("create the pixel map unique_ptr fail.");
|
||||
return ERR_IMAGE_MALLOC_ABNORMAL;
|
||||
}
|
||||
return AddImage(*pixelMap_.get());
|
||||
@ -216,11 +217,11 @@ uint32_t ImagePacker::AddImage(ImageSource &source, uint32_t index)
|
||||
}
|
||||
pixelMap_ = source.CreatePixelMap(index, opts, ret);
|
||||
if (ret != SUCCESS) {
|
||||
HiLog::Error(LABEL, "image source create pixel map failed.");
|
||||
IMAGE_LOGE("image source create pixel map failed.");
|
||||
return ret;
|
||||
}
|
||||
if (pixelMap_ == nullptr || pixelMap_.get() == nullptr) {
|
||||
HiLog::Error(LABEL, "create the pixel map unique_ptr fail.");
|
||||
IMAGE_LOGE("create the pixel map unique_ptr fail.");
|
||||
return ERR_IMAGE_MALLOC_ABNORMAL;
|
||||
}
|
||||
return AddImage(*pixelMap_.get());
|
||||
@ -232,7 +233,7 @@ uint32_t ImagePacker::FinalizePacking()
|
||||
return DoEncodingFunc([](ImagePlugin::AbsImageEncoder* encoder) {
|
||||
auto res = encoder->FinalizeEncode();
|
||||
if (res != SUCCESS) {
|
||||
HiLog::Error(LABEL, "FinalizePacking failed %{public}d.", res);
|
||||
IMAGE_LOGE("FinalizePacking failed %{public}d.", res);
|
||||
}
|
||||
return res;
|
||||
}, false);
|
||||
@ -258,18 +259,18 @@ static ImagePlugin::AbsImageEncoder* GetEncoder(PluginServer &pluginServer, std:
|
||||
bool ImagePacker::GetEncoderPlugin(const PackOption &option)
|
||||
{
|
||||
encoders_.clear();
|
||||
HiLog::Debug(LABEL, "GetEncoderPlugin current encoder plugin size %{public}zu.", encoders_.size());
|
||||
IMAGE_LOGD("GetEncoderPlugin current encoder plugin size %{public}zu.", encoders_.size());
|
||||
auto encoder = GetEncoder(pluginServer_, EXTENDED_ENCODER);
|
||||
if (encoder != nullptr) {
|
||||
encoders_.emplace_back(std::unique_ptr<ImagePlugin::AbsImageEncoder>(encoder));
|
||||
} else {
|
||||
HiLog::Error(LABEL, "GetEncoderPlugin get ext_encoder plugin failed.");
|
||||
IMAGE_LOGE("GetEncoderPlugin get ext_encoder plugin failed.");
|
||||
}
|
||||
encoder = GetEncoder(pluginServer_, option.format);
|
||||
if (encoder != nullptr) {
|
||||
encoders_.emplace_back(std::unique_ptr<ImagePlugin::AbsImageEncoder>(encoder));
|
||||
} else {
|
||||
HiLog::Debug(LABEL, "GetEncoderPlugin get %{public}s plugin failed, use ext_encoder plugin",
|
||||
IMAGE_LOGD("GetEncoderPlugin get %{public}s plugin failed, use ext_encoder plugin",
|
||||
option.format.c_str());
|
||||
}
|
||||
return encoders_.size() != SIZE_ZERO;
|
||||
@ -297,7 +298,7 @@ bool ImagePacker::IsPackOptionValid(const PackOption &option)
|
||||
uint32_t ImagePacker::DoEncodingFunc(std::function<uint32_t(ImagePlugin::AbsImageEncoder*)> func, bool forAll)
|
||||
{
|
||||
if (encoders_.size() == SIZE_ZERO) {
|
||||
HiLog::Error(LABEL, "DoEncodingFunc encoders is empty.");
|
||||
IMAGE_LOGE("DoEncodingFunc encoders is empty.");
|
||||
return ERR_IMAGE_DECODE_ABNORMAL;
|
||||
}
|
||||
std::vector<uint32_t> rets;
|
||||
@ -305,7 +306,7 @@ uint32_t ImagePacker::DoEncodingFunc(std::function<uint32_t(ImagePlugin::AbsImag
|
||||
bool isSuccessOnce = false;
|
||||
for (size_t i = SIZE_ZERO; i < encoders_.size(); i++) {
|
||||
if (!forAll && isSuccessOnce) {
|
||||
HiLog::Debug(LABEL, "DoEncodingFunc encoding successed, reset other encoder.");
|
||||
IMAGE_LOGD("DoEncodingFunc encoding successed, reset other encoder.");
|
||||
encoders_.at(i).reset();
|
||||
continue;
|
||||
}
|
||||
@ -315,7 +316,7 @@ uint32_t ImagePacker::DoEncodingFunc(std::function<uint32_t(ImagePlugin::AbsImag
|
||||
isSuccessOnce = true;
|
||||
}
|
||||
if (!forAll && !isSuccessOnce) {
|
||||
HiLog::Debug(LABEL, "DoEncodingFunc failed.");
|
||||
IMAGE_LOGD("DoEncodingFunc failed.");
|
||||
}
|
||||
}
|
||||
if (isSuccessOnce) {
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -14,16 +14,18 @@
|
||||
*/
|
||||
|
||||
#include "incremental_pixel_map.h"
|
||||
#include "hilog/log.h"
|
||||
#include "image_log.h"
|
||||
#include "image_source.h"
|
||||
#include "log_tags.h"
|
||||
#include "media_errors.h"
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_IMAGE
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "IncrementalPixelMap"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
using namespace OHOS::HiviewDFX;
|
||||
|
||||
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_IMAGE, "IncrementalPixelMap" };
|
||||
|
||||
static IncrementalDecodingState ConvertImageStateToIncrementalState(ImageDecodingState imageState)
|
||||
{
|
||||
@ -50,7 +52,7 @@ static IncrementalDecodingState ConvertImageStateToIncrementalState(ImageDecodin
|
||||
return IncrementalDecodingState::IMAGE_DECODED;
|
||||
}
|
||||
default: {
|
||||
HiLog::Error(LABEL, "unexpected imageState %{public}d.", imageState);
|
||||
IMAGE_LOGE("unexpected imageState %{public}d.", imageState);
|
||||
return IncrementalDecodingState::UNRESOLVED;
|
||||
}
|
||||
}
|
||||
@ -77,11 +79,11 @@ uint32_t IncrementalPixelMap::PromoteDecoding(uint8_t &decodeProgress)
|
||||
if (imageSource_ == nullptr) {
|
||||
if (decodingStatus_.state == IncrementalDecodingState::BASE_INFO_ERROR ||
|
||||
decodingStatus_.state == IncrementalDecodingState::IMAGE_ERROR) {
|
||||
HiLog::Error(LABEL, "promote decode failed for state %{public}d, errorDetail %{public}u.",
|
||||
decodingStatus_.state, decodingStatus_.errorDetail);
|
||||
IMAGE_LOGE("promote decode failed for state %{public}d, errorDetail %{public}u.", decodingStatus_.state,
|
||||
decodingStatus_.errorDetail);
|
||||
return decodingStatus_.errorDetail;
|
||||
}
|
||||
HiLog::Error(LABEL, "promote decode failed or terminated, image source is null.");
|
||||
IMAGE_LOGE("promote decode failed or terminated, image source is null.");
|
||||
return ERR_IMAGE_SOURCE_DATA;
|
||||
}
|
||||
ImageDecodingState imageState = ImageDecodingState::UNRESOLVED;
|
||||
@ -94,7 +96,7 @@ uint32_t IncrementalPixelMap::PromoteDecoding(uint8_t &decodeProgress)
|
||||
if (ret != SUCCESS && ret != ERR_IMAGE_SOURCE_DATA_INCOMPLETE) {
|
||||
DetachSource();
|
||||
decodingStatus_.errorDetail = ret;
|
||||
HiLog::Error(LABEL, "promote decode failed, ret=%{public}u.", ret);
|
||||
IMAGE_LOGE("promote decode failed, ret=%{public}u.", ret);
|
||||
}
|
||||
if (ret == SUCCESS) {
|
||||
DetachSource();
|
||||
|
@ -17,9 +17,8 @@
|
||||
|
||||
#include <cerrno>
|
||||
#include <unistd.h>
|
||||
#include "hilog/log.h"
|
||||
#include "image_log.h"
|
||||
#include "image_utils.h"
|
||||
#include "log_tags.h"
|
||||
#include "media_errors.h"
|
||||
#include "securec.h"
|
||||
|
||||
@ -30,10 +29,14 @@
|
||||
#define SUPPORT_SHARED_MEMORY
|
||||
#endif
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_IMAGE
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "MemoryManager"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
using namespace OHOS::HiviewDFX;
|
||||
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_IMAGE, "MemoryManager" };
|
||||
static const size_t SIZE_ZERO = 0;
|
||||
static const int LINUX_SUCCESS = 0;
|
||||
// Define pixel map malloc max size 600MB
|
||||
@ -41,18 +44,18 @@ constexpr int32_t PIXEL_MAP_MAX_RAM_SIZE = 600 * 1024 * 1024;
|
||||
|
||||
uint32_t HeapMemory::Create()
|
||||
{
|
||||
HiLog::Debug(LABEL, "HeapMemory::Create IN");
|
||||
IMAGE_LOGD("HeapMemory::Create IN");
|
||||
if (data.data != nullptr) {
|
||||
HiLog::Debug(LABEL, "HeapMemory::Create has created");
|
||||
IMAGE_LOGD("HeapMemory::Create has created");
|
||||
return SUCCESS;
|
||||
}
|
||||
if (data.size == 0 || data.size > PIXEL_MAP_MAX_RAM_SIZE) {
|
||||
HiLog::Error(LABEL, "HeapMemory::Create Invalid value of bufferSize");
|
||||
IMAGE_LOGE("HeapMemory::Create Invalid value of bufferSize");
|
||||
return ERR_IMAGE_DATA_ABNORMAL;
|
||||
}
|
||||
data.data = static_cast<uint8_t *>(malloc(data.size));
|
||||
if (data.data == nullptr) {
|
||||
HiLog::Error(LABEL, "HeapMemory::Create malloc buffer failed");
|
||||
IMAGE_LOGE("HeapMemory::Create malloc buffer failed");
|
||||
return ERR_IMAGE_MALLOC_ABNORMAL;
|
||||
}
|
||||
#if defined(IOS_PLATFORM) || defined(A_PLATFORM)
|
||||
@ -64,9 +67,9 @@ uint32_t HeapMemory::Create()
|
||||
uint32_t HeapMemory::Release()
|
||||
{
|
||||
#if !defined(IOS_PLATFORM) &&!defined(A_PLATFORM)
|
||||
HiLog::Debug(LABEL, "HeapMemory::Release IN");
|
||||
IMAGE_LOGD("HeapMemory::Release IN");
|
||||
if (data.data == nullptr) {
|
||||
HiLog::Info(LABEL, "HeapMemory::Release nullptr data");
|
||||
IMAGE_LOGI("HeapMemory::Release nullptr data");
|
||||
return ERR_IMAGE_DATA_ABNORMAL;
|
||||
}
|
||||
free(data.data);
|
||||
@ -90,27 +93,27 @@ static inline void ReleaseSharedMemory(int* fdPtr, uint8_t* ptr = nullptr, size_
|
||||
uint32_t SharedMemory::Create()
|
||||
{
|
||||
#ifdef SUPPORT_SHARED_MEMORY
|
||||
HiLog::Debug(LABEL, "SharedMemory::Create IN tag %{public}s, data size %{public}zu",
|
||||
IMAGE_LOGD("SharedMemory::Create IN tag %{public}s, data size %{public}zu",
|
||||
(data.tag == nullptr)?"nullptr":data.tag, data.size);
|
||||
|
||||
if (data.tag == nullptr || data.size == SIZE_ZERO) {
|
||||
HiLog::Error(LABEL, "SharedMemory::Create tag is nullptr or data size %{public}zu", data.size);
|
||||
IMAGE_LOGE("SharedMemory::Create tag is nullptr or data size %{public}zu", data.size);
|
||||
return ERR_IMAGE_DATA_ABNORMAL;
|
||||
}
|
||||
auto fdPtr = std::make_unique<int>();
|
||||
*fdPtr = AshmemCreate(data.tag, data.size);
|
||||
if (*fdPtr < 0) {
|
||||
HiLog::Error(LABEL, "SharedMemory::Create AshmemCreate fd:[%{public}d].", *fdPtr);
|
||||
IMAGE_LOGE("SharedMemory::Create AshmemCreate fd:[%{public}d].", *fdPtr);
|
||||
return ERR_IMAGE_DATA_ABNORMAL;
|
||||
}
|
||||
if (AshmemSetProt(*fdPtr, PROT_READ | PROT_WRITE) < LINUX_SUCCESS) {
|
||||
HiLog::Error(LABEL, "SharedMemory::Create AshmemSetProt errno %{public}d.", errno);
|
||||
IMAGE_LOGE("SharedMemory::Create AshmemSetProt errno %{public}d.", errno);
|
||||
ReleaseSharedMemory(fdPtr.get());
|
||||
return ERR_IMAGE_DATA_ABNORMAL;
|
||||
}
|
||||
data.data = ::mmap(nullptr, data.size, PROT_READ | PROT_WRITE, MAP_SHARED, *fdPtr, 0);
|
||||
if (data.data == MAP_FAILED) {
|
||||
HiLog::Error(LABEL, "SharedMemory::Create mmap failed, errno:%{public}d", errno);
|
||||
IMAGE_LOGE("SharedMemory::Create mmap failed, errno:%{public}d", errno);
|
||||
ReleaseSharedMemory(fdPtr.get(), static_cast<uint8_t*>(data.data), data.size);
|
||||
return ERR_IMAGE_DATA_ABNORMAL;
|
||||
}
|
||||
@ -118,7 +121,7 @@ uint32_t SharedMemory::Create()
|
||||
extend.data = fdPtr.release();
|
||||
return SUCCESS;
|
||||
#else
|
||||
HiLog::Error(LABEL, "SharedMemory::Create unsupported");
|
||||
IMAGE_LOGE("SharedMemory::Create unsupported");
|
||||
return ERR_IMAGE_DATA_UNSUPPORT;
|
||||
#endif
|
||||
}
|
||||
@ -126,7 +129,7 @@ uint32_t SharedMemory::Create()
|
||||
uint32_t SharedMemory::Release()
|
||||
{
|
||||
#ifdef SUPPORT_SHARED_MEMORY
|
||||
HiLog::Debug(LABEL, "SharedMemory::Release IN");
|
||||
IMAGE_LOGD("SharedMemory::Release IN");
|
||||
ReleaseSharedMemory(static_cast<int*>(extend.data), static_cast<uint8_t*>(data.data), data.size);
|
||||
data.data = nullptr;
|
||||
data.size = SIZE_ZERO;
|
||||
@ -137,7 +140,7 @@ uint32_t SharedMemory::Release()
|
||||
}
|
||||
return SUCCESS;
|
||||
#else
|
||||
HiLog::Error(LABEL, "SharedMemory::Release unsupported");
|
||||
IMAGE_LOGE("SharedMemory::Release unsupported");
|
||||
return ERR_IMAGE_DATA_UNSUPPORT;
|
||||
#endif
|
||||
}
|
||||
@ -145,7 +148,7 @@ uint32_t SharedMemory::Release()
|
||||
uint32_t DmaMemory::Create()
|
||||
{
|
||||
#if defined(_WIN32) || defined(_APPLE) || defined(A_PLATFORM) || defined(IOS_PLATFORM)
|
||||
HiLog::Error(LABEL, "Unsupport dma mem alloc");
|
||||
IMAGE_LOGE("Unsupport dma mem alloc");
|
||||
return ERR_IMAGE_DATA_UNSUPPORT;
|
||||
#else
|
||||
sptr<SurfaceBuffer> sb = SurfaceBuffer::Create();
|
||||
@ -161,13 +164,13 @@ uint32_t DmaMemory::Create()
|
||||
};
|
||||
GSError ret = sb->Alloc(requestConfig);
|
||||
if (ret != GSERROR_OK) {
|
||||
HiLog::Error(LABEL, "SurfaceBuffer Alloc failed, %{public}s", GSErrorStr(ret).c_str());
|
||||
IMAGE_LOGE("SurfaceBuffer Alloc failed, %{public}s", GSErrorStr(ret).c_str());
|
||||
return ERR_DMA_NOT_EXIST;
|
||||
}
|
||||
void* nativeBuffer = sb.GetRefPtr();
|
||||
int32_t err = ImageUtils::SurfaceBuffer_Reference(nativeBuffer);
|
||||
if (err != OHOS::GSERROR_OK) {
|
||||
HiLog::Error(LABEL, "NativeBufferReference failed");
|
||||
IMAGE_LOGE("NativeBufferReference failed");
|
||||
return ERR_DMA_DATA_ABNORMAL;
|
||||
}
|
||||
data.data = static_cast<uint8_t*>(sb->GetVirAddr());
|
||||
@ -180,7 +183,7 @@ uint32_t DmaMemory::Create()
|
||||
uint32_t DmaMemory::Release()
|
||||
{
|
||||
#if defined(_WIN32) || defined(_APPLE) || defined(A_PLATFORM) || defined(IOS_PLATFORM)
|
||||
HiLog::Error(LABEL, "Unsupport dma mem release");
|
||||
IMAGE_LOGE("Unsupport dma mem release");
|
||||
return ERR_IMAGE_DATA_UNSUPPORT;
|
||||
#else
|
||||
data.data = nullptr;
|
||||
@ -188,7 +191,7 @@ uint32_t DmaMemory::Release()
|
||||
if (extend.data != nullptr) {
|
||||
int32_t err = ImageUtils::SurfaceBuffer_Unreference(static_cast<SurfaceBuffer*>(extend.data));
|
||||
if (err != OHOS::GSERROR_OK) {
|
||||
HiLog::Error(LABEL, "NativeBufferReference failed");
|
||||
IMAGE_LOGE("NativeBufferReference failed");
|
||||
return ERR_DMA_DATA_ABNORMAL;
|
||||
}
|
||||
extend.data = nullptr;
|
||||
@ -215,7 +218,7 @@ std::unique_ptr<AbsMemory> MemoryManager::CreateMemory(AllocatorType type, Memor
|
||||
res = std::make_unique<DmaMemory>();
|
||||
break;
|
||||
case AllocatorType::CUSTOM_ALLOC:
|
||||
HiLog::Error(LABEL, "MemoryManager::CreateMemory unsupported CUSTOM_ALLOC now");
|
||||
IMAGE_LOGE("MemoryManager::CreateMemory unsupported CUSTOM_ALLOC now");
|
||||
return nullptr;
|
||||
case AllocatorType::DEFAULT:
|
||||
case AllocatorType::HEAP_ALLOC:
|
||||
@ -224,7 +227,7 @@ std::unique_ptr<AbsMemory> MemoryManager::CreateMemory(AllocatorType type, Memor
|
||||
break;
|
||||
}
|
||||
if (res == nullptr) {
|
||||
HiLog::Error(LABEL, "MemoryManager::CreateMemory unsupported %{public}d", type);
|
||||
IMAGE_LOGE("MemoryManager::CreateMemory unsupported %{public}d", type);
|
||||
return nullptr;
|
||||
}
|
||||
res->data.data = data.data;
|
||||
|
@ -14,15 +14,17 @@
|
||||
*/
|
||||
|
||||
#include <cinttypes>
|
||||
#include "image_log.h"
|
||||
#include "media_errors.h"
|
||||
#include "hilog/log.h"
|
||||
#include "log_tags.h"
|
||||
#include "native_image.h"
|
||||
|
||||
using OHOS::HiviewDFX::HiLog;
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_IMAGE
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "NativeImage"
|
||||
|
||||
namespace {
|
||||
constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_TAG_DOMAIN_ID_IMAGE, "NativeImage"};
|
||||
constexpr int32_t NUMI_0 = 0;
|
||||
constexpr uint32_t NUM_0 = 0;
|
||||
constexpr uint32_t NUM_1 = 1;
|
||||
@ -95,14 +97,14 @@ int32_t NativeImage::SplitYUV422SPComponent()
|
||||
{
|
||||
auto rawBuffer = GetSurfaceBufferAddr();
|
||||
if (rawBuffer == nullptr) {
|
||||
HiLog::Error(LABEL, "SurfaceBuffer viraddr is nullptr");
|
||||
IMAGE_LOGE("SurfaceBuffer viraddr is nullptr");
|
||||
return ERR_MEDIA_NULL_POINTER;
|
||||
}
|
||||
|
||||
uint64_t surfaceSize = NUM_0;
|
||||
auto res = GetDataSize(surfaceSize);
|
||||
if (res != SUCCESS || surfaceSize == NUM_0) {
|
||||
HiLog::Error(LABEL, "S size is 0");
|
||||
IMAGE_LOGE("S size is 0");
|
||||
return ERR_MEDIA_DATA_UNSUPPORT;
|
||||
}
|
||||
|
||||
@ -110,7 +112,7 @@ int32_t NativeImage::SplitYUV422SPComponent()
|
||||
int32_t height = NUM_0;
|
||||
res = GetSize(width, height);
|
||||
if (res != SUCCESS || width <= NUMI_0 || height <= NUMI_0) {
|
||||
HiLog::Error(LABEL, "Invaild width %{public}" PRId32 " height %{public}" PRId32, width, height);
|
||||
IMAGE_LOGE("Invaild width %{public}" PRId32 " height %{public}" PRId32, width, height);
|
||||
return ERR_MEDIA_DATA_UNSUPPORT;
|
||||
}
|
||||
|
||||
@ -119,7 +121,7 @@ int32_t NativeImage::SplitYUV422SPComponent()
|
||||
yuv.ySize = static_cast<uint64_t>(width * height);
|
||||
yuv.uvSize = static_cast<uint64_t>(height * uvStride);
|
||||
if (surfaceSize < (yuv.ySize + yuv.uvSize * NUM_2)) {
|
||||
HiLog::Error(LABEL, "S size %{public}" PRIu64 " < y plane %{public}" PRIu64
|
||||
IMAGE_LOGE("S size %{public}" PRIu64 " < y plane %{public}" PRIu64
|
||||
" + uv plane %{public}" PRIu64, surfaceSize, yuv.ySize, yuv.uvSize * NUM_2);
|
||||
return ERR_MEDIA_DATA_UNSUPPORT;
|
||||
}
|
||||
@ -128,7 +130,7 @@ int32_t NativeImage::SplitYUV422SPComponent()
|
||||
NativeComponent* u = CreateComponent(int32_t(ComponentType::YUV_U), yuv.uvSize, uvStride, NUM_2, nullptr);
|
||||
NativeComponent* v = CreateComponent(int32_t(ComponentType::YUV_V), yuv.uvSize, uvStride, NUM_2, nullptr);
|
||||
if ((y == nullptr) || (u == nullptr) || (v == nullptr)) {
|
||||
HiLog::Error(LABEL, "Create Component failed");
|
||||
IMAGE_LOGE("Create Component failed");
|
||||
return ERR_MEDIA_DATA_UNSUPPORT;
|
||||
}
|
||||
yuv.y = y->raw;
|
||||
@ -166,7 +168,7 @@ int32_t NativeImage::CombineYUVComponents()
|
||||
return res;
|
||||
}
|
||||
if (!IsYUV422SPFormat(format)) {
|
||||
HiLog::Info(LABEL, "No need to combine components for NO YUV format now");
|
||||
IMAGE_LOGI("No need to combine components for NO YUV format now");
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
@ -174,7 +176,7 @@ int32_t NativeImage::CombineYUVComponents()
|
||||
auto u = GetComponent(int32_t(ComponentType::YUV_U));
|
||||
auto v = GetComponent(int32_t(ComponentType::YUV_V));
|
||||
if ((y == nullptr) || (u == nullptr) || (v == nullptr)) {
|
||||
HiLog::Error(LABEL, "No component need to combine");
|
||||
IMAGE_LOGE("No component need to combine");
|
||||
return ERR_MEDIA_DATA_UNSUPPORT;
|
||||
}
|
||||
YUVData data;
|
||||
@ -194,7 +196,7 @@ int32_t NativeImage::CombineYUVComponents()
|
||||
static std::unique_ptr<NativeComponent> BuildComponent(size_t size, int32_t row, int32_t pixel, uint8_t* vir)
|
||||
{
|
||||
if (size == NUM_0 && vir == nullptr) {
|
||||
HiLog::Error(LABEL, "Could't create 0 size component data");
|
||||
IMAGE_LOGE("Could't create 0 size component data");
|
||||
return nullptr;
|
||||
}
|
||||
std::unique_ptr<NativeComponent> component = std::make_unique<NativeComponent>();
|
||||
@ -223,7 +225,7 @@ NativeComponent* NativeImage::CreateComponent(int32_t type, size_t size, int32_t
|
||||
{
|
||||
NativeComponent* res = GetCachedComponent(type);
|
||||
if (res != nullptr) {
|
||||
HiLog::Info(LABEL, "Component %{public}d already exist. No need create", type);
|
||||
IMAGE_LOGI("Component %{public}d already exist. No need create", type);
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -262,22 +264,21 @@ int32_t NativeImage::GetDataSize(uint64_t &size)
|
||||
size = static_cast<uint64_t>(buffer_->GetSize());
|
||||
auto extraData = buffer_->GetExtraData();
|
||||
if (extraData == nullptr) {
|
||||
HiLog::Info(LABEL, "Nullptr s extra data. return buffer size %{public}" PRIu64, size);
|
||||
IMAGE_LOGI("Nullptr s extra data. return buffer size %{public}" PRIu64, size);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
int32_t extraDataSize = NUMI_0;
|
||||
auto res = extraData->ExtraGet(DATA_SIZE_TAG, extraDataSize);
|
||||
if (res != NUM_0) {
|
||||
HiLog::Info(LABEL, "S ExtraGet dataSize error %{public}d", res);
|
||||
IMAGE_LOGI("S ExtraGet dataSize error %{public}d", res);
|
||||
} else if (extraDataSize <= NUMI_0) {
|
||||
HiLog::Info(LABEL, "S ExtraGet dataSize Ok, but size <= 0");
|
||||
IMAGE_LOGI("S ExtraGet dataSize Ok, but size <= 0");
|
||||
} else if (static_cast<uint64_t>(extraDataSize) > size) {
|
||||
HiLog::Info(LABEL,
|
||||
"S ExtraGet dataSize Ok,but dataSize %{public}d is bigger than bufferSize %{public}" PRIu64,
|
||||
IMAGE_LOGI("S ExtraGet dataSize Ok,but dataSize %{public}d is bigger than bufferSize %{public}" PRIu64,
|
||||
extraDataSize, size);
|
||||
} else {
|
||||
HiLog::Info(LABEL, "S ExtraGet dataSize %{public}d", extraDataSize);
|
||||
IMAGE_LOGI("S ExtraGet dataSize %{public}d", extraDataSize);
|
||||
size = extraDataSize;
|
||||
}
|
||||
return SUCCESS;
|
||||
@ -327,7 +328,7 @@ void NativeImage::release()
|
||||
if (buffer_ == nullptr) {
|
||||
return;
|
||||
}
|
||||
HiLog::Info(LABEL, "NativeImage release");
|
||||
IMAGE_LOGI("NativeImage release");
|
||||
if (components_.size() > 0) {
|
||||
components_.clear();
|
||||
}
|
||||
|
@ -15,6 +15,7 @@
|
||||
|
||||
#include "pixel_astc.h"
|
||||
|
||||
#include "image_log.h"
|
||||
#include "image_utils.h"
|
||||
#include "image_trace.h"
|
||||
#include "image_type_converter.h"
|
||||
@ -22,52 +23,54 @@
|
||||
#include "include/core/SkBitmap.h"
|
||||
#include "include/core/SkCanvas.h"
|
||||
#include "include/core/SkImage.h"
|
||||
#include "hilog/log.h"
|
||||
#include "hitrace_meter.h"
|
||||
#include "log_tags.h"
|
||||
#include "media_errors.h"
|
||||
#include "pubdef.h"
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_IMAGE
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "PixelAstc"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
using namespace OHOS::HiviewDFX;
|
||||
using namespace std;
|
||||
constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_IMAGE, "PixelAstc" };
|
||||
|
||||
PixelAstc::~PixelAstc()
|
||||
{
|
||||
HiLog::Info(LABEL, "PixelAstc destory");
|
||||
IMAGE_LOGI("PixelAstc destory");
|
||||
FreePixelMap();
|
||||
}
|
||||
|
||||
const uint8_t *PixelAstc::GetPixel8(int32_t x, int32_t y)
|
||||
{
|
||||
HiLog::Error(LABEL, "GetPixel8 is not support on pixelastc");
|
||||
IMAGE_LOGE("GetPixel8 is not support on pixelastc");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const uint16_t *PixelAstc::GetPixel16(int32_t x, int32_t y)
|
||||
{
|
||||
HiLog::Error(LABEL, "GetPixel16 is not support on pixelastc");
|
||||
IMAGE_LOGE("GetPixel16 is not support on pixelastc");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const uint32_t *PixelAstc::GetPixel32(int32_t x, int32_t y)
|
||||
{
|
||||
HiLog::Error(LABEL, "GetPixel32 is not support on pixelastc");
|
||||
IMAGE_LOGE("GetPixel32 is not support on pixelastc");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool PixelAstc::GetARGB32Color(int32_t x, int32_t y, uint32_t &color)
|
||||
{
|
||||
HiLog::Error(LABEL, "GetARGB32Color is not support on pixelastc");
|
||||
IMAGE_LOGE("GetARGB32Color is not support on pixelastc");
|
||||
return false;
|
||||
}
|
||||
|
||||
void PixelAstc::scale(float xAxis, float yAxis)
|
||||
{
|
||||
if (xAxis == 0 || yAxis == 0) {
|
||||
HiLog::Error(LABEL, "scale param incorrect on pixelastc");
|
||||
IMAGE_LOGE("scale param incorrect on pixelastc");
|
||||
return;
|
||||
} else {
|
||||
TransformData transformData;
|
||||
@ -85,7 +88,7 @@ void PixelAstc::scale(float xAxis, float yAxis)
|
||||
|
||||
bool PixelAstc::resize(float xAxis, float yAxis)
|
||||
{
|
||||
HiLog::Error(LABEL, "resize is not support on pixelastc");
|
||||
IMAGE_LOGE("resize is not support on pixelastc");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -133,7 +136,7 @@ uint32_t PixelAstc::crop(const Rect &rect)
|
||||
imageInfo.size.height = rect.height;
|
||||
SetImageInfo(imageInfo, true);
|
||||
} else {
|
||||
HiLog::Error(LABEL, "crop failed");
|
||||
IMAGE_LOGE("crop failed");
|
||||
return ERR_IMAGE_CROP;
|
||||
}
|
||||
return SUCCESS;
|
||||
@ -141,127 +144,127 @@ uint32_t PixelAstc::crop(const Rect &rect)
|
||||
|
||||
uint32_t PixelAstc::SetAlpha(const float percent)
|
||||
{
|
||||
HiLog::Error(LABEL, "SetAlpha is not support on pixelastc");
|
||||
IMAGE_LOGE("SetAlpha is not support on pixelastc");
|
||||
return ERR_IMAGE_DATA_UNSUPPORT;
|
||||
}
|
||||
|
||||
uint8_t PixelAstc::GetARGB32ColorA(uint32_t color)
|
||||
{
|
||||
HiLog::Error(LABEL, "GetARGB32ColorA is not support on pixelastc");
|
||||
IMAGE_LOGE("GetARGB32ColorA is not support on pixelastc");
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t PixelAstc::GetARGB32ColorR(uint32_t color)
|
||||
{
|
||||
HiLog::Error(LABEL, "GetARGB32ColorR is not support on pixelastc");
|
||||
IMAGE_LOGE("GetARGB32ColorR is not support on pixelastc");
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t PixelAstc::GetARGB32ColorG(uint32_t color)
|
||||
{
|
||||
HiLog::Error(LABEL, "GetARGB32ColorG is not support on pixelastc");
|
||||
IMAGE_LOGE("GetARGB32ColorG is not support on pixelastc");
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t PixelAstc::GetARGB32ColorB(uint32_t color)
|
||||
{
|
||||
HiLog::Error(LABEL, "GetARGB32ColorB is not support on pixelastc");
|
||||
IMAGE_LOGE("GetARGB32ColorB is not support on pixelastc");
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool PixelAstc::IsSameImage(const PixelMap &other)
|
||||
{
|
||||
HiLog::Error(LABEL, "IsSameImage is not support on pixelastc");
|
||||
IMAGE_LOGE("IsSameImage is not support on pixelastc");
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t PixelAstc::ReadPixels(const uint64_t &bufferSize, const uint32_t &offset, const uint32_t &stride,
|
||||
const Rect ®ion, uint8_t *dst)
|
||||
{
|
||||
HiLog::Error(LABEL, "ReadPixels is not support on pixelastc");
|
||||
IMAGE_LOGE("ReadPixels is not support on pixelastc");
|
||||
return ERR_IMAGE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
uint32_t PixelAstc::ReadPixels(const uint64_t &bufferSize, uint8_t *dst)
|
||||
{
|
||||
HiLog::Error(LABEL, "ReadPixels is not support on pixelastc");
|
||||
IMAGE_LOGE("ReadPixels is not support on pixelastc");
|
||||
return ERR_IMAGE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
uint32_t PixelAstc::ReadPixel(const Position &pos, uint32_t &dst)
|
||||
{
|
||||
HiLog::Error(LABEL, "ReadPixel is not support on pixelastc");
|
||||
IMAGE_LOGE("ReadPixel is not support on pixelastc");
|
||||
return ERR_IMAGE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
uint32_t PixelAstc::ResetConfig(const Size &size, const PixelFormat &format)
|
||||
{
|
||||
HiLog::Error(LABEL, "ResetConfig is not support on pixelastc");
|
||||
IMAGE_LOGE("ResetConfig is not support on pixelastc");
|
||||
return ERR_IMAGE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
bool PixelAstc::SetAlphaType(const AlphaType &alphaType)
|
||||
{
|
||||
HiLog::Error(LABEL, "SetAlphaType is not support on pixelastc");
|
||||
IMAGE_LOGE("SetAlphaType is not support on pixelastc");
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t PixelAstc::WritePixel(const Position &pos, const uint32_t &color)
|
||||
{
|
||||
HiLog::Error(LABEL, "WritePixel is not support on pixelastc");
|
||||
IMAGE_LOGE("WritePixel is not support on pixelastc");
|
||||
return ERR_IMAGE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
uint32_t PixelAstc::WritePixels(const uint8_t *source, const uint64_t &bufferSize, const uint32_t &offset,
|
||||
const uint32_t &stride, const Rect ®ion)
|
||||
{
|
||||
HiLog::Error(LABEL, "WritePixels is not support on pixelastc");
|
||||
IMAGE_LOGE("WritePixels is not support on pixelastc");
|
||||
return ERR_IMAGE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
uint32_t PixelAstc::WritePixels(const uint8_t *source, const uint64_t &bufferSize)
|
||||
{
|
||||
HiLog::Error(LABEL, "WritePixels is not support on pixelastc");
|
||||
IMAGE_LOGE("WritePixels is not support on pixelastc");
|
||||
return ERR_IMAGE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
bool PixelAstc::WritePixels(const uint32_t &color)
|
||||
{
|
||||
HiLog::Error(LABEL, "WritePixels is not support on pixelastc");
|
||||
IMAGE_LOGE("WritePixels is not support on pixelastc");
|
||||
return false;
|
||||
}
|
||||
|
||||
void PixelAstc::SetTransformered(bool isTransformered)
|
||||
{
|
||||
HiLog::Error(LABEL, "SetTransformered is not support on pixelastc");
|
||||
IMAGE_LOGE("SetTransformered is not support on pixelastc");
|
||||
}
|
||||
|
||||
bool PixelAstc::IsTransformered()
|
||||
{
|
||||
HiLog::Error(LABEL, "IsTransformered is not support on pixelastc");
|
||||
IMAGE_LOGE("IsTransformered is not support on pixelastc");
|
||||
return false;
|
||||
}
|
||||
|
||||
void PixelAstc::SetRowStride(uint32_t stride)
|
||||
{
|
||||
HiLog::Error(LABEL, "SetRowStride is not support on pixelastc");
|
||||
IMAGE_LOGE("SetRowStride is not support on pixelastc");
|
||||
}
|
||||
|
||||
int32_t PixelAstc::GetRowStride()
|
||||
{
|
||||
HiLog::Error(LABEL, "GetRowStride is not support on pixelastc");
|
||||
IMAGE_LOGE("GetRowStride is not support on pixelastc");
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool PixelAstc::IsSourceAsResponse()
|
||||
{
|
||||
HiLog::Error(LABEL, "IsSourceAsResponse is not support on pixelastc");
|
||||
IMAGE_LOGE("IsSourceAsResponse is not support on pixelastc");
|
||||
return false;
|
||||
}
|
||||
|
||||
void* PixelAstc::GetWritablePixels() const
|
||||
{
|
||||
HiLog::Error(LABEL, "GetWritablePixels is not support on pixelastc");
|
||||
IMAGE_LOGE("GetWritablePixels is not support on pixelastc");
|
||||
return nullptr;
|
||||
}
|
||||
} // namespace Media
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -15,8 +15,7 @@
|
||||
|
||||
#include "pixel_map_parcel.h"
|
||||
#include <unistd.h>
|
||||
#include "hilog/log.h"
|
||||
#include "log_tags.h"
|
||||
#include "image_log.h"
|
||||
#include "media_errors.h"
|
||||
#ifndef _WIN32
|
||||
#include "securec.h"
|
||||
@ -29,11 +28,15 @@
|
||||
#include "ashmem.h"
|
||||
#endif
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_IMAGE
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "PixelMapParcel"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
using namespace OHOS::HiviewDFX;
|
||||
using namespace std;
|
||||
constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_IMAGE, "PixelMapParcel" };
|
||||
|
||||
constexpr int32_t PIXEL_MAP_INFO_MAX_LENGTH = 128;
|
||||
|
||||
@ -63,18 +66,18 @@ uint8_t *PixelMapParcel::ReadAshmemDataFromParcel(OHOS::MessageParcel& data, int
|
||||
uint8_t *base = nullptr;
|
||||
int fd = data.ReadFileDescriptor();
|
||||
if (fd < 0) {
|
||||
HiLog::Error(LABEL, "read fileDescriptor failed, fd < 0");
|
||||
IMAGE_LOGE("read fileDescriptor failed, fd < 0");
|
||||
return nullptr;
|
||||
}
|
||||
void* ptr = ::mmap(nullptr, bufferSize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||
if (ptr == MAP_FAILED) {
|
||||
::close(fd);
|
||||
HiLog::Error(LABEL, "mmap shared memory failed");
|
||||
IMAGE_LOGE("mmap shared memory failed");
|
||||
return nullptr;
|
||||
}
|
||||
context = new int32_t();
|
||||
if (context == nullptr) {
|
||||
HiLog::Error(LABEL, "alloc context failed.");
|
||||
IMAGE_LOGE("alloc context failed.");
|
||||
::munmap(ptr, bufferSize);
|
||||
::close(fd);
|
||||
return nullptr;
|
||||
@ -89,22 +92,22 @@ uint8_t *PixelMapParcel::ReadHeapDataFromParcel(OHOS::MessageParcel& data, int32
|
||||
const uint8_t *addr = data.ReadBuffer(bufferSize);
|
||||
uint8_t *base = nullptr;
|
||||
if (addr == nullptr) {
|
||||
HiLog::Error(LABEL, "read buffer from parcel failed, read buffer addr is null");
|
||||
IMAGE_LOGE("read buffer from parcel failed, read buffer addr is null");
|
||||
return nullptr;
|
||||
}
|
||||
if (bufferSize <= 0 || bufferSize > PIXEL_MAP_MAX_RAM_SIZE) {
|
||||
HiLog::Error(LABEL, "read bufferSize failed, invalid bufferSize.");
|
||||
IMAGE_LOGE("read bufferSize failed, invalid bufferSize.");
|
||||
return nullptr;
|
||||
}
|
||||
base = static_cast<uint8_t *>(malloc(bufferSize));
|
||||
if (base == nullptr) {
|
||||
HiLog::Error(LABEL, "alloc new pixel memory size:[%{public}d] failed.", bufferSize);
|
||||
IMAGE_LOGE("alloc new pixel memory size:[%{public}d] failed.", bufferSize);
|
||||
return nullptr;
|
||||
}
|
||||
if (memcpy_s(base, bufferSize, addr, bufferSize) != 0) {
|
||||
free(base);
|
||||
base = nullptr;
|
||||
HiLog::Error(LABEL, "memcpy pixel data size:[%{public}d] error.", bufferSize);
|
||||
IMAGE_LOGE("memcpy pixel data size:[%{public}d] error.", bufferSize);
|
||||
return nullptr;
|
||||
}
|
||||
return base;
|
||||
@ -114,7 +117,7 @@ std::unique_ptr<PixelMap> PixelMapParcel::CreateFromParcel(OHOS::MessageParcel&
|
||||
{
|
||||
unique_ptr<PixelMap> pixelMap = make_unique<PixelMap>();
|
||||
if (pixelMap == nullptr) {
|
||||
HiLog::Error(LABEL, "create pixelmap pointer fail");
|
||||
IMAGE_LOGE("create pixelmap pointer fail");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -140,7 +143,7 @@ std::unique_ptr<PixelMap> PixelMapParcel::CreateFromParcel(OHOS::MessageParcel&
|
||||
uint32_t ret = pixelMap->SetImageInfo(imgInfo);
|
||||
if (ret != SUCCESS) {
|
||||
ReleaseMemory(allocType, base, reinterpret_cast<void *>(context), bufferSize);
|
||||
HiLog::Error(LABEL, "create pixel map from parcel failed, set image info error.");
|
||||
IMAGE_LOGE("create pixel map from parcel failed, set image info error.");
|
||||
return nullptr;
|
||||
}
|
||||
pixelMap->SetPixelsAddr(base, reinterpret_cast<void *>(context), bufferSize, allocType, nullptr);
|
||||
@ -152,40 +155,40 @@ bool PixelMapParcel::WriteImageInfo(PixelMap* pixelMap, OHOS::MessageParcel& dat
|
||||
int32_t bufferSize = pixelMap->GetByteCount();
|
||||
if (static_cast<size_t>(bufferSize + PIXEL_MAP_INFO_MAX_LENGTH) > data.GetDataCapacity() &&
|
||||
!data.SetDataCapacity(bufferSize + PIXEL_MAP_INFO_MAX_LENGTH)) {
|
||||
HiLog::Error(LABEL, "set parcel max capacity:[%{public}d] failed.", bufferSize + PIXEL_MAP_INFO_MAX_LENGTH);
|
||||
IMAGE_LOGE("set parcel max capacity:[%{public}d] failed.", bufferSize + PIXEL_MAP_INFO_MAX_LENGTH);
|
||||
return false;
|
||||
}
|
||||
if (!data.WriteInt32(pixelMap->GetWidth())) {
|
||||
HiLog::Error(LABEL, "write pixel map width:[%{public}d] to parcel failed.", pixelMap->GetWidth());
|
||||
IMAGE_LOGE("write pixel map width:[%{public}d] to parcel failed.", pixelMap->GetWidth());
|
||||
return false;
|
||||
}
|
||||
if (!data.WriteInt32(pixelMap->GetHeight())) {
|
||||
HiLog::Error(LABEL, "write pixel map height:[%{public}d] to parcel failed.", pixelMap->GetHeight());
|
||||
IMAGE_LOGE("write pixel map height:[%{public}d] to parcel failed.", pixelMap->GetHeight());
|
||||
return false;
|
||||
}
|
||||
if (!data.WriteInt32(static_cast<int32_t>(pixelMap->GetPixelFormat()))) {
|
||||
HiLog::Error(LABEL, "write pixel map pixel format:[%{public}d] to parcel failed.", pixelMap->GetPixelFormat());
|
||||
IMAGE_LOGE("write pixel map pixel format:[%{public}d] to parcel failed.", pixelMap->GetPixelFormat());
|
||||
return false;
|
||||
}
|
||||
if (!data.WriteInt32(static_cast<int32_t>(pixelMap->GetColorSpace()))) {
|
||||
HiLog::Error(LABEL, "write pixel map color space:[%{public}d] to parcel failed.", pixelMap->GetColorSpace());
|
||||
IMAGE_LOGE("write pixel map color space:[%{public}d] to parcel failed.", pixelMap->GetColorSpace());
|
||||
return false;
|
||||
}
|
||||
if (!data.WriteInt32(static_cast<int32_t>(pixelMap->GetAlphaType()))) {
|
||||
HiLog::Error(LABEL, "write pixel map alpha type:[%{public}d] to parcel failed.", pixelMap->GetAlphaType());
|
||||
IMAGE_LOGE("write pixel map alpha type:[%{public}d] to parcel failed.", pixelMap->GetAlphaType());
|
||||
return false;
|
||||
}
|
||||
if (!data.WriteInt32(pixelMap->GetBaseDensity())) {
|
||||
HiLog::Error(LABEL, "write pixel map base density:[%{public}d] to parcel failed.", pixelMap->GetBaseDensity());
|
||||
IMAGE_LOGE("write pixel map base density:[%{public}d] to parcel failed.", pixelMap->GetBaseDensity());
|
||||
return false;
|
||||
}
|
||||
if (!data.WriteInt32(bufferSize)) {
|
||||
HiLog::Error(LABEL, "write pixel map buffer size:[%{public}d] to parcel failed.", bufferSize);
|
||||
IMAGE_LOGE("write pixel map buffer size:[%{public}d] to parcel failed.", bufferSize);
|
||||
return false;
|
||||
}
|
||||
if (!data.WriteInt32(static_cast<int32_t>(pixelMap->GetAllocatorType()))) {
|
||||
HiLog::Error(LABEL, "write pixel map allocator type:[%{public}d] to parcel failed.",
|
||||
pixelMap->GetAllocatorType());
|
||||
IMAGE_LOGE("write pixel map allocator type:[%{public}d] to parcel failed.",
|
||||
pixelMap->GetAllocatorType());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -198,29 +201,29 @@ bool PixelMapParcel::WriteToParcel(PixelMap* pixelMap, OHOS::MessageParcel& data
|
||||
}
|
||||
int32_t bufferSize = pixelMap->GetByteCount();
|
||||
if (!WriteImageInfo(pixelMap, data)) {
|
||||
HiLog::Error(LABEL, "write pixel map info failed.");
|
||||
IMAGE_LOGE("write pixel map info failed.");
|
||||
return false;
|
||||
}
|
||||
if (pixelMap->GetAllocatorType() == AllocatorType::SHARE_MEM_ALLOC) {
|
||||
#if !defined(_WIN32) && !defined(_APPLE)
|
||||
int *fd = static_cast<int *>(pixelMap->GetFd());
|
||||
if (*fd < 0) {
|
||||
HiLog::Error(LABEL, "write pixel map failed, fd < 0.");
|
||||
IMAGE_LOGE("write pixel map failed, fd < 0.");
|
||||
return false;
|
||||
}
|
||||
if (!data.WriteFileDescriptor(*fd)) {
|
||||
HiLog::Error(LABEL, "write pixel map fd:[%{public}d] to parcel failed.", *fd);
|
||||
IMAGE_LOGE("write pixel map fd:[%{public}d] to parcel failed.", *fd);
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
const uint8_t *addr = pixelMap->GetPixels();
|
||||
if (addr == nullptr) {
|
||||
HiLog::Error(LABEL, "write to parcel failed, pixel memory is null.");
|
||||
IMAGE_LOGE("write to parcel failed, pixel memory is null.");
|
||||
return false;
|
||||
}
|
||||
if (!data.WriteBuffer(addr, bufferSize)) {
|
||||
HiLog::Error(LABEL, "write pixel map buffer to parcel failed.");
|
||||
IMAGE_LOGE("write pixel map buffer to parcel failed.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -19,11 +19,16 @@
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
|
||||
#include "hilog/log.h"
|
||||
#include "image_log.h"
|
||||
#include "image_type.h"
|
||||
#include "log_tags.h"
|
||||
#include "matrix.h"
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_IMAGE
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "BasicTransformer"
|
||||
|
||||
static constexpr uint32_t IMAGE_SUCCESS = 0; // success
|
||||
static constexpr uint32_t IMAGE_BASE_ERROR = 1000; // base error
|
||||
static constexpr uint32_t ERR_IMAGE_GENERAL_ERROR = IMAGE_BASE_ERROR + 1; // general error
|
||||
@ -44,10 +49,6 @@ namespace Media {
|
||||
struct BilinearPixelProcArgs;
|
||||
using BilinearPixelProcArgs = struct BilinearPixelProcArgs;
|
||||
|
||||
using namespace OHOS::HiviewDFX;
|
||||
static constexpr OHOS::HiviewDFX::HiLogLabel BASIC_TRANSFORMER_LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_IMAGE,
|
||||
"BasicTransformer" };
|
||||
|
||||
static inline bool CheckOutOfRange(const Point &pt, const Size &size)
|
||||
{
|
||||
if ((pt.x >= 0) && (pt.x < size.width) && (pt.y >= 0) && (pt.y < size.height)) {
|
||||
@ -115,7 +116,7 @@ struct PixmapInfo {
|
||||
|
||||
void PrintPixmapInfo(const std::string &strFlag) const
|
||||
{
|
||||
HiLog::Debug(BASIC_TRANSFORMER_LABEL, "[PixmapInfo][%{public}s][width, height:%{public}d, %{public}d]"
|
||||
IMAGE_LOGD("[PixmapInfo][%{public}s][width, height:%{public}d, %{public}d]"
|
||||
"[bufferSize:%{public}u][pixelFormat:%{public}d].", strFlag.c_str(), imageInfo.size.width,
|
||||
imageInfo.size.height, bufferSize, static_cast<int32_t>(imageInfo.pixelFormat));
|
||||
}
|
||||
|
@ -31,6 +31,12 @@
|
||||
#include <sys/mman.h>
|
||||
#endif
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_IMAGE
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "BasicTransformer"
|
||||
|
||||
namespace {
|
||||
constexpr uint32_t RGB24_R_MASK = 0x00ff0000;
|
||||
constexpr uint32_t RGB24_G_MASK = 0x0000ff00;
|
||||
@ -111,7 +117,7 @@ bool BasicTransformer::CheckAllocateBuffer(PixmapInfo &outPixmap, AllocateMem al
|
||||
int &fd, uint64_t &bufferSize, Size &dstSize)
|
||||
{
|
||||
if (bufferSize == 0 || bufferSize > PIXEL_MAP_MAX_RAM_SIZE) {
|
||||
HiLog::Error(BASIC_TRANSFORMER_LABEL, "[BasicTransformer]Invalid value of bufferSize");
|
||||
IMAGE_LOGE("[BasicTransformer]Invalid value of bufferSize");
|
||||
return false;
|
||||
}
|
||||
if (allocate == nullptr) {
|
||||
@ -123,7 +129,7 @@ bool BasicTransformer::CheckAllocateBuffer(PixmapInfo &outPixmap, AllocateMem al
|
||||
outPixmap.context = tmp.release();
|
||||
}
|
||||
if (outPixmap.data == nullptr) {
|
||||
HiLog::Error(BASIC_TRANSFORMER_LABEL, "[BasicTransformer]apply heap memory failed");
|
||||
IMAGE_LOGE("[BasicTransformer]apply heap memory failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -152,12 +158,12 @@ void BasicTransformer::ReleaseBuffer(AllocatorType allocatorType, int fd, int da
|
||||
uint32_t BasicTransformer::TransformPixmap(const PixmapInfo &inPixmap, PixmapInfo &outPixmap, AllocateMem allocate)
|
||||
{
|
||||
if (inPixmap.data == nullptr) {
|
||||
HiLog::Error(BASIC_TRANSFORMER_LABEL, "[BasicTransformer]input data is null.");
|
||||
IMAGE_LOGE("[BasicTransformer]input data is null.");
|
||||
return ERR_IMAGE_GENERAL_ERROR;
|
||||
}
|
||||
int32_t pixelBytes = ImageUtils::GetPixelBytes(inPixmap.imageInfo.pixelFormat);
|
||||
if (pixelBytes == 0) {
|
||||
HiLog::Error(BASIC_TRANSFORMER_LABEL, "[BasicTransformer]input pixel is invalid.");
|
||||
IMAGE_LOGE("[BasicTransformer]input pixel is invalid.");
|
||||
return ERR_IMAGE_INVALID_PIXEL;
|
||||
}
|
||||
|
||||
@ -165,13 +171,13 @@ uint32_t BasicTransformer::TransformPixmap(const PixmapInfo &inPixmap, PixmapInf
|
||||
GetDstDimension(inPixmap.imageInfo.size, dstSize);
|
||||
outPixmap.imageInfo.size = dstSize;
|
||||
if (dstSize.width <= 0 || dstSize.height <= 0) {
|
||||
HiLog::Error(BASIC_TRANSFORMER_LABEL, "[BasicTransformer]buffer size is invalid.");
|
||||
IMAGE_LOGE("[BasicTransformer]buffer size is invalid.");
|
||||
return ERR_IMAGE_ALLOC_MEMORY_FAILED;
|
||||
}
|
||||
|
||||
uint64_t bufferSize = static_cast<uint64_t>(dstSize.width) * dstSize.height * pixelBytes;
|
||||
if (bufferSize > PIXEL_MAP_MAX_RAM_SIZE) {
|
||||
HiLog::Error(BASIC_TRANSFORMER_LABEL, "[BasicTransformer] buffer size:%{public}llu out of range.",
|
||||
IMAGE_LOGE("[BasicTransformer] buffer size:%{public}llu out of range.",
|
||||
static_cast<unsigned long long>(bufferSize));
|
||||
return ERR_IMAGE_ALLOC_MEMORY_FAILED;
|
||||
}
|
||||
@ -186,14 +192,14 @@ uint32_t BasicTransformer::TransformPixmap(const PixmapInfo &inPixmap, PixmapInf
|
||||
outPixmap.imageInfo.baseDensity = inPixmap.imageInfo.baseDensity;
|
||||
|
||||
if (memset_s(outPixmap.data, bufferSize * sizeof(uint8_t), COLOR_DEFAULT, bufferSize * sizeof(uint8_t)) != EOK) {
|
||||
HiLog::Error(BASIC_TRANSFORMER_LABEL, "[BasicTransformer]apply heap memory failed.");
|
||||
IMAGE_LOGE("[BasicTransformer]apply heap memory failed.");
|
||||
ReleaseBuffer((allocate == nullptr) ? AllocatorType::HEAP_ALLOC : AllocatorType::SHARE_MEM_ALLOC,
|
||||
fd, bufferSize, outPixmap.data);
|
||||
return ERR_IMAGE_GENERAL_ERROR;
|
||||
}
|
||||
|
||||
if (!DrawPixelmap(inPixmap, pixelBytes, dstSize, outPixmap.data)) {
|
||||
HiLog::Error(BASIC_TRANSFORMER_LABEL, "[BasicTransformer] the matrix can not invert.");
|
||||
IMAGE_LOGE("[BasicTransformer] the matrix can not invert.");
|
||||
ReleaseBuffer((allocate == nullptr) ? AllocatorType::HEAP_ALLOC : AllocatorType::SHARE_MEM_ALLOC,
|
||||
fd, bufferSize, outPixmap.data);
|
||||
return ERR_IMAGE_MATRIX_NOT_INVERT;
|
||||
@ -336,7 +342,7 @@ void BasicTransformer::BilinearPixelProc(const AroundPos aroundPos, struct Bilin
|
||||
break;
|
||||
}
|
||||
default:
|
||||
HiLog::Error(BASIC_TRANSFORMER_LABEL, "[BasicTransformer] pixel format not supported, format:%{public}d",
|
||||
IMAGE_LOGE("[BasicTransformer] pixel format not supported, format:%{public}d",
|
||||
args.format);
|
||||
}
|
||||
}
|
||||
|
@ -15,13 +15,16 @@
|
||||
|
||||
#include "matrix.h"
|
||||
|
||||
#include "hilog/log.h"
|
||||
#include "log_tags.h"
|
||||
#include "image_log.h"
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_IMAGE
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "Matrix"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
using namespace OHOS::HiviewDFX;
|
||||
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_IMAGE, "Matrix" };
|
||||
|
||||
Matrix &Matrix::Reset()
|
||||
{
|
||||
@ -236,7 +239,7 @@ const Matrix::CalcXYProc Matrix::gCalcXYProcs[] = { Matrix::IdentityXY, Matrix::
|
||||
// Matrix print function, including 9 elements
|
||||
void Matrix::Print()
|
||||
{
|
||||
HiLog::Debug(LABEL, "[Matrix][%{public}8.4f %{public}8.4f %{public}8.4f]"
|
||||
IMAGE_LOGD("[Matrix][%{public}8.4f %{public}8.4f %{public}8.4f]"
|
||||
"[%{public}8.4f %{public}8.4f %{public}8.4f][%{public}8.4f %{public}8.4f %{public}8.4f].",
|
||||
fMat_[0], fMat_[1], fMat_[2], fMat_[3], fMat_[4], fMat_[5], fMat_[6], fMat_[7], fMat_[8]);
|
||||
}
|
||||
|
@ -18,14 +18,17 @@
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
|
||||
#include "hilog/log.h"
|
||||
#include "log_tags.h"
|
||||
#include "image_log.h"
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_IMAGE
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "PixelConvert"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
using namespace std;
|
||||
using namespace OHOS::HiviewDFX;
|
||||
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_IMAGE, "PixelConvert" };
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
constexpr bool IS_LITTLE_ENDIAN = true;
|
||||
#else
|
||||
@ -1061,14 +1064,14 @@ PixelConvert::PixelConvert(ProcFuncType funcPtr, ProcFuncExtension extension, bo
|
||||
std::unique_ptr<PixelConvert> PixelConvert::Create(const ImageInfo &srcInfo, const ImageInfo &dstInfo)
|
||||
{
|
||||
if (srcInfo.pixelFormat == PixelFormat::UNKNOWN || dstInfo.pixelFormat == PixelFormat::UNKNOWN) {
|
||||
HiLog::Error(LABEL, "source or destination pixel format unknown");
|
||||
IMAGE_LOGE("source or destination pixel format unknown");
|
||||
return nullptr;
|
||||
}
|
||||
uint32_t srcFormat = static_cast<uint32_t>(srcInfo.pixelFormat);
|
||||
uint32_t dstFormat = static_cast<uint32_t>(dstInfo.pixelFormat);
|
||||
ProcFuncType funcPtr = GetProcFuncType(srcFormat, dstFormat);
|
||||
if (funcPtr == nullptr) {
|
||||
HiLog::Error(LABEL, "not found convert function. pixelFormat %{public}u -> %{public}u", srcFormat, dstFormat);
|
||||
IMAGE_LOGE("not found convert function. pixelFormat %{public}u -> %{public}u", srcFormat, dstFormat);
|
||||
return nullptr;
|
||||
}
|
||||
ProcFuncExtension extension;
|
||||
@ -1083,7 +1086,7 @@ std::unique_ptr<PixelConvert> PixelConvert::Create(const ImageInfo &srcInfo, con
|
||||
AlphaConvertType PixelConvert::GetAlphaConvertType(const AlphaType &srcType, const AlphaType &dstType)
|
||||
{
|
||||
if (srcType == AlphaType::IMAGE_ALPHA_TYPE_UNKNOWN || dstType == AlphaType::IMAGE_ALPHA_TYPE_UNKNOWN) {
|
||||
HiLog::Debug(LABEL, "source or destination alpha type unknown");
|
||||
IMAGE_LOGD("source or destination alpha type unknown");
|
||||
return AlphaConvertType::NO_CONVERT;
|
||||
}
|
||||
if ((srcType == AlphaType::IMAGE_ALPHA_TYPE_PREMUL) && (dstType == AlphaType::IMAGE_ALPHA_TYPE_UNPREMUL)) {
|
||||
@ -1104,11 +1107,11 @@ AlphaConvertType PixelConvert::GetAlphaConvertType(const AlphaType &srcType, con
|
||||
void PixelConvert::Convert(void *destinationPixels, const uint8_t *sourcePixels, uint32_t sourcePixelsNum)
|
||||
{
|
||||
if ((destinationPixels == nullptr) || (sourcePixels == nullptr)) {
|
||||
HiLog::Error(LABEL, "destinationPixel or sourcePixel is null");
|
||||
IMAGE_LOGE("destinationPixel or sourcePixel is null");
|
||||
return;
|
||||
}
|
||||
if (!isNeedConvert_) {
|
||||
HiLog::Debug(LABEL, "no need convert");
|
||||
IMAGE_LOGD("no need convert");
|
||||
return;
|
||||
}
|
||||
procFunc_(destinationPixels, sourcePixels, sourcePixelsNum, procFuncExtension_);
|
||||
|
@ -18,10 +18,9 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include "basic_transformer.h"
|
||||
#include "hilog/log.h"
|
||||
#include "image_log.h"
|
||||
#include "image_trace.h"
|
||||
#include "image_utils.h"
|
||||
#include "log_tags.h"
|
||||
#include "media_errors.h"
|
||||
#include "memory_manager.h"
|
||||
#include "pixel_convert_adapter.h"
|
||||
@ -44,11 +43,16 @@ extern "C" {
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_IMAGE
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "PostProc"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
using namespace std;
|
||||
using namespace OHOS::HiviewDFX;
|
||||
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_IMAGE, "PostProc" };
|
||||
constexpr uint32_t NEED_NEXT = 1;
|
||||
constexpr float EPSILON = 1e-6;
|
||||
constexpr uint8_t HALF = 2;
|
||||
@ -72,21 +76,21 @@ uint32_t PostProc::DecodePostProc(const DecodeOptions &opts, PixelMap &pixelMap,
|
||||
GetDstImageInfo(opts, pixelMap, srcImageInfo, dstImageInfo);
|
||||
uint32_t errorCode = ConvertProc(opts.CropRect, dstImageInfo, pixelMap, srcImageInfo);
|
||||
if (errorCode != SUCCESS) {
|
||||
HiLog::Error(LABEL, "[PostProc]crop pixel map failed, errcode:%{public}u", errorCode);
|
||||
IMAGE_LOGE("[PostProc]crop pixel map failed, errcode:%{public}u", errorCode);
|
||||
return errorCode;
|
||||
}
|
||||
decodeOpts_.allocatorType = opts.allocatorType;
|
||||
bool isNeedRotate = !ImageUtils::FloatCompareZero(opts.rotateDegrees);
|
||||
if (isNeedRotate) {
|
||||
if (!RotatePixelMap(opts.rotateDegrees, pixelMap)) {
|
||||
HiLog::Error(LABEL, "[PostProc]rotate:transform pixel map failed");
|
||||
IMAGE_LOGE("[PostProc]rotate:transform pixel map failed");
|
||||
return ERR_IMAGE_TRANSFORM;
|
||||
}
|
||||
}
|
||||
decodeOpts_.allocatorType = opts.allocatorType;
|
||||
if (opts.desiredSize.height > 0 && opts.desiredSize.width > 0) {
|
||||
if (!ScalePixelMap(opts.desiredSize, pixelMap)) {
|
||||
HiLog::Error(LABEL, "[PostProc]scale:transform pixel map failed");
|
||||
IMAGE_LOGE("[PostProc]scale:transform pixel map failed");
|
||||
return ERR_IMAGE_TRANSFORM;
|
||||
}
|
||||
} else {
|
||||
@ -99,7 +103,7 @@ uint32_t PostProc::DecodePostProc(const DecodeOptions &opts, PixelMap &pixelMap,
|
||||
size.height = targetHeight;
|
||||
size.width = targetWidth;
|
||||
if (!ScalePixelMap(size, pixelMap)) {
|
||||
HiLog::Error(LABEL, "[PostProc]density scale:transform pixel map failed");
|
||||
IMAGE_LOGE("[PostProc]density scale:transform pixel map failed");
|
||||
return ERR_IMAGE_TRANSFORM;
|
||||
}
|
||||
info.baseDensity = opts.fitDensity;
|
||||
@ -139,7 +143,7 @@ bool PostProc::CenterScale(const Size &size, PixelMap &pixelMap)
|
||||
int32_t targetWidth = size.width;
|
||||
int32_t targetHeight = size.height;
|
||||
if (targetWidth <= 0 || targetHeight <= 0 || srcWidth <= 0 || srcHeight <= 0) {
|
||||
HiLog::Error(LABEL, "[PostProc]params invalid, targetWidth:%{public}d, targetHeight:%{public}d, "
|
||||
IMAGE_LOGE("[PostProc]params invalid, targetWidth:%{public}d, targetHeight:%{public}d, "
|
||||
"srcWidth:%{public}d, srcHeight:%{public}d", targetWidth, targetHeight, srcWidth, srcHeight);
|
||||
return false;
|
||||
}
|
||||
@ -164,7 +168,7 @@ bool PostProc::CenterScale(const Size &size, PixelMap &pixelMap)
|
||||
return true;
|
||||
}
|
||||
if (!ScalePixelMap(scale, scale, pixelMap)) {
|
||||
HiLog::Error(LABEL, "[PostProc]center scale pixelmap %{public}f fail", scale);
|
||||
IMAGE_LOGE("[PostProc]center scale pixelmap %{public}f fail", scale);
|
||||
return false;
|
||||
}
|
||||
srcWidth = pixelMap.GetWidth();
|
||||
@ -173,7 +177,7 @@ bool PostProc::CenterScale(const Size &size, PixelMap &pixelMap)
|
||||
return true;
|
||||
}
|
||||
if (srcWidth < targetWidth || srcHeight < targetHeight) {
|
||||
HiLog::Error(LABEL, "[PostProc]src size [%{public}d, %{public}d] must less than dst size [%{public}d,"
|
||||
IMAGE_LOGE("[PostProc]src size [%{public}d, %{public}d] must less than dst size [%{public}d,"
|
||||
"%{public}d]", srcWidth, srcHeight, targetWidth, targetHeight);
|
||||
return false;
|
||||
}
|
||||
@ -207,7 +211,7 @@ bool PostProc::CopyPixels(PixelMap& pixelMap, uint8_t* dstPixels, const Size& ds
|
||||
srcStartPixel = srcPixels + scanLine * srcRowStride;
|
||||
errno_t errRet = memcpy_s(dstStartPixel, targetRowBytes, srcStartPixel, copyRowBytes);
|
||||
if (errRet != EOK) {
|
||||
HiLog::Error(LABEL, "[PostProc]memcpy scanline %{public}d fail, errorCode = %{public}d", scanLine, errRet);
|
||||
IMAGE_LOGE("[PostProc]memcpy scanline %{public}d fail, errorCode = %{public}d", scanLine, errRet);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -223,7 +227,7 @@ bool PostProc::CenterDisplay(PixelMap &pixelMap, int32_t srcWidth, int32_t srcHe
|
||||
dstImageInfo.size.width = targetWidth;
|
||||
dstImageInfo.size.height = targetHeight;
|
||||
if (pixelMap.SetImageInfo(dstImageInfo, true) != SUCCESS) {
|
||||
HiLog::Error(LABEL, "update ImageInfo failed");
|
||||
IMAGE_LOGE("update ImageInfo failed");
|
||||
return false;
|
||||
}
|
||||
int32_t bufferSize = pixelMap.GetByteCount();
|
||||
@ -238,18 +242,18 @@ bool PostProc::CenterDisplay(PixelMap &pixelMap, int32_t srcWidth, int32_t srcHe
|
||||
} else if (pixelMap.GetAllocatorType() == AllocatorType::DMA_ALLOC) {
|
||||
dstPixels = AllocDmaMemory(dstImageInfo.size, bufferSize, &nativeBuffer, targetRowStride);
|
||||
if (dstPixels == nullptr) {
|
||||
HiLog::Error(LABEL, "[PostProc]CenterDisplay AllocDmaMemory failed");
|
||||
IMAGE_LOGE("[PostProc]CenterDisplay AllocDmaMemory failed");
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
dstPixels = AllocSharedMemory(dstImageInfo.size, bufferSize, fd, pixelMap.GetUniqueId());
|
||||
if (dstPixels == nullptr) {
|
||||
HiLog::Error(LABEL, "[PostProc]CenterDisplay AllocSharedMemory failed");
|
||||
IMAGE_LOGE("[PostProc]CenterDisplay AllocSharedMemory failed");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (!CopyPixels(pixelMap, dstPixels, dstImageInfo.size, srcWidth, srcHeight, srcRowStride, targetRowStride)) {
|
||||
HiLog::Error(LABEL, "[PostProc]CopyPixels failed");
|
||||
IMAGE_LOGE("[PostProc]CopyPixels failed");
|
||||
ReleaseBuffer(pixelMap.GetAllocatorType(), fd, bufferSize, &dstPixels, nativeBuffer);
|
||||
return false;
|
||||
}
|
||||
@ -283,7 +287,7 @@ bool PostProc::ProcessScanlineFilter(ScanlineFilter &scanlineFilter, const Rect
|
||||
uint32_t ret = scanlineFilter.FilterLine(resultData + ((scanLine - cropRect.top) * rowBytes), rowBytes,
|
||||
srcData + (scanLine * pixelMap.GetRowBytes()));
|
||||
if (ret != SUCCESS) {
|
||||
HiLog::Error(LABEL, "[PostProc]scan line failed, ret:%{public}u", ret);
|
||||
IMAGE_LOGE("[PostProc]scan line failed, ret:%{public}u", ret);
|
||||
return false;
|
||||
}
|
||||
scanLine++;
|
||||
@ -300,7 +304,7 @@ uint32_t PostProc::CheckScanlineFilter(const Rect &cropRect, ImageInfo &dstImage
|
||||
if (decodeOpts_.allocatorType == AllocatorType::SHARE_MEM_ALLOC) {
|
||||
resultData = AllocSharedMemory(dstImageInfo.size, bufferSize, fd, pixelMap.GetUniqueId());
|
||||
if (resultData == nullptr) {
|
||||
HiLog::Error(LABEL, "[PostProc]AllocSharedMemory failed");
|
||||
IMAGE_LOGE("[PostProc]AllocSharedMemory failed");
|
||||
return ERR_IMAGE_CROP;
|
||||
}
|
||||
} else {
|
||||
@ -309,14 +313,14 @@ uint32_t PostProc::CheckScanlineFilter(const Rect &cropRect, ImageInfo &dstImage
|
||||
}
|
||||
}
|
||||
if (ImageUtils::CheckMulOverflow(dstImageInfo.size.width, pixelBytes)) {
|
||||
HiLog::Error(LABEL, "[PostProc]size.width:%{public}d, is too large",
|
||||
IMAGE_LOGE("[PostProc]size.width:%{public}d, is too large",
|
||||
dstImageInfo.size.width);
|
||||
ReleaseBuffer(decodeOpts_.allocatorType, fd, bufferSize, &resultData);
|
||||
return ERR_IMAGE_CROP;
|
||||
}
|
||||
uint32_t rowBytes = pixelBytes * dstImageInfo.size.width;
|
||||
if (!ProcessScanlineFilter(scanlineFilter, cropRect, pixelMap, resultData, rowBytes)) {
|
||||
HiLog::Error(LABEL, "[PostProc]ProcessScanlineFilter failed");
|
||||
IMAGE_LOGE("[PostProc]ProcessScanlineFilter failed");
|
||||
ReleaseBuffer(decodeOpts_.allocatorType, fd, bufferSize, &resultData);
|
||||
return ERR_IMAGE_CROP;
|
||||
}
|
||||
@ -348,7 +352,7 @@ uint32_t PostProc::ConvertProc(const Rect &cropRect, ImageInfo &dstImageInfo, Pi
|
||||
// we suppose a quick method to scanline in mostly seen cases: NO CROP && hasPixelConvert
|
||||
if (GetCropValue(cropRect, srcImageInfo.size) == CropValue::NOCROP &&
|
||||
dstImageInfo.pixelFormat == PixelFormat::ARGB_8888 && hasPixelConvert) {
|
||||
HiLog::Info(LABEL, "[PostProc]no need crop, only pixel convert.");
|
||||
IMAGE_LOGI("[PostProc]no need crop, only pixel convert.");
|
||||
return PixelConvertProc(dstImageInfo, pixelMap, srcImageInfo);
|
||||
}
|
||||
|
||||
@ -361,7 +365,7 @@ uint32_t PostProc::ConvertProc(const Rect &cropRect, ImageInfo &dstImageInfo, Pi
|
||||
return ERR_IMAGE_CROP;
|
||||
}
|
||||
if (ImageUtils::CheckMulOverflow(dstImageInfo.size.width, dstImageInfo.size.height, pixelBytes)) {
|
||||
HiLog::Error(LABEL, "[PostProc]size.width:%{public}d, size.height:%{public}d is too large",
|
||||
IMAGE_LOGE("[PostProc]size.width:%{public}d, size.height:%{public}d is too large",
|
||||
dstImageInfo.size.width, dstImageInfo.size.height);
|
||||
return ERR_IMAGE_CROP;
|
||||
}
|
||||
@ -412,17 +416,17 @@ uint32_t PostProc::AllocBuffer(ImageInfo imageInfo, uint8_t **resultData, uint64
|
||||
return ERR_IMAGE_CROP;
|
||||
}
|
||||
if (ImageUtils::CheckMulOverflow(imageInfo.size.width, imageInfo.size.height, pixelBytes)) {
|
||||
HiLog::Error(LABEL, "[PostProc]size.width:%{public}d, size.height:%{public}d is too large",
|
||||
IMAGE_LOGE("[PostProc]size.width:%{public}d, size.height:%{public}d is too large",
|
||||
imageInfo.size.width, imageInfo.size.height);
|
||||
return ERR_IMAGE_CROP;
|
||||
}
|
||||
bufferSize = static_cast<uint64_t>(imageInfo.size.width) * imageInfo.size.height * pixelBytes;
|
||||
HiLog::Debug(LABEL, "[PostProc]size.width:%{public}d, size.height:%{public}d, bufferSize:%{public}lld",
|
||||
IMAGE_LOGD("[PostProc]size.width:%{public}d, size.height:%{public}d, bufferSize:%{public}lld",
|
||||
imageInfo.size.width, imageInfo.size.height, static_cast<long long>(bufferSize));
|
||||
if (decodeOpts_.allocatorType == AllocatorType::SHARE_MEM_ALLOC) {
|
||||
*resultData = AllocSharedMemory(imageInfo.size, bufferSize, fd, id);
|
||||
if (*resultData == nullptr) {
|
||||
HiLog::Error(LABEL, "[PostProc]AllocSharedMemory failed");
|
||||
IMAGE_LOGE("[PostProc]AllocSharedMemory failed");
|
||||
return ERR_IMAGE_CROP;
|
||||
}
|
||||
} else {
|
||||
@ -436,19 +440,19 @@ uint32_t PostProc::AllocBuffer(ImageInfo imageInfo, uint8_t **resultData, uint64
|
||||
bool PostProc::AllocHeapBuffer(uint64_t bufferSize, uint8_t **buffer)
|
||||
{
|
||||
if (bufferSize == 0 || bufferSize > MALLOC_MAX_LENTH) {
|
||||
HiLog::Error(LABEL, "[PostProc]Invalid value of bufferSize");
|
||||
IMAGE_LOGE("[PostProc]Invalid value of bufferSize");
|
||||
return false;
|
||||
}
|
||||
*buffer = static_cast<uint8_t *>(malloc(bufferSize));
|
||||
if (*buffer == nullptr) {
|
||||
HiLog::Error(LABEL, "[PostProc]alloc covert color buffersize[%{public}llu] failed.",
|
||||
IMAGE_LOGE("[PostProc]alloc covert color buffersize[%{public}llu] failed.",
|
||||
static_cast<unsigned long long>(bufferSize));
|
||||
return false;
|
||||
}
|
||||
#ifdef _WIN32
|
||||
errno_t backRet = memset_s(*buffer, 0, bufferSize);
|
||||
if (backRet != EOK) {
|
||||
HiLog::Error(LABEL, "[PostProc]memset convertData fail, errorCode = %{public}d", backRet);
|
||||
IMAGE_LOGE("[PostProc]memset convertData fail, errorCode = %{public}d", backRet);
|
||||
ReleaseBuffer(AllocatorType::HEAP_ALLOC, 0, 0, buffer);
|
||||
return false;
|
||||
}
|
||||
@ -456,7 +460,7 @@ bool PostProc::AllocHeapBuffer(uint64_t bufferSize, uint8_t **buffer)
|
||||
#else
|
||||
errno_t errRet = memset_s(*buffer, bufferSize, 0, bufferSize);
|
||||
if (errRet != EOK) {
|
||||
HiLog::Error(LABEL, "[PostProc]memset convertData fail, errorCode = %{public}d", errRet);
|
||||
IMAGE_LOGE("[PostProc]memset convertData fail, errorCode = %{public}d", errRet);
|
||||
ReleaseBuffer(AllocatorType::HEAP_ALLOC, 0, 0, buffer);
|
||||
return false;
|
||||
}
|
||||
@ -472,19 +476,19 @@ uint8_t *PostProc::AllocSharedMemory(const Size &size, const uint64_t bufferSize
|
||||
std::string name = "Parcel RawData, uniqueId: " + std::to_string(getpid()) + '_' + std::to_string(uniqueId);
|
||||
fd = AshmemCreate(name.c_str(), bufferSize);
|
||||
if (fd < 0) {
|
||||
HiLog::Error(LABEL, "[PostProc]AllocSharedMemory fd error, bufferSize %{public}lld",
|
||||
IMAGE_LOGE("[PostProc]AllocSharedMemory fd error, bufferSize %{public}lld",
|
||||
static_cast<long long>(bufferSize));
|
||||
return nullptr;
|
||||
}
|
||||
int result = AshmemSetProt(fd, PROT_READ | PROT_WRITE);
|
||||
if (result < 0) {
|
||||
HiLog::Error(LABEL, "[PostProc]AshmemSetProt error");
|
||||
IMAGE_LOGE("[PostProc]AshmemSetProt error");
|
||||
::close(fd);
|
||||
return nullptr;
|
||||
}
|
||||
void* ptr = ::mmap(nullptr, bufferSize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||
if (ptr == MAP_FAILED) {
|
||||
HiLog::Error(LABEL, "[PostProc]mmap error, errno: %{public}s, fd %{public}d, bufferSize %{public}lld",
|
||||
IMAGE_LOGE("[PostProc]mmap error, errno: %{public}s, fd %{public}d, bufferSize %{public}lld",
|
||||
strerror(errno), fd, (long long)bufferSize);
|
||||
::close(fd);
|
||||
return nullptr;
|
||||
@ -526,7 +530,7 @@ void PostProc::ReleaseBuffer(AllocatorType allocatorType, int fd,
|
||||
if (nativeBuffer != nullptr) {
|
||||
int32_t err = ImageUtils::SurfaceBuffer_Unreference(static_cast<SurfaceBuffer*>(nativeBuffer));
|
||||
if (err != OHOS::GSERROR_OK) {
|
||||
HiLog::Error(LABEL, "PostProc NativeBufferReference failed");
|
||||
IMAGE_LOGE("PostProc NativeBufferReference failed");
|
||||
}
|
||||
}
|
||||
return;
|
||||
@ -546,10 +550,10 @@ uint32_t PostProc::NeedScanlineFilter(const Rect &cropRect, const Size &srcSize,
|
||||
{
|
||||
CropValue value = GetCropValue(cropRect, srcSize);
|
||||
if (value == CropValue::NOCROP && !hasPixelConvert) {
|
||||
HiLog::Info(LABEL, "[PostProc]no need crop and pixel convert.");
|
||||
IMAGE_LOGI("[PostProc]no need crop and pixel convert.");
|
||||
return SUCCESS;
|
||||
} else if (value == CropValue::INVALID) {
|
||||
HiLog::Error(LABEL, "[PostProc]invalid corp region, top:%{public}d, left:%{public}d, "
|
||||
IMAGE_LOGE("[PostProc]invalid corp region, top:%{public}d, left:%{public}d, "
|
||||
"width:%{public}d, height:%{public}d", cropRect.top, cropRect.left, cropRect.width, cropRect.height);
|
||||
return ERR_IMAGE_CROP;
|
||||
}
|
||||
@ -584,7 +588,7 @@ bool PostProc::ScalePixelMap(const Size &size, PixelMap &pixelMap)
|
||||
int32_t srcWidth = pixelMap.GetWidth();
|
||||
int32_t srcHeight = pixelMap.GetHeight();
|
||||
if (srcWidth <= 0 || srcHeight <= 0) {
|
||||
HiLog::Error(LABEL, "[PostProc]src width:%{public}d, height:%{public}d is invalid.", srcWidth, srcHeight);
|
||||
IMAGE_LOGE("[PostProc]src width:%{public}d, height:%{public}d is invalid.", srcWidth, srcHeight);
|
||||
return false;
|
||||
}
|
||||
float scaleX = static_cast<float>(size.width) / static_cast<float>(srcWidth);
|
||||
@ -613,7 +617,7 @@ bool PostProc::TranslatePixelMap(float tX, float tY, PixelMap &pixelMap)
|
||||
bool PostProc::Transform(BasicTransformer &trans, const PixmapInfo &input, PixelMap &pixelMap)
|
||||
{
|
||||
if (pixelMap.IsTransformered()) {
|
||||
HiLog::Error(LABEL, "[PostProc]Transform pixelmap is transforming");
|
||||
IMAGE_LOGE("[PostProc]Transform pixelmap is transforming");
|
||||
return false;
|
||||
}
|
||||
pixelMap.SetTransformered(true);
|
||||
@ -747,19 +751,19 @@ bool PostProc::ScalePixelMapEx(const Size &desiredSize, PixelMap &pixelMap, cons
|
||||
int32_t srcWidth = pixelMap.GetWidth();
|
||||
int32_t srcHeight = pixelMap.GetHeight();
|
||||
if (srcWidth <= 0 || srcHeight <= 0 || !pixelMap.GetWritablePixels()) {
|
||||
HiLog::Error(LABEL, "pixelMap param is invalid, src width:%{public}d, height:%{public}d", srcWidth, srcHeight);
|
||||
IMAGE_LOGE("pixelMap param is invalid, src width:%{public}d, height:%{public}d", srcWidth, srcHeight);
|
||||
return false;
|
||||
}
|
||||
AVPixelFormat pixelFormat;
|
||||
if (!GetScaleFormat(imgInfo.pixelFormat, pixelFormat)) {
|
||||
HiLog::Error(LABEL, "pixelMap format is invalid, format: %{public}d", imgInfo.pixelFormat);
|
||||
IMAGE_LOGE("pixelMap format is invalid, format: %{public}d", imgInfo.pixelFormat);
|
||||
return false;
|
||||
}
|
||||
uint32_t dstBufferSize = desiredSize.height * desiredSize.width * ImageUtils::GetPixelBytes(imgInfo.pixelFormat);
|
||||
MemoryData memoryData = {nullptr, dstBufferSize, "ScalePixelMapEx ImageData", desiredSize};
|
||||
auto mem = MemoryManager::CreateMemory(pixelMap.GetAllocatorType(), memoryData);
|
||||
if (mem == nullptr) {
|
||||
HiLog::Error(LABEL, "ScalePixelMapEx CreateMemory failed");
|
||||
IMAGE_LOGE("ScalePixelMapEx CreateMemory failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -778,7 +782,7 @@ bool PostProc::ScalePixelMapEx(const Size &desiredSize, PixelMap &pixelMap, cons
|
||||
if (!res) {
|
||||
sws_freeContext(swsContext);
|
||||
mem->Release();
|
||||
HiLog::Error(LABEL, "sws_scale failed");
|
||||
IMAGE_LOGE("sws_scale failed");
|
||||
return false;
|
||||
}
|
||||
pixelMap.SetPixelsAddr(mem->data.data, mem->extend.data, dstBufferSize, mem->GetType(), nullptr);
|
||||
|
@ -15,9 +15,8 @@
|
||||
|
||||
#include "scan_line_filter.h"
|
||||
|
||||
#include "hilog/log.h"
|
||||
#include "image_log.h"
|
||||
#include "image_utils.h"
|
||||
#include "log_tags.h"
|
||||
#include "media_errors.h"
|
||||
#ifndef _WIN32
|
||||
#include "securec.h"
|
||||
@ -25,10 +24,14 @@
|
||||
#include "memory.h"
|
||||
#endif
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_IMAGE
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "ScanLineFilter"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
using namespace OHOS::HiviewDFX;
|
||||
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_IMAGE, "ScanLineFilter" };
|
||||
|
||||
ScanlineFilter::ScanlineFilter(const PixelFormat &srcPixelFormat) : srcBpp_(ImageUtils::GetPixelBytes(srcPixelFormat))
|
||||
{}
|
||||
@ -66,23 +69,23 @@ void ScanlineFilter::SetPixelConvert(const ImageInfo &srcImageInfo, const ImageI
|
||||
uint32_t ScanlineFilter::FilterLine(void *destRowPixels, uint32_t destRowBytes, const void *srcRowPixels)
|
||||
{
|
||||
if (destRowPixels == nullptr || srcRowPixels == nullptr) {
|
||||
HiLog::Error(LABEL, "[ScanlineFilter]the src or dest pixel point is null.");
|
||||
IMAGE_LOGE("[ScanlineFilter]the src or dest pixel point is null.");
|
||||
return ERR_IMAGE_CROP;
|
||||
}
|
||||
auto startPixel = static_cast<const uint8_t *>(srcRowPixels) + srcRegion_.left * srcBpp_;
|
||||
if (startPixel == nullptr) {
|
||||
HiLog::Error(LABEL, "[ScanlineFilter]the shift src pixel point is null.");
|
||||
IMAGE_LOGE("[ScanlineFilter]the shift src pixel point is null.");
|
||||
return ERR_IMAGE_CROP;
|
||||
}
|
||||
if (!needPixelConvert_) {
|
||||
errno_t ret = memcpy_s(destRowPixels, destRowBytes, startPixel, srcRegion_.width * srcBpp_);
|
||||
if (ret != 0) {
|
||||
HiLog::Error(LABEL, "[ScanlineFilter]memcpy failed,ret=%{public}d.", ret);
|
||||
IMAGE_LOGE("[ScanlineFilter]memcpy failed,ret=%{public}d.", ret);
|
||||
return ERR_IMAGE_CROP;
|
||||
}
|
||||
} else {
|
||||
if (!ConvertPixels(destRowPixels, startPixel, srcRegion_.width)) {
|
||||
HiLog::Error(LABEL, "[ScanlineFilter]convert color failed.");
|
||||
IMAGE_LOGE("[ScanlineFilter]convert color failed.");
|
||||
return ERR_IMAGE_COLOR_CONVERT;
|
||||
}
|
||||
}
|
||||
@ -92,12 +95,12 @@ uint32_t ScanlineFilter::FilterLine(void *destRowPixels, uint32_t destRowBytes,
|
||||
bool ScanlineFilter::ConvertPixels(void *destRowPixels, const uint8_t *startPixel, uint32_t reqPixelNum)
|
||||
{
|
||||
if (destRowPixels == nullptr || startPixel == nullptr) {
|
||||
HiLog::Error(LABEL, "[ScanlineFilter]convert color failed, the destRowPixels or startPixel is null.");
|
||||
IMAGE_LOGE("[ScanlineFilter]convert color failed, the destRowPixels or startPixel is null.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (pixelConverter_ == nullptr) {
|
||||
HiLog::Error(LABEL, "[ScanlineFilter]pixel converter is null");
|
||||
IMAGE_LOGE("[ScanlineFilter]pixel converter is null");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -15,19 +15,22 @@
|
||||
|
||||
#include "image_creator.h"
|
||||
|
||||
#include "hilog/log.h"
|
||||
#include "image_creator_buffer_processor.h"
|
||||
#include "image_creator_manager.h"
|
||||
#include "image_log.h"
|
||||
#include "image_packer.h"
|
||||
#include "image_source.h"
|
||||
#include "image_utils.h"
|
||||
#include "log_tags.h"
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_IMAGE
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "imageCreator"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_TAG_DOMAIN_ID_IMAGE, "imageCreator"};
|
||||
std::map<uint8_t*, ImageCreator*> ImageCreator::bufferCreatorMap_;
|
||||
using namespace OHOS::HiviewDFX;
|
||||
ImageCreator::~ImageCreator()
|
||||
{
|
||||
if (iraContext_ != nullptr) {
|
||||
@ -42,7 +45,7 @@ ImageCreator::~ImageCreator()
|
||||
|
||||
GSError ImageCreator::OnBufferRelease(sptr<SurfaceBuffer> &buffer)
|
||||
{
|
||||
HiLog::Info(LABEL, "OnBufferRelease");
|
||||
IMAGE_LOGI("OnBufferRelease");
|
||||
if (buffer == nullptr) {
|
||||
return GSERROR_NO_ENTRY;
|
||||
}
|
||||
@ -52,7 +55,7 @@ GSError ImageCreator::OnBufferRelease(sptr<SurfaceBuffer> &buffer)
|
||||
}
|
||||
auto icr = iter->second;
|
||||
if (icr->surfaceBufferReleaseListener_ == nullptr) {
|
||||
HiLog::Info(LABEL, "empty icr");
|
||||
IMAGE_LOGI("empty icr");
|
||||
return GSERROR_NO_ENTRY;
|
||||
}
|
||||
icr->surfaceBufferReleaseListener_->OnSurfaceBufferRelease();
|
||||
@ -68,7 +71,7 @@ std::shared_ptr<ImageCreatorContext> ImageCreatorContext ::CreateImageCreatorCon
|
||||
|
||||
void ImageCreatorSurfaceListener ::OnBufferAvailable()
|
||||
{
|
||||
HiLog::Debug(LABEL, "CreatorBufferAvailable");
|
||||
IMAGE_LOGD("CreatorBufferAvailable");
|
||||
if (ic_->surfaceBufferAvaliableListener_ != nullptr) {
|
||||
ic_->surfaceBufferAvaliableListener_->OnSurfaceBufferAvaliable();
|
||||
}
|
||||
@ -81,7 +84,7 @@ std::shared_ptr<ImageCreator> ImageCreator::CreateImageCreator(int32_t width,
|
||||
iva->iraContext_ = ImageCreatorContext::CreateImageCreatorContext();
|
||||
iva->creatorConsumerSurface_ = IConsumerSurface::Create();
|
||||
if (iva->creatorConsumerSurface_ == nullptr) {
|
||||
HiLog::Debug(LABEL, "SurfaceAsConsumer == nullptr");
|
||||
IMAGE_LOGD("SurfaceAsConsumer == nullptr");
|
||||
return iva;
|
||||
}
|
||||
iva->creatorConsumerSurface_->SetDefaultWidthAndHeight(width, height);
|
||||
@ -94,7 +97,7 @@ std::shared_ptr<ImageCreator> ImageCreator::CreateImageCreator(int32_t width,
|
||||
iva->creatorProducerSurface_ = Surface::CreateSurfaceAsProducer(p);
|
||||
iva->creatorProducerSurface_->SetQueueSize(capicity);
|
||||
if (iva->creatorProducerSurface_ == nullptr) {
|
||||
HiLog::Debug(LABEL, "SurfaceAsProducer == nullptr");
|
||||
IMAGE_LOGD("SurfaceAsProducer == nullptr");
|
||||
return iva;
|
||||
}
|
||||
iva->iraContext_->SetCreatorBufferConsumer(iva->creatorConsumerSurface_);
|
||||
@ -113,7 +116,7 @@ std::shared_ptr<ImageCreator> ImageCreator::CreateImageCreator(int32_t width,
|
||||
|
||||
int64_t CreatorPackImage(uint8_t *tempBuffer, uint32_t bufferSize, std::unique_ptr<PixelMap> pixelMap)
|
||||
{
|
||||
HiLog::Debug(LABEL, "PackImage");
|
||||
IMAGE_LOGD("PackImage");
|
||||
ImagePacker imagePacker;
|
||||
PackOption option;
|
||||
option.format = ImageReceiver::OPTION_FORMAT;
|
||||
@ -123,16 +126,16 @@ int64_t CreatorPackImage(uint8_t *tempBuffer, uint32_t bufferSize, std::unique_p
|
||||
|
||||
uint32_t ret = imagePacker.GetSupportedFormats(formats);
|
||||
if (ret != SUCCESS) {
|
||||
HiLog::Error(LABEL, "image packer get supported format failed, ret=%{public}u.", ret);
|
||||
IMAGE_LOGE("image packer get supported format failed, ret=%{public}u.", ret);
|
||||
return 0;
|
||||
} else {
|
||||
HiLog::Debug(LABEL, "SUCCESS");
|
||||
IMAGE_LOGD("SUCCESS");
|
||||
}
|
||||
imagePacker.StartPacking(tempBuffer, bufferSize, option);
|
||||
imagePacker.AddImage(*pixelMap);
|
||||
int64_t packedSize = 0;
|
||||
imagePacker.FinalizePacking(packedSize);
|
||||
HiLog::Info(LABEL, "packedSize=%{public}lld.", static_cast<long long>(packedSize));
|
||||
IMAGE_LOGI("packedSize=%{public}lld.", static_cast<long long>(packedSize));
|
||||
return packedSize;
|
||||
}
|
||||
static const int BIT4 = 4;
|
||||
@ -148,13 +151,13 @@ static void dumpBuffer(const uint8_t* tempBuffer, int64_t size)
|
||||
ss.push_back(xx[tempBuffer[i]&BIT4_MASK]);
|
||||
if (i % PRINT_WIDTH == PRINT_WIDTH_MOD) {
|
||||
ss.push_back('\0');
|
||||
HiLog::Info(LABEL, "buffer[%{public}d] = [%{public}s]", i, ss.data());
|
||||
IMAGE_LOGI("buffer[%{public}d] = [%{public}s]", i, ss.data());
|
||||
ss.clear();
|
||||
ss.resize(0);
|
||||
}
|
||||
}
|
||||
ss.push_back('\0');
|
||||
HiLog::Info(LABEL, "buffer[LAST] = [%{public}s]", ss.data());
|
||||
IMAGE_LOGI("buffer[LAST] = [%{public}s]", ss.data());
|
||||
ss.clear();
|
||||
ss.resize(0);
|
||||
}
|
||||
@ -167,10 +170,10 @@ int32_t ImageCreator::SaveSTP(uint32_t *buffer,
|
||||
if (pixelMap.get() != nullptr) {
|
||||
ImageInfo imageInfo;
|
||||
pixelMap->GetImageInfo(imageInfo);
|
||||
HiLog::Debug(LABEL, "create pixel map imageInfo.size.width=%{public}u.",
|
||||
IMAGE_LOGD("create pixel map imageInfo.size.width=%{public}u.",
|
||||
imageInfo.size.width);
|
||||
} else {
|
||||
HiLog::Error(LABEL, "pixelMap.get() == nullptr");
|
||||
IMAGE_LOGE("pixelMap.get() == nullptr");
|
||||
return ERR_MEDIA_INVALID_VALUE;
|
||||
}
|
||||
ImagePacker imagePacker;
|
||||
@ -199,18 +202,18 @@ static void ReleaseBuffer(AllocatorType allocatorType, uint8_t **buffer)
|
||||
static bool AllocHeapBuffer(uint64_t bufferSize, uint8_t **buffer)
|
||||
{
|
||||
if (bufferSize == 0 || bufferSize > MALLOC_MAX_LENTH) {
|
||||
HiLog::Error(LABEL, "[PostProc]Invalid value of bufferSize");
|
||||
IMAGE_LOGE("[PostProc]Invalid value of bufferSize");
|
||||
return false;
|
||||
}
|
||||
*buffer = static_cast<uint8_t *>(malloc(bufferSize));
|
||||
if (*buffer == nullptr) {
|
||||
HiLog::Error(LABEL, "[PostProc]alloc covert color buffersize[%{public}llu] failed.",
|
||||
IMAGE_LOGE("[PostProc]alloc covert color buffersize[%{public}llu] failed.",
|
||||
static_cast<unsigned long long>(bufferSize));
|
||||
return false;
|
||||
}
|
||||
errno_t errRet = memset_s(*buffer, bufferSize, 0, bufferSize);
|
||||
if (errRet != EOK) {
|
||||
HiLog::Error(LABEL, "[PostProc]memset convertData fail, errorCode = %{public}d", errRet);
|
||||
IMAGE_LOGE("[PostProc]memset convertData fail, errorCode = %{public}d", errRet);
|
||||
ReleaseBuffer(AllocatorType::HEAP_ALLOC, buffer);
|
||||
return false;
|
||||
}
|
||||
@ -226,14 +229,14 @@ int32_t ImageCreator::SaveSenderBufferAsImage(OHOS::sptr<OHOS::SurfaceBuffer> bu
|
||||
uint8_t *addr2 = nullptr;
|
||||
int32_t size = buffer->GetSize();
|
||||
if (!AllocHeapBuffer(size, &addr2)) {
|
||||
HiLog::Error(LABEL, "AllocHeapBuffer failed");
|
||||
IMAGE_LOGE("AllocHeapBuffer failed");
|
||||
return ERR_MEDIA_INVALID_VALUE;
|
||||
}
|
||||
errorcode = SaveSTP(addr, addr2, static_cast<uint32_t>(size), initializationOpts);
|
||||
(iraContext_->GetCreatorBufferConsumer())->ReleaseBuffer(buffer, -1);
|
||||
HiLog::Info(LABEL, "start release");
|
||||
IMAGE_LOGI("start release");
|
||||
} else {
|
||||
HiLog::Debug(LABEL, "SaveBufferAsImage buffer == nullptr");
|
||||
IMAGE_LOGD("SaveBufferAsImage buffer == nullptr");
|
||||
}
|
||||
return errorcode;
|
||||
}
|
||||
@ -254,7 +257,7 @@ OHOS::sptr<OHOS::SurfaceBuffer> ImageCreator::DequeueImage()
|
||||
if (surfaceError == SURFACE_ERROR_OK) {
|
||||
iraContext_->currentCreatorBuffer_ = buffer;
|
||||
} else {
|
||||
HiLog::Debug(LABEL, "error : request buffer is null");
|
||||
IMAGE_LOGD("error : request buffer is null");
|
||||
}
|
||||
if (buffer != nullptr && buffer->GetVirAddr() != nullptr) {
|
||||
bufferCreatorMap_.insert(
|
||||
@ -265,16 +268,16 @@ OHOS::sptr<OHOS::SurfaceBuffer> ImageCreator::DequeueImage()
|
||||
|
||||
void ImageCreator::QueueImage(OHOS::sptr<OHOS::SurfaceBuffer> &buffer)
|
||||
{
|
||||
HiLog::Info(LABEL, "start Queue Image");
|
||||
IMAGE_LOGI("start Queue Image");
|
||||
int32_t flushFence = -1;
|
||||
BufferFlushConfig config;
|
||||
config.damage.w = iraContext_->GetWidth();
|
||||
config.damage.h = iraContext_->GetHeight();
|
||||
sptr<Surface> creatorSurface = iraContext_->GetCreatorBufferProducer();
|
||||
SurfaceError surfaceError = creatorSurface->FlushBuffer(buffer, flushFence, config);
|
||||
HiLog::Info(LABEL, "finish Queue Image");
|
||||
IMAGE_LOGI("finish Queue Image");
|
||||
if (surfaceError != SURFACE_ERROR_OK) {
|
||||
HiLog::Debug(LABEL, "Queue fail");
|
||||
IMAGE_LOGD("Queue fail");
|
||||
}
|
||||
}
|
||||
sptr<IConsumerSurface> ImageCreator::GetCreatorSurface()
|
||||
@ -286,7 +289,7 @@ sptr<IConsumerSurface> ImageCreator::getSurfaceById(std::string id)
|
||||
{
|
||||
ImageCreatorManager& imageCreatorManager = ImageCreatorManager::getInstance();
|
||||
sptr<IConsumerSurface> surface = imageCreatorManager.GetSurfaceByKeyId(id);
|
||||
HiLog::Debug(LABEL, "getSurfaceByCreatorId");
|
||||
IMAGE_LOGD("getSurfaceByCreatorId");
|
||||
return surface;
|
||||
}
|
||||
void ImageCreator::ReleaseCreator()
|
||||
|
@ -15,14 +15,17 @@
|
||||
|
||||
#include "pixel_map_from_surface.h"
|
||||
|
||||
#include "image_log.h"
|
||||
#include "sync_fence.h"
|
||||
#include "hilog/log.h"
|
||||
#include "log_tags.h"
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_IMAGE
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "PixelMap"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_IMAGE, "PixelMap" };
|
||||
using namespace OHOS::HiviewDFX;
|
||||
|
||||
PixelMapFromSurface::PixelMapFromSurface()
|
||||
{}
|
||||
@ -70,7 +73,7 @@ bool PixelMapFromSurface::GetNativeWindowBufferFromSurface(const sptr<Surface> &
|
||||
int ret = surface->GetLastFlushedBuffer(surfaceBuffer_, fence, matrix);
|
||||
if (ret != OHOS::GSERROR_OK || surfaceBuffer_ == nullptr) {
|
||||
Clear();
|
||||
HiLog::Error(LABEL,
|
||||
IMAGE_LOGE(
|
||||
"CreatePixelMapFromSurface: GetLastFlushedBuffer from nativeWindow failed, err: %{public}d",
|
||||
ret);
|
||||
return false;
|
||||
@ -81,7 +84,7 @@ bool PixelMapFromSurface::GetNativeWindowBufferFromSurface(const sptr<Surface> &
|
||||
if (srcRect.width > bufferWidth || srcRect.height > bufferHeight ||
|
||||
srcRect.left >= bufferWidth || srcRect.top >= bufferHeight ||
|
||||
srcRect.left + srcRect.width > bufferWidth || srcRect.top + srcRect.height > bufferHeight) {
|
||||
HiLog::Error(LABEL,
|
||||
IMAGE_LOGE(
|
||||
"CreatePixelMapFromSurface: invalid argument: srcRect[%{public}d, %{public}d, %{public}d, %{public}d],"
|
||||
"bufferSize:[%{public}d, %{public}d]",
|
||||
srcRect.left, srcRect.top, srcRect.width, srcRect.height,
|
||||
@ -108,7 +111,7 @@ bool PixelMapFromSurface::CreateEGLImage()
|
||||
nativeWindowBuffer_, attrs);
|
||||
if (eglImage_ == EGL_NO_IMAGE_KHR) {
|
||||
Clear();
|
||||
HiLog::Error(LABEL, "%{public}s create egl image fail %{public}d", __func__, eglGetError());
|
||||
IMAGE_LOGE("%{public}s create egl image fail %{public}d", __func__, eglGetError());
|
||||
return false;
|
||||
}
|
||||
glGenTextures(1, &texId_);
|
||||
@ -121,7 +124,7 @@ bool PixelMapFromSurface::CreateEGLImage()
|
||||
eglGetProcAddress("glEGLImageTargetTexture2DOES"));
|
||||
if (glEGLImageTargetTexture2DOESFunc == nullptr) {
|
||||
Clear();
|
||||
HiLog::Error(LABEL, "%{public}s glEGLImageTargetTexture2DOES func not found: %{public}d",
|
||||
IMAGE_LOGE("%{public}s glEGLImageTargetTexture2DOES func not found: %{public}d",
|
||||
__func__, eglGetError());
|
||||
return false;
|
||||
}
|
||||
@ -149,7 +152,7 @@ bool PixelMapFromSurface::DrawImage(const Rect &srcRect)
|
||||
kTopLeft_GrSurfaceOrigin, colorType, kPremul_SkAlphaType, nullptr);
|
||||
if (image == nullptr) {
|
||||
Clear();
|
||||
HiLog::Error(LABEL, "%{public}s create SkImage failed.", __func__);
|
||||
IMAGE_LOGE("%{public}s create SkImage failed.", __func__);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -158,7 +161,7 @@ bool PixelMapFromSurface::DrawImage(const Rect &srcRect)
|
||||
imageInfo, 0, kTopLeft_GrSurfaceOrigin, nullptr);
|
||||
if (targetSurface_ == nullptr) {
|
||||
Clear();
|
||||
HiLog::Error(LABEL, "%{public}s SkSurface::MakeRenderTarget failed.", __func__);
|
||||
IMAGE_LOGE("%{public}s SkSurface::MakeRenderTarget failed.", __func__);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -177,7 +180,7 @@ bool PixelMapFromSurface::DrawImage(const Rect &srcRect)
|
||||
std::unique_ptr<PixelMap> PixelMapFromSurface::Create(uint64_t surfaceId, const Rect &srcRect)
|
||||
{
|
||||
if (srcRect.left < 0 || srcRect.top < 0 || srcRect.width <= 0 || srcRect.height <= 0) {
|
||||
HiLog::Error(LABEL,
|
||||
IMAGE_LOGE(
|
||||
"CreatePixelMapFromSurface: invalid argument: srcRect[%{public}d, %{public}d, %{public}d, %{public}d]",
|
||||
srcRect.left, srcRect.top, srcRect.width, srcRect.height);
|
||||
return nullptr;
|
||||
@ -186,7 +189,7 @@ std::unique_ptr<PixelMap> PixelMapFromSurface::Create(uint64_t surfaceId, const
|
||||
Clear();
|
||||
sptr<Surface> surface = SurfaceUtils::GetInstance()->GetSurface(surfaceId);
|
||||
if (surface == nullptr) {
|
||||
HiLog::Error(LABEL,
|
||||
IMAGE_LOGE(
|
||||
"CreatePixelMapFromSurface: can't find surface for surfaceId: %{public}" PRIu64 ".", surfaceId);
|
||||
return nullptr;
|
||||
}
|
||||
@ -199,7 +202,7 @@ std::unique_ptr<PixelMap> PixelMapFromSurface::Create(uint64_t surfaceId, const
|
||||
renderContext_ = std::make_unique<RenderContext>();
|
||||
if (!renderContext_->Init()) {
|
||||
Clear();
|
||||
HiLog::Error(LABEL, "CreatePixelMapFromSurface: init renderContext failed.");
|
||||
IMAGE_LOGE("CreatePixelMapFromSurface: init renderContext failed.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -15,13 +15,16 @@
|
||||
|
||||
#include "render_context.h"
|
||||
|
||||
#include "hilog/log.h"
|
||||
#include "log_tags.h"
|
||||
#include "image_log.h"
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_IMAGE
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "PixelMap"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_IMAGE, "PixelMap" };
|
||||
using namespace OHOS::HiviewDFX;
|
||||
|
||||
RenderContext::RenderContext()
|
||||
{}
|
||||
@ -48,19 +51,19 @@ bool RenderContext::InitEGLContext()
|
||||
{
|
||||
eglDisplay_ = eglGetPlatformDisplay(EGL_PLATFORM_OHOS_KHR, EGL_DEFAULT_DISPLAY, nullptr);
|
||||
if (eglDisplay_ == EGL_NO_DISPLAY) {
|
||||
HiLog::Error(LABEL, "RenderContext::Init: eglGetDisplay error: ");
|
||||
IMAGE_LOGE("RenderContext::Init: eglGetDisplay error: ");
|
||||
return false;
|
||||
}
|
||||
|
||||
EGLint major = 0;
|
||||
EGLint minor = 0;
|
||||
if (eglInitialize(eglDisplay_, &major, &minor) == EGL_FALSE) {
|
||||
HiLog::Error(LABEL, "Failed to initialize EGLDisplay");
|
||||
IMAGE_LOGE("Failed to initialize EGLDisplay");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (eglBindAPI(EGL_OPENGL_ES_API) == EGL_FALSE) {
|
||||
HiLog::Error(LABEL, "Failed to bind OpenGL ES API");
|
||||
IMAGE_LOGE("Failed to bind OpenGL ES API");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -71,14 +74,14 @@ bool RenderContext::InitEGLContext()
|
||||
|
||||
ret = eglChooseConfig(eglDisplay_, configAttribs, &config_, 1, &count);
|
||||
if (!(ret && static_cast<unsigned int>(count) >= 1)) {
|
||||
HiLog::Error(LABEL, "Failed to eglChooseConfig");
|
||||
IMAGE_LOGE("Failed to eglChooseConfig");
|
||||
return false;
|
||||
}
|
||||
|
||||
static const EGLint contextAttribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
|
||||
eglContext_ = eglCreateContext(eglDisplay_, config_, EGL_NO_CONTEXT, contextAttribs);
|
||||
if (eglContext_ == EGL_NO_CONTEXT) {
|
||||
HiLog::Error(LABEL, "Failed to create egl context %{public}x", eglGetError());
|
||||
IMAGE_LOGE("Failed to create egl context %{public}x", eglGetError());
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -96,8 +99,7 @@ bool RenderContext::CreatePbufferSurface()
|
||||
EGLint attribs[] = {EGL_WIDTH, 1, EGL_HEIGHT, 1, EGL_NONE};
|
||||
pbufferSurface_ = eglCreatePbufferSurface(eglDisplay_, config_, attribs);
|
||||
if (pbufferSurface_ == EGL_NO_SURFACE) {
|
||||
HiLog::Error(
|
||||
LABEL,
|
||||
IMAGE_LOGE(
|
||||
"RenderContext::CreatePbufferSurface failed, error is %{public}x",
|
||||
eglGetError());
|
||||
return false;
|
||||
@ -116,8 +118,7 @@ void RenderContext::MakeCurrent(EGLSurface surface) const
|
||||
if (eglMakeCurrent(eglDisplay_, currSurface, currSurface, eglContext_) != EGL_TRUE) {
|
||||
EGLint surfaceId = -1;
|
||||
eglQuerySurface(eglDisplay_, surface, EGL_CONFIG_ID, &surfaceId);
|
||||
HiLog::Error(
|
||||
LABEL,
|
||||
IMAGE_LOGE(
|
||||
"RenderContext::MakeCurrent failed for eglSurface %{public}d, error is %{public}x",
|
||||
surfaceId,
|
||||
eglGetError());
|
||||
@ -128,7 +129,7 @@ bool RenderContext::InitGrContext()
|
||||
{
|
||||
sk_sp<const GrGLInterface> glInterface(GrGLCreateNativeInterface());
|
||||
if (glInterface == nullptr) {
|
||||
HiLog::Error(LABEL, "SetUpGrContext failed to make native interface");
|
||||
IMAGE_LOGE("SetUpGrContext failed to make native interface");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -151,8 +152,7 @@ void RenderContext::Clear() noexcept
|
||||
if (pbufferSurface_ != EGL_NO_SURFACE) {
|
||||
EGLBoolean ret = eglDestroySurface(eglDisplay_, pbufferSurface_);
|
||||
if (ret != EGL_TRUE) {
|
||||
HiLog::Error(LABEL, "RenderContext::Clear() failed to destroy pbuffer surface, error is %{public}x.",
|
||||
eglGetError());
|
||||
IMAGE_LOGE("RenderContext::Clear() failed to destroy pbuffer surface, error is %{public}x.", eglGetError());
|
||||
}
|
||||
pbufferSurface_ = EGL_NO_SURFACE;
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ config("pixelconvertadapter_public_config") {
|
||||
"//base/hiviewdfx/hilog/interfaces/native/innerkits/include",
|
||||
"//foundation/communication/ipc/utils/include",
|
||||
"//foundation/multimedia/media_utils_lite/interfaces/kits",
|
||||
"${image_subsystem}/frameworks/innerkitsimpl/utils/include",
|
||||
"$skia_root/skia/include/core",
|
||||
"$skia_root/skia/include/encode",
|
||||
"$skia_root/skia",
|
||||
@ -172,6 +173,7 @@ if (use_clang_ios) {
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"graphic_2d:color_manager",
|
||||
"hilog:libhilog",
|
||||
]
|
||||
}
|
||||
|
||||
|
@ -16,9 +16,8 @@
|
||||
#ifndef FRAMEWORKS_INNERKITSIMPL_PIXELCONVERTER_INCLUDE_PIXEL_MAP_JNI_UTILS_H
|
||||
#define FRAMEWORKS_INNERKITSIMPL_PIXELCONVERTER_INCLUDE_PIXEL_MAP_JNI_UTILS_H
|
||||
|
||||
#include "hilog/log.h"
|
||||
#include "image_log.h"
|
||||
#include "jkit_utils.h"
|
||||
#include "log_tags.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
|
@ -17,7 +17,7 @@
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "hilog/log.h"
|
||||
#include "image_log.h"
|
||||
#include "include/core/SkBitmap.h"
|
||||
#include "include/core/SkCanvas.h"
|
||||
#include "include/core/SkColor.h"
|
||||
@ -25,17 +25,20 @@
|
||||
#include "include/core/SkImageInfo.h"
|
||||
#include "include/core/SkPaint.h"
|
||||
#include "include/core/SkPixmap.h"
|
||||
#include "log_tags.h"
|
||||
#ifdef _WIN32
|
||||
#include <iomanip>
|
||||
#endif
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_IMAGE
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "PixelConvertAdapter"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
using namespace OHOS::HiviewDFX;
|
||||
using namespace std;
|
||||
|
||||
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_IMAGE, "PixelConvertAdapter" };
|
||||
static const uint8_t NUM_0 = 0;
|
||||
static const uint8_t NUM_1 = 1;
|
||||
static const uint8_t NUM_2 = 2;
|
||||
@ -62,7 +65,7 @@ static SkColorType PixelFormatConvert(const PixelFormat &pixelFormat)
|
||||
static void ARGBToRGBA(uint8_t* srcPixels, uint8_t* dstPixels, uint32_t byteCount)
|
||||
{
|
||||
if (byteCount % NUM_4 != NUM_0) {
|
||||
HiLog::Error(LABEL, "Pixel count must multiple of 4.");
|
||||
IMAGE_LOGE("Pixel count must multiple of 4.");
|
||||
return;
|
||||
}
|
||||
uint8_t *src = srcPixels;
|
||||
@ -81,7 +84,7 @@ static void ARGBToRGBA(uint8_t* srcPixels, uint8_t* dstPixels, uint32_t byteCoun
|
||||
static void RGBAToARGB(uint8_t* srcPixels, uint8_t* dstPixels, uint32_t byteCount)
|
||||
{
|
||||
if (byteCount % NUM_4 != NUM_0) {
|
||||
HiLog::Error(LABEL, "Pixel count must multiple of 4.");
|
||||
IMAGE_LOGE("Pixel count must multiple of 4.");
|
||||
return;
|
||||
}
|
||||
uint8_t *src = srcPixels;
|
||||
@ -100,7 +103,7 @@ static void RGBAToARGB(uint8_t* srcPixels, uint8_t* dstPixels, uint32_t byteCoun
|
||||
static void RGBxToRGB(const uint8_t* srcPixels, uint8_t* dstPixels, uint32_t byteCount)
|
||||
{
|
||||
if (byteCount % NUM_4 != NUM_0) {
|
||||
HiLog::Error(LABEL, "Pixel count must multiple of 4.");
|
||||
IMAGE_LOGE("Pixel count must multiple of 4.");
|
||||
return;
|
||||
}
|
||||
const uint8_t *src = srcPixels;
|
||||
@ -118,7 +121,7 @@ static void RGBxToRGB(const uint8_t* srcPixels, uint8_t* dstPixels, uint32_t byt
|
||||
static void RGBToRGBx(const uint8_t* srcPixels, uint8_t* dstPixels, uint32_t byteCount)
|
||||
{
|
||||
if (byteCount % NUM_3 != NUM_0) {
|
||||
HiLog::Error(LABEL, "Pixel count must multiple of 3.");
|
||||
IMAGE_LOGE("Pixel count must multiple of 3.");
|
||||
return;
|
||||
}
|
||||
const uint8_t *src = srcPixels;
|
||||
@ -150,7 +153,7 @@ bool PixelConvertAdapter::WritePixelsConvert(const void *srcPixels, uint32_t src
|
||||
{
|
||||
// basic valid check, other parameters valid check in writePixels method
|
||||
if (srcPixels == nullptr || dstPixels == nullptr) {
|
||||
HiLog::Error(LABEL, "src or dst pixels invalid.");
|
||||
IMAGE_LOGE("src or dst pixels invalid.");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -182,11 +185,11 @@ bool PixelConvertAdapter::WritePixelsConvert(const void *srcPixels, uint32_t src
|
||||
|
||||
SkBitmap dstBitmap;
|
||||
if (!dstBitmap.installPixels(dstImageInfo, dstPixels, dstRowBytes)) {
|
||||
HiLog::Error(LABEL, "WritePixelsConvert dst bitmap install pixels failed.");
|
||||
IMAGE_LOGE("WritePixelsConvert dst bitmap install pixels failed.");
|
||||
return false;
|
||||
}
|
||||
if (!dstBitmap.writePixels(srcPixmap, dstPos.x, dstPos.y)) {
|
||||
HiLog::Error(LABEL, "WritePixelsConvert dst bitmap write pixels by source failed.");
|
||||
IMAGE_LOGE("WritePixelsConvert dst bitmap write pixels by source failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -206,7 +209,7 @@ bool PixelConvertAdapter::ReadPixelsConvert(const void *srcPixels, const Positio
|
||||
{
|
||||
// basic valid check, other parameters valid check in readPixels method
|
||||
if (srcPixels == nullptr || dstPixels == nullptr) {
|
||||
HiLog::Error(LABEL, "src or dst pixels invalid.");
|
||||
IMAGE_LOGE("src or dst pixels invalid.");
|
||||
return false;
|
||||
}
|
||||
SkAlphaType srcAlphaType = static_cast<SkAlphaType>(srcInfo.alphaType);
|
||||
@ -218,11 +221,11 @@ bool PixelConvertAdapter::ReadPixelsConvert(const void *srcPixels, const Positio
|
||||
|
||||
SkBitmap srcBitmap;
|
||||
if (!srcBitmap.installPixels(srcImageInfo, const_cast<void *>(srcPixels), srcRowBytes)) {
|
||||
HiLog::Error(LABEL, "ReadPixelsConvert src bitmap install pixels failed.");
|
||||
IMAGE_LOGE("ReadPixelsConvert src bitmap install pixels failed.");
|
||||
return false;
|
||||
}
|
||||
if (!srcBitmap.readPixels(dstImageInfo, dstPixels, dstRowBytes, srcPos.x, srcPos.y)) {
|
||||
HiLog::Error(LABEL, "ReadPixelsConvert read dst pixels from source failed.");
|
||||
IMAGE_LOGE("ReadPixelsConvert read dst pixels from source failed.");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -232,7 +235,7 @@ bool PixelConvertAdapter::EraseBitmap(const void *srcPixels, uint32_t srcRowByte
|
||||
uint32_t color)
|
||||
{
|
||||
if (srcPixels == nullptr) {
|
||||
HiLog::Error(LABEL, "srcPixels is null.");
|
||||
IMAGE_LOGE("srcPixels is null.");
|
||||
return false;
|
||||
}
|
||||
SkAlphaType srcAlphaType = static_cast<SkAlphaType>(srcInfo.alphaType);
|
||||
@ -240,7 +243,7 @@ bool PixelConvertAdapter::EraseBitmap(const void *srcPixels, uint32_t srcRowByte
|
||||
SkImageInfo srcImageInfo = SkImageInfo::Make(srcInfo.size.width, srcInfo.size.height, srcColorType, srcAlphaType);
|
||||
SkBitmap srcBitmap;
|
||||
if (!srcBitmap.installPixels(srcImageInfo, const_cast<void *>(srcPixels), srcRowBytes)) {
|
||||
HiLog::Error(LABEL, "ReadPixelsConvert src bitmap install pixels failed.");
|
||||
IMAGE_LOGE("ReadPixelsConvert src bitmap install pixels failed.");
|
||||
return false;
|
||||
}
|
||||
const SkColor4f skColor = SkColor4f::FromColor(color);
|
||||
|
@ -15,245 +15,252 @@
|
||||
|
||||
#include "image_receiver.h"
|
||||
|
||||
#include "hilog/log.h"
|
||||
#include "image_log.h"
|
||||
#include "image_packer.h"
|
||||
#include "image_source.h"
|
||||
#include "image_utils.h"
|
||||
#include "image_receiver_buffer_processor.h"
|
||||
#include "image_receiver_manager.h"
|
||||
#include "log_tags.h"
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_IMAGE
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "imageReceiver"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
ImageReceiver::~ImageReceiver()
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(imageReceiverMutex_);
|
||||
if (receiverConsumerSurface_ != nullptr) {
|
||||
receiverConsumerSurface_->UnregisterConsumerListener();
|
||||
}
|
||||
receiverConsumerSurface_ = nullptr;
|
||||
receiverProducerSurface_ = nullptr;
|
||||
iraContext_ = nullptr;
|
||||
surfaceBufferAvaliableListener_ = nullptr;
|
||||
bufferProcessor_ = nullptr;
|
||||
namespace Media {
|
||||
|
||||
ImageReceiver::~ImageReceiver()
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(imageReceiverMutex_);
|
||||
if (receiverConsumerSurface_ != nullptr) {
|
||||
receiverConsumerSurface_->UnregisterConsumerListener();
|
||||
}
|
||||
receiverConsumerSurface_ = nullptr;
|
||||
receiverProducerSurface_ = nullptr;
|
||||
iraContext_ = nullptr;
|
||||
surfaceBufferAvaliableListener_ = nullptr;
|
||||
bufferProcessor_ = nullptr;
|
||||
}
|
||||
|
||||
enum class Mode {
|
||||
MODE_PREVIEW = 0,
|
||||
MODE_PHOTO
|
||||
};
|
||||
|
||||
int64_t PackImage(int &fd, std::unique_ptr<PixelMap> pixelMap)
|
||||
{
|
||||
IMAGE_LOGD("PackImage");
|
||||
ImagePacker imagePacker;
|
||||
PackOption option;
|
||||
option.format = ImageReceiver::OPTION_FORMAT;
|
||||
option.quality = ImageReceiver::OPTION_QUALITY;
|
||||
option.numberHint = ImageReceiver::OPTION_NUMBERHINT;
|
||||
std::set<std::string> formats;
|
||||
if (pixelMap == nullptr) {
|
||||
IMAGE_LOGE("pixelMap is nullptr");
|
||||
return 0;
|
||||
}
|
||||
uint32_t ret = imagePacker.GetSupportedFormats(formats);
|
||||
if (ret != SUCCESS) {
|
||||
IMAGE_LOGE("image packer get supported format failed, ret=%{public}u.", ret);
|
||||
return 0;
|
||||
} else {
|
||||
IMAGE_LOGD("SUCCESS");
|
||||
}
|
||||
imagePacker.StartPacking(fd, option);
|
||||
imagePacker.AddImage(*pixelMap);
|
||||
int64_t packedSize = 0;
|
||||
imagePacker.FinalizePacking(packedSize);
|
||||
IMAGE_LOGD("packedSize=%{public}lld.", static_cast<long long>(packedSize));
|
||||
IMAGE_LOGD("packedSize=%{public}lld.", static_cast<long long>(packedSize));
|
||||
return packedSize;
|
||||
}
|
||||
|
||||
std::unique_ptr<PixelMap> ImageReceiver::getSurfacePixelMap(InitializationOptions initializationOpts)
|
||||
{
|
||||
uint32_t *addr = reinterpret_cast<uint32_t *>(iraContext_->currentBuffer_->GetVirAddr());
|
||||
int32_t size = iraContext_->currentBuffer_->GetSize();
|
||||
return PixelMap::Create(addr, (uint32_t)size, initializationOpts);
|
||||
}
|
||||
|
||||
static int32_t SaveSTP(uint32_t *buffer,
|
||||
uint32_t bufferSize,
|
||||
int &fd,
|
||||
InitializationOptions initializationOpts)
|
||||
{
|
||||
int64_t errorCode = -1;
|
||||
std::unique_ptr<PixelMap> pixelMap = PixelMap::Create(buffer, bufferSize, initializationOpts);
|
||||
if (pixelMap.get() != nullptr) {
|
||||
ImageInfo imageInfo;
|
||||
pixelMap->GetImageInfo(imageInfo);
|
||||
IMAGE_LOGD("create pixel map imageInfo.size.width=%{public}u.", imageInfo.size.width);
|
||||
} else {
|
||||
IMAGE_LOGE("pixelMap.get() == nullptr");
|
||||
return ERR_MEDIA_INVALID_VALUE;
|
||||
}
|
||||
ImagePacker imagePacker;
|
||||
errorCode = PackImage(fd, std::move(pixelMap));
|
||||
if (errorCode > 0) {
|
||||
errorCode = SUCCESS;
|
||||
} else {
|
||||
errorCode = ERR_MEDIA_INVALID_VALUE;
|
||||
}
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
int32_t ImageReceiver::SaveBufferAsImage(int &fd,
|
||||
OHOS::sptr<OHOS::SurfaceBuffer> buffer,
|
||||
InitializationOptions initializationOpts)
|
||||
{
|
||||
int32_t errorcode = 0;
|
||||
if (buffer != nullptr) {
|
||||
uint32_t *addr = reinterpret_cast<uint32_t *>(buffer->GetVirAddr());
|
||||
int32_t size = buffer->GetSize();
|
||||
errorcode = SaveSTP(addr, static_cast<uint32_t>(size), fd, initializationOpts);
|
||||
if ((iraContext_->GetReceiverBufferConsumer()) != nullptr) {
|
||||
(iraContext_->GetReceiverBufferConsumer())->ReleaseBuffer(buffer, -1);
|
||||
} else {
|
||||
IMAGE_LOGD("iraContext_->GetReceiverBufferConsumer() == nullptr");
|
||||
}
|
||||
constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_TAG_DOMAIN_ID_IMAGE, "imageReceiver"};
|
||||
using namespace OHOS::HiviewDFX;
|
||||
} else {
|
||||
IMAGE_LOGD("SaveBufferAsImage buffer == nullptr");
|
||||
}
|
||||
return errorcode;
|
||||
}
|
||||
|
||||
enum class Mode {
|
||||
MODE_PREVIEW = 0,
|
||||
MODE_PHOTO
|
||||
};
|
||||
int32_t ImageReceiver::SaveBufferAsImage(int &fd,
|
||||
InitializationOptions initializationOpts)
|
||||
{
|
||||
if (iraContext_->currentBuffer_ != nullptr) {
|
||||
return SaveBufferAsImage(fd, iraContext_->currentBuffer_, initializationOpts);
|
||||
}
|
||||
IMAGE_LOGD("iraContext_->GetCurrentBuffer() == nullptr");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int64_t PackImage(int &fd, std::unique_ptr<PixelMap> pixelMap)
|
||||
{
|
||||
HiLog::Debug(LABEL, "PackImage");
|
||||
ImagePacker imagePacker;
|
||||
PackOption option;
|
||||
option.format = ImageReceiver::OPTION_FORMAT;
|
||||
option.quality = ImageReceiver::OPTION_QUALITY;
|
||||
option.numberHint = ImageReceiver::OPTION_NUMBERHINT;
|
||||
std::set<std::string> formats;
|
||||
if (pixelMap == nullptr) {
|
||||
HiLog::Error(LABEL, "pixelMap is nullptr");
|
||||
return 0;
|
||||
}
|
||||
uint32_t ret = imagePacker.GetSupportedFormats(formats);
|
||||
if (ret != SUCCESS) {
|
||||
HiLog::Error(LABEL, "image packer get supported format failed, ret=%{public}u.", ret);
|
||||
return 0;
|
||||
void ImageReceiver::ReleaseBuffer(OHOS::sptr<OHOS::SurfaceBuffer> &buffer) __attribute__((no_sanitize("cfi")))
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(imageReceiverMutex_);
|
||||
if (buffer != nullptr) {
|
||||
if (iraContext_ != nullptr) {
|
||||
auto listenerConsumerSurface = iraContext_->GetReceiverBufferConsumer();
|
||||
if (listenerConsumerSurface != nullptr) {
|
||||
listenerConsumerSurface->ReleaseBuffer(buffer, -1);
|
||||
} else {
|
||||
HiLog::Debug(LABEL, "SUCCESS");
|
||||
IMAGE_LOGD("listenerConsumerSurface == nullptr");
|
||||
}
|
||||
imagePacker.StartPacking(fd, option);
|
||||
imagePacker.AddImage(*pixelMap);
|
||||
int64_t packedSize = 0;
|
||||
imagePacker.FinalizePacking(packedSize);
|
||||
HiLog::Debug(LABEL, "packedSize=%{public}lld.", static_cast<long long>(packedSize));
|
||||
HiLog::Debug(LABEL, "packedSize=%{public}lld.", static_cast<long long>(packedSize));
|
||||
return packedSize;
|
||||
} else {
|
||||
IMAGE_LOGD("iraContext_ == nullptr");
|
||||
}
|
||||
buffer = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
std::unique_ptr<PixelMap> ImageReceiver::getSurfacePixelMap(InitializationOptions initializationOpts)
|
||||
{
|
||||
uint32_t *addr = reinterpret_cast<uint32_t *>(iraContext_->currentBuffer_->GetVirAddr());
|
||||
int32_t size = iraContext_->currentBuffer_->GetSize();
|
||||
return PixelMap::Create(addr, (uint32_t)size, initializationOpts);
|
||||
}
|
||||
void ImageReceiverSurfaceListener ::OnBufferAvailable()
|
||||
{
|
||||
IMAGE_LOGD("OnBufferAvailable");
|
||||
auto ir = ir_.lock();
|
||||
if (ir && ir->surfaceBufferAvaliableListener_ != nullptr) {
|
||||
ir->surfaceBufferAvaliableListener_->OnSurfaceBufferAvaliable();
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t SaveSTP(uint32_t *buffer,
|
||||
uint32_t bufferSize,
|
||||
int &fd,
|
||||
InitializationOptions initializationOpts)
|
||||
{
|
||||
int64_t errorCode = -1;
|
||||
std::unique_ptr<PixelMap> pixelMap = PixelMap::Create(buffer, bufferSize, initializationOpts);
|
||||
if (pixelMap.get() != nullptr) {
|
||||
ImageInfo imageInfo;
|
||||
pixelMap->GetImageInfo(imageInfo);
|
||||
HiLog::Debug(LABEL, "create pixel map imageInfo.size.width=%{public}u.", imageInfo.size.width);
|
||||
} else {
|
||||
HiLog::Error(LABEL, "pixelMap.get() == nullptr");
|
||||
return ERR_MEDIA_INVALID_VALUE;
|
||||
}
|
||||
ImagePacker imagePacker;
|
||||
errorCode = PackImage(fd, std::move(pixelMap));
|
||||
if (errorCode > 0) {
|
||||
errorCode = SUCCESS;
|
||||
} else {
|
||||
errorCode = ERR_MEDIA_INVALID_VALUE;
|
||||
}
|
||||
return errorCode;
|
||||
}
|
||||
std::shared_ptr<ImageReceiverContext> ImageReceiverContext ::CreateImageReceiverContext()
|
||||
{
|
||||
std::shared_ptr<ImageReceiverContext> irc = std::make_shared<ImageReceiverContext>();
|
||||
return irc;
|
||||
}
|
||||
|
||||
int32_t ImageReceiver::SaveBufferAsImage(int &fd,
|
||||
OHOS::sptr<OHOS::SurfaceBuffer> buffer,
|
||||
InitializationOptions initializationOpts)
|
||||
{
|
||||
int32_t errorcode = 0;
|
||||
if (buffer != nullptr) {
|
||||
uint32_t *addr = reinterpret_cast<uint32_t *>(buffer->GetVirAddr());
|
||||
int32_t size = buffer->GetSize();
|
||||
errorcode = SaveSTP(addr, static_cast<uint32_t>(size), fd, initializationOpts);
|
||||
if ((iraContext_->GetReceiverBufferConsumer()) != nullptr) {
|
||||
(iraContext_->GetReceiverBufferConsumer())->ReleaseBuffer(buffer, -1);
|
||||
} else {
|
||||
HiLog::Debug(LABEL, "iraContext_->GetReceiverBufferConsumer() == nullptr");
|
||||
}
|
||||
} else {
|
||||
HiLog::Debug(LABEL, "SaveBufferAsImage buffer == nullptr");
|
||||
}
|
||||
return errorcode;
|
||||
}
|
||||
sptr<Surface> ImageReceiver::getSurfaceById(std::string id)
|
||||
{
|
||||
ImageReceiverManager& imageReceiverManager = ImageReceiverManager::getInstance();
|
||||
sptr<Surface> surface = imageReceiverManager.getSurfaceByKeyId(id);
|
||||
IMAGE_LOGD("getSurfaceById");
|
||||
return surface;
|
||||
}
|
||||
|
||||
int32_t ImageReceiver::SaveBufferAsImage(int &fd,
|
||||
InitializationOptions initializationOpts)
|
||||
{
|
||||
if (iraContext_->currentBuffer_ != nullptr) {
|
||||
return SaveBufferAsImage(fd, iraContext_->currentBuffer_, initializationOpts);
|
||||
}
|
||||
HiLog::Debug(LABEL, "iraContext_->GetCurrentBuffer() == nullptr");
|
||||
return 0;
|
||||
}
|
||||
std::shared_ptr<ImageReceiver> ImageReceiver::CreateImageReceiver(int32_t width,
|
||||
int32_t height,
|
||||
int32_t format,
|
||||
int32_t capicity)
|
||||
{
|
||||
std::shared_ptr<ImageReceiver> iva = std::make_shared<ImageReceiver>();
|
||||
iva->iraContext_ = ImageReceiverContext::CreateImageReceiverContext();
|
||||
iva->receiverConsumerSurface_ = IConsumerSurface::Create();
|
||||
if (iva->receiverConsumerSurface_ == nullptr) {
|
||||
IMAGE_LOGD("SurfaceAsConsumer == nullptr");
|
||||
return iva;
|
||||
}
|
||||
|
||||
void ImageReceiver::ReleaseBuffer(OHOS::sptr<OHOS::SurfaceBuffer> &buffer) __attribute__((no_sanitize("cfi")))
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(imageReceiverMutex_);
|
||||
if (buffer != nullptr) {
|
||||
if (iraContext_ != nullptr) {
|
||||
auto listenerConsumerSurface = iraContext_->GetReceiverBufferConsumer();
|
||||
if (listenerConsumerSurface != nullptr) {
|
||||
listenerConsumerSurface->ReleaseBuffer(buffer, -1);
|
||||
} else {
|
||||
HiLog::Debug(LABEL, "listenerConsumerSurface == nullptr");
|
||||
}
|
||||
} else {
|
||||
HiLog::Debug(LABEL, "iraContext_ == nullptr");
|
||||
}
|
||||
buffer = nullptr;
|
||||
}
|
||||
}
|
||||
void ImageReceiverSurfaceListener ::OnBufferAvailable()
|
||||
{
|
||||
HiLog::Debug(LABEL, "OnBufferAvailable");
|
||||
auto ir = ir_.lock();
|
||||
if (ir && ir->surfaceBufferAvaliableListener_ != nullptr) {
|
||||
ir->surfaceBufferAvaliableListener_->OnSurfaceBufferAvaliable();
|
||||
}
|
||||
}
|
||||
iva->receiverConsumerSurface_->SetDefaultWidthAndHeight(width, height);
|
||||
iva->receiverConsumerSurface_->SetQueueSize(capicity);
|
||||
auto p = iva->receiverConsumerSurface_->GetProducer();
|
||||
iva->receiverProducerSurface_ = Surface::CreateSurfaceAsProducer(p);
|
||||
if (iva->receiverProducerSurface_ == nullptr) {
|
||||
IMAGE_LOGD("SurfaceAsProducer == nullptr");
|
||||
return iva;
|
||||
}
|
||||
|
||||
std::shared_ptr<ImageReceiverContext> ImageReceiverContext ::CreateImageReceiverContext()
|
||||
{
|
||||
std::shared_ptr<ImageReceiverContext> irc = std::make_shared<ImageReceiverContext>();
|
||||
return irc;
|
||||
}
|
||||
sptr<Surface> ImageReceiver::getSurfaceById(std::string id)
|
||||
{
|
||||
ImageReceiverManager& imageReceiverManager = ImageReceiverManager::getInstance();
|
||||
sptr<Surface> surface = imageReceiverManager.getSurfaceByKeyId(id);
|
||||
HiLog::Debug(LABEL, "getSurfaceById");
|
||||
return surface;
|
||||
}
|
||||
std::shared_ptr<ImageReceiver> ImageReceiver::CreateImageReceiver(int32_t width,
|
||||
int32_t height,
|
||||
int32_t format,
|
||||
int32_t capicity)
|
||||
{
|
||||
std::shared_ptr<ImageReceiver> iva = std::make_shared<ImageReceiver>();
|
||||
iva->iraContext_ = ImageReceiverContext::CreateImageReceiverContext();
|
||||
iva->receiverConsumerSurface_ = IConsumerSurface::Create();
|
||||
if (iva->receiverConsumerSurface_ == nullptr) {
|
||||
HiLog::Debug(LABEL, "SurfaceAsConsumer == nullptr");
|
||||
return iva;
|
||||
}
|
||||
iva->iraContext_->SetReceiverBufferConsumer(iva->receiverConsumerSurface_);
|
||||
iva->iraContext_->SetReceiverBufferProducer(iva->receiverProducerSurface_);
|
||||
iva->iraContext_->SetWidth(width);
|
||||
iva->iraContext_->SetHeight(height);
|
||||
iva->iraContext_->SetFormat(format);
|
||||
iva->iraContext_->SetCapicity(capicity);
|
||||
ImageReceiverManager& imageReceiverManager = ImageReceiverManager::getInstance();
|
||||
std::string receiverKey = imageReceiverManager.SaveImageReceiver(iva);
|
||||
iva->iraContext_->SetReceiverKey(receiverKey);
|
||||
sptr<ImageReceiverSurfaceListener> listener = new ImageReceiverSurfaceListener();
|
||||
listener->ir_ = iva;
|
||||
iva->receiverConsumerSurface_->
|
||||
RegisterConsumerListener((sptr<IBufferConsumerListener> &)listener);
|
||||
return iva;
|
||||
}
|
||||
|
||||
iva->receiverConsumerSurface_->SetDefaultWidthAndHeight(width, height);
|
||||
iva->receiverConsumerSurface_->SetQueueSize(capicity);
|
||||
auto p = iva->receiverConsumerSurface_->GetProducer();
|
||||
iva->receiverProducerSurface_ = Surface::CreateSurfaceAsProducer(p);
|
||||
if (iva->receiverProducerSurface_ == nullptr) {
|
||||
HiLog::Debug(LABEL, "SurfaceAsProducer == nullptr");
|
||||
return iva;
|
||||
}
|
||||
OHOS::sptr<OHOS::SurfaceBuffer> ImageReceiver::ReadNextImage()
|
||||
{
|
||||
int32_t flushFence = 0;
|
||||
int64_t timestamp = 0;
|
||||
OHOS::Rect damage = {};
|
||||
OHOS::sptr<OHOS::SurfaceBuffer> buffer;
|
||||
sptr<IConsumerSurface> listenerConsumerSurface = iraContext_->GetReceiverBufferConsumer();
|
||||
SurfaceError surfaceError = listenerConsumerSurface->AcquireBuffer(buffer, flushFence, timestamp, damage);
|
||||
if (surfaceError == SURFACE_ERROR_OK) {
|
||||
iraContext_->currentBuffer_ = buffer;
|
||||
} else {
|
||||
IMAGE_LOGD("buffer is null");
|
||||
}
|
||||
return iraContext_->GetCurrentBuffer();
|
||||
}
|
||||
|
||||
iva->iraContext_->SetReceiverBufferConsumer(iva->receiverConsumerSurface_);
|
||||
iva->iraContext_->SetReceiverBufferProducer(iva->receiverProducerSurface_);
|
||||
iva->iraContext_->SetWidth(width);
|
||||
iva->iraContext_->SetHeight(height);
|
||||
iva->iraContext_->SetFormat(format);
|
||||
iva->iraContext_->SetCapicity(capicity);
|
||||
ImageReceiverManager& imageReceiverManager = ImageReceiverManager::getInstance();
|
||||
std::string receiverKey = imageReceiverManager.SaveImageReceiver(iva);
|
||||
iva->iraContext_->SetReceiverKey(receiverKey);
|
||||
sptr<ImageReceiverSurfaceListener> listener = new ImageReceiverSurfaceListener();
|
||||
listener->ir_ = iva;
|
||||
iva->receiverConsumerSurface_->
|
||||
RegisterConsumerListener((sptr<IBufferConsumerListener> &)listener);
|
||||
return iva;
|
||||
}
|
||||
OHOS::sptr<OHOS::SurfaceBuffer> ImageReceiver::ReadLastImage()
|
||||
{
|
||||
int32_t flushFence = 0;
|
||||
int64_t timestamp = 0;
|
||||
OHOS::Rect damage = {};
|
||||
OHOS::sptr<OHOS::SurfaceBuffer> buffer;
|
||||
OHOS::sptr<OHOS::SurfaceBuffer> bufferBefore;
|
||||
sptr<IConsumerSurface> listenerConsumerSurface = iraContext_->GetReceiverBufferConsumer();
|
||||
SurfaceError surfaceError = listenerConsumerSurface->AcquireBuffer(buffer, flushFence, timestamp, damage);
|
||||
while (surfaceError == SURFACE_ERROR_OK) {
|
||||
bufferBefore = buffer;
|
||||
surfaceError = listenerConsumerSurface->AcquireBuffer(buffer, flushFence, timestamp, damage);
|
||||
}
|
||||
iraContext_->currentBuffer_ = bufferBefore;
|
||||
return iraContext_->GetCurrentBuffer();
|
||||
}
|
||||
|
||||
OHOS::sptr<OHOS::SurfaceBuffer> ImageReceiver::ReadNextImage()
|
||||
{
|
||||
int32_t flushFence = 0;
|
||||
int64_t timestamp = 0;
|
||||
OHOS::Rect damage = {};
|
||||
OHOS::sptr<OHOS::SurfaceBuffer> buffer;
|
||||
sptr<IConsumerSurface> listenerConsumerSurface = iraContext_->GetReceiverBufferConsumer();
|
||||
SurfaceError surfaceError = listenerConsumerSurface->AcquireBuffer(buffer, flushFence, timestamp, damage);
|
||||
if (surfaceError == SURFACE_ERROR_OK) {
|
||||
iraContext_->currentBuffer_ = buffer;
|
||||
} else {
|
||||
HiLog::Debug(LABEL, "buffer is null");
|
||||
}
|
||||
return iraContext_->GetCurrentBuffer();
|
||||
}
|
||||
sptr<Surface> ImageReceiver::GetReceiverSurface()
|
||||
{
|
||||
return iraContext_->GetReceiverBufferProducer();
|
||||
}
|
||||
|
||||
OHOS::sptr<OHOS::SurfaceBuffer> ImageReceiver::ReadLastImage()
|
||||
{
|
||||
int32_t flushFence = 0;
|
||||
int64_t timestamp = 0;
|
||||
OHOS::Rect damage = {};
|
||||
OHOS::sptr<OHOS::SurfaceBuffer> buffer;
|
||||
OHOS::sptr<OHOS::SurfaceBuffer> bufferBefore;
|
||||
sptr<IConsumerSurface> listenerConsumerSurface = iraContext_->GetReceiverBufferConsumer();
|
||||
SurfaceError surfaceError = listenerConsumerSurface->AcquireBuffer(buffer, flushFence, timestamp, damage);
|
||||
while (surfaceError == SURFACE_ERROR_OK) {
|
||||
bufferBefore = buffer;
|
||||
surfaceError = listenerConsumerSurface->AcquireBuffer(buffer, flushFence, timestamp, damage);
|
||||
}
|
||||
iraContext_->currentBuffer_ = bufferBefore;
|
||||
return iraContext_->GetCurrentBuffer();
|
||||
}
|
||||
|
||||
sptr<Surface> ImageReceiver::GetReceiverSurface()
|
||||
{
|
||||
return iraContext_->GetReceiverBufferProducer();
|
||||
}
|
||||
|
||||
void ImageReceiver::ReleaseReceiver()
|
||||
{
|
||||
ImageReceiver::~ImageReceiver();
|
||||
}
|
||||
void ImageReceiver::ReleaseReceiver()
|
||||
{
|
||||
ImageReceiver::~ImageReceiver();
|
||||
}
|
||||
|
||||
std::shared_ptr<IBufferProcessor> ImageReceiver::GetBufferProcessor()
|
||||
{
|
||||
@ -275,6 +282,7 @@ std::shared_ptr<NativeImage> ImageReceiver::NextNativeImage()
|
||||
}
|
||||
return std::make_shared<NativeImage>(surfaceBuffer, GetBufferProcessor());
|
||||
}
|
||||
|
||||
std::shared_ptr<NativeImage> ImageReceiver::LastNativeImage()
|
||||
{
|
||||
if (GetBufferProcessor() == nullptr) {
|
||||
@ -287,5 +295,5 @@ std::shared_ptr<NativeImage> ImageReceiver::LastNativeImage()
|
||||
}
|
||||
return std::make_shared<NativeImage>(surfaceBuffer, GetBufferProcessor());
|
||||
}
|
||||
} // namespace Media
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
||||
|
@ -15,14 +15,17 @@
|
||||
|
||||
#include "buffer_packer_stream.h"
|
||||
|
||||
#include "hilog/log.h"
|
||||
#include "log_tags.h"
|
||||
#include "image_log.h"
|
||||
#include "securec.h"
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_IMAGE
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "BufferPackerStream"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
using namespace OHOS::HiviewDFX;
|
||||
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_TAG_DOMAIN_ID_IMAGE, "BufferPackerStream"};
|
||||
|
||||
BufferPackerStream::BufferPackerStream(uint8_t *outputData, uint32_t maxSize)
|
||||
: outputData_(outputData), maxSize_(maxSize)
|
||||
@ -31,21 +34,21 @@ BufferPackerStream::BufferPackerStream(uint8_t *outputData, uint32_t maxSize)
|
||||
bool BufferPackerStream::Write(const uint8_t *buffer, uint32_t size)
|
||||
{
|
||||
if ((buffer == nullptr) || (size == 0)) {
|
||||
HiLog::Error(LABEL, "input parameter invalid.");
|
||||
IMAGE_LOGE("input parameter invalid.");
|
||||
return false;
|
||||
}
|
||||
if (outputData_ == nullptr) {
|
||||
HiLog::Error(LABEL, "output stream is null.");
|
||||
IMAGE_LOGE("output stream is null.");
|
||||
return false;
|
||||
}
|
||||
uint32_t leftSize = maxSize_ - offset_;
|
||||
if (size > leftSize) {
|
||||
HiLog::Error(LABEL, "write data:[%{public}lld] out of max size:[%{public}u].",
|
||||
static_cast<long long>(size + offset_), maxSize_);
|
||||
IMAGE_LOGE("write data:[%{public}lld] out of max size:[%{public}u].",
|
||||
static_cast<long long>(size + offset_), maxSize_);
|
||||
return false;
|
||||
}
|
||||
if (memcpy_s(outputData_ + offset_, leftSize, buffer, size) != EOK) {
|
||||
HiLog::Error(LABEL, "memory copy failed.");
|
||||
IMAGE_LOGE("memory copy failed.");
|
||||
return false;
|
||||
}
|
||||
offset_ += size;
|
||||
|
@ -16,19 +16,22 @@
|
||||
#include "buffer_source_stream.h"
|
||||
|
||||
#include <string>
|
||||
#include "hilog/log.h"
|
||||
#include "log_tags.h"
|
||||
#ifndef _WIN32
|
||||
#include "securec.h"
|
||||
#else
|
||||
#include "memory.h"
|
||||
#endif
|
||||
#include "buffer_packer_stream.h"
|
||||
#include "image_log.h"
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_IMAGE
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "BufferSourceStream"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
using namespace OHOS::HiviewDFX;
|
||||
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_TAG_DOMAIN_ID_IMAGE, "BufferSourceStream"};
|
||||
using namespace std;
|
||||
using namespace ImagePlugin;
|
||||
|
||||
@ -47,19 +50,19 @@ BufferSourceStream::~BufferSourceStream()
|
||||
std::unique_ptr<BufferSourceStream> BufferSourceStream::CreateSourceStream(const uint8_t *data, uint32_t size)
|
||||
{
|
||||
if ((data == nullptr) || (size == 0)) {
|
||||
HiLog::Error(LABEL, "[BufferSourceStream]input the parameter exception.");
|
||||
IMAGE_LOGE("[BufferSourceStream]input the parameter exception.");
|
||||
return nullptr;
|
||||
}
|
||||
uint8_t *dataCopy = static_cast<uint8_t *>(malloc(size));
|
||||
if (dataCopy == nullptr) {
|
||||
HiLog::Error(LABEL, "[BufferSourceStream]malloc the input data buffer fail.");
|
||||
IMAGE_LOGE("[BufferSourceStream]malloc the input data buffer fail.");
|
||||
return nullptr;
|
||||
}
|
||||
errno_t ret = memcpy_s(dataCopy, size, data, size);
|
||||
if (ret != EOK) {
|
||||
free(dataCopy);
|
||||
dataCopy = nullptr;
|
||||
HiLog::Error(LABEL, "[BufferSourceStream]copy the input data fail, ret:%{public}d.", ret);
|
||||
IMAGE_LOGE("[BufferSourceStream]copy the input data fail, ret:%{public}d.", ret);
|
||||
return nullptr;
|
||||
}
|
||||
return (unique_ptr<BufferSourceStream>(new BufferSourceStream(dataCopy, size, 0)));
|
||||
@ -68,7 +71,7 @@ std::unique_ptr<BufferSourceStream> BufferSourceStream::CreateSourceStream(const
|
||||
bool BufferSourceStream::Read(uint32_t desiredSize, DataStreamBuffer &outData)
|
||||
{
|
||||
if (!Peek(desiredSize, outData)) {
|
||||
HiLog::Error(LABEL, "[BufferSourceStream]read fail.");
|
||||
IMAGE_LOGE("[BufferSourceStream]read fail.");
|
||||
return false;
|
||||
}
|
||||
dataOffset_ += outData.dataSize;
|
||||
@ -78,11 +81,11 @@ bool BufferSourceStream::Read(uint32_t desiredSize, DataStreamBuffer &outData)
|
||||
bool BufferSourceStream::Peek(uint32_t desiredSize, DataStreamBuffer &outData)
|
||||
{
|
||||
if (desiredSize == 0) {
|
||||
HiLog::Error(LABEL, "[BufferSourceStream]input the parameter exception.");
|
||||
IMAGE_LOGE("[BufferSourceStream]input the parameter exception.");
|
||||
return false;
|
||||
}
|
||||
if (dataSize_ == dataOffset_) {
|
||||
HiLog::Error(LABEL, "[BufferSourceStream]buffer read finish, offset:%{public}zu ,dataSize%{public}zu.",
|
||||
IMAGE_LOGE("[BufferSourceStream]buffer read finish, offset:%{public}zu ,dataSize%{public}zu.",
|
||||
dataOffset_, dataSize_);
|
||||
return false;
|
||||
}
|
||||
@ -92,7 +95,7 @@ bool BufferSourceStream::Peek(uint32_t desiredSize, DataStreamBuffer &outData)
|
||||
}
|
||||
outData.dataSize = desiredSize;
|
||||
outData.inputStreamBuffer = inputBuffer_ + dataOffset_;
|
||||
HiLog::Debug(LABEL, "[BufferSourceStream]Peek end. desiredSize:%{public}d, offset:%{public}zu,"
|
||||
IMAGE_LOGD("[BufferSourceStream]Peek end. desiredSize:%{public}d, offset:%{public}zu,"
|
||||
"dataSize%{public}zu.", desiredSize, dataOffset_, dataSize_);
|
||||
return true;
|
||||
}
|
||||
@ -100,7 +103,7 @@ bool BufferSourceStream::Peek(uint32_t desiredSize, DataStreamBuffer &outData)
|
||||
bool BufferSourceStream::Read(uint32_t desiredSize, uint8_t *outBuffer, uint32_t bufferSize, uint32_t &readSize)
|
||||
{
|
||||
if (!Peek(desiredSize, outBuffer, bufferSize, readSize)) {
|
||||
HiLog::Error(LABEL, "[BufferSourceStream]read fail.");
|
||||
IMAGE_LOGE("[BufferSourceStream]read fail.");
|
||||
return false;
|
||||
}
|
||||
dataOffset_ += readSize;
|
||||
@ -110,12 +113,12 @@ bool BufferSourceStream::Read(uint32_t desiredSize, uint8_t *outBuffer, uint32_t
|
||||
bool BufferSourceStream::Peek(uint32_t desiredSize, uint8_t *outBuffer, uint32_t bufferSize, uint32_t &readSize)
|
||||
{
|
||||
if (desiredSize == 0 || outBuffer == nullptr || desiredSize > bufferSize) {
|
||||
HiLog::Error(LABEL, "[BufferSourceStream]input the parameter exception, desiredSize:%{public}u,"
|
||||
IMAGE_LOGE("[BufferSourceStream]input the parameter exception, desiredSize:%{public}u,"
|
||||
"bufferSize:%{public}u.", desiredSize, bufferSize);
|
||||
return false;
|
||||
}
|
||||
if (dataSize_ == dataOffset_) {
|
||||
HiLog::Error(LABEL, "[BufferSourceStream]buffer read finish, offset:%{public}zu ,dataSize%{public}zu.",
|
||||
IMAGE_LOGE("[BufferSourceStream]buffer read finish, offset:%{public}zu ,dataSize%{public}zu.",
|
||||
dataOffset_, dataSize_);
|
||||
return false;
|
||||
}
|
||||
@ -124,7 +127,7 @@ bool BufferSourceStream::Peek(uint32_t desiredSize, uint8_t *outBuffer, uint32_t
|
||||
}
|
||||
errno_t ret = memcpy_s(outBuffer, bufferSize, inputBuffer_ + dataOffset_, desiredSize);
|
||||
if (ret != EOK) {
|
||||
HiLog::Error(LABEL, "[BufferSourceStream]copy data fail, ret:%{public}d, bufferSize:%{public}u,"
|
||||
IMAGE_LOGE("[BufferSourceStream]copy data fail, ret:%{public}d, bufferSize:%{public}u,"
|
||||
"offset:%{public}zu, desiredSize:%{public}u.", ret, bufferSize, dataOffset_, desiredSize);
|
||||
return false;
|
||||
}
|
||||
@ -140,7 +143,7 @@ uint32_t BufferSourceStream::Tell()
|
||||
bool BufferSourceStream::Seek(uint32_t position)
|
||||
{
|
||||
if (position > dataSize_) {
|
||||
HiLog::Error(LABEL, "[BufferSourceStream]Seek the position greater than the Data Size,position:%{public}u.",
|
||||
IMAGE_LOGE("[BufferSourceStream]Seek the position greater than the Data Size,position:%{public}u.",
|
||||
position);
|
||||
return false;
|
||||
}
|
||||
|
@ -18,14 +18,17 @@
|
||||
#include <cerrno>
|
||||
|
||||
#include "directory_ex.h"
|
||||
#include "hilog/log.h"
|
||||
#include "image_log.h"
|
||||
#include "image_utils.h"
|
||||
#include "log_tags.h"
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_IMAGE
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "FilePackerStream"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
using namespace OHOS::HiviewDFX;
|
||||
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_IMAGE, "FilePackerStream" };
|
||||
|
||||
FilePackerStream::FilePackerStream(const std::string &filePath)
|
||||
{
|
||||
@ -42,20 +45,20 @@ FilePackerStream::FilePackerStream(const std::string &filePath)
|
||||
std::string realPath;
|
||||
if (!ImageUtils::PathToRealPath(dirPath, realPath)) {
|
||||
file_ = nullptr;
|
||||
HiLog::Error(LABEL, "convert to real path failed.");
|
||||
IMAGE_LOGE("convert to real path failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ForceCreateDirectory(realPath)) {
|
||||
file_ = nullptr;
|
||||
HiLog::Error(LABEL, "create directory failed.");
|
||||
IMAGE_LOGE("create directory failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
std::string fullPath = realPath + "/" + fileName;
|
||||
file_ = fopen(fullPath.c_str(), "wb");
|
||||
if (file_ == nullptr) {
|
||||
HiLog::Error(LABEL, "fopen file failed, error:%{public}d", errno);
|
||||
IMAGE_LOGE("fopen file failed, error:%{public}d", errno);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -63,7 +66,7 @@ FilePackerStream::FilePackerStream(const int fd)
|
||||
{
|
||||
file_ = fdopen(fd, "wb");
|
||||
if (file_ == nullptr) {
|
||||
HiLog::Error(LABEL, "fopen file failed, error:%{public}d", errno);
|
||||
IMAGE_LOGE("fopen file failed, error:%{public}d", errno);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -78,15 +81,15 @@ FilePackerStream::~FilePackerStream()
|
||||
bool FilePackerStream::Write(const uint8_t *buffer, uint32_t size)
|
||||
{
|
||||
if ((buffer == nullptr) || (size == 0)) {
|
||||
HiLog::Error(LABEL, "input parameter invalid.");
|
||||
IMAGE_LOGE("input parameter invalid.");
|
||||
return false;
|
||||
}
|
||||
if (file_ == nullptr) {
|
||||
HiLog::Error(LABEL, "output file is null.");
|
||||
IMAGE_LOGE("output file is null.");
|
||||
return false;
|
||||
}
|
||||
if (fwrite(buffer, sizeof(uint8_t), size, file_) != size) {
|
||||
HiLog::Error(LABEL, "write %{public}u bytes failed.", size);
|
||||
IMAGE_LOGE("write %{public}u bytes failed.", size);
|
||||
fclose(file_);
|
||||
file_ = nullptr;
|
||||
return false;
|
||||
|
@ -19,9 +19,8 @@
|
||||
|
||||
#include "directory_ex.h"
|
||||
#include "file_packer_stream.h"
|
||||
#include "hilog/log.h"
|
||||
#include "image_log.h"
|
||||
#include "image_utils.h"
|
||||
#include "log_tags.h"
|
||||
#include "media_errors.h"
|
||||
|
||||
#if !defined(_WIN32) && !defined(_APPLE) &&!defined(IOS_PLATFORM) &&!defined(A_PLATFORM)
|
||||
@ -29,12 +28,16 @@
|
||||
#define SUPPORT_MMAP
|
||||
#endif
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_IMAGE
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "FileSourceStream"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
using namespace OHOS::HiviewDFX;
|
||||
using namespace std;
|
||||
using namespace ImagePlugin;
|
||||
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_IMAGE, "FileSourceStream" };
|
||||
|
||||
FileSourceStream::FileSourceStream(std::FILE *file, size_t size, size_t offset, size_t original)
|
||||
: filePtr_(file), fileSize_(size), fileOffset_(offset), fileOriginalOffset_(original)
|
||||
@ -42,7 +45,7 @@ FileSourceStream::FileSourceStream(std::FILE *file, size_t size, size_t offset,
|
||||
|
||||
FileSourceStream::~FileSourceStream()
|
||||
{
|
||||
HiLog::Debug(LABEL, "[FileSourceStream]destructor enter.");
|
||||
IMAGE_LOGD("[FileSourceStream]destructor enter.");
|
||||
fclose(filePtr_);
|
||||
ResetReadBuffer();
|
||||
}
|
||||
@ -51,22 +54,22 @@ unique_ptr<FileSourceStream> FileSourceStream::CreateSourceStream(const string &
|
||||
{
|
||||
string realPath;
|
||||
if (!PathToRealPath(pathName, realPath)) {
|
||||
HiLog::Error(LABEL, "[FileSourceStream]input the file path exception, pathName=%{public}s", pathName.c_str());
|
||||
IMAGE_LOGE("[FileSourceStream]input the file path exception, pathName=%{public}s", pathName.c_str());
|
||||
return nullptr;
|
||||
}
|
||||
size_t size = 0;
|
||||
if (!ImageUtils::GetFileSize(realPath, size)) {
|
||||
HiLog::Error(LABEL, "[FileSourceStream]get the file size fail.");
|
||||
IMAGE_LOGE("[FileSourceStream]get the file size fail.");
|
||||
return nullptr;
|
||||
}
|
||||
FILE *filePtr = fopen(realPath.c_str(), "rb");
|
||||
if (filePtr == nullptr) {
|
||||
HiLog::Error(LABEL, "[FileSourceStream]open file fail.");
|
||||
IMAGE_LOGE("[FileSourceStream]open file fail.");
|
||||
return nullptr;
|
||||
}
|
||||
int64_t offset = ftell(filePtr);
|
||||
if (offset < 0) {
|
||||
HiLog::Error(LABEL, "[FileSourceStream]get the position fail.");
|
||||
IMAGE_LOGE("[FileSourceStream]get the position fail.");
|
||||
fclose(filePtr);
|
||||
return nullptr;
|
||||
}
|
||||
@ -79,28 +82,28 @@ unique_ptr<FileSourceStream> FileSourceStream::CreateSourceStream(const int fd)
|
||||
|
||||
int dupFd = dup(fd);
|
||||
if (dupFd < 0) {
|
||||
HiLog::Error(LABEL, "[FileSourceStream]Fail to dup fd.");
|
||||
IMAGE_LOGE("[FileSourceStream]Fail to dup fd.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!ImageUtils::GetFileSize(dupFd, size)) {
|
||||
HiLog::Error(LABEL, "[FileSourceStream]get the file size fail.");
|
||||
IMAGE_LOGE("[FileSourceStream]get the file size fail.");
|
||||
return nullptr;
|
||||
}
|
||||
FILE *filePtr = fdopen(dupFd, "rb");
|
||||
if (filePtr == nullptr) {
|
||||
HiLog::Error(LABEL, "[FileSourceStream]open file fail.");
|
||||
IMAGE_LOGE("[FileSourceStream]open file fail.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int ret = fseek(filePtr, 0, SEEK_SET);
|
||||
if (ret != 0) {
|
||||
HiLog::Error(LABEL, "[FileSourceStream]Go to 0 position fail, ret:%{public}d.", ret);
|
||||
IMAGE_LOGE("[FileSourceStream]Go to 0 position fail, ret:%{public}d.", ret);
|
||||
}
|
||||
|
||||
int64_t offset = ftell(filePtr);
|
||||
if (offset < 0) {
|
||||
HiLog::Error(LABEL, "[FileSourceStream]get the position fail.");
|
||||
IMAGE_LOGE("[FileSourceStream]get the position fail.");
|
||||
fclose(filePtr);
|
||||
return nullptr;
|
||||
}
|
||||
@ -112,19 +115,19 @@ unique_ptr<FileSourceStream> FileSourceStream::CreateSourceStream(
|
||||
{
|
||||
int dupFd = dup(fd);
|
||||
if (dupFd < 0) {
|
||||
HiLog::Error(LABEL, "[FileSourceStream]Fail to dup fd.");
|
||||
IMAGE_LOGE("[FileSourceStream]Fail to dup fd.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
FILE *filePtr = fdopen(dupFd, "rb");
|
||||
if (filePtr == nullptr) {
|
||||
HiLog::Error(LABEL, "[FileSourceStream]open file fail.");
|
||||
IMAGE_LOGE("[FileSourceStream]open file fail.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int ret = fseek(filePtr, offset, SEEK_SET);
|
||||
if (ret != 0) {
|
||||
HiLog::Error(LABEL, "[FileSourceStream]Go to %{public}d position fail, ret:%{public}d.", offset, ret);
|
||||
IMAGE_LOGE("[FileSourceStream]Go to %{public}d position fail, ret:%{public}d.", offset, ret);
|
||||
return nullptr;
|
||||
}
|
||||
return make_unique<FileSourceStream>(filePtr, length, offset, offset);
|
||||
@ -133,11 +136,11 @@ unique_ptr<FileSourceStream> FileSourceStream::CreateSourceStream(
|
||||
bool FileSourceStream::Read(uint32_t desiredSize, DataStreamBuffer &outData)
|
||||
{
|
||||
if (desiredSize == 0 || filePtr_ == nullptr) {
|
||||
HiLog::Error(LABEL, "[FileSourceStream]read stream input parameter exception.");
|
||||
IMAGE_LOGE("[FileSourceStream]read stream input parameter exception.");
|
||||
return false;
|
||||
}
|
||||
if (!GetData(desiredSize, outData)) {
|
||||
HiLog::Info(LABEL, "[FileSourceStream]read dataStreamBuffer fail.");
|
||||
IMAGE_LOGI("[FileSourceStream]read dataStreamBuffer fail.");
|
||||
return false;
|
||||
}
|
||||
fileOffset_ += outData.dataSize;
|
||||
@ -147,16 +150,16 @@ bool FileSourceStream::Read(uint32_t desiredSize, DataStreamBuffer &outData)
|
||||
bool FileSourceStream::Peek(uint32_t desiredSize, DataStreamBuffer &outData)
|
||||
{
|
||||
if (desiredSize == 0 || filePtr_ == nullptr) {
|
||||
HiLog::Error(LABEL, "[FileSourceStream]peek stream input parameter exception.");
|
||||
IMAGE_LOGE("[FileSourceStream]peek stream input parameter exception.");
|
||||
return false;
|
||||
}
|
||||
if (!GetData(desiredSize, outData)) {
|
||||
HiLog::Info(LABEL, "[FileSourceStream]peek dataStreamBuffer fail, desiredSize:%{public}zu", desiredSize);
|
||||
IMAGE_LOGI("[FileSourceStream]peek dataStreamBuffer fail, desiredSize:%{public}zu", desiredSize);
|
||||
return false;
|
||||
}
|
||||
int ret = fseek(filePtr_, fileOffset_, SEEK_SET);
|
||||
if (ret != 0) {
|
||||
HiLog::Error(LABEL, "[FileSourceStream]go to original position fail, ret:%{public}d.", ret);
|
||||
IMAGE_LOGE("[FileSourceStream]go to original position fail, ret:%{public}d.", ret);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -165,12 +168,12 @@ bool FileSourceStream::Peek(uint32_t desiredSize, DataStreamBuffer &outData)
|
||||
bool FileSourceStream::Read(uint32_t desiredSize, uint8_t *outBuffer, uint32_t bufferSize, uint32_t &readSize)
|
||||
{
|
||||
if (desiredSize == 0 || outBuffer == nullptr || desiredSize > bufferSize || desiredSize > fileSize_) {
|
||||
HiLog::Error(LABEL, "[FileSourceStream]input parameter exception, desiredSize:%{public}u,"
|
||||
IMAGE_LOGE("[FileSourceStream]input parameter exception, desiredSize:%{public}u,"
|
||||
"bufferSize:%{public}u,fileSize_:%{public}zu.", desiredSize, bufferSize, fileSize_);
|
||||
return false;
|
||||
}
|
||||
if (!GetData(desiredSize, outBuffer, bufferSize, readSize)) {
|
||||
HiLog::Info(LABEL, "[FileSourceStream]read outBuffer fail.");
|
||||
IMAGE_LOGI("[FileSourceStream]read outBuffer fail.");
|
||||
return false;
|
||||
}
|
||||
fileOffset_ += readSize;
|
||||
@ -180,17 +183,17 @@ bool FileSourceStream::Read(uint32_t desiredSize, uint8_t *outBuffer, uint32_t b
|
||||
bool FileSourceStream::Peek(uint32_t desiredSize, uint8_t *outBuffer, uint32_t bufferSize, uint32_t &readSize)
|
||||
{
|
||||
if (desiredSize == 0 || outBuffer == nullptr || desiredSize > bufferSize || desiredSize > fileSize_) {
|
||||
HiLog::Error(LABEL, "[FileSourceStream]input parameter exception, desiredSize:%{public}u,"
|
||||
IMAGE_LOGE("[FileSourceStream]input parameter exception, desiredSize:%{public}u,"
|
||||
"bufferSize:%{public}u, fileSize_:%{public}zu.", desiredSize, bufferSize, fileSize_);
|
||||
return false;
|
||||
}
|
||||
if (!GetData(desiredSize, outBuffer, bufferSize, readSize)) {
|
||||
HiLog::Info(LABEL, "[FileSourceStream]peek outBuffer fail.");
|
||||
IMAGE_LOGI("[FileSourceStream]peek outBuffer fail.");
|
||||
return false;
|
||||
}
|
||||
int ret = fseek(filePtr_, fileOffset_, SEEK_SET);
|
||||
if (ret != 0) {
|
||||
HiLog::Error(LABEL, "[FileSourceStream]go to original position fail, ret:%{public}d.", ret);
|
||||
IMAGE_LOGE("[FileSourceStream]go to original position fail, ret:%{public}d.", ret);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -199,7 +202,7 @@ bool FileSourceStream::Peek(uint32_t desiredSize, uint8_t *outBuffer, uint32_t b
|
||||
bool FileSourceStream::Seek(uint32_t position)
|
||||
{
|
||||
if (position > fileSize_) {
|
||||
HiLog::Error(LABEL, "[FileSourceStream]Seek the position greater than the file size, position:%{public}u.",
|
||||
IMAGE_LOGE("[FileSourceStream]Seek the position greater than the file size, position:%{public}u.",
|
||||
position);
|
||||
return false;
|
||||
}
|
||||
@ -207,7 +210,7 @@ bool FileSourceStream::Seek(uint32_t position)
|
||||
fileOffset_ = ((targetPosition < fileSize_) ? targetPosition : fileSize_);
|
||||
int ret = fseek(filePtr_, fileOffset_, SEEK_SET);
|
||||
if (ret != 0) {
|
||||
HiLog::Error(LABEL, "[FileSourceStream]go to offset position fail, ret:%{public}d.", ret);
|
||||
IMAGE_LOGE("[FileSourceStream]go to offset position fail, ret:%{public}d.", ret);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -221,7 +224,7 @@ uint32_t FileSourceStream::Tell()
|
||||
bool FileSourceStream::GetData(uint32_t desiredSize, uint8_t *outBuffer, uint32_t bufferSize, uint32_t &readSize)
|
||||
{
|
||||
if (fileSize_ == fileOffset_) {
|
||||
HiLog::Error(LABEL, "[FileSourceStream]read finish, offset:%{public}zu ,dataSize%{public}zu.",
|
||||
IMAGE_LOGE("[FileSourceStream]read finish, offset:%{public}zu ,dataSize%{public}zu.",
|
||||
fileOffset_, fileSize_);
|
||||
return false;
|
||||
}
|
||||
@ -230,7 +233,7 @@ bool FileSourceStream::GetData(uint32_t desiredSize, uint8_t *outBuffer, uint32_
|
||||
}
|
||||
size_t bytesRead = fread(outBuffer, sizeof(outBuffer[0]), desiredSize, filePtr_);
|
||||
if (bytesRead < desiredSize) {
|
||||
HiLog::Info(LABEL, "[FileSourceStream]read outBuffer fail, bytesRead:%{public}zu", bytesRead);
|
||||
IMAGE_LOGI("[FileSourceStream]read outBuffer fail, bytesRead:%{public}zu", bytesRead);
|
||||
return false;
|
||||
}
|
||||
readSize = desiredSize;
|
||||
@ -240,20 +243,20 @@ bool FileSourceStream::GetData(uint32_t desiredSize, uint8_t *outBuffer, uint32_
|
||||
bool FileSourceStream::GetData(uint32_t desiredSize, DataStreamBuffer &outData)
|
||||
{
|
||||
if (fileSize_ == fileOffset_) {
|
||||
HiLog::Error(LABEL, "[FileSourceStream]read finish, offset:%{public}zu ,dataSize%{public}zu.",
|
||||
IMAGE_LOGE("[FileSourceStream]read finish, offset:%{public}zu ,dataSize%{public}zu.",
|
||||
fileOffset_, fileSize_);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (desiredSize == 0 || desiredSize > MALLOC_MAX_LENTH) {
|
||||
HiLog::Error(LABEL, "[FileSourceStream]Invalid value, desiredSize out of size.");
|
||||
IMAGE_LOGE("[FileSourceStream]Invalid value, desiredSize out of size.");
|
||||
return false;
|
||||
}
|
||||
|
||||
ResetReadBuffer();
|
||||
readBuffer_ = static_cast<uint8_t *>(malloc(desiredSize));
|
||||
if (readBuffer_ == nullptr) {
|
||||
HiLog::Error(LABEL, "[FileSourceStream]malloc the desiredSize fail.");
|
||||
IMAGE_LOGE("[FileSourceStream]malloc the desiredSize fail.");
|
||||
return false;
|
||||
}
|
||||
outData.bufferSize = desiredSize;
|
||||
@ -262,7 +265,7 @@ bool FileSourceStream::GetData(uint32_t desiredSize, DataStreamBuffer &outData)
|
||||
}
|
||||
size_t bytesRead = fread(readBuffer_, sizeof(uint8_t), desiredSize, filePtr_);
|
||||
if (bytesRead < desiredSize) {
|
||||
HiLog::Info(LABEL, "[FileSourceStream]read dataStreamBuffer fail, bytesRead:%{public}zu", bytesRead);
|
||||
IMAGE_LOGI("[FileSourceStream]read dataStreamBuffer fail, bytesRead:%{public}zu", bytesRead);
|
||||
free(readBuffer_);
|
||||
readBuffer_ = nullptr;
|
||||
return false;
|
||||
@ -281,12 +284,12 @@ static bool DupFd(FILE *f, int &res)
|
||||
{
|
||||
res = fileno(f);
|
||||
if (res < 0) {
|
||||
HiLog::Error(LABEL, "[FileSourceStream]Fail to fileno fd.");
|
||||
IMAGE_LOGE("[FileSourceStream]Fail to fileno fd.");
|
||||
return false;
|
||||
}
|
||||
res = dup(res);
|
||||
if (res < 0) {
|
||||
HiLog::Error(LABEL, "[FileSourceStream]Fail to dup fd.");
|
||||
IMAGE_LOGE("[FileSourceStream]Fail to dup fd.");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -303,7 +306,7 @@ uint8_t *FileSourceStream::GetDataPtr()
|
||||
}
|
||||
auto mmptr = ::mmap(nullptr, fileSize_, PROT_READ, MAP_SHARED, mmapFd_, 0);
|
||||
if (mmptr == MAP_FAILED) {
|
||||
HiLog::Error(LABEL, "[FileSourceStream] mmap failed, errno:%{public}d", errno);
|
||||
IMAGE_LOGE("[FileSourceStream] mmap failed, errno:%{public}d", errno);
|
||||
return nullptr;
|
||||
}
|
||||
fileData_ = static_cast<uint8_t*>(mmptr);
|
||||
@ -335,7 +338,7 @@ OutputDataStream* FileSourceStream::ToOutputDataStream()
|
||||
{
|
||||
int dupFd = -1;
|
||||
if (DupFd(filePtr_, dupFd)) {
|
||||
HiLog::Error(LABEL, "[FileSourceStream] ToOutputDataStream fd failed");
|
||||
IMAGE_LOGE("[FileSourceStream] ToOutputDataStream fd failed");
|
||||
return nullptr;
|
||||
}
|
||||
return new (std::nothrow) FilePackerStream(dupFd);
|
||||
|
@ -17,20 +17,23 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include "hilog/log.h"
|
||||
#include "log_tags.h"
|
||||
#include "image_log.h"
|
||||
#ifndef _WIN32
|
||||
#include "securec.h"
|
||||
#else
|
||||
#include "memory.h"
|
||||
#endif
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_IMAGE
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "IncrementalSourceStream"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
using namespace OHOS::HiviewDFX;
|
||||
using namespace std;
|
||||
using namespace ImagePlugin;
|
||||
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_IMAGE, "IncrementalSourceStream" };
|
||||
|
||||
IncrementalSourceStream::IncrementalSourceStream(IncrementalMode mode)
|
||||
: incrementalMode_(mode), isFinalize_(false), dataSize_(0), dataOffset_(0)
|
||||
@ -38,14 +41,14 @@ IncrementalSourceStream::IncrementalSourceStream(IncrementalMode mode)
|
||||
|
||||
unique_ptr<IncrementalSourceStream> IncrementalSourceStream::CreateSourceStream(IncrementalMode mode)
|
||||
{
|
||||
HiLog::Debug(LABEL, "[IncrementalSourceStream]mode:%{public}d.", mode);
|
||||
IMAGE_LOGD("[IncrementalSourceStream]mode:%{public}d.", mode);
|
||||
return (unique_ptr<IncrementalSourceStream>(new IncrementalSourceStream(mode)));
|
||||
}
|
||||
|
||||
bool IncrementalSourceStream::Read(uint32_t desiredSize, DataStreamBuffer &outData)
|
||||
{
|
||||
if (!Peek(desiredSize, outData)) {
|
||||
HiLog::Error(LABEL, "[IncrementalSourceStream]read fail.");
|
||||
IMAGE_LOGE("[IncrementalSourceStream]read fail.");
|
||||
return false;
|
||||
}
|
||||
dataOffset_ += outData.dataSize;
|
||||
@ -55,11 +58,11 @@ bool IncrementalSourceStream::Read(uint32_t desiredSize, DataStreamBuffer &outDa
|
||||
bool IncrementalSourceStream::Peek(uint32_t desiredSize, DataStreamBuffer &outData)
|
||||
{
|
||||
if (desiredSize == 0) {
|
||||
HiLog::Error(LABEL, "[IncrementalSourceStream]input the parameter exception.");
|
||||
IMAGE_LOGE("[IncrementalSourceStream]input the parameter exception.");
|
||||
return false;
|
||||
}
|
||||
if (sourceData_.empty() || dataSize_ == 0 || dataOffset_ >= dataSize_) {
|
||||
HiLog::Error(LABEL, "[IncrementalSourceStream]source data exception. dataSize_:%{public}zu,"
|
||||
IMAGE_LOGE("[IncrementalSourceStream]source data exception. dataSize_:%{public}zu,"
|
||||
"dataOffset_:%{public}zu.", dataSize_, dataOffset_);
|
||||
return false;
|
||||
}
|
||||
@ -69,7 +72,7 @@ bool IncrementalSourceStream::Peek(uint32_t desiredSize, DataStreamBuffer &outDa
|
||||
}
|
||||
outData.dataSize = desiredSize;
|
||||
outData.inputStreamBuffer = sourceData_.data() + dataOffset_;
|
||||
HiLog::Debug(LABEL, "[IncrementalSourceStream]Peek end. desiredSize:%{public}u, offset:%{public}zu,"
|
||||
IMAGE_LOGD("[IncrementalSourceStream]Peek end. desiredSize:%{public}u, offset:%{public}zu,"
|
||||
"dataSize_:%{public}zu,dataOffset_:%{public}zu.", desiredSize, dataOffset_, dataSize_, dataOffset_);
|
||||
return true;
|
||||
}
|
||||
@ -77,7 +80,7 @@ bool IncrementalSourceStream::Peek(uint32_t desiredSize, DataStreamBuffer &outDa
|
||||
bool IncrementalSourceStream::Read(uint32_t desiredSize, uint8_t *outBuffer, uint32_t bufferSize, uint32_t &readSize)
|
||||
{
|
||||
if (!Peek(desiredSize, outBuffer, bufferSize, readSize)) {
|
||||
HiLog::Error(LABEL, "[IncrementalSourceStream]read fail.");
|
||||
IMAGE_LOGE("[IncrementalSourceStream]read fail.");
|
||||
return false;
|
||||
}
|
||||
dataOffset_ += readSize;
|
||||
@ -87,12 +90,12 @@ bool IncrementalSourceStream::Read(uint32_t desiredSize, uint8_t *outBuffer, uin
|
||||
bool IncrementalSourceStream::Peek(uint32_t desiredSize, uint8_t *outBuffer, uint32_t bufferSize, uint32_t &readSize)
|
||||
{
|
||||
if (desiredSize == 0 || outBuffer == nullptr || desiredSize > bufferSize) {
|
||||
HiLog::Error(LABEL, "[IncrementalSourceStream]input parameter exception, desiredSize:%{public}u,"
|
||||
IMAGE_LOGE("[IncrementalSourceStream]input parameter exception, desiredSize:%{public}u,"
|
||||
"bufferSize:%{public}u.", desiredSize, bufferSize);
|
||||
return false;
|
||||
}
|
||||
if (sourceData_.empty() || dataSize_ == 0 || dataOffset_ >= dataSize_) {
|
||||
HiLog::Error(LABEL, "[IncrementalSourceStream]source data exception. dataSize_:%{public}zu,"
|
||||
IMAGE_LOGE("[IncrementalSourceStream]source data exception. dataSize_:%{public}zu,"
|
||||
"dataOffset_:%{public}zu.", dataSize_, dataOffset_);
|
||||
return false;
|
||||
}
|
||||
@ -101,7 +104,7 @@ bool IncrementalSourceStream::Peek(uint32_t desiredSize, uint8_t *outBuffer, uin
|
||||
}
|
||||
errno_t ret = memcpy_s(outBuffer, bufferSize, sourceData_.data() + dataOffset_, desiredSize);
|
||||
if (ret != 0) {
|
||||
HiLog::Error(LABEL, "[IncrementalSourceStream]copy data fail, ret:%{public}d, bufferSize:%{public}u,"
|
||||
IMAGE_LOGE("[IncrementalSourceStream]copy data fail, ret:%{public}d, bufferSize:%{public}u,"
|
||||
"offset:%{public}zu, desiredSize:%{public}u, dataSize:%{public}zu.", ret, bufferSize, dataOffset_,
|
||||
desiredSize, dataSize_);
|
||||
return false;
|
||||
@ -118,7 +121,7 @@ uint32_t IncrementalSourceStream::Tell()
|
||||
bool IncrementalSourceStream::Seek(uint32_t position)
|
||||
{
|
||||
if (position >= dataSize_) {
|
||||
HiLog::Error(LABEL, "[IncrementalSourceStream]Seek the position greater than the Data Size.");
|
||||
IMAGE_LOGE("[IncrementalSourceStream]Seek the position greater than the Data Size.");
|
||||
return false;
|
||||
}
|
||||
dataOffset_ = position;
|
||||
@ -128,11 +131,11 @@ bool IncrementalSourceStream::Seek(uint32_t position)
|
||||
uint32_t IncrementalSourceStream::UpdateData(const uint8_t *data, uint32_t size, bool isCompleted)
|
||||
{
|
||||
if (data == nullptr) {
|
||||
HiLog::Error(LABEL, "[IncrementalSourceStream]input the parameter exception.");
|
||||
IMAGE_LOGE("[IncrementalSourceStream]input the parameter exception.");
|
||||
return ERR_IMAGE_DATA_ABNORMAL;
|
||||
}
|
||||
if (size == 0) {
|
||||
HiLog::Debug(LABEL, "[IncrementalSourceStream]no need to update data.");
|
||||
IMAGE_LOGD("[IncrementalSourceStream]no need to update data.");
|
||||
return SUCCESS;
|
||||
}
|
||||
if (incrementalMode_ == IncrementalMode::INCREMENTAL_DATA) {
|
||||
|
@ -15,16 +15,19 @@
|
||||
|
||||
#include "istream_source_stream.h"
|
||||
|
||||
#include "hilog/log.h"
|
||||
#include "image_log.h"
|
||||
#include "image_utils.h"
|
||||
#include "log_tags.h"
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_IMAGE
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "IstreamSourceStream"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
using namespace OHOS::HiviewDFX;
|
||||
using namespace std;
|
||||
using namespace ImagePlugin;
|
||||
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_IMAGE, "IstreamSourceStream" };
|
||||
|
||||
IstreamSourceStream::IstreamSourceStream(unique_ptr<istream> inputStream, size_t size, size_t original, size_t offset)
|
||||
: inputStream_(move(inputStream)), streamSize_(size), streamOriginalOffset_(original), streamOffset_(offset)
|
||||
@ -39,16 +42,16 @@ std::unique_ptr<IstreamSourceStream> IstreamSourceStream::CreateSourceStream(uni
|
||||
{
|
||||
if ((inputStream == nullptr) || (inputStream->rdbuf() == nullptr) ||
|
||||
inputStream.get() == nullptr) {
|
||||
HiLog::Error(LABEL, "[IstreamSourceStream]input parameter exception.");
|
||||
IMAGE_LOGE("[IstreamSourceStream]input parameter exception.");
|
||||
return nullptr;
|
||||
}
|
||||
size_t streamSize = 0;
|
||||
if (!ImageUtils::GetInputStreamSize(*(inputStream.get()), streamSize)) {
|
||||
HiLog::Error(LABEL, "[IstreamSourceStream]Get the input stream exception.");
|
||||
IMAGE_LOGE("[IstreamSourceStream]Get the input stream exception.");
|
||||
return nullptr;
|
||||
}
|
||||
if (streamSize == 0) {
|
||||
HiLog::Error(LABEL, "[IstreamSourceStream]input stream size exception.");
|
||||
IMAGE_LOGE("[IstreamSourceStream]input stream size exception.");
|
||||
return nullptr;
|
||||
}
|
||||
size_t original = inputStream->tellg();
|
||||
@ -59,11 +62,11 @@ std::unique_ptr<IstreamSourceStream> IstreamSourceStream::CreateSourceStream(uni
|
||||
bool IstreamSourceStream::Read(uint32_t desiredSize, DataStreamBuffer &outData)
|
||||
{
|
||||
if (desiredSize == 0) {
|
||||
HiLog::Error(LABEL, "[IstreamSourceStream]read stream input parameter exception.");
|
||||
IMAGE_LOGE("[IstreamSourceStream]read stream input parameter exception.");
|
||||
return false;
|
||||
}
|
||||
if (!GetData(desiredSize, outData)) {
|
||||
HiLog::Error(LABEL, "[IstreamSourceStream]read fail.");
|
||||
IMAGE_LOGE("[IstreamSourceStream]read fail.");
|
||||
return false;
|
||||
}
|
||||
streamOffset_ += outData.dataSize;
|
||||
@ -73,11 +76,11 @@ bool IstreamSourceStream::Read(uint32_t desiredSize, DataStreamBuffer &outData)
|
||||
bool IstreamSourceStream::Peek(uint32_t desiredSize, DataStreamBuffer &outData)
|
||||
{
|
||||
if (desiredSize == 0) {
|
||||
HiLog::Error(LABEL, "[IstreamSourceStream]peek stream input parameter exception.");
|
||||
IMAGE_LOGE("[IstreamSourceStream]peek stream input parameter exception.");
|
||||
return false;
|
||||
}
|
||||
if (!GetData(desiredSize, outData)) {
|
||||
HiLog::Error(LABEL, "[IstreamSourceStream]peek fail.");
|
||||
IMAGE_LOGE("[IstreamSourceStream]peek fail.");
|
||||
return false;
|
||||
}
|
||||
inputStream_->seekg(streamOffset_);
|
||||
@ -87,12 +90,12 @@ bool IstreamSourceStream::Peek(uint32_t desiredSize, DataStreamBuffer &outData)
|
||||
bool IstreamSourceStream::Read(uint32_t desiredSize, uint8_t *outBuffer, uint32_t bufferSize, uint32_t &readSize)
|
||||
{
|
||||
if (desiredSize == 0 || outBuffer == nullptr || desiredSize > bufferSize) {
|
||||
HiLog::Error(LABEL, "[IstreamSourceStream]input the parameter exception, desiredSize:%{public}u,"
|
||||
IMAGE_LOGE("[IstreamSourceStream]input the parameter exception, desiredSize:%{public}u,"
|
||||
"bufferSize:%{public}u.", desiredSize, bufferSize);
|
||||
return false;
|
||||
}
|
||||
if (!GetData(desiredSize, outBuffer, bufferSize, readSize)) {
|
||||
HiLog::Error(LABEL, "[IstreamSourceStream]read fail.");
|
||||
IMAGE_LOGE("[IstreamSourceStream]read fail.");
|
||||
return false;
|
||||
}
|
||||
streamOffset_ += readSize;
|
||||
@ -102,12 +105,12 @@ bool IstreamSourceStream::Read(uint32_t desiredSize, uint8_t *outBuffer, uint32_
|
||||
bool IstreamSourceStream::Peek(uint32_t desiredSize, uint8_t *outBuffer, uint32_t bufferSize, uint32_t &readSize)
|
||||
{
|
||||
if (desiredSize == 0 || outBuffer == nullptr || desiredSize > bufferSize) {
|
||||
HiLog::Error(LABEL, "[IstreamSourceStream]input the parameter exception, desiredSize:%{public}u,"
|
||||
IMAGE_LOGE("[IstreamSourceStream]input the parameter exception, desiredSize:%{public}u,"
|
||||
"bufferSize:%{public}u.", desiredSize, bufferSize);
|
||||
return false;
|
||||
}
|
||||
if (!GetData(desiredSize, outBuffer, bufferSize, readSize)) {
|
||||
HiLog::Error(LABEL, "[IstreamSourceStream]peek fail.");
|
||||
IMAGE_LOGE("[IstreamSourceStream]peek fail.");
|
||||
return false;
|
||||
}
|
||||
inputStream_->seekg(streamOffset_);
|
||||
@ -117,7 +120,7 @@ bool IstreamSourceStream::Peek(uint32_t desiredSize, uint8_t *outBuffer, uint32_
|
||||
bool IstreamSourceStream::Seek(uint32_t position)
|
||||
{
|
||||
if (position > streamSize_) {
|
||||
HiLog::Error(LABEL, "[IstreamSourceStream]Seek the position error, position:%{public}u,"
|
||||
IMAGE_LOGE("[IstreamSourceStream]Seek the position error, position:%{public}u,"
|
||||
"streamSize_:%{public}zu.", position, streamSize_);
|
||||
return false;
|
||||
}
|
||||
@ -135,7 +138,7 @@ uint32_t IstreamSourceStream::Tell()
|
||||
bool IstreamSourceStream::GetData(uint32_t desiredSize, uint8_t *outBuffer, uint32_t bufferSize, uint32_t &readSize)
|
||||
{
|
||||
if (streamSize_ == 0 || streamOffset_ >= streamSize_) {
|
||||
HiLog::Error(LABEL, "[IstreamSourceStream]get source data fail. streamSize:%{public}zu,"
|
||||
IMAGE_LOGE("[IstreamSourceStream]get source data fail. streamSize:%{public}zu,"
|
||||
"streamOffset:%{public}zu.", streamSize_, streamOffset_);
|
||||
return false;
|
||||
}
|
||||
@ -143,7 +146,7 @@ bool IstreamSourceStream::GetData(uint32_t desiredSize, uint8_t *outBuffer, uint
|
||||
desiredSize = (streamSize_ - streamOffset_);
|
||||
}
|
||||
if (!inputStream_->read(reinterpret_cast<char *>(outBuffer), desiredSize)) {
|
||||
HiLog::Error(LABEL, "[IstreamSourceStream]read the inputstream fail.");
|
||||
IMAGE_LOGE("[IstreamSourceStream]read the inputstream fail.");
|
||||
return false;
|
||||
}
|
||||
readSize = desiredSize;
|
||||
@ -153,19 +156,19 @@ bool IstreamSourceStream::GetData(uint32_t desiredSize, uint8_t *outBuffer, uint
|
||||
bool IstreamSourceStream::GetData(uint32_t desiredSize, DataStreamBuffer &outData)
|
||||
{
|
||||
if (streamSize_ == 0 || streamOffset_ >= streamSize_) {
|
||||
HiLog::Error(LABEL, "[IstreamSourceStream]get source data fail. streamSize:%{public}zu,"
|
||||
IMAGE_LOGE("[IstreamSourceStream]get source data fail. streamSize:%{public}zu,"
|
||||
"streamOffset:%{public}zu.", streamSize_, streamOffset_);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (desiredSize == 0 || desiredSize > MALLOC_MAX_LENTH) {
|
||||
HiLog::Error(LABEL, "IstreamSourceStream]Invalid value, desiredSize out of size.");
|
||||
IMAGE_LOGE("IstreamSourceStream]Invalid value, desiredSize out of size.");
|
||||
return false;
|
||||
}
|
||||
ResetReadBuffer();
|
||||
databuffer_ = static_cast<uint8_t *>(malloc(desiredSize));
|
||||
if (databuffer_ == nullptr) {
|
||||
HiLog::Error(LABEL, "[IstreamSourceStream]malloc the output data buffer fail.");
|
||||
IMAGE_LOGE("[IstreamSourceStream]malloc the output data buffer fail.");
|
||||
return false;
|
||||
}
|
||||
outData.bufferSize = desiredSize;
|
||||
@ -174,7 +177,7 @@ bool IstreamSourceStream::GetData(uint32_t desiredSize, DataStreamBuffer &outDat
|
||||
}
|
||||
inputStream_->seekg(streamOffset_);
|
||||
if (!inputStream_->read(reinterpret_cast<char *>(databuffer_), desiredSize)) {
|
||||
HiLog::Error(LABEL, "[IstreamSourceStream]read the inputstream fail.");
|
||||
IMAGE_LOGE("[IstreamSourceStream]read the inputstream fail.");
|
||||
free(databuffer_);
|
||||
databuffer_ = nullptr;
|
||||
return false;
|
||||
|
@ -15,20 +15,24 @@
|
||||
|
||||
#include "ostream_packer_stream.h"
|
||||
|
||||
#include "hilog/log.h"
|
||||
#include "image_log.h"
|
||||
#include "log_tags.h"
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_IMAGE
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "OstreamPackerStream"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
using namespace OHOS::HiviewDFX;
|
||||
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_TAG_DOMAIN_ID_IMAGE, "OstreamPackerStream"};
|
||||
|
||||
OstreamPackerStream::OstreamPackerStream(std::ostream &outputStream) : outputStream_(&outputStream) {}
|
||||
|
||||
bool OstreamPackerStream::Write(const uint8_t *buffer, uint32_t size)
|
||||
{
|
||||
if ((buffer == nullptr) || (size == 0)) {
|
||||
HiLog::Error(LABEL, "input parameter invalid.");
|
||||
IMAGE_LOGE("input parameter invalid.");
|
||||
return false;
|
||||
}
|
||||
outputStream_->write(reinterpret_cast<const char *>(buffer), size);
|
||||
|
@ -16,12 +16,10 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
#include "hilog/log.h"
|
||||
#include "native_window.h"
|
||||
#include "pixel_map_from_surface.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace OHOS::HiviewDFX;
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
|
@ -19,8 +19,6 @@
|
||||
#include "exif_maker_note.h"
|
||||
#include "securec.h"
|
||||
#include "string_ex.h"
|
||||
#include "hilog/log.h"
|
||||
#include "log_tags.h"
|
||||
#include "media_errors.h"
|
||||
#include "exif_info.h"
|
||||
#include "jpeg_decoder.h"
|
||||
@ -28,7 +26,6 @@
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace OHOS::Media;
|
||||
using namespace OHOS::HiviewDFX;
|
||||
namespace OHOS {
|
||||
namespace ImagePlugin {
|
||||
constexpr unsigned char HW_MNOTE_HEADER[] = { 'H', 'U', 'A', 'W', 'E', 'I', '\0', '\0' };
|
||||
|
@ -20,19 +20,23 @@
|
||||
#include "color_space.h"
|
||||
#endif
|
||||
#include "directory_ex.h"
|
||||
#include "hilog/log.h"
|
||||
#include "image_log.h"
|
||||
#include "image_packer.h"
|
||||
#include "image_source.h"
|
||||
#include "image_type.h"
|
||||
#include "image_utils.h"
|
||||
#include "log_tags.h"
|
||||
#include "media_errors.h"
|
||||
#include "pixel_map.h"
|
||||
#include "image_source_util.h"
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_IMAGE
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "ImageColorSpaceTest"
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace OHOS::Media;
|
||||
using namespace OHOS::HiviewDFX;
|
||||
using namespace OHOS::ImageSourceUtil;
|
||||
|
||||
namespace OHOS {
|
||||
@ -42,10 +46,6 @@ static const std::string IMAGE_OUTPUT_JPEG_INCLUDE_ICC_PATH = "/data/test/test_j
|
||||
static const std::string IMAGE_INPUT_JPEG_NOT_INCLUDE_ICC_PATH = "/data/local/tmp/image/test.jpg";
|
||||
static const std::string IMAGE_OUTPUT_JPEG_NOT_INCLUDE_ICC_PATH = "/data/test/test_jpeg_no_include_icc_profile.jpg";
|
||||
|
||||
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL_TEST = {
|
||||
LOG_CORE, LOG_TAG_DOMAIN_ID_IMAGE, "ImageColorSpaceTest"
|
||||
};
|
||||
|
||||
class ImageColorSpaceTest : public testing::Test {
|
||||
public:
|
||||
ImageColorSpaceTest() {};
|
||||
@ -68,7 +68,7 @@ HWTEST_F(ImageColorSpaceTest, JpegColorSpaceDecode001, TestSize.Level3)
|
||||
opts.formatHint = "image/jpeg";
|
||||
std::unique_ptr<ImageSource> imageSource =
|
||||
ImageSource::CreateImageSource(IMAGE_INPUT_JPEG_INCLUDE_ICC_PATH, opts, errorCode);
|
||||
HiLog::Debug(LABEL_TEST, "create image source error code=%{public}u.", errorCode);
|
||||
IMAGE_LOGD("create image source error code=%{public}u.", errorCode);
|
||||
ASSERT_EQ(errorCode, SUCCESS);
|
||||
ASSERT_NE(imageSource.get(), nullptr);
|
||||
|
||||
@ -79,7 +79,7 @@ HWTEST_F(ImageColorSpaceTest, JpegColorSpaceDecode001, TestSize.Level3)
|
||||
*/
|
||||
DecodeOptions decodeOpts;
|
||||
std::unique_ptr<PixelMap> pixelMap = imageSource->CreatePixelMap(decodeOpts, errorCode);
|
||||
HiLog::Debug(LABEL_TEST, "create pixel map error code=%{public}u.", errorCode);
|
||||
IMAGE_LOGD("create pixel map error code=%{public}u.", errorCode);
|
||||
ASSERT_EQ(errorCode, SUCCESS);
|
||||
ASSERT_NE(pixelMap.get(), nullptr);
|
||||
#ifdef IMAGE_COLORSPACE_FLAG
|
||||
@ -107,7 +107,7 @@ HWTEST_F(ImageColorSpaceTest, JpegColorSpaceEncode001, TestSize.Level3)
|
||||
opts.formatHint = "image/jpeg";
|
||||
std::unique_ptr<ImageSource> imageSource =
|
||||
ImageSource::CreateImageSource(IMAGE_INPUT_JPEG_INCLUDE_ICC_PATH, opts, errorCode);
|
||||
HiLog::Debug(LABEL_TEST, "create image source error code==%{public}u.", errorCode);
|
||||
IMAGE_LOGD("create image source error code==%{public}u.", errorCode);
|
||||
ASSERT_EQ(errorCode, SUCCESS);
|
||||
ASSERT_NE(imageSource.get(), nullptr);
|
||||
|
||||
@ -118,7 +118,7 @@ HWTEST_F(ImageColorSpaceTest, JpegColorSpaceEncode001, TestSize.Level3)
|
||||
*/
|
||||
DecodeOptions decodeOpts;
|
||||
std::unique_ptr<PixelMap> pixelMapOne = imageSource->CreatePixelMap(decodeOpts, errorCode);
|
||||
HiLog::Debug(LABEL_TEST, "create pixel map error code=%{public}u.", errorCode);
|
||||
IMAGE_LOGD("create pixel map error code=%{public}u.", errorCode);
|
||||
ASSERT_EQ(errorCode, SUCCESS);
|
||||
ASSERT_NE(pixelMapOne.get(), nullptr);
|
||||
#ifdef IMAGE_COLORSPACE_FLAG
|
||||
@ -176,7 +176,7 @@ HWTEST_F(ImageColorSpaceTest, JpegColorSpaceDecode002, TestSize.Level3)
|
||||
opts.formatHint = "image/jpeg";
|
||||
std::unique_ptr<ImageSource> imageSource =
|
||||
ImageSource::CreateImageSource(IMAGE_INPUT_JPEG_NOT_INCLUDE_ICC_PATH, opts, errorCode);
|
||||
HiLog::Debug(LABEL_TEST, "create image source error code=%{public}u.", errorCode);
|
||||
IMAGE_LOGD("create image source error code=%{public}u.", errorCode);
|
||||
ASSERT_EQ(errorCode, SUCCESS);
|
||||
ASSERT_NE(imageSource.get(), nullptr);
|
||||
|
||||
@ -187,7 +187,7 @@ HWTEST_F(ImageColorSpaceTest, JpegColorSpaceDecode002, TestSize.Level3)
|
||||
*/
|
||||
DecodeOptions decodeOpts;
|
||||
std::unique_ptr<PixelMap> pixelMap = imageSource->CreatePixelMap(decodeOpts, errorCode);
|
||||
HiLog::Debug(LABEL_TEST, "create pixel map error code=%{public}u.", errorCode);
|
||||
IMAGE_LOGD("create pixel map error code=%{public}u.", errorCode);
|
||||
ASSERT_EQ(errorCode, SUCCESS);
|
||||
ASSERT_NE(pixelMap.get(), nullptr);
|
||||
#ifdef IMAGE_COLORSPACE_FLAG
|
||||
@ -212,7 +212,7 @@ HWTEST_F(ImageColorSpaceTest, JpegColorSpaceEncode002, TestSize.Level3)
|
||||
opts.formatHint = "image/jpeg";
|
||||
std::unique_ptr<ImageSource> imageSource =
|
||||
ImageSource::CreateImageSource(IMAGE_INPUT_JPEG_NOT_INCLUDE_ICC_PATH, opts, errorCode);
|
||||
HiLog::Debug(LABEL_TEST, "create image source error code==%{public}u.", errorCode);
|
||||
IMAGE_LOGD("create image source error code==%{public}u.", errorCode);
|
||||
ASSERT_EQ(errorCode, SUCCESS);
|
||||
ASSERT_NE(imageSource.get(), nullptr);
|
||||
|
||||
@ -223,7 +223,7 @@ HWTEST_F(ImageColorSpaceTest, JpegColorSpaceEncode002, TestSize.Level3)
|
||||
*/
|
||||
DecodeOptions decodeOpts;
|
||||
std::unique_ptr<PixelMap> pixelMapOne = imageSource->CreatePixelMap(decodeOpts, errorCode);
|
||||
HiLog::Debug(LABEL_TEST, "create pixel map error code=%{public}u.", errorCode);
|
||||
IMAGE_LOGD("create pixel map error code=%{public}u.", errorCode);
|
||||
ASSERT_EQ(errorCode, SUCCESS);
|
||||
ASSERT_NE(pixelMapOne.get(), nullptr);
|
||||
#ifdef IMAGE_COLORSPACE_FLAG
|
||||
|
@ -15,7 +15,6 @@
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <fstream>
|
||||
#include "hilog/log.h"
|
||||
#include "image_creator.h"
|
||||
#include "image_packer.h"
|
||||
#include "image_source.h"
|
||||
|
@ -20,7 +20,6 @@
|
||||
#include "image_packer.h"
|
||||
#include "image_source.h"
|
||||
#include "image_utils.h"
|
||||
#include "hilog/log.h"
|
||||
#include "image_receiver_manager.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
|
@ -21,7 +21,6 @@
|
||||
#include "image_source.h"
|
||||
#include "image_type.h"
|
||||
#include "image_utils.h"
|
||||
#include "hilog/log.h"
|
||||
#include "image_receiver_manager.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
|
@ -16,7 +16,6 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <fstream>
|
||||
#include "directory_ex.h"
|
||||
#include "hilog/log.h"
|
||||
#include "image_packer.h"
|
||||
#include "image_source.h"
|
||||
#include "image_source_util.h"
|
||||
@ -27,7 +26,6 @@
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace OHOS::Media;
|
||||
using namespace OHOS::HiviewDFX;
|
||||
using namespace OHOS::ImageSourceUtil;
|
||||
namespace OHOS {
|
||||
namespace Multimedia {
|
||||
|
@ -19,14 +19,18 @@
|
||||
#include "media_errors.h"
|
||||
#include "image_source.h"
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_IMAGE
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "ImageSourceGifExTest"
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace OHOS::Media;
|
||||
using namespace OHOS::HiviewDFX;
|
||||
using namespace OHOS::ImageSourceUtil;
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
namespace {
|
||||
static constexpr HiLogLabel LABEL_TEST = { LOG_CORE, LOG_TAG_DOMAIN_ID_IMAGE, "ImageSourceGifExTest" };
|
||||
static const std::string INPUT_PATH = "/data/local/tmp/image/";
|
||||
static const std::string OUTPUT_PATH = "/data/local/tmp/image/output_";
|
||||
static const std::string OUTPUT_EXT = ".jpg";
|
||||
@ -168,7 +172,7 @@ HWTEST_F(ImageSourceGifExTest, GetDelayTime001, TestSize.Level3)
|
||||
ASSERT_EQ(delayTimes->size(), TEST_FILE_SINGLE_FRAME_GIF_FRAME_COUNT);
|
||||
|
||||
for (auto delayTime : *delayTimes) {
|
||||
HiLog::Debug(LABEL_TEST, "delay time is %{public}u.", delayTime);
|
||||
IMAGE_LOGD("delay time is %{public}u.", delayTime);
|
||||
}
|
||||
|
||||
GTEST_LOG_(INFO) << "ImageSourceGifExTest: GetDelayTime001 end";
|
||||
@ -196,7 +200,7 @@ HWTEST_F(ImageSourceGifExTest, GetDelayTime002, TestSize.Level3)
|
||||
ASSERT_EQ(delayTimes->size(), TEST_FILE_MULTI_FRAME_GIF_FRAME_COUNT);
|
||||
|
||||
for (auto delayTime : *delayTimes) {
|
||||
HiLog::Debug(LABEL_TEST, "delay time is %{public}u.", delayTime);
|
||||
IMAGE_LOGD("delay time is %{public}u.", delayTime);
|
||||
}
|
||||
|
||||
GTEST_LOG_(INFO) << "ImageSourceGifExTest: GetDelayTime002 end";
|
||||
|
@ -16,28 +16,28 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <fstream>
|
||||
#include "directory_ex.h"
|
||||
#include "hilog/log.h"
|
||||
#include "image_log.h"
|
||||
#include "image_packer.h"
|
||||
#include "image_source.h"
|
||||
#include "image_source_util.h"
|
||||
#include "image_type.h"
|
||||
#include "image_utils.h"
|
||||
#include "incremental_pixel_map.h"
|
||||
#include "log_tags.h"
|
||||
#include "media_errors.h"
|
||||
#include "pixel_map.h"
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_IMAGE
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "ImageSourceGifTest"
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace OHOS::Media;
|
||||
using namespace OHOS::HiviewDFX;
|
||||
using namespace OHOS::ImageSourceUtil;
|
||||
|
||||
namespace OHOS {
|
||||
namespace Multimedia {
|
||||
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL_TEST = {
|
||||
LOG_CORE, LOG_TAG_DOMAIN_ID_IMAGE, "ImageSourceGifTest"
|
||||
};
|
||||
|
||||
class ImageSourceGifTest : public testing::Test {
|
||||
public:
|
||||
ImageSourceGifTest() {}
|
||||
@ -120,7 +120,7 @@ HWTEST_F(ImageSourceGifTest, GifImageDecode004, TestSize.Level3)
|
||||
DecodeOptions decodeOpts;
|
||||
decodeOpts.desiredPixelFormat = PixelFormat::BGRA_8888;
|
||||
std::unique_ptr<PixelMap> pixelMap = imageSource->CreatePixelMap(decodeOpts, errorCode);
|
||||
HiLog::Debug(LABEL_TEST, "create bitmap code=%{public}d.", errorCode);
|
||||
IMAGE_LOGD("create bitmap code=%{public}d.", errorCode);
|
||||
ASSERT_EQ(errorCode, SUCCESS);
|
||||
ASSERT_NE(pixelMap.get(), nullptr);
|
||||
/**
|
||||
@ -135,7 +135,7 @@ HWTEST_F(ImageSourceGifTest, GifImageDecode004, TestSize.Level3)
|
||||
uint8_t red = pixelMap->GetARGB32ColorR(color);
|
||||
uint8_t green = pixelMap->GetARGB32ColorG(color);
|
||||
uint8_t blue = pixelMap->GetARGB32ColorB(color);
|
||||
HiLog::Debug(LABEL_TEST, "point:[%u, %u] ARGB:[%u, %u, %u, %u]", posX, posY, alpha, red, green, blue);
|
||||
IMAGE_LOGD("point:[%u, %u] ARGB:[%u, %u, %u, %u]", posX, posY, alpha, red, green, blue);
|
||||
EXPECT_EQ(255, alpha);
|
||||
EXPECT_EQ(244, red);
|
||||
EXPECT_EQ(63, green);
|
||||
@ -183,7 +183,7 @@ HWTEST_F(ImageSourceGifTest, GifImageDecode005, TestSize.Level3)
|
||||
uint8_t green = pixelMap->GetARGB32ColorG(color);
|
||||
uint8_t blue = pixelMap->GetARGB32ColorB(color);
|
||||
uint8_t alpha = pixelMap->GetARGB32ColorA(color);
|
||||
HiLog::Debug(LABEL_TEST, "point:[%u, %u] RGBA:[%u, %u, %u, %u]", posX, posY, red, green, blue, alpha);
|
||||
IMAGE_LOGD("point:[%u, %u] RGBA:[%u, %u, %u, %u]", posX, posY, red, green, blue, alpha);
|
||||
EXPECT_EQ(255, alpha);
|
||||
EXPECT_EQ(244, red);
|
||||
EXPECT_EQ(63, green);
|
||||
|
@ -17,13 +17,12 @@
|
||||
#include <fstream>
|
||||
#include <fcntl.h>
|
||||
#include "directory_ex.h"
|
||||
#include "hilog/log.h"
|
||||
#include "image_log.h"
|
||||
#include "image_packer.h"
|
||||
#include "image_source.h"
|
||||
#include "image_type.h"
|
||||
#include "image_utils.h"
|
||||
#include "incremental_pixel_map.h"
|
||||
#include "log_tags.h"
|
||||
#include "media_errors.h"
|
||||
#include "pixel_map.h"
|
||||
#include "image_receiver.h"
|
||||
@ -32,16 +31,18 @@
|
||||
#include "graphic_common.h"
|
||||
#include "image_receiver_manager.h"
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_IMAGE
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "ImageSourceJpegTest"
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace OHOS::Media;
|
||||
using namespace OHOS::HiviewDFX;
|
||||
using namespace OHOS::ImageSourceUtil;
|
||||
|
||||
namespace OHOS {
|
||||
namespace Multimedia {
|
||||
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL_TEST = {
|
||||
LOG_CORE, LOG_TAG_DOMAIN_ID_IMAGE, "ImageSourceJpegTest"
|
||||
};
|
||||
static constexpr uint32_t DEFAULT_DELAY_UTIME = 10000; // 10 ms.
|
||||
static const std::string IMAGE_INPUT_JPEG_PATH = "/data/local/tmp/image/test.jpg";
|
||||
static const std::string IMAGE_INPUT_HW_JPEG_PATH = "/data/local/tmp/image/test_hw.jpg";
|
||||
@ -257,7 +258,7 @@ HWTEST_F(ImageSourceJpegTest, TC036, TestSize.Level3)
|
||||
decodeOpts.desiredSize.height = 400;
|
||||
decodeOpts.rotateDegrees = 90;
|
||||
std::unique_ptr<PixelMap> pixelMap = imageSource->CreatePixelMap(decodeOpts, errorCode);
|
||||
HiLog::Debug(LABEL_TEST, "create pixel map error code=%{public}u.", errorCode);
|
||||
IMAGE_LOGD("create pixel map error code=%{public}u.", errorCode);
|
||||
ASSERT_EQ(errorCode, SUCCESS);
|
||||
ASSERT_NE(pixelMap.get(), nullptr);
|
||||
EXPECT_EQ(200, pixelMap->GetWidth());
|
||||
@ -987,7 +988,7 @@ HWTEST_F(ImageSourceJpegTest, JpegImageDecode011, TestSize.Level3)
|
||||
*/
|
||||
DecodeOptions decodeOpts;
|
||||
std::unique_ptr<PixelMap> pixelMap = imageSource->CreatePixelMap(decodeOpts, status);
|
||||
HiLog::Debug(LABEL_TEST, "create pixel map ret=%{public}u.", status);
|
||||
IMAGE_LOGD("create pixel map ret=%{public}u.", status);
|
||||
ASSERT_EQ(status, SUCCESS);
|
||||
ASSERT_NE(pixelMap.get(), nullptr);
|
||||
|
||||
@ -1042,7 +1043,7 @@ HWTEST_F(ImageSourceJpegTest, JpgImageCrop001, TestSize.Level3)
|
||||
decodeOpts.desiredSize.height = 400;
|
||||
decodeOpts.rotateDegrees = 90;
|
||||
std::unique_ptr<PixelMap> pixelMap = imageSource->CreatePixelMap(decodeOpts, errorCode);
|
||||
HiLog::Debug(LABEL_TEST, "create pixel map error code=%{public}u.", errorCode);
|
||||
IMAGE_LOGD("create pixel map error code=%{public}u.", errorCode);
|
||||
ASSERT_EQ(errorCode, SUCCESS);
|
||||
ASSERT_NE(pixelMap.get(), nullptr);
|
||||
EXPECT_EQ(200, pixelMap->GetWidth());
|
||||
@ -1073,7 +1074,7 @@ HWTEST_F(ImageSourceJpegTest, JpegImageHwDecode001, TestSize.Level3)
|
||||
*/
|
||||
DecodeOptions decodeOpts;
|
||||
std::unique_ptr<PixelMap> pixelMap = imageSource->CreatePixelMap(decodeOpts, errorCode);
|
||||
HiLog::Debug(LABEL_TEST, "create pixel map ret=%{public}u.", errorCode);
|
||||
IMAGE_LOGD("create pixel map ret=%{public}u.", errorCode);
|
||||
ASSERT_EQ(errorCode, SUCCESS);
|
||||
ASSERT_NE(pixelMap.get(), nullptr);
|
||||
/**
|
||||
|
@ -16,26 +16,27 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <fstream>
|
||||
#include "directory_ex.h"
|
||||
#include "hilog/log.h"
|
||||
#include "image_log.h"
|
||||
#include "image_packer.h"
|
||||
#include "image_source.h"
|
||||
#include "image_source_util.h"
|
||||
#include "image_type.h"
|
||||
#include "image_utils.h"
|
||||
#include "incremental_pixel_map.h"
|
||||
#include "log_tags.h"
|
||||
#include "media_errors.h"
|
||||
#include "pixel_map.h"
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_IMAGE
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "ImageSourcePngTest"
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace OHOS::Media;
|
||||
using namespace OHOS::HiviewDFX;
|
||||
using namespace OHOS::ImageSourceUtil;
|
||||
namespace OHOS {
|
||||
namespace Multimedia {
|
||||
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL_TEST = {
|
||||
LOG_CORE, LOG_TAG_DOMAIN_ID_IMAGE, "ImageSourcePngTest"
|
||||
};
|
||||
static constexpr uint32_t DEFAULT_DELAY_UTIME = 10000; // 10 ms.
|
||||
|
||||
class ImageSourcePngTest : public testing::Test {
|
||||
@ -68,7 +69,7 @@ HWTEST_F(ImageSourcePngTest, PngImageDecode001, TestSize.Level3)
|
||||
*/
|
||||
DecodeOptions decodeOpts;
|
||||
std::unique_ptr<PixelMap> pixelMap = imageSource->CreatePixelMap(decodeOpts, errorCode);
|
||||
HiLog::Debug(LABEL_TEST, "create pixel map error code=%{public}u.", errorCode);
|
||||
IMAGE_LOGD("create pixel map error code=%{public}u.", errorCode);
|
||||
ASSERT_EQ(errorCode, SUCCESS);
|
||||
ASSERT_NE(pixelMap.get(), nullptr);
|
||||
/**
|
||||
@ -204,7 +205,7 @@ HWTEST_F(ImageSourcePngTest, PngImageDecode006, TestSize.Level3)
|
||||
*/
|
||||
DecodeOptions decodeOpts;
|
||||
std::unique_ptr<PixelMap> pixelMap = imageSource->CreatePixelMap(decodeOpts, errorCode);
|
||||
HiLog::Debug(LABEL_TEST, "create pixel map error code=%{public}u.", errorCode);
|
||||
IMAGE_LOGD("create pixel map error code=%{public}u.", errorCode);
|
||||
ASSERT_EQ(errorCode, SUCCESS);
|
||||
ASSERT_NE(pixelMap.get(), nullptr);
|
||||
/**
|
||||
@ -258,7 +259,7 @@ HWTEST_F(ImageSourcePngTest, PngImageDecode007, TestSize.Level3)
|
||||
uint32_t ret = imageSource->UpdateData(buffer + updateSize, updateOnceSize, isCompleted);
|
||||
ASSERT_EQ(ret, SUCCESS);
|
||||
uint8_t decodeProgress = 0;
|
||||
HiLog::Debug(LABEL_TEST, "updateOnceSize:%{public}u,updateSize:%{public}u,bufferSize:%{public}zu",
|
||||
IMAGE_LOGD("updateOnceSize:%{public}u,updateSize:%{public}u,bufferSize:%{public}zu",
|
||||
updateOnceSize, updateSize, bufferSize);
|
||||
incPixelMap->PromoteDecoding(decodeProgress);
|
||||
updateSize += updateOnceSize;
|
||||
@ -490,7 +491,7 @@ HWTEST_F(ImageSourcePngTest, PngImageCrop001, TestSize.Level3)
|
||||
decodeOpts.CropRect.left = 3;
|
||||
decodeOpts.CropRect.height = 40;
|
||||
std::unique_ptr<PixelMap> pixelMap = imageSource->CreatePixelMap(decodeOpts, errorCode);
|
||||
HiLog::Debug(LABEL_TEST, "create pixel map error code=%{public}u.", errorCode);
|
||||
IMAGE_LOGD("create pixel map error code=%{public}u.", errorCode);
|
||||
ASSERT_EQ(errorCode, SUCCESS);
|
||||
ASSERT_NE(pixelMap.get(), nullptr);
|
||||
EXPECT_EQ(200, pixelMap->GetWidth());
|
||||
|
@ -15,7 +15,6 @@
|
||||
|
||||
#include <fstream>
|
||||
#include <gtest/gtest.h>
|
||||
#include "hilog/log.h"
|
||||
#include "directory_ex.h"
|
||||
#include "image_source_util.h"
|
||||
#include "image_packer.h"
|
||||
@ -27,7 +26,6 @@
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace OHOS::Media;
|
||||
using namespace OHOS::HiviewDFX;
|
||||
|
||||
namespace OHOS {
|
||||
namespace Multimedia {
|
||||
|
@ -38,7 +38,6 @@
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace OHOS::Media;
|
||||
using namespace OHOS::HiviewDFX;
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
static const std::string IMAGE_INPUT_JPEG_PATH = "/data/local/tmp/image/test.jpg";
|
||||
@ -1510,5 +1509,307 @@ HWTEST_F(ImageSourceTest, CreatePixelMapForYUVTest001, TestSize.Level3)
|
||||
ASSERT_EQ(ret, nullptr);
|
||||
GTEST_LOG_(INFO) << "ImageSourceTest: CreatePixelMapForYUVTest001 end";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: End2EndTest001
|
||||
* @tc.desc: test CreateImageSource and CreatePixelMap of jpg resource
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ImageSourceTest, End2EndTest001, TestSize.Level3)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "ImageSourceTest: End2EndTest001 start";
|
||||
uint32_t errorCode = 0;
|
||||
SourceOptions opts;
|
||||
std::unique_ptr<ImageSource> imageSource =
|
||||
ImageSource::CreateImageSource("/data/local/tmp/image/test.jpg", opts, errorCode);
|
||||
ASSERT_EQ(errorCode, SUCCESS);
|
||||
ASSERT_NE(imageSource.get(), nullptr);
|
||||
|
||||
int32_t jpegWidth = 472;
|
||||
int32_t jpegHeight = 226;
|
||||
|
||||
DecodeOptions decodeOpts;
|
||||
std::unique_ptr<PixelMap> pixelMap = imageSource->CreatePixelMap(decodeOpts, errorCode);
|
||||
ASSERT_EQ(errorCode, SUCCESS);
|
||||
ASSERT_NE(pixelMap.get(), nullptr);
|
||||
ASSERT_EQ(jpegWidth, pixelMap->GetWidth());
|
||||
ASSERT_EQ(jpegHeight, pixelMap->GetHeight());
|
||||
|
||||
int32_t desiredWidth = 400;
|
||||
int32_t desiredHeight = 200;
|
||||
|
||||
decodeOpts.desiredSize.width = desiredWidth;
|
||||
decodeOpts.desiredSize.height = desiredHeight;
|
||||
pixelMap = imageSource->CreatePixelMap(decodeOpts, errorCode);
|
||||
ASSERT_EQ(errorCode, SUCCESS);
|
||||
ASSERT_NE(pixelMap.get(), nullptr);
|
||||
ASSERT_EQ(desiredWidth, pixelMap->GetWidth());
|
||||
ASSERT_EQ(desiredHeight, pixelMap->GetHeight());
|
||||
|
||||
GTEST_LOG_(INFO) << "ImageSourceTest: End2EndTest001 end";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: End2EndTest002
|
||||
* @tc.desc: test CreateImageSource and CreatePixelMap of png resource
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ImageSourceTest, End2EndTest002, TestSize.Level3)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "ImageSourceTest: End2EndTest002 start";
|
||||
uint32_t errorCode = 0;
|
||||
SourceOptions opts;
|
||||
std::unique_ptr<ImageSource> imageSource =
|
||||
ImageSource::CreateImageSource("/data/local/tmp/image/test.png", opts, errorCode);
|
||||
ASSERT_EQ(errorCode, SUCCESS);
|
||||
ASSERT_NE(imageSource.get(), nullptr);
|
||||
|
||||
int32_t pngWidth = 472;
|
||||
int32_t pngHeight = 75;
|
||||
|
||||
DecodeOptions decodeOpts;
|
||||
std::unique_ptr<PixelMap> pixelMap = imageSource->CreatePixelMap(decodeOpts, errorCode);
|
||||
ASSERT_EQ(errorCode, SUCCESS);
|
||||
ASSERT_NE(pixelMap.get(), nullptr);
|
||||
ASSERT_EQ(pngWidth, pixelMap->GetWidth());
|
||||
ASSERT_EQ(pngHeight, pixelMap->GetHeight());
|
||||
|
||||
int32_t desiredWidth = 400;
|
||||
int32_t desiredHeight = 200;
|
||||
|
||||
decodeOpts.desiredSize.width = desiredWidth;
|
||||
decodeOpts.desiredSize.height = desiredHeight;
|
||||
pixelMap = imageSource->CreatePixelMap(decodeOpts, errorCode);
|
||||
ASSERT_EQ(errorCode, SUCCESS);
|
||||
ASSERT_NE(pixelMap.get(), nullptr);
|
||||
ASSERT_EQ(desiredWidth, pixelMap->GetWidth());
|
||||
ASSERT_EQ(desiredHeight, pixelMap->GetHeight());
|
||||
|
||||
GTEST_LOG_(INFO) << "ImageSourceTest: End2EndTest002 end";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: End2EndTest003
|
||||
* @tc.desc: test CreateImageSource and CreatePixelMap of bmp resource
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ImageSourceTest, End2EndTest003, TestSize.Level3)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "ImageSourceTest: End2EndTest003 start";
|
||||
uint32_t errorCode = 0;
|
||||
SourceOptions opts;
|
||||
std::unique_ptr<ImageSource> imageSource =
|
||||
ImageSource::CreateImageSource("/data/local/tmp/image/test.bmp", opts, errorCode);
|
||||
ASSERT_EQ(errorCode, SUCCESS);
|
||||
ASSERT_NE(imageSource.get(), nullptr);
|
||||
|
||||
int32_t bmpWidth = 472;
|
||||
int32_t bmpHeight = 75;
|
||||
|
||||
DecodeOptions decodeOpts;
|
||||
std::unique_ptr<PixelMap> pixelMap = imageSource->CreatePixelMap(decodeOpts, errorCode);
|
||||
ASSERT_EQ(errorCode, SUCCESS);
|
||||
ASSERT_NE(pixelMap.get(), nullptr);
|
||||
ASSERT_EQ(bmpWidth, pixelMap->GetWidth());
|
||||
ASSERT_EQ(bmpHeight, pixelMap->GetHeight());
|
||||
|
||||
int32_t desiredWidth = 400;
|
||||
int32_t desiredHeight = 200;
|
||||
|
||||
decodeOpts.desiredSize.width = desiredWidth;
|
||||
decodeOpts.desiredSize.height = desiredHeight;
|
||||
pixelMap = imageSource->CreatePixelMap(decodeOpts, errorCode);
|
||||
ASSERT_EQ(errorCode, SUCCESS);
|
||||
ASSERT_NE(pixelMap.get(), nullptr);
|
||||
ASSERT_EQ(desiredWidth, pixelMap->GetWidth());
|
||||
ASSERT_EQ(desiredHeight, pixelMap->GetHeight());
|
||||
|
||||
GTEST_LOG_(INFO) << "ImageSourceTest: End2EndTest003 end";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: End2EndTest004
|
||||
* @tc.desc: test CreateImageSource and CreatePixelMap of ico resource
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ImageSourceTest, End2EndTest004, TestSize.Level3)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "ImageSourceTest: End2EndTest004 start";
|
||||
uint32_t errorCode = 0;
|
||||
SourceOptions opts;
|
||||
std::unique_ptr<ImageSource> imageSource =
|
||||
ImageSource::CreateImageSource("/data/local/tmp/image/test.ico", opts, errorCode);
|
||||
ASSERT_EQ(errorCode, SUCCESS);
|
||||
ASSERT_NE(imageSource.get(), nullptr);
|
||||
|
||||
int32_t icoWidth = 48;
|
||||
int32_t icoHeight = 48;
|
||||
|
||||
DecodeOptions decodeOpts;
|
||||
std::unique_ptr<PixelMap> pixelMap = imageSource->CreatePixelMap(decodeOpts, errorCode);
|
||||
ASSERT_EQ(errorCode, SUCCESS);
|
||||
ASSERT_NE(pixelMap.get(), nullptr);
|
||||
ASSERT_EQ(icoWidth, pixelMap->GetWidth());
|
||||
ASSERT_EQ(icoHeight, pixelMap->GetHeight());
|
||||
|
||||
int32_t desiredWidth = 56;
|
||||
int32_t desiredHeight = 56;
|
||||
|
||||
decodeOpts.desiredSize.width = desiredWidth;
|
||||
decodeOpts.desiredSize.height = desiredHeight;
|
||||
pixelMap = imageSource->CreatePixelMap(decodeOpts, errorCode);
|
||||
ASSERT_EQ(errorCode, SUCCESS);
|
||||
ASSERT_NE(pixelMap.get(), nullptr);
|
||||
ASSERT_EQ(desiredWidth, pixelMap->GetWidth());
|
||||
ASSERT_EQ(desiredHeight, pixelMap->GetHeight());
|
||||
|
||||
GTEST_LOG_(INFO) << "ImageSourceTest: End2EndTest004 end";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: End2EndTest005
|
||||
* @tc.desc: test CreateImageSource and CreatePixelMap of svg resource
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ImageSourceTest, End2EndTest005, TestSize.Level3)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "ImageSourceTest: End2EndTest005 start";
|
||||
uint32_t errorCode = 0;
|
||||
SourceOptions opts;
|
||||
std::unique_ptr<ImageSource> imageSource =
|
||||
ImageSource::CreateImageSource("/data/local/tmp/image/test.svg", opts, errorCode);
|
||||
ASSERT_EQ(errorCode, SUCCESS);
|
||||
ASSERT_NE(imageSource.get(), nullptr);
|
||||
|
||||
int32_t desiredWidth = 56;
|
||||
int32_t desiredHeight = 56;
|
||||
DecodeOptions decodeOpts;
|
||||
decodeOpts.desiredSize.width = desiredWidth;
|
||||
decodeOpts.desiredSize.height = desiredHeight;
|
||||
std::unique_ptr<PixelMap> pixelMap = imageSource->CreatePixelMap(decodeOpts, errorCode);
|
||||
ASSERT_EQ(errorCode, SUCCESS);
|
||||
ASSERT_NE(pixelMap.get(), nullptr);
|
||||
ASSERT_EQ(desiredWidth, pixelMap->GetWidth());
|
||||
ASSERT_EQ(desiredHeight, pixelMap->GetHeight());
|
||||
|
||||
GTEST_LOG_(INFO) << "ImageSourceTest: End2EndTest005 end";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: End2EndTest006
|
||||
* @tc.desc: test CreateImageSource and CreatePixelMap of gif resource
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ImageSourceTest, End2EndTest006, TestSize.Level3)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "ImageSourceTest: End2EndTest006 start";
|
||||
uint32_t errorCode = 0;
|
||||
SourceOptions opts;
|
||||
std::unique_ptr<ImageSource> imageSource =
|
||||
ImageSource::CreateImageSource("/data/local/tmp/image/test.gif", opts, errorCode);
|
||||
ASSERT_EQ(errorCode, SUCCESS);
|
||||
ASSERT_NE(imageSource.get(), nullptr);
|
||||
|
||||
int32_t gifWidth = 198;
|
||||
int32_t gifHeight = 202;
|
||||
|
||||
DecodeOptions decodeOpts;
|
||||
std::unique_ptr<PixelMap> pixelMap = imageSource->CreatePixelMap(decodeOpts, errorCode);
|
||||
ASSERT_EQ(errorCode, SUCCESS);
|
||||
ASSERT_NE(pixelMap.get(), nullptr);
|
||||
ASSERT_EQ(gifWidth, pixelMap->GetWidth());
|
||||
ASSERT_EQ(gifHeight, pixelMap->GetHeight());
|
||||
|
||||
int32_t desiredWidth = 150;
|
||||
int32_t desiredHeight = 150;
|
||||
|
||||
decodeOpts.desiredSize.width = desiredWidth;
|
||||
decodeOpts.desiredSize.height = desiredHeight;
|
||||
pixelMap = imageSource->CreatePixelMap(decodeOpts, errorCode);
|
||||
ASSERT_EQ(errorCode, SUCCESS);
|
||||
ASSERT_NE(pixelMap.get(), nullptr);
|
||||
ASSERT_EQ(desiredWidth, pixelMap->GetWidth());
|
||||
ASSERT_EQ(desiredHeight, pixelMap->GetHeight());
|
||||
|
||||
GTEST_LOG_(INFO) << "ImageSourceTest: End2EndTest006 end";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: End2EndTest007
|
||||
* @tc.desc: test CreateImageSource and CreatePixelMap of webp resource
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ImageSourceTest, End2EndTest007, TestSize.Level3)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "ImageSourceTest: End2EndTest007 start";
|
||||
uint32_t errorCode = 0;
|
||||
SourceOptions opts;
|
||||
std::unique_ptr<ImageSource> imageSource =
|
||||
ImageSource::CreateImageSource("/data/local/tmp/image/test.webp", opts, errorCode);
|
||||
ASSERT_EQ(errorCode, SUCCESS);
|
||||
ASSERT_NE(imageSource.get(), nullptr);
|
||||
|
||||
int32_t webpWidth = 286;
|
||||
int32_t webpHeight = 221;
|
||||
|
||||
DecodeOptions decodeOpts;
|
||||
std::unique_ptr<PixelMap> pixelMap = imageSource->CreatePixelMap(decodeOpts, errorCode);
|
||||
ASSERT_EQ(errorCode, SUCCESS);
|
||||
ASSERT_NE(pixelMap.get(), nullptr);
|
||||
ASSERT_EQ(webpWidth, pixelMap->GetWidth());
|
||||
ASSERT_EQ(webpHeight, pixelMap->GetHeight());
|
||||
|
||||
int32_t desiredWidth = 150;
|
||||
int32_t desiredHeight = 150;
|
||||
|
||||
decodeOpts.desiredSize.width = desiredWidth;
|
||||
decodeOpts.desiredSize.height = desiredHeight;
|
||||
pixelMap = imageSource->CreatePixelMap(decodeOpts, errorCode);
|
||||
ASSERT_EQ(errorCode, SUCCESS);
|
||||
ASSERT_NE(pixelMap.get(), nullptr);
|
||||
ASSERT_EQ(desiredWidth, pixelMap->GetWidth());
|
||||
ASSERT_EQ(desiredHeight, pixelMap->GetHeight());
|
||||
|
||||
GTEST_LOG_(INFO) << "ImageSourceTest: End2EndTest007 end";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: End2EndTest008
|
||||
* @tc.desc: test CreateImageSource and CreatePixelMap of dng resource
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ImageSourceTest, End2EndTest008, TestSize.Level3)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "ImageSourceTest: End2EndTest008 start";
|
||||
uint32_t errorCode = 0;
|
||||
SourceOptions opts;
|
||||
std::unique_ptr<ImageSource> imageSource =
|
||||
ImageSource::CreateImageSource("/data/local/tmp/image/test.dng", opts, errorCode);
|
||||
ASSERT_EQ(errorCode, SUCCESS);
|
||||
ASSERT_NE(imageSource.get(), nullptr);
|
||||
|
||||
int32_t webpWidth = 160;
|
||||
int32_t webpHeight = 120;
|
||||
|
||||
DecodeOptions decodeOpts;
|
||||
std::unique_ptr<PixelMap> pixelMap = imageSource->CreatePixelMap(decodeOpts, errorCode);
|
||||
ASSERT_EQ(errorCode, SUCCESS);
|
||||
ASSERT_NE(pixelMap.get(), nullptr);
|
||||
ASSERT_EQ(webpWidth, pixelMap->GetWidth());
|
||||
ASSERT_EQ(webpHeight, pixelMap->GetHeight());
|
||||
|
||||
int32_t desiredWidth = 100;
|
||||
int32_t desiredHeight = 100;
|
||||
|
||||
decodeOpts.desiredSize.width = desiredWidth;
|
||||
decodeOpts.desiredSize.height = desiredHeight;
|
||||
pixelMap = imageSource->CreatePixelMap(decodeOpts, errorCode);
|
||||
ASSERT_EQ(errorCode, SUCCESS);
|
||||
ASSERT_NE(pixelMap.get(), nullptr);
|
||||
ASSERT_EQ(desiredWidth, pixelMap->GetWidth());
|
||||
ASSERT_EQ(desiredHeight, pixelMap->GetHeight());
|
||||
|
||||
GTEST_LOG_(INFO) << "ImageSourceTest: End2EndTest008 end";
|
||||
}
|
||||
} // namespace Multimedia
|
||||
} // namespace OHOS
|
@ -16,20 +16,23 @@
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include "directory_ex.h"
|
||||
#include "hilog/log.h"
|
||||
#include "image_log.h"
|
||||
#include "image_packer.h"
|
||||
#include "image_type.h"
|
||||
#include "image_utils.h"
|
||||
#include "log_tags.h"
|
||||
#include "media_errors.h"
|
||||
#include "pixel_map.h"
|
||||
#include "image_source_util.h"
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_IMAGE
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "ImageSourceUtil"
|
||||
|
||||
using namespace OHOS::Media;
|
||||
using namespace OHOS::HiviewDFX;
|
||||
using namespace OHOS::ImageSourceUtil;
|
||||
|
||||
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL_TEST = { LOG_CORE, LOG_TAG_DOMAIN_ID_IMAGE, "ImageSourceUtil" };
|
||||
namespace OHOS {
|
||||
namespace ImageSourceUtil {
|
||||
constexpr uint32_t NUM_1 = 1;
|
||||
@ -45,12 +48,12 @@ int64_t PackImage(const std::string &filePath, std::unique_ptr<PixelMap> pixelMa
|
||||
option.numberHint = NUM_1;
|
||||
std::set<std::string> formats;
|
||||
if (pixelMap == nullptr) {
|
||||
HiLog::Error(LABEL_TEST, "pixelMap is nullptr");
|
||||
IMAGE_LOGE("pixelMap is nullptr");
|
||||
return 0;
|
||||
}
|
||||
uint32_t ret = imagePacker.GetSupportedFormats(formats);
|
||||
if (ret != SUCCESS) {
|
||||
HiLog::Error(LABEL_TEST, "image packer get supported format failed, ret=%{public}u.", ret);
|
||||
IMAGE_LOGE("image packer get supported format failed, ret=%{public}u.", ret);
|
||||
return 0;
|
||||
}
|
||||
imagePacker.StartPacking(filePath, option);
|
||||
@ -69,18 +72,18 @@ int64_t PackImage(std::unique_ptr<ImageSource> imageSource)
|
||||
option.numberHint = 1;
|
||||
std::set<std::string> formats;
|
||||
if (imageSource == nullptr) {
|
||||
HiLog::Error(LABEL_TEST, "imageSource is nullptr");
|
||||
IMAGE_LOGE("imageSource is nullptr");
|
||||
return 0;
|
||||
}
|
||||
uint32_t ret = imagePacker.GetSupportedFormats(formats);
|
||||
if (ret != SUCCESS) {
|
||||
HiLog::Error(LABEL_TEST, "image packer get supported format failed, ret=%{public}u.", ret);
|
||||
IMAGE_LOGE("image packer get supported format failed, ret=%{public}u.", ret);
|
||||
return 0;
|
||||
}
|
||||
int64_t bufferSize = BUFFER_SIZE;
|
||||
uint8_t *resultBuffer = reinterpret_cast<uint8_t *>(malloc(bufferSize));
|
||||
if (resultBuffer == nullptr) {
|
||||
HiLog::Error(LABEL_TEST, "image packer malloc buffer failed.");
|
||||
IMAGE_LOGE("image packer malloc buffer failed.");
|
||||
return 0;
|
||||
}
|
||||
imagePacker.StartPacking(resultBuffer, bufferSize, option);
|
||||
@ -94,32 +97,31 @@ bool ReadFileToBuffer(const std::string &filePath, uint8_t *buffer, size_t buffe
|
||||
{
|
||||
std::string realPath;
|
||||
if (!OHOS::PathToRealPath(filePath, realPath)) {
|
||||
HiLog::Error(LABEL_TEST, "file path to real path failed, file path=%{public}s.", filePath.c_str());
|
||||
IMAGE_LOGE("file path to real path failed, file path=%{public}s.", filePath.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (buffer == nullptr) {
|
||||
HiLog::Error(LABEL_TEST, "buffer is nullptr");
|
||||
IMAGE_LOGE("buffer is nullptr");
|
||||
return false;
|
||||
}
|
||||
|
||||
FILE *fp = fopen(realPath.c_str(), "rb");
|
||||
if (fp == nullptr) {
|
||||
HiLog::Error(LABEL_TEST, "open file failed, real path=%{public}s.", realPath.c_str());
|
||||
IMAGE_LOGE("open file failed, real path=%{public}s.", realPath.c_str());
|
||||
return false;
|
||||
}
|
||||
fseek(fp, 0, SEEK_END);
|
||||
size_t fileSize = ftell(fp);
|
||||
fseek(fp, 0, SEEK_SET);
|
||||
if (bufferSize < fileSize) {
|
||||
HiLog::Error(LABEL_TEST, "buffer size:(%{public}zu) is smaller than file size:(%{public}zu).", bufferSize,
|
||||
fileSize);
|
||||
IMAGE_LOGE("buffer size:(%{public}zu) is smaller than file size:(%{public}zu).", bufferSize, fileSize);
|
||||
fclose(fp);
|
||||
return false;
|
||||
}
|
||||
size_t retSize = fread(buffer, 1, fileSize, fp);
|
||||
if (retSize != fileSize) {
|
||||
HiLog::Error(LABEL_TEST, "read file result size = %{public}zu, size = %{public}zu.", retSize, fileSize);
|
||||
IMAGE_LOGE("read file result size = %{public}zu, size = %{public}zu.", retSize, fileSize);
|
||||
fclose(fp);
|
||||
return false;
|
||||
}
|
||||
|
@ -16,7 +16,6 @@
|
||||
#include <fstream>
|
||||
#include <gtest/gtest.h>
|
||||
#include "directory_ex.h"
|
||||
#include "hilog/log.h"
|
||||
#include "image_packer.h"
|
||||
#include "image_source.h"
|
||||
#include "image_source_util.h"
|
||||
@ -27,7 +26,6 @@
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace OHOS::Media;
|
||||
using namespace OHOS::HiviewDFX;
|
||||
|
||||
namespace OHOS {
|
||||
namespace Multimedia {
|
||||
|
@ -16,27 +16,28 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <fstream>
|
||||
#include "directory_ex.h"
|
||||
#include "hilog/log.h"
|
||||
#include "image_log.h"
|
||||
#include "image_packer.h"
|
||||
#include "image_source.h"
|
||||
#include "image_source_util.h"
|
||||
#include "image_type.h"
|
||||
#include "image_utils.h"
|
||||
#include "incremental_pixel_map.h"
|
||||
#include "log_tags.h"
|
||||
#include "media_errors.h"
|
||||
#include "pixel_map.h"
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_IMAGE
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "ImageSourceWebpTest"
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace OHOS::Media;
|
||||
using namespace OHOS::HiviewDFX;
|
||||
using namespace OHOS::ImageSourceUtil;
|
||||
|
||||
namespace OHOS {
|
||||
namespace Multimedia {
|
||||
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL_TEST = {
|
||||
LOG_CORE, LOG_TAG_DOMAIN_ID_IMAGE, "ImageSourceWebpTest"
|
||||
};
|
||||
static constexpr uint32_t DEFAULT_DELAY_UTIME = 10000; // 10 ms.
|
||||
static const std::string IMAGE_INPUT_WEBP_PATH = "/data/local/tmp/image/test_large.webp";
|
||||
static const std::string IMAGE_INPUT_HW_JPEG_PATH = "/data/local/tmp/image/test_hw.jpg";
|
||||
@ -530,7 +531,7 @@ HWTEST_F(ImageSourceWebpTest, WebpImageCrop001, TestSize.Level3)
|
||||
decodeOpts.desiredSize.height = 300;
|
||||
decodeOpts.rotateDegrees = 90;
|
||||
std::unique_ptr<PixelMap> pixelMap = imageSource->CreatePixelMap(decodeOpts, errorCode);
|
||||
HiLog::Debug(LABEL_TEST, "create pixel map error code=%{public}u.", errorCode);
|
||||
IMAGE_LOGD("create pixel map error code=%{public}u.", errorCode);
|
||||
ASSERT_EQ(errorCode, SUCCESS);
|
||||
ASSERT_NE(pixelMap.get(), nullptr);
|
||||
EXPECT_EQ(200, pixelMap->GetWidth());
|
||||
|
@ -19,7 +19,6 @@
|
||||
#include "jpeg_decoder.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace OHOS::HiviewDFX;
|
||||
namespace OHOS {
|
||||
namespace ImagePlugin {
|
||||
class JpegUtilsTest : public testing::Test {
|
||||
|
@ -18,13 +18,10 @@
|
||||
#include <dirent.h>
|
||||
#include <iostream>
|
||||
#include <sys/stat.h>
|
||||
#include "hilog/log.h"
|
||||
#include "log_tags.h"
|
||||
#include "unistd.h"
|
||||
#include "directory_ex.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace OHOS::HiviewDFX;
|
||||
namespace OHOS {
|
||||
namespace Multimedia {
|
||||
class MockDirectoryExTest : public testing::Test {
|
||||
|
@ -18,12 +18,10 @@
|
||||
|
||||
#include "astc_codec.h"
|
||||
#include "buffer_packer_stream.h"
|
||||
#include "hilog/log.h"
|
||||
#include "image_compressor.h"
|
||||
#include "image_source_util.h"
|
||||
#include "image_system_properties.h"
|
||||
#include "image_utils.h"
|
||||
#include "log_tags.h"
|
||||
#include "media_errors.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
|
@ -16,14 +16,11 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <fstream>
|
||||
#include <cmath>
|
||||
#include <log_tags.h>
|
||||
#include "hilog/log.h"
|
||||
#include "securec.h"
|
||||
#include "memory.h"
|
||||
#include "nine_patch_listener.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace OHOS::HiviewDFX;
|
||||
namespace OHOS {
|
||||
namespace Multimedia {
|
||||
class NinePathListenerTest : public testing::Test {
|
||||
|
@ -19,7 +19,6 @@
|
||||
#include "image_source.h"
|
||||
#include "image_type.h"
|
||||
#include "image_utils.h"
|
||||
#include "hilog/log.h"
|
||||
#include "media_errors.h"
|
||||
#include "pixel_map.h"
|
||||
#include "image_source_util.h"
|
||||
|
@ -19,12 +19,16 @@
|
||||
#include "hilog/log.h"
|
||||
#include "log_tags.h"
|
||||
|
||||
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_IMAGE, "ImageCode" };
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_IMAGE
|
||||
|
||||
#define IMAGE_LOGF(...) (void)OHOS::HiviewDFX::HiLog::Fatal(LABEL, __VA_ARGS__)
|
||||
#define IMAGE_LOGE(...) (void)OHOS::HiviewDFX::HiLog::Error(LABEL, __VA_ARGS__)
|
||||
#define IMAGE_LOGW(...) (void)OHOS::HiviewDFX::HiLog::Warn(LABEL, __VA_ARGS__)
|
||||
#define IMAGE_LOGI(...) (void)OHOS::HiviewDFX::HiLog::Info(LABEL, __VA_ARGS__)
|
||||
#define IMAGE_LOGD(...) (void)OHOS::HiviewDFX::HiLog::Debug(LABEL, __VA_ARGS__)
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "ImageCode"
|
||||
|
||||
#define IMAGE_LOGF(...) HILOG_FATAL(LOG_CORE, __VA_ARGS__)
|
||||
#define IMAGE_LOGE(...) HILOG_ERROR(LOG_CORE, __VA_ARGS__)
|
||||
#define IMAGE_LOGW(...) HILOG_WARN(LOG_CORE, __VA_ARGS__)
|
||||
#define IMAGE_LOGI(...) HILOG_INFO(LOG_CORE, __VA_ARGS__)
|
||||
#define IMAGE_LOGD(...) HILOG_DEBUG(LOG_CORE, __VA_ARGS__)
|
||||
|
||||
#endif // FRAMEWORKS_INNERKITSIMPL_UTILS_INCLUDE_IMAGE_LOG_H
|
||||
|
@ -26,8 +26,7 @@
|
||||
#include <sstream>
|
||||
|
||||
#include "__config"
|
||||
#include "hilog/log.h"
|
||||
#include "log_tags.h"
|
||||
#include "image_log.h"
|
||||
#include "ios"
|
||||
#include "istream"
|
||||
#include "media_errors.h"
|
||||
@ -47,13 +46,17 @@
|
||||
#include "refbase.h"
|
||||
#endif
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_IMAGE
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "imageUtils"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
using namespace OHOS::HiviewDFX;
|
||||
using namespace std;
|
||||
using namespace MultimediaPlugin;
|
||||
|
||||
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_IMAGE, "imageUtils" };
|
||||
constexpr int32_t ALPHA8_BYTES = 1;
|
||||
constexpr int32_t RGB565_BYTES = 2;
|
||||
constexpr int32_t RGB888_BYTES = 3;
|
||||
@ -74,13 +77,13 @@ static const string FILE_DIR_IN_THE_SANDBOX = "/data/storage/el2/base/files/";
|
||||
bool ImageUtils::GetFileSize(const string &pathName, size_t &size)
|
||||
{
|
||||
if (pathName.empty()) {
|
||||
HiLog::Error(LABEL, "[ImageUtil]input parameter exception.");
|
||||
IMAGE_LOGE("[ImageUtil]input parameter exception.");
|
||||
return false;
|
||||
}
|
||||
struct stat statbuf;
|
||||
int ret = stat(pathName.c_str(), &statbuf);
|
||||
if (ret != 0) {
|
||||
HiLog::Error(LABEL, "[ImageUtil]get the file size failed, ret:%{public}d, errno:%{public}d.", ret, errno);
|
||||
IMAGE_LOGE("[ImageUtil]get the file size failed, ret:%{public}d, errno:%{public}d.", ret, errno);
|
||||
return false;
|
||||
}
|
||||
size = statbuf.st_size;
|
||||
@ -97,7 +100,7 @@ bool ImageUtils::GetFileSize(const int fd, size_t &size)
|
||||
|
||||
int ret = fstat(fd, &statbuf);
|
||||
if (ret != 0) {
|
||||
HiLog::Error(LABEL, "[ImageUtil]get the file size failed, ret:%{public}d, errno:%{public}d.", ret, errno);
|
||||
IMAGE_LOGE("[ImageUtil]get the file size failed, ret:%{public}d, errno:%{public}d.", ret, errno);
|
||||
return false;
|
||||
}
|
||||
size = statbuf.st_size;
|
||||
@ -107,7 +110,7 @@ bool ImageUtils::GetFileSize(const int fd, size_t &size)
|
||||
bool ImageUtils::GetInputStreamSize(istream &inputStream, size_t &size)
|
||||
{
|
||||
if (inputStream.rdbuf() == nullptr) {
|
||||
HiLog::Error(LABEL, "[ImageUtil]input parameter exception.");
|
||||
IMAGE_LOGE("[ImageUtil]input parameter exception.");
|
||||
return false;
|
||||
}
|
||||
size_t original = inputStream.tellg();
|
||||
@ -149,7 +152,7 @@ int32_t ImageUtils::GetPixelBytes(const PixelFormat &pixelFormat)
|
||||
pixelBytes = ASTC_4X4_BYTES;
|
||||
break;
|
||||
default:
|
||||
HiLog::Error(LABEL, "[ImageUtil]get pixel bytes failed, pixelFormat:%{public}d.",
|
||||
IMAGE_LOGE("[ImageUtil]get pixel bytes failed, pixelFormat:%{public}d.",
|
||||
static_cast<int32_t>(pixelFormat));
|
||||
break;
|
||||
}
|
||||
@ -170,10 +173,10 @@ uint32_t ImageUtils::RegisterPluginServer()
|
||||
PluginServer &pluginServer = DelayedRefSingleton<PluginServer>::GetInstance();
|
||||
uint32_t result = pluginServer.Register(std::move(pluginPaths));
|
||||
if (result != SUCCESS) {
|
||||
HiLog::Error(LABEL, "[ImageUtil]failed to register plugin server, ERRNO: %{public}u.", result);
|
||||
IMAGE_LOGE("[ImageUtil]failed to register plugin server, ERRNO: %{public}u.", result);
|
||||
} else {
|
||||
g_pluginRegistered = true;
|
||||
HiLog::Info(LABEL, "[ImageUtil]success to register plugin server");
|
||||
IMAGE_LOGI("[ImageUtil]success to register plugin server");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -183,7 +186,7 @@ PluginServer& ImageUtils::GetPluginServer()
|
||||
if (!g_pluginRegistered) {
|
||||
uint32_t result = RegisterPluginServer();
|
||||
if (result != SUCCESS) {
|
||||
HiLog::Info(LABEL, "[ImageUtil]failed to register plugin server, ERRNO: %{public}u.", result);
|
||||
IMAGE_LOGI("[ImageUtil]failed to register plugin server, ERRNO: %{public}u.", result);
|
||||
}
|
||||
}
|
||||
return DelayedRefSingleton<PluginServer>::GetInstance();
|
||||
@ -192,12 +195,12 @@ PluginServer& ImageUtils::GetPluginServer()
|
||||
bool ImageUtils::PathToRealPath(const string &path, string &realPath)
|
||||
{
|
||||
if (path.empty()) {
|
||||
HiLog::Error(LABEL, "path is empty!");
|
||||
IMAGE_LOGE("path is empty!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((path.length() >= PATH_MAX)) {
|
||||
HiLog::Error(LABEL, "path len is error, the len is: [%{public}lu]", static_cast<unsigned long>(path.length()));
|
||||
IMAGE_LOGE("path len is error, the len is: [%{public}lu]", static_cast<unsigned long>(path.length()));
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -205,11 +208,11 @@ bool ImageUtils::PathToRealPath(const string &path, string &realPath)
|
||||
|
||||
#ifdef _WIN32
|
||||
if (_fullpath(tmpPath, path.c_str(), path.length()) == nullptr) {
|
||||
HiLog::Warn(LABEL, "path to _fullpath error");
|
||||
IMAGE_LOGW("path to _fullpath error");
|
||||
}
|
||||
#else
|
||||
if (realpath(path.c_str(), tmpPath) == nullptr) {
|
||||
HiLog::Error(LABEL, "path to realpath is nullptr");
|
||||
IMAGE_LOGE("path to realpath is nullptr");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
@ -249,7 +252,7 @@ AlphaType ImageUtils::GetValidAlphaTypeByFormat(const AlphaType &dstType, const
|
||||
case PixelFormat::NV12:
|
||||
case PixelFormat::CMYK:
|
||||
default: {
|
||||
HiLog::Error(LABEL, "GetValidAlphaTypeByFormat unsupport the format(%{public}d).", format);
|
||||
IMAGE_LOGE("GetValidAlphaTypeByFormat unsupport the format(%{public}d).", format);
|
||||
return AlphaType::IMAGE_ALPHA_TYPE_UNKNOWN;
|
||||
}
|
||||
}
|
||||
@ -260,11 +263,11 @@ bool ImageUtils::IsValidImageInfo(const ImageInfo &info)
|
||||
{
|
||||
if (info.size.width <= 0 || info.size.height <= 0 || info.size.width > MAX_DIMENSION ||
|
||||
info.size.height > MAX_DIMENSION) {
|
||||
HiLog::Error(LABEL, "width(%{public}d) or height(%{public}d) is invalid.", info.size.width, info.size.height);
|
||||
IMAGE_LOGE("width(%{public}d) or height(%{public}d) is invalid.", info.size.width, info.size.height);
|
||||
return false;
|
||||
}
|
||||
if (info.pixelFormat == PixelFormat::UNKNOWN || info.alphaType == AlphaType::IMAGE_ALPHA_TYPE_UNKNOWN) {
|
||||
HiLog::Error(LABEL, "check pixelformat and alphatype is invalid.");
|
||||
IMAGE_LOGE("check pixelformat and alphatype is invalid.");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -273,12 +276,12 @@ bool ImageUtils::IsValidImageInfo(const ImageInfo &info)
|
||||
bool ImageUtils::CheckMulOverflow(int32_t width, int32_t bytesPerPixel)
|
||||
{
|
||||
if (width == 0 || bytesPerPixel == 0) {
|
||||
HiLog::Error(LABEL, "param is 0");
|
||||
IMAGE_LOGE("param is 0");
|
||||
return true;
|
||||
}
|
||||
int64_t rowSize = static_cast<int64_t>(width) * bytesPerPixel;
|
||||
if ((rowSize / width) != bytesPerPixel) {
|
||||
HiLog::Error(LABEL, "width * bytesPerPixel overflow!");
|
||||
IMAGE_LOGE("width * bytesPerPixel overflow!");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -287,17 +290,17 @@ bool ImageUtils::CheckMulOverflow(int32_t width, int32_t bytesPerPixel)
|
||||
bool ImageUtils::CheckMulOverflow(int32_t width, int32_t height, int32_t bytesPerPixel)
|
||||
{
|
||||
if (width == 0 || height == 0 || bytesPerPixel == 0) {
|
||||
HiLog::Error(LABEL, "param is 0");
|
||||
IMAGE_LOGE("param is 0");
|
||||
return true;
|
||||
}
|
||||
int64_t rectSize = static_cast<int64_t>(width) * height;
|
||||
if ((rectSize / width) != height) {
|
||||
HiLog::Error(LABEL, "width * height overflow!");
|
||||
IMAGE_LOGE("width * height overflow!");
|
||||
return true;
|
||||
}
|
||||
int64_t bufferSize = rectSize * bytesPerPixel;
|
||||
if ((bufferSize / bytesPerPixel) != rectSize) {
|
||||
HiLog::Error(LABEL, "bytesPerPixel overflow!");
|
||||
IMAGE_LOGE("bytesPerPixel overflow!");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -306,7 +309,7 @@ bool ImageUtils::CheckMulOverflow(int32_t width, int32_t height, int32_t bytesPe
|
||||
static void ReversePixels(uint8_t* srcPixels, uint8_t* dstPixels, uint32_t byteCount)
|
||||
{
|
||||
if (byteCount % NUM_4 != NUM_0) {
|
||||
HiLog::Error(LABEL, "Pixel count must multiple of 4.");
|
||||
IMAGE_LOGE("Pixel count must multiple of 4.");
|
||||
return;
|
||||
}
|
||||
uint8_t *src = srcPixels;
|
||||
@ -336,7 +339,7 @@ void ImageUtils::ARGBToBGRA(uint8_t* srcPixels, uint8_t* dstPixels, uint32_t byt
|
||||
int32_t ImageUtils::SurfaceBuffer_Reference(void* buffer)
|
||||
{
|
||||
if (buffer == nullptr) {
|
||||
HiLog::Error(LABEL, "parameter error, please check input parameter");
|
||||
IMAGE_LOGE("parameter error, please check input parameter");
|
||||
return ERR_SURFACEBUFFER_REFERENCE_FAILED;
|
||||
}
|
||||
OHOS::RefBase *ref = reinterpret_cast<OHOS::RefBase *>(buffer);
|
||||
@ -347,7 +350,7 @@ int32_t ImageUtils::SurfaceBuffer_Reference(void* buffer)
|
||||
int32_t ImageUtils::SurfaceBuffer_Unreference(void* buffer)
|
||||
{
|
||||
if (buffer == nullptr) {
|
||||
HiLog::Error(LABEL, "parameter error, please check input parameter");
|
||||
IMAGE_LOGE("parameter error, please check input parameter");
|
||||
return ERR_SURFACEBUFFER_UNREFERENCE_FAILED;
|
||||
}
|
||||
OHOS::RefBase *ref = reinterpret_cast<OHOS::RefBase *>(buffer);
|
||||
@ -361,19 +364,19 @@ void ImageUtils::DumpPixelMapIfDumpEnabled(std::unique_ptr<PixelMap>& pixelMap,
|
||||
return;
|
||||
}
|
||||
if (pixelMap == nullptr) {
|
||||
HiLog::Info(LABEL, "ImageUtils::DumpPixelMapIfDumpEnabled pixelMap is null");
|
||||
IMAGE_LOGI("ImageUtils::DumpPixelMapIfDumpEnabled pixelMap is null");
|
||||
return;
|
||||
}
|
||||
|
||||
HiLog::Info(LABEL, "ImageUtils::DumpPixelMapIfDumpEnabled start");
|
||||
IMAGE_LOGI("ImageUtils::DumpPixelMapIfDumpEnabled start");
|
||||
std::string fileName = FILE_DIR_IN_THE_SANDBOX + GetLocalTime() + "_imageId" + std::to_string(imageId) +
|
||||
GetPixelMapName(pixelMap.get()) + ".dat";
|
||||
int32_t totalSize = pixelMap->GetRowStride() * pixelMap->GetHeight();
|
||||
if (SUCCESS != SaveDataToFile(fileName, reinterpret_cast<const char*>(pixelMap->GetPixels()), totalSize)) {
|
||||
HiLog::Info(LABEL, "ImageUtils::DumpPixelMapIfDumpEnabled failed");
|
||||
IMAGE_LOGI("ImageUtils::DumpPixelMapIfDumpEnabled failed");
|
||||
return;
|
||||
}
|
||||
HiLog::Info(LABEL, "ImageUtils::DumpPixelMapIfDumpEnabled success, path = %{public}s", fileName.c_str());
|
||||
IMAGE_LOGI("ImageUtils::DumpPixelMapIfDumpEnabled success, path = %{public}s", fileName.c_str());
|
||||
}
|
||||
|
||||
void ImageUtils::DumpPixelMapBeforeEncode(PixelMap& pixelMap)
|
||||
@ -381,15 +384,15 @@ void ImageUtils::DumpPixelMapBeforeEncode(PixelMap& pixelMap)
|
||||
if (!ImageSystemProperties::GetDumpImageEnabled()) {
|
||||
return;
|
||||
}
|
||||
HiLog::Info(LABEL, "ImageUtils::DumpPixelMapBeforeEncode start");
|
||||
IMAGE_LOGI("ImageUtils::DumpPixelMapBeforeEncode start");
|
||||
std::string fileName = FILE_DIR_IN_THE_SANDBOX + GetLocalTime() + "_beforeEncode" + GetPixelMapName(&pixelMap) +
|
||||
".dat";
|
||||
int32_t totalSize = pixelMap.GetRowStride() * pixelMap.GetHeight();
|
||||
if (SUCCESS != SaveDataToFile(fileName, reinterpret_cast<const char*>(pixelMap.GetPixels()), totalSize)) {
|
||||
HiLog::Info(LABEL, "ImageUtils::DumpPixelMapBeforeEncode failed");
|
||||
IMAGE_LOGI("ImageUtils::DumpPixelMapBeforeEncode failed");
|
||||
return;
|
||||
}
|
||||
HiLog::Info(LABEL, "ImageUtils::DumpPixelMapBeforeEncode success, path = %{public}s", fileName.c_str());
|
||||
IMAGE_LOGI("ImageUtils::DumpPixelMapBeforeEncode success, path = %{public}s", fileName.c_str());
|
||||
}
|
||||
|
||||
void ImageUtils::DumpDataIfDumpEnabled(const char* data, const size_t& totalSize,
|
||||
@ -401,17 +404,17 @@ void ImageUtils::DumpDataIfDumpEnabled(const char* data, const size_t& totalSize
|
||||
std::string fileName = FILE_DIR_IN_THE_SANDBOX + GetLocalTime() + "_imageId" + std::to_string(imageId) +
|
||||
"_data_total" + std::to_string(totalSize) + "." + fileSuffix;
|
||||
if (SUCCESS != SaveDataToFile(fileName, data, totalSize)) {
|
||||
HiLog::Info(LABEL, "ImageUtils::DumpDataIfDumpEnabled failed");
|
||||
IMAGE_LOGI("ImageUtils::DumpDataIfDumpEnabled failed");
|
||||
return;
|
||||
}
|
||||
HiLog::Info(LABEL, "ImageUtils::DumpDataIfDumpEnabled success, path = %{public}s", fileName.c_str());
|
||||
IMAGE_LOGI("ImageUtils::DumpDataIfDumpEnabled success, path = %{public}s", fileName.c_str());
|
||||
}
|
||||
|
||||
uint32_t ImageUtils::SaveDataToFile(const std::string& fileName, const char* data, const size_t& totalSize)
|
||||
{
|
||||
std::ofstream outFile(fileName, std::ofstream::out);
|
||||
if (!outFile.is_open()) {
|
||||
HiLog::Info(LABEL, "ImageUtils::SaveDataToFile write error, path=%{public}s", fileName.c_str());
|
||||
IMAGE_LOGI("ImageUtils::SaveDataToFile write error, path=%{public}s", fileName.c_str());
|
||||
return IMAGE_RESULT_SAVE_DATA_TO_FILE_FAILED;
|
||||
}
|
||||
outFile.write(data, totalSize);
|
||||
@ -435,7 +438,7 @@ std::string ImageUtils::GetLocalTime()
|
||||
std::string ImageUtils::GetPixelMapName(PixelMap* pixelMap)
|
||||
{
|
||||
if (!pixelMap) {
|
||||
HiLog::Error(LABEL, "ImageUtils::GetPixelMapName error, pixelMap is null");
|
||||
IMAGE_LOGE("ImageUtils::GetPixelMapName error, pixelMap is null");
|
||||
return "";
|
||||
}
|
||||
std::string pixelMapStr = "_pixelMap_w" + std::to_string(pixelMap->GetWidth()) +
|
||||
|
@ -16,14 +16,12 @@
|
||||
#include "image_creator_napi.h"
|
||||
#include <uv.h>
|
||||
#include "media_errors.h"
|
||||
#include "hilog/log.h"
|
||||
#include "image_log.h"
|
||||
#include "image_napi_utils.h"
|
||||
#include "image_creator_context.h"
|
||||
#include "image_napi.h"
|
||||
#include "image_creator_manager.h"
|
||||
#include "log_tags.h"
|
||||
|
||||
using OHOS::HiviewDFX::HiLog;
|
||||
using std::string;
|
||||
using std::shared_ptr;
|
||||
using std::unique_ptr;
|
||||
@ -31,8 +29,13 @@ using std::vector;
|
||||
using std::make_shared;
|
||||
using std::make_unique;
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_IMAGE
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "ImageCreatorNapi"
|
||||
|
||||
namespace {
|
||||
constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_TAG_DOMAIN_ID_IMAGE, "ImageCreatorNapi"};
|
||||
constexpr int32_t TEST_WIDTH = 8192;
|
||||
constexpr int32_t TEST_HEIGHT = 8;
|
||||
constexpr int32_t TEST_FORMAT = 4;
|
||||
@ -161,7 +164,7 @@ napi_value ImageCreatorNapi::Init(napi_env env, napi_value exports)
|
||||
IMAGE_ERR("define properties fail")
|
||||
);
|
||||
|
||||
HiLog::Debug(LABEL, "Init success");
|
||||
IMAGE_DEBUG("Init success");
|
||||
|
||||
IMAGE_FUNCTION_OUT();
|
||||
return exports;
|
||||
|
@ -16,14 +16,18 @@
|
||||
#include "image_napi.h"
|
||||
|
||||
#include "napi/native_node_api.h"
|
||||
#include "hilog/log.h"
|
||||
#include "image_log.h"
|
||||
#include "media_errors.h"
|
||||
#include "image_format.h"
|
||||
#include "image_napi_utils.h"
|
||||
#include "log_tags.h"
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_IMAGE
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "ImageNapi"
|
||||
|
||||
namespace {
|
||||
constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_TAG_DOMAIN_ID_IMAGE, "ImageNapi"};
|
||||
constexpr int NUM0 = 0;
|
||||
constexpr int NUM1 = 1;
|
||||
constexpr int NUM2 = 2;
|
||||
@ -32,7 +36,6 @@ namespace {
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
using OHOS::HiviewDFX::HiLog;
|
||||
struct ImageAsyncContext {
|
||||
napi_env env = nullptr;
|
||||
napi_async_work work = nullptr;
|
||||
@ -560,7 +563,7 @@ static bool BuildJsComponentObject(napi_env env, int32_t type, uint8_t* buffer,
|
||||
static void TestGetComponentCallBack(napi_env env, napi_status status, ImageAsyncContext* context)
|
||||
{
|
||||
if (context == nullptr) {
|
||||
HiLog::Error(LABEL, "Invalid input context");
|
||||
IMAGE_ERR("Invalid input context");
|
||||
return;
|
||||
}
|
||||
napi_value result;
|
||||
@ -590,13 +593,13 @@ static void JsGetComponentCallBack(napi_env env, napi_status status, ImageAsyncC
|
||||
}
|
||||
|
||||
if (context == nullptr) {
|
||||
HiLog::Error(LABEL, "Invalid input context");
|
||||
IMAGE_ERR("Invalid input context");
|
||||
return;
|
||||
}
|
||||
context->status = ERROR;
|
||||
NativeComponent* component = context->component;
|
||||
if (component == nullptr) {
|
||||
HiLog::Error(LABEL, "Invalid component");
|
||||
IMAGE_ERR("Invalid component");
|
||||
CommonCallbackRoutine(env, context, result);
|
||||
return;
|
||||
}
|
||||
@ -609,7 +612,7 @@ static void JsGetComponentCallBack(napi_env env, napi_status status, ImageAsyncC
|
||||
}
|
||||
|
||||
if (buffer == nullptr || component->size == NUM0) {
|
||||
HiLog::Error(LABEL, "Invalid buffer");
|
||||
IMAGE_ERR("Invalid buffer");
|
||||
CommonCallbackRoutine(env, context, result);
|
||||
return;
|
||||
}
|
||||
@ -617,7 +620,7 @@ static void JsGetComponentCallBack(napi_env env, napi_status status, ImageAsyncC
|
||||
if (BuildJsComponentObject(env, context->componentType, buffer, component, &result)) {
|
||||
context->status = SUCCESS;
|
||||
} else {
|
||||
HiLog::Error(LABEL, "napi_create_arraybuffer failed!");
|
||||
IMAGE_ERR("napi_create_arraybuffer failed!");
|
||||
}
|
||||
|
||||
IMAGE_FUNCTION_OUT();
|
||||
@ -626,13 +629,13 @@ static void JsGetComponentCallBack(napi_env env, napi_status status, ImageAsyncC
|
||||
static void JsGetComponentExec(napi_env env, ImageAsyncContext* context)
|
||||
{
|
||||
if (context == nullptr || context->napi == nullptr) {
|
||||
HiLog::Error(LABEL, "Invalid input context");
|
||||
IMAGE_ERR("Invalid input context");
|
||||
return;
|
||||
}
|
||||
|
||||
auto native = context->napi->GetNative();
|
||||
if (native == nullptr) {
|
||||
HiLog::Error(LABEL, "Empty native");
|
||||
IMAGE_ERR("Empty native");
|
||||
return;
|
||||
}
|
||||
context->component = native->GetComponent(context->componentType);
|
||||
|
@ -16,18 +16,21 @@
|
||||
#include "image_packer_mdk_kits.h"
|
||||
|
||||
#include <map>
|
||||
#include "hilog/log.h"
|
||||
#include "log_tags.h"
|
||||
#include "image_log.h"
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_IMAGE
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "ImagePackerMdk"
|
||||
|
||||
namespace {
|
||||
constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_TAG_DOMAIN_ID_IMAGE, "ImagePackerMdk"};
|
||||
constexpr size_t SIZE_ZERO = 0;
|
||||
constexpr int INVALID_FD = -1;
|
||||
}
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
using OHOS::HiviewDFX::HiLog;
|
||||
using ImagePackerNativeFunc = int32_t (*)(struct ImagePackerArgs* args);
|
||||
|
||||
enum class PackingSourceType : int32_t {
|
||||
@ -44,7 +47,7 @@ static bool IsInstanceOf(napi_env env, napi_value value, napi_value global, cons
|
||||
{
|
||||
napi_value constructor = nullptr;
|
||||
if (napi_get_named_property(env, global, type, &constructor) != napi_ok) {
|
||||
HiLog::Error(LABEL, "Get constructor property failed!");
|
||||
IMAGE_LOGE("Get constructor property failed!");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -59,34 +62,34 @@ static PackingSourceType ParserPackingArgumentType(napi_env env, napi_value sour
|
||||
{
|
||||
napi_value global = nullptr;
|
||||
if (napi_get_global(env, &global) != napi_ok) {
|
||||
HiLog::Error(LABEL, "Get global property failed!");
|
||||
IMAGE_LOGE("Get global property failed!");
|
||||
return PackingSourceType::TYPE_INVALID;
|
||||
}
|
||||
|
||||
if (IsInstanceOf(env, source, global, "ImageSource")) {
|
||||
HiLog::Debug(LABEL, "This is ImageSource!");
|
||||
IMAGE_LOGD("This is ImageSource!");
|
||||
return PackingSourceType::TYPE_IMAGE_SOURCE;
|
||||
} else if (IsInstanceOf(env, source, global, "PixelMap")) {
|
||||
HiLog::Debug(LABEL, "This is PixelMap!");
|
||||
IMAGE_LOGD("This is PixelMap!");
|
||||
return PackingSourceType::TYPE_PIXEL_MAP;
|
||||
}
|
||||
|
||||
HiLog::Error(LABEL, "Invalid type!");
|
||||
IMAGE_LOGE("Invalid type!");
|
||||
return PackingSourceType::TYPE_INVALID;
|
||||
}
|
||||
|
||||
static int32_t ImagePackerNapiCreate(struct ImagePackerArgs* args)
|
||||
{
|
||||
if (args == nullptr || args->inEnv == nullptr || args->outVal == nullptr) {
|
||||
HiLog::Error(LABEL, "ImagePackerNapiCreate bad parameter");
|
||||
IMAGE_LOGE("ImagePackerNapiCreate bad parameter");
|
||||
return IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
*(args->outVal) = ImagePackerNapi::CreateImagePacker(args->inEnv, nullptr);
|
||||
if (*(args->outVal) == nullptr) {
|
||||
HiLog::Error(LABEL, "ImageSourceNapiCreate native create failed");
|
||||
IMAGE_LOGE("ImageSourceNapiCreate native create failed");
|
||||
return IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
HiLog::Debug(LABEL, "ImagePackerNapiCreate success");
|
||||
IMAGE_LOGD("ImagePackerNapiCreate success");
|
||||
return IMAGE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
@ -114,7 +117,7 @@ static int32_t DoStartPacking(std::shared_ptr<ImagePacker> &packer, struct Image
|
||||
} else if (args->inNum0 > INVALID_FD) {
|
||||
return packer->StartPacking(args->inNum0, option);
|
||||
}
|
||||
HiLog::Error(LABEL, "DoNativePacking StartPacking failed");
|
||||
IMAGE_LOGE("DoNativePacking StartPacking failed");
|
||||
return IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
|
||||
@ -130,7 +133,7 @@ static int32_t DoAddImage(std::shared_ptr<ImagePacker> &packer,
|
||||
if (image != nullptr) {
|
||||
return packer->AddImage(*image);
|
||||
} else {
|
||||
HiLog::Error(LABEL, "DoNativePacking get image source native failed");
|
||||
IMAGE_LOGE("DoNativePacking get image source native failed");
|
||||
return IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
} else if (type == PackingSourceType::TYPE_PIXEL_MAP) {
|
||||
@ -138,11 +141,11 @@ static int32_t DoAddImage(std::shared_ptr<ImagePacker> &packer,
|
||||
if (pixel != nullptr) {
|
||||
return packer->AddImage(*pixel);
|
||||
} else {
|
||||
HiLog::Error(LABEL, "DoNativePacking get pixelmap native failed");
|
||||
IMAGE_LOGE("DoNativePacking get pixelmap native failed");
|
||||
return IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
}
|
||||
HiLog::Error(LABEL, "DoNativePacking unsupport packing source type %{public}d", type);
|
||||
IMAGE_LOGE("DoNativePacking unsupport packing source type %{public}d", type);
|
||||
return IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
|
||||
@ -158,17 +161,17 @@ static int32_t DoNativePacking(struct ImagePackerArgs* args)
|
||||
}
|
||||
auto nativeImagePacker = ImagePackerNapi::GetNative(args->inNapi);
|
||||
if (nativeImagePacker == nullptr) {
|
||||
HiLog::Error(LABEL, "DoNativePacking get native failed");
|
||||
IMAGE_LOGE("DoNativePacking get native failed");
|
||||
return IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
int32_t res = DoStartPacking(nativeImagePacker, args);
|
||||
if (res != IMAGE_RESULT_SUCCESS) {
|
||||
HiLog::Error(LABEL, "DoNativePacking StartPacking failed");
|
||||
IMAGE_LOGE("DoNativePacking StartPacking failed");
|
||||
return res;
|
||||
}
|
||||
res = DoAddImage(nativeImagePacker, type, args);
|
||||
if (res != IMAGE_RESULT_SUCCESS) {
|
||||
HiLog::Error(LABEL, "DoNativePacking AddImage failed");
|
||||
IMAGE_LOGE("DoNativePacking AddImage failed");
|
||||
return res;
|
||||
}
|
||||
int64_t packedSize = SIZE_ZERO;
|
||||
@ -184,7 +187,7 @@ static int32_t ImagePackerNapiPackToData(struct ImagePackerArgs* args)
|
||||
args->inNapi == nullptr || args->inVal == nullptr ||
|
||||
args->inOpts == nullptr || args->outData == nullptr ||
|
||||
args->dataSize == nullptr || *(args->dataSize) == SIZE_ZERO) {
|
||||
HiLog::Error(LABEL, "ImagePackerNapiPackToData bad parameter");
|
||||
IMAGE_LOGE("ImagePackerNapiPackToData bad parameter");
|
||||
return IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
return DoNativePacking(args);
|
||||
@ -195,7 +198,7 @@ static int32_t ImagePackerNapiPackToFile(struct ImagePackerArgs* args)
|
||||
if (args == nullptr || args->inEnv == nullptr ||
|
||||
args->inNapi == nullptr || args->inVal == nullptr ||
|
||||
args->inOpts == nullptr || args->inNum0 <= INVALID_FD) {
|
||||
HiLog::Error(LABEL, "ImagePackerNapiPackToFile bad parameter");
|
||||
IMAGE_LOGE("ImagePackerNapiPackToFile bad parameter");
|
||||
return IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
return DoNativePacking(args);
|
||||
|
@ -14,20 +14,23 @@
|
||||
*/
|
||||
|
||||
#include "image_packer_napi.h"
|
||||
#include "hilog/log.h"
|
||||
#include "media_errors.h"
|
||||
|
||||
#include "image_log.h"
|
||||
#include "image_napi_utils.h"
|
||||
#include "image_packer.h"
|
||||
#include "image_source.h"
|
||||
#include "image_source_napi.h"
|
||||
#include "pixel_map_napi.h"
|
||||
#include "image_trace.h"
|
||||
#include "hitrace_meter.h"
|
||||
#include "log_tags.h"
|
||||
#include "media_errors.h"
|
||||
#include "pixel_map_napi.h"
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_IMAGE
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "ImagePackerNapi"
|
||||
|
||||
using OHOS::HiviewDFX::HiLog;
|
||||
namespace {
|
||||
constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_TAG_DOMAIN_ID_IMAGE, "ImagePackerNapi"};
|
||||
constexpr uint32_t NUM_0 = 0;
|
||||
constexpr uint32_t NUM_1 = 1;
|
||||
constexpr uint32_t NUM_2 = 2;
|
||||
@ -113,7 +116,7 @@ static void ImagePackerErrorToNapiError(napi_env env, ImagePackerAsyncContext *c
|
||||
auto msg = (ctx->error.msg.empty()) ? "Internal error" : ctx->error.msg;
|
||||
if (!ctx->error.hasErrorCode) {
|
||||
if (napi_create_string_utf8(env, msg.c_str(), NAPI_AUTO_LENGTH, &out) != napi_ok) {
|
||||
HiLog::Error(LABEL, "Create error msg only error");
|
||||
IMAGE_LOGE("Create error msg only error");
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -122,17 +125,17 @@ static void ImagePackerErrorToNapiError(napi_env env, ImagePackerAsyncContext *c
|
||||
napi_value message;
|
||||
napi_value code;
|
||||
if (napi_create_object(env, &out) != napi_ok) {
|
||||
HiLog::Error(LABEL, "Create error object error");
|
||||
IMAGE_LOGE("Create error object error");
|
||||
return;
|
||||
}
|
||||
if (napi_create_int32(env, errorCode, &code) != napi_ok ||
|
||||
napi_set_named_property(env, out, "code", code) != napi_ok) {
|
||||
HiLog::Error(LABEL, "Create error code error");
|
||||
IMAGE_LOGE("Create error code error");
|
||||
return;
|
||||
}
|
||||
if (napi_create_string_utf8(env, msg.c_str(), NAPI_AUTO_LENGTH, &message) != napi_ok ||
|
||||
napi_set_named_property(env, out, "message", message) != napi_ok) {
|
||||
HiLog::Error(LABEL, "Create error msg error");
|
||||
IMAGE_LOGE("Create error msg error");
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -175,7 +178,7 @@ static void BuildMsgOnError(ImagePackerAsyncContext* ctx, bool assertion, const
|
||||
if (ctx == nullptr || assertion) {
|
||||
return;
|
||||
}
|
||||
HiLog::Error(LABEL, "%{public}s", msg.c_str());
|
||||
IMAGE_LOGE("%{public}s", msg.c_str());
|
||||
ctx->error.hasErrorCode = false;
|
||||
ctx->error.msg = msg;
|
||||
}
|
||||
@ -186,7 +189,7 @@ static void BuildMsgOnError(ImagePackerAsyncContext* ctx, bool assertion,
|
||||
if (ctx == nullptr || assertion) {
|
||||
return;
|
||||
}
|
||||
HiLog::Error(LABEL, "%{public}s", msg.c_str());
|
||||
IMAGE_LOGE("%{public}s", msg.c_str());
|
||||
ctx->error.hasErrorCode = true;
|
||||
ctx->error.errorCode = errorCode;
|
||||
ctx->error.msg = msg;
|
||||
@ -196,7 +199,7 @@ STATIC_EXEC_FUNC(Packing)
|
||||
{
|
||||
int64_t packedSize = 0;
|
||||
auto context = static_cast<ImagePackerAsyncContext*>(data);
|
||||
HiLog::Info(LABEL, "ImagePacker BufferSize %{public}" PRId64, context->resultBufferSize);
|
||||
IMAGE_LOGI("ImagePacker BufferSize %{public}" PRId64, context->resultBufferSize);
|
||||
context->resultBuffer = std::make_unique<uint8_t[]>(
|
||||
(context->resultBufferSize <= 0)?DEFAULT_BUFFER_SIZE:context->resultBufferSize);
|
||||
if (context->resultBuffer == nullptr) {
|
||||
@ -206,14 +209,14 @@ STATIC_EXEC_FUNC(Packing)
|
||||
context->rImagePacker->StartPacking(context->resultBuffer.get(),
|
||||
context->resultBufferSize, context->packOption);
|
||||
if (context->packType == TYPE_IMAGE_SOURCE) {
|
||||
HiLog::Info(LABEL, "ImagePacker set image source");
|
||||
IMAGE_LOGI("ImagePacker set image source");
|
||||
if (context->rImageSource == nullptr) {
|
||||
BuildMsgOnError(context, context->rImageSource == nullptr, "ImageSource is nullptr");
|
||||
return;
|
||||
}
|
||||
context->rImagePacker->AddImage(*(context->rImageSource));
|
||||
} else {
|
||||
HiLog::Info(LABEL, "ImagePacker set pixelmap");
|
||||
IMAGE_LOGI("ImagePacker set pixelmap");
|
||||
if (context->rPixelMap == nullptr) {
|
||||
BuildMsgOnError(context, context->rImageSource == nullptr, "Pixelmap is nullptr");
|
||||
return;
|
||||
@ -221,13 +224,13 @@ STATIC_EXEC_FUNC(Packing)
|
||||
context->rImagePacker->AddImage(*(context->rPixelMap));
|
||||
}
|
||||
context->rImagePacker->FinalizePacking(packedSize);
|
||||
HiLog::Debug(LABEL, "packedSize=%{public}" PRId64, packedSize);
|
||||
IMAGE_LOGD("packedSize=%{public}" PRId64, packedSize);
|
||||
if (packedSize > 0 && (packedSize < context->resultBufferSize)) {
|
||||
context->packedSize = packedSize;
|
||||
context->status = SUCCESS;
|
||||
} else {
|
||||
context->status = ERROR;
|
||||
HiLog::Error(LABEL, "Packing failed, packedSize outside size.");
|
||||
IMAGE_LOGE("Packing failed, packedSize outside size.");
|
||||
}
|
||||
}
|
||||
|
||||
@ -249,7 +252,7 @@ STATIC_COMPLETE_FUNC(Packing)
|
||||
if (!ImageNapiUtils::CreateArrayBuffer(env, context->resultBuffer.get(),
|
||||
context->packedSize, &result)) {
|
||||
context->status = ERROR;
|
||||
HiLog::Error(LABEL, "napi_create_arraybuffer failed!");
|
||||
IMAGE_LOGE("napi_create_arraybuffer failed!");
|
||||
napi_get_undefined(env, &result);
|
||||
} else {
|
||||
context->status = SUCCESS;
|
||||
@ -277,27 +280,27 @@ napi_value ImagePackerNapi::Init(napi_env env, napi_value exports)
|
||||
IMG_NAPI_CHECK_RET_D(IMG_IS_OK(
|
||||
napi_define_class(env, CLASS_NAME_IMAGEPACKER.c_str(), NAPI_AUTO_LENGTH, Constructor,
|
||||
nullptr, IMG_ARRAY_SIZE(props), props, &constructor)), nullptr,
|
||||
HiLog::Error(LABEL, "define class fail")
|
||||
IMAGE_LOGE("define class fail")
|
||||
);
|
||||
|
||||
IMG_NAPI_CHECK_RET_D(IMG_IS_OK(
|
||||
napi_create_reference(env, constructor, 1, &sConstructor_)),
|
||||
nullptr,
|
||||
HiLog::Error(LABEL, "create reference fail")
|
||||
IMAGE_LOGE("create reference fail")
|
||||
);
|
||||
|
||||
IMG_NAPI_CHECK_RET_D(IMG_IS_OK(
|
||||
napi_set_named_property(env, exports, CLASS_NAME_IMAGEPACKER.c_str(), constructor)),
|
||||
nullptr,
|
||||
HiLog::Error(LABEL, "set named property fail")
|
||||
IMAGE_LOGE("set named property fail")
|
||||
);
|
||||
IMG_NAPI_CHECK_RET_D(IMG_IS_OK(
|
||||
napi_define_properties(env, exports, IMG_ARRAY_SIZE(static_prop), static_prop)),
|
||||
nullptr,
|
||||
HiLog::Error(LABEL, "define properties fail")
|
||||
IMAGE_LOGE("define properties fail")
|
||||
);
|
||||
|
||||
HiLog::Debug(LABEL, "Init success");
|
||||
IMAGE_LOGD("Init success");
|
||||
return exports;
|
||||
}
|
||||
|
||||
@ -321,7 +324,7 @@ napi_value ImagePackerNapi::Constructor(napi_env env, napi_callback_info info)
|
||||
pImgPackerNapi.release();
|
||||
return thisVar;
|
||||
} else {
|
||||
HiLog::Error(LABEL, "Failure wrapping js to native napi");
|
||||
IMAGE_LOGE("Failure wrapping js to native napi");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -344,7 +347,7 @@ napi_value ImagePackerNapi::CreateImagePacker(napi_env env, napi_callback_info i
|
||||
if (status == napi_ok) {
|
||||
return result;
|
||||
} else {
|
||||
HiLog::Error(LABEL, "New instance could not be obtained");
|
||||
IMAGE_LOGE("New instance could not be obtained");
|
||||
}
|
||||
}
|
||||
return result;
|
||||
@ -359,11 +362,11 @@ static int64_t parseBufferSize(napi_env env, napi_value root)
|
||||
napi_value tempValue = nullptr;
|
||||
int64_t tmpNumber = DEFAULT_BUFFER_SIZE;
|
||||
if (napi_get_named_property(env, root, "bufferSize", &tempValue) != napi_ok) {
|
||||
HiLog::Info(LABEL, "No bufferSize, Using default");
|
||||
IMAGE_LOGI("No bufferSize, Using default");
|
||||
return tmpNumber;
|
||||
}
|
||||
napi_get_value_int64(env, tempValue, &tmpNumber);
|
||||
HiLog::Info(LABEL, "BufferSize is %{public}" PRId64, tmpNumber);
|
||||
IMAGE_LOGI("BufferSize is %{public}" PRId64, tmpNumber);
|
||||
if (tmpNumber < 0) {
|
||||
return DEFAULT_BUFFER_SIZE;
|
||||
}
|
||||
@ -374,11 +377,11 @@ static bool parsePackOptionOfQuality(napi_env env, napi_value root, PackOption*
|
||||
{
|
||||
uint32_t tmpNumber = 0;
|
||||
if (!GET_UINT32_BY_NAME(root, "quality", tmpNumber)) {
|
||||
HiLog::Error(LABEL, "No quality in pack option");
|
||||
IMAGE_LOGE("No quality in pack option");
|
||||
return false;
|
||||
}
|
||||
if (tmpNumber > SIZE) {
|
||||
HiLog::Error(LABEL, "Invalid quality");
|
||||
IMAGE_LOGE("Invalid quality");
|
||||
opts->quality = BYTE_FULL;
|
||||
} else {
|
||||
opts->quality = static_cast<uint8_t>(tmpNumber & 0xff);
|
||||
@ -391,7 +394,7 @@ static bool parsePackOptions(napi_env env, napi_value root, PackOption* opts)
|
||||
napi_value tmpValue = nullptr;
|
||||
|
||||
if (!GET_NODE_BY_NAME(root, "format", tmpValue)) {
|
||||
HiLog::Error(LABEL, "No format in pack option");
|
||||
IMAGE_LOGE("No format in pack option");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -399,39 +402,39 @@ static bool parsePackOptions(napi_env env, napi_value root, PackOption* opts)
|
||||
napi_is_array(env, tmpValue, &isFormatArray);
|
||||
auto formatType = ImageNapiUtils::getType(env, tmpValue);
|
||||
|
||||
HiLog::Debug(LABEL, "parsePackOptions format type %{public}d, is array %{public}d",
|
||||
IMAGE_LOGD("parsePackOptions format type %{public}d, is array %{public}d",
|
||||
formatType, isFormatArray);
|
||||
|
||||
char buffer[SIZE] = {0};
|
||||
size_t res = 0;
|
||||
if (napi_string == formatType) {
|
||||
if (napi_get_value_string_utf8(env, tmpValue, buffer, SIZE, &res) != napi_ok) {
|
||||
HiLog::Error(LABEL, "Parse pack option format failed");
|
||||
IMAGE_LOGE("Parse pack option format failed");
|
||||
return false;
|
||||
}
|
||||
opts->format = std::string(buffer);
|
||||
} else if (isFormatArray) {
|
||||
uint32_t len = 0;
|
||||
if (napi_get_array_length(env, tmpValue, &len) != napi_ok) {
|
||||
HiLog::Error(LABEL, "Parse pack napi_get_array_length failed");
|
||||
IMAGE_LOGE("Parse pack napi_get_array_length failed");
|
||||
return false;
|
||||
}
|
||||
HiLog::Debug(LABEL, "Parse pack array_length=%{public}u", len);
|
||||
IMAGE_LOGD("Parse pack array_length=%{public}u", len);
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
napi_value item;
|
||||
napi_get_element(env, tmpValue, i, &item);
|
||||
if (napi_get_value_string_utf8(env, item, buffer, SIZE, &res) != napi_ok) {
|
||||
HiLog::Error(LABEL, "Parse format in item failed %{public}zu", i);
|
||||
IMAGE_LOGE("Parse format in item failed %{public}zu", i);
|
||||
continue;
|
||||
}
|
||||
opts->format = std::string(buffer);
|
||||
HiLog::Debug(LABEL, "format is %{public}s.", opts->format.c_str());
|
||||
IMAGE_LOGD("format is %{public}s.", opts->format.c_str());
|
||||
}
|
||||
} else {
|
||||
HiLog::Error(LABEL, "Invalid pack option format type");
|
||||
IMAGE_LOGE("Invalid pack option format type");
|
||||
return false;
|
||||
}
|
||||
HiLog::Debug(LABEL, "parsePackOptions format:[%{public}s]", opts->format.c_str());
|
||||
IMAGE_LOGD("parsePackOptions format:[%{public}s]", opts->format.c_str());
|
||||
return parsePackOptionOfQuality(env, root, opts);
|
||||
}
|
||||
|
||||
@ -446,43 +449,43 @@ static int32_t ParserPackingArgumentType(napi_env env, napi_value argv)
|
||||
|
||||
ret = napi_get_named_property(env, global, "ImageSource", &constructor);
|
||||
if (ret != napi_ok) {
|
||||
HiLog::Error(LABEL, "Get ImageSourceNapi property failed!");
|
||||
IMAGE_LOGE("Get ImageSourceNapi property failed!");
|
||||
}
|
||||
|
||||
ret = napi_instanceof(env, argv, constructor, &isInstance);
|
||||
if (ret == napi_ok && isInstance) {
|
||||
HiLog::Debug(LABEL, "This is ImageSourceNapi type!");
|
||||
IMAGE_LOGD("This is ImageSourceNapi type!");
|
||||
return TYPE_IMAGE_SOURCE;
|
||||
}
|
||||
|
||||
ret = napi_get_named_property(env, global, "PixelMap", &constructor);
|
||||
if (ret != napi_ok) {
|
||||
HiLog::Error(LABEL, "Get PixelMapNapi property failed!");
|
||||
IMAGE_LOGE("Get PixelMapNapi property failed!");
|
||||
}
|
||||
|
||||
ret = napi_instanceof(env, argv, constructor, &isInstance);
|
||||
if (ret == napi_ok && isInstance) {
|
||||
HiLog::Debug(LABEL, "This is PixelMapNapi type!");
|
||||
IMAGE_LOGD("This is PixelMapNapi type!");
|
||||
return TYPE_PIXEL_MAP;
|
||||
}
|
||||
|
||||
HiLog::Error(LABEL, "Invalid type!");
|
||||
IMAGE_LOGE("Invalid type!");
|
||||
return TYPE_IMAGE_SOURCE;
|
||||
}
|
||||
|
||||
static std::shared_ptr<ImageSource> GetImageSourceFromNapi(napi_env env, napi_value value)
|
||||
{
|
||||
if (env == nullptr || value == nullptr) {
|
||||
HiLog::Error(LABEL, "GetImageSourceFromNapi input is null");
|
||||
IMAGE_LOGE("GetImageSourceFromNapi input is null");
|
||||
}
|
||||
std::unique_ptr<ImageSourceNapi> imageSourceNapi = std::make_unique<ImageSourceNapi>();
|
||||
napi_status status = napi_unwrap(env, value, reinterpret_cast<void**>(&imageSourceNapi));
|
||||
if (!IMG_IS_OK(status)) {
|
||||
HiLog::Error(LABEL, "GetImageSourceFromNapi napi unwrap failed");
|
||||
IMAGE_LOGE("GetImageSourceFromNapi napi unwrap failed");
|
||||
return nullptr;
|
||||
}
|
||||
if (imageSourceNapi == nullptr) {
|
||||
HiLog::Error(LABEL, "GetImageSourceFromNapi imageSourceNapi is nullptr");
|
||||
IMAGE_LOGE("GetImageSourceFromNapi imageSourceNapi is nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
return imageSourceNapi.release()->nativeImgSrc;
|
||||
@ -548,7 +551,7 @@ napi_value ImagePackerNapi::Packing(napi_env env, napi_callback_info info)
|
||||
}
|
||||
|
||||
IMG_NAPI_CHECK_RET_D(IMG_IS_OK(status),
|
||||
nullptr, HiLog::Error(LABEL, "fail to create async work"));
|
||||
nullptr, IMAGE_LOGE("fail to create async work"));
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -563,18 +566,18 @@ napi_value ImagePackerNapi::GetSupportedFormats(napi_env env, napi_callback_info
|
||||
|
||||
IMG_JS_ARGS(env, info, status, argCount, nullptr, thisVar);
|
||||
|
||||
IMG_NAPI_CHECK_RET_D(IMG_IS_OK(status), result, HiLog::Error(LABEL, "fail to napi_get_cb_info"));
|
||||
IMG_NAPI_CHECK_RET_D(IMG_IS_OK(status), result, IMAGE_LOGE("fail to napi_get_cb_info"));
|
||||
|
||||
std::unique_ptr<ImagePackerAsyncContext> context = std::make_unique<ImagePackerAsyncContext>();
|
||||
status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&context->constructor_));
|
||||
|
||||
IMG_NAPI_CHECK_RET_D(IMG_IS_READY(status, context->constructor_),
|
||||
nullptr, HiLog::Error(LABEL, "fail to unwrap context"));
|
||||
nullptr, IMAGE_LOGE("fail to unwrap context"));
|
||||
std::set<std::string> formats;
|
||||
uint32_t ret = context->constructor_->nativeImgPck->GetSupportedFormats(formats);
|
||||
|
||||
IMG_NAPI_CHECK_RET_D((ret == SUCCESS),
|
||||
nullptr, HiLog::Error(LABEL, "fail to get supported formats"));
|
||||
nullptr, IMAGE_LOGE("fail to get supported formats"));
|
||||
|
||||
napi_create_array(env, &result);
|
||||
size_t i = 0;
|
||||
@ -613,15 +616,15 @@ napi_value ImagePackerNapi::Release(napi_env env, napi_callback_info info)
|
||||
size_t argCount = 1;
|
||||
|
||||
IMG_JS_ARGS(env, info, status, argCount, argValue, thisVar);
|
||||
HiLog::Debug(LABEL, "Release argCount is [%{public}zu]", argCount);
|
||||
IMG_NAPI_CHECK_RET_D(IMG_IS_OK(status), result, HiLog::Error(LABEL, "fail to napi_get_cb_info"));
|
||||
IMAGE_LOGD("Release argCount is [%{public}zu]", argCount);
|
||||
IMG_NAPI_CHECK_RET_D(IMG_IS_OK(status), result, IMAGE_LOGE("fail to napi_get_cb_info"));
|
||||
|
||||
std::unique_ptr<ImagePackerAsyncContext> context = std::make_unique<ImagePackerAsyncContext>();
|
||||
status = napi_remove_wrap(env, thisVar, reinterpret_cast<void**>(&context->constructor_));
|
||||
|
||||
IMG_NAPI_CHECK_RET_D(IMG_IS_READY(status, context->constructor_), result,
|
||||
HiLog::Error(LABEL, "fail to unwrap context"));
|
||||
HiLog::Debug(LABEL, "Release argCount is [%{public}zu]", argCount);
|
||||
IMAGE_LOGE("fail to unwrap context"));
|
||||
IMAGE_LOGD("Release argCount is [%{public}zu]", argCount);
|
||||
if (argCount == 1 && ImageNapiUtils::getType(env, argValue[NUM_0]) == napi_function) {
|
||||
napi_create_reference(env, argValue[NUM_0], refCount, &context->callbackRef);
|
||||
}
|
||||
@ -684,7 +687,7 @@ STATIC_EXEC_FUNC(PackToFile)
|
||||
return;
|
||||
}
|
||||
if (context->packType == TYPE_IMAGE_SOURCE) {
|
||||
HiLog::Info(LABEL, "ImagePacker set image source");
|
||||
IMAGE_LOGI("ImagePacker set image source");
|
||||
if (context->rImageSource == nullptr) {
|
||||
BuildMsgOnError(context, context->rImageSource == nullptr,
|
||||
"ImageSource is nullptr", ERR_IMAGE_INVALID_PARAMETER);
|
||||
@ -692,7 +695,7 @@ STATIC_EXEC_FUNC(PackToFile)
|
||||
}
|
||||
context->rImagePacker->AddImage(*(context->rImageSource));
|
||||
} else {
|
||||
HiLog::Info(LABEL, "ImagePacker set pixelmap");
|
||||
IMAGE_LOGI("ImagePacker set pixelmap");
|
||||
if (context->rPixelMap == nullptr) {
|
||||
BuildMsgOnError(context, context->rImageSource == nullptr,
|
||||
"Pixelmap is nullptr", ERR_IMAGE_INVALID_PARAMETER);
|
||||
@ -701,14 +704,14 @@ STATIC_EXEC_FUNC(PackToFile)
|
||||
context->rImagePacker->AddImage(*(context->rPixelMap));
|
||||
}
|
||||
auto packRes = context->rImagePacker->FinalizePacking(packedSize);
|
||||
HiLog::Debug(LABEL, "packRes=%{public}d packedSize=%{public}" PRId64, packRes, packedSize);
|
||||
IMAGE_LOGD("packRes=%{public}d packedSize=%{public}" PRId64, packRes, packedSize);
|
||||
if (packRes == SUCCESS && packedSize > 0) {
|
||||
context->packedSize = packedSize;
|
||||
context->status = SUCCESS;
|
||||
} else {
|
||||
context->status = ERROR;
|
||||
BuildMsgOnError(context, packRes == SUCCESS, "PackedSize outside size", packRes);
|
||||
HiLog::Error(LABEL, "Packing failed, packedSize outside size.");
|
||||
IMAGE_LOGE("Packing failed, packedSize outside size.");
|
||||
}
|
||||
}
|
||||
|
||||
@ -755,7 +758,7 @@ napi_value ImagePackerNapi::PackToFile(napi_env env, napi_callback_info info)
|
||||
}
|
||||
|
||||
IMG_NAPI_CHECK_RET_D(IMG_IS_OK(status),
|
||||
nullptr, HiLog::Error(LABEL, "fail to create async work"));
|
||||
nullptr, IMAGE_LOGE("fail to create async work"));
|
||||
return result;
|
||||
}
|
||||
void ImagePackerNapi::release()
|
||||
|
@ -16,14 +16,18 @@
|
||||
#include "image_receiver_napi.h"
|
||||
#include <uv.h>
|
||||
#include "media_errors.h"
|
||||
#include "hilog/log.h"
|
||||
#include "image_log.h"
|
||||
#include "image_napi_utils.h"
|
||||
#include "image_receiver_context.h"
|
||||
#include "image_napi.h"
|
||||
#include "image_receiver_context.h"
|
||||
#include "image_receiver_manager.h"
|
||||
#include "log_tags.h"
|
||||
|
||||
using OHOS::HiviewDFX::HiLog;
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_IMAGE
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "ImageReceiverNapi"
|
||||
|
||||
using std::string;
|
||||
using std::shared_ptr;
|
||||
using std::unique_ptr;
|
||||
@ -31,10 +35,6 @@ using std::vector;
|
||||
using std::make_shared;
|
||||
using std::make_unique;
|
||||
|
||||
namespace {
|
||||
constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_TAG_DOMAIN_ID_IMAGE, "ImageReceiverNapi"};
|
||||
}
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
static const std::string CLASS_NAME = "ImageReceiver";
|
||||
|
@ -15,13 +15,17 @@
|
||||
|
||||
#include "image_source_mdk_kits.h"
|
||||
#include <map>
|
||||
#include "hilog/log.h"
|
||||
#include "log_tags.h"
|
||||
#include "image_log.h"
|
||||
#include "media_errors.h"
|
||||
#include "securec.h"
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_IMAGE
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "ImageSourceMdk"
|
||||
|
||||
namespace {
|
||||
constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_TAG_DOMAIN_ID_IMAGE, "ImageSourceMdk"};
|
||||
constexpr size_t SIZE_ZERO = 0;
|
||||
constexpr int32_t INVALID_FD = -1;
|
||||
constexpr uint32_t DEFAULT_INDEX = 0;
|
||||
@ -31,7 +35,6 @@ namespace {
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
using OHOS::HiviewDFX::HiLog;
|
||||
using ImageSourceNapiFunc = int32_t (*)(struct ImageSourceArgs* args);
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -97,7 +100,7 @@ static ImageSourceNapi* UnwrapNativeObject(napi_env env, napi_value value)
|
||||
napi_valuetype valueType;
|
||||
napi_typeof(env, value, &valueType);
|
||||
if (valueType != napi_object) {
|
||||
HiLog::Error(LABEL, "UnwrapNativeObject value not a object");
|
||||
IMAGE_LOGE("UnwrapNativeObject value not a object");
|
||||
return nullptr;
|
||||
}
|
||||
std::unique_ptr<ImageSourceNapi> napi = nullptr;
|
||||
@ -105,7 +108,7 @@ static ImageSourceNapi* UnwrapNativeObject(napi_env env, napi_value value)
|
||||
if ((status == napi_ok) && napi != nullptr) {
|
||||
return napi.release();
|
||||
}
|
||||
HiLog::Error(LABEL, "UnwrapNativeObject unwrap error");
|
||||
IMAGE_LOGE("UnwrapNativeObject unwrap error");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -113,7 +116,7 @@ static int32_t ImageSourceNativeCreate(struct OhosImageSource* source,
|
||||
struct OhosImageSourceOps* ops, std::shared_ptr<ImageSource> &result, ImageResource &resource)
|
||||
{
|
||||
if (source == nullptr) {
|
||||
HiLog::Error(LABEL, "ImageSourceNativeCreate source nullptr");
|
||||
IMAGE_LOGE("ImageSourceNativeCreate source nullptr");
|
||||
return IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
uint32_t errorCode = ERR_MEDIA_INVALID_VALUE;
|
||||
@ -123,20 +126,20 @@ static int32_t ImageSourceNativeCreate(struct OhosImageSource* source,
|
||||
}
|
||||
std::unique_ptr<ImageSource> nativeImageSource = nullptr;
|
||||
if (source->uri != nullptr && source->uriSize != SIZE_ZERO) {
|
||||
HiLog::Debug(LABEL, "ImageSourceNativeCreate by path");
|
||||
IMAGE_LOGD("ImageSourceNativeCreate by path");
|
||||
std::string url(source->uri, source->uriSize);
|
||||
HiLog::Debug(LABEL, "ImageSourceNativeCreate by path %{public}s", url.c_str());
|
||||
IMAGE_LOGD("ImageSourceNativeCreate by path %{public}s", url.c_str());
|
||||
auto path = UrlToPath(url);
|
||||
nativeImageSource = ImageSource::CreateImageSource(path, opts, errorCode);
|
||||
resource.type = ImageResourceType::IMAGE_RESOURCE_PATH;
|
||||
resource.path = path;
|
||||
} else if (source->fd != INVALID_FD) {
|
||||
HiLog::Debug(LABEL, "ImageSourceNativeCreate by fd");
|
||||
IMAGE_LOGD("ImageSourceNativeCreate by fd");
|
||||
nativeImageSource = ImageSource::CreateImageSource(source->fd, opts, errorCode);
|
||||
resource.type = ImageResourceType::IMAGE_RESOURCE_FD;
|
||||
resource.fd = source->fd;
|
||||
} else if (source->buffer != nullptr && source->bufferSize != SIZE_ZERO) {
|
||||
HiLog::Debug(LABEL, "ImageSourceNativeCreate by buffer");
|
||||
IMAGE_LOGD("ImageSourceNativeCreate by buffer");
|
||||
nativeImageSource = ImageSource::CreateImageSource(source->buffer,
|
||||
source->bufferSize, opts, errorCode);
|
||||
resource.type = ImageResourceType::IMAGE_RESOURCE_BUFFER;
|
||||
@ -145,10 +148,10 @@ static int32_t ImageSourceNativeCreate(struct OhosImageSource* source,
|
||||
}
|
||||
if (nativeImageSource != nullptr) {
|
||||
result = std::move(nativeImageSource);
|
||||
HiLog::Debug(LABEL, "ImageSourceNativeCreate success");
|
||||
IMAGE_LOGD("ImageSourceNativeCreate success");
|
||||
return IMAGE_RESULT_SUCCESS;
|
||||
}
|
||||
HiLog::Error(LABEL, "ImageSourceNativeCreate no match source");
|
||||
IMAGE_LOGE("ImageSourceNativeCreate no match source");
|
||||
return IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
|
||||
@ -157,12 +160,12 @@ static int32_t ImageSourceCreateNapi(napi_env env, napi_value* res,
|
||||
std::shared_ptr<IncrementalPixelMap> incrementalPixelMap, ImageResource* resource)
|
||||
{
|
||||
if (ImageSourceNapi::CreateImageSourceNapi(env, res) != SUCCESS) {
|
||||
HiLog::Error(LABEL, "ImageSourceCreateNapi napi create failed");
|
||||
IMAGE_LOGE("ImageSourceCreateNapi napi create failed");
|
||||
return IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
auto napi = UnwrapNativeObject(env, *(res));
|
||||
if (napi == nullptr) {
|
||||
HiLog::Error(LABEL, "ImageSourceCreateNapi napi unwrap check failed");
|
||||
IMAGE_LOGE("ImageSourceCreateNapi napi unwrap check failed");
|
||||
return IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
|
||||
@ -175,7 +178,7 @@ static int32_t ImageSourceCreateNapi(napi_env env, napi_value* res,
|
||||
if (resource != nullptr) {
|
||||
napi->SetImageResource(*resource);
|
||||
}
|
||||
HiLog::Debug(LABEL, "ImageSourceCreateNapi success");
|
||||
IMAGE_LOGD("ImageSourceCreateNapi success");
|
||||
return IMAGE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
@ -188,15 +191,15 @@ static int32_t ImageSourceNapiCreate(struct ImageSourceArgs* args)
|
||||
ImageResource resource;
|
||||
ImageSourceNativeCreate(args->source, args->sourceOps, imageSource, resource);
|
||||
if (imageSource == nullptr) {
|
||||
HiLog::Error(LABEL, "ImageSourceNapiCreate native create failed");
|
||||
IMAGE_LOGE("ImageSourceNapiCreate native create failed");
|
||||
return IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
if (ImageSourceCreateNapi(args->inEnv, args->outVal, imageSource, nullptr, &resource) != SUCCESS) {
|
||||
HiLog::Error(LABEL, "ImageSourceNapiCreate napi create failed");
|
||||
IMAGE_LOGE("ImageSourceNapiCreate napi create failed");
|
||||
args->outVal = nullptr;
|
||||
return IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
HiLog::Debug(LABEL, "ImageSourceNapiCreate success");
|
||||
IMAGE_LOGD("ImageSourceNapiCreate success");
|
||||
return IMAGE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
@ -209,12 +212,12 @@ static int32_t ImageSourceNapiCreateFromUri(struct ImageSourceArgs* args)
|
||||
if (args->sourceOps != nullptr) {
|
||||
ParseImageSourceOps(opts, args->sourceOps);
|
||||
}
|
||||
HiLog::Debug(LABEL, "ImageSourceNapiCreateFromUri by path %{public}s", args->uri.c_str());
|
||||
IMAGE_LOGD("ImageSourceNapiCreateFromUri by path %{public}s", args->uri.c_str());
|
||||
auto path = UrlToPath(args->uri);
|
||||
uint32_t errorCode = ERR_MEDIA_INVALID_VALUE;
|
||||
std::unique_ptr<ImageSource> nativeImageSource = ImageSource::CreateImageSource(path, opts, errorCode);
|
||||
if (nativeImageSource == nullptr) {
|
||||
HiLog::Debug(LABEL, "ImageSourceNapiCreateFromUri create failed:%{public}d", errorCode);
|
||||
IMAGE_LOGD("ImageSourceNapiCreateFromUri create failed:%{public}d", errorCode);
|
||||
return IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
ImageResource resource;
|
||||
@ -222,15 +225,15 @@ static int32_t ImageSourceNapiCreateFromUri(struct ImageSourceArgs* args)
|
||||
resource.path = path;
|
||||
std::shared_ptr<ImageSource> imageSource = std::move(nativeImageSource);
|
||||
if (imageSource == nullptr) {
|
||||
HiLog::Error(LABEL, "ImageSourceNapiCreateFromUri native create failed");
|
||||
IMAGE_LOGE("ImageSourceNapiCreateFromUri native create failed");
|
||||
return IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
if (ImageSourceCreateNapi(args->inEnv, args->outVal, imageSource, nullptr, &resource) != SUCCESS) {
|
||||
HiLog::Error(LABEL, "ImageSourceNapiCreateFromUri napi create failed");
|
||||
IMAGE_LOGE("ImageSourceNapiCreateFromUri napi create failed");
|
||||
args->outVal = nullptr;
|
||||
return IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
HiLog::Debug(LABEL, "ImageSourceNapiCreateFromUri success");
|
||||
IMAGE_LOGD("ImageSourceNapiCreateFromUri success");
|
||||
return IMAGE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
@ -243,11 +246,11 @@ static int32_t ImageSourceNapiCreateFromFd(struct ImageSourceArgs* args)
|
||||
if (args->sourceOps != nullptr) {
|
||||
ParseImageSourceOps(opts, args->sourceOps);
|
||||
}
|
||||
HiLog::Debug(LABEL, "ImageSourceNapiCreateFromFd");
|
||||
IMAGE_LOGD("ImageSourceNapiCreateFromFd");
|
||||
uint32_t errorCode = ERR_MEDIA_INVALID_VALUE;
|
||||
std::unique_ptr<ImageSource> nativeImageSource = ImageSource::CreateImageSource(args->fd, opts, errorCode);
|
||||
if (nativeImageSource == nullptr) {
|
||||
HiLog::Debug(LABEL, "ImageSourceNapiCreateFromFd create failed:%{public}d", errorCode);
|
||||
IMAGE_LOGD("ImageSourceNapiCreateFromFd create failed:%{public}d", errorCode);
|
||||
return IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
ImageResource resource;
|
||||
@ -255,15 +258,15 @@ static int32_t ImageSourceNapiCreateFromFd(struct ImageSourceArgs* args)
|
||||
resource.fd = args->fd;
|
||||
std::shared_ptr<ImageSource> imageSource = std::move(nativeImageSource);
|
||||
if (imageSource == nullptr) {
|
||||
HiLog::Error(LABEL, "ImageSourceNapiCreateFromFd native create failed");
|
||||
IMAGE_LOGE("ImageSourceNapiCreateFromFd native create failed");
|
||||
return IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
if (ImageSourceCreateNapi(args->inEnv, args->outVal, imageSource, nullptr, &resource) != SUCCESS) {
|
||||
HiLog::Error(LABEL, "ImageSourceNapiCreateFromFd napi create failed");
|
||||
IMAGE_LOGE("ImageSourceNapiCreateFromFd napi create failed");
|
||||
args->outVal = nullptr;
|
||||
return IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
HiLog::Debug(LABEL, "ImageSourceNapiCreateFromFd success");
|
||||
IMAGE_LOGD("ImageSourceNapiCreateFromFd success");
|
||||
return IMAGE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
@ -277,12 +280,12 @@ static int32_t ImageSourceNapiCreateFromData(struct ImageSourceArgs* args)
|
||||
if (args->sourceOps != nullptr) {
|
||||
ParseImageSourceOps(opts, args->sourceOps);
|
||||
}
|
||||
HiLog::Debug(LABEL, "ImageSourceNapiCreateFromData");
|
||||
IMAGE_LOGD("ImageSourceNapiCreateFromData");
|
||||
uint32_t errorCode = ERR_MEDIA_INVALID_VALUE;
|
||||
std::unique_ptr<ImageSource> nativeImageSource = ImageSource::CreateImageSource(
|
||||
args->dataArray.data, args->dataArray.dataSize, opts, errorCode);
|
||||
if (nativeImageSource == nullptr) {
|
||||
HiLog::Debug(LABEL, "ImageSourceNapiCreateFromData create failed:%{public}d", errorCode);
|
||||
IMAGE_LOGD("ImageSourceNapiCreateFromData create failed:%{public}d", errorCode);
|
||||
return IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
ImageResource resource;
|
||||
@ -291,15 +294,15 @@ static int32_t ImageSourceNapiCreateFromData(struct ImageSourceArgs* args)
|
||||
resource.bufferSize = args->dataArray.dataSize;
|
||||
std::shared_ptr<ImageSource> imageSource = std::move(nativeImageSource);
|
||||
if (imageSource == nullptr) {
|
||||
HiLog::Error(LABEL, "ImageSourceNapiCreateFromData native create failed");
|
||||
IMAGE_LOGE("ImageSourceNapiCreateFromData native create failed");
|
||||
return IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
if (ImageSourceCreateNapi(args->inEnv, args->outVal, imageSource, nullptr, &resource) != SUCCESS) {
|
||||
HiLog::Error(LABEL, "ImageSourceNapiCreateFromData napi create failed");
|
||||
IMAGE_LOGE("ImageSourceNapiCreateFromData napi create failed");
|
||||
args->outVal = nullptr;
|
||||
return IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
HiLog::Debug(LABEL, "ImageSourceNapiCreateFromData success");
|
||||
IMAGE_LOGD("ImageSourceNapiCreateFromData success");
|
||||
return IMAGE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
@ -319,13 +322,13 @@ static int32_t ImageSourceNapiCreateFromRawFile(struct ImageSourceArgs* args)
|
||||
ParseImageSourceOps(opts, args->sourceOps);
|
||||
}
|
||||
RawFileDescriptor rawFile = args->rawFile;
|
||||
HiLog::Debug(LABEL, "ImageSourceNapiCreateFromRawFile");
|
||||
IMAGE_LOGD("ImageSourceNapiCreateFromRawFile");
|
||||
uint32_t errorCode = ERR_MEDIA_INVALID_VALUE;
|
||||
int32_t rawFileLength = rawFile.start + rawFile.length;
|
||||
std::unique_ptr<ImageSource> nativeImageSource = ImageSource::CreateImageSource(
|
||||
rawFile.fd, rawFile.start, rawFileLength, opts, errorCode);
|
||||
if (nativeImageSource == nullptr) {
|
||||
HiLog::Debug(LABEL, "ImageSourceNapiCreateFromRawFile create failed:%{public}d", errorCode);
|
||||
IMAGE_LOGD("ImageSourceNapiCreateFromRawFile create failed:%{public}d", errorCode);
|
||||
return IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
ImageResource resource;
|
||||
@ -335,38 +338,38 @@ static int32_t ImageSourceNapiCreateFromRawFile(struct ImageSourceArgs* args)
|
||||
resource.fileLength = rawFileLength;
|
||||
std::shared_ptr<ImageSource> imageSource = std::move(nativeImageSource);
|
||||
if (imageSource == nullptr) {
|
||||
HiLog::Error(LABEL, "ImageSourceNapiCreateFromRawFile native create failed");
|
||||
IMAGE_LOGE("ImageSourceNapiCreateFromRawFile native create failed");
|
||||
return IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
if (ImageSourceCreateNapi(args->inEnv, args->outVal, imageSource, nullptr, &resource) != SUCCESS) {
|
||||
HiLog::Error(LABEL, "ImageSourceNapiCreateFromRawFile napi create failed");
|
||||
IMAGE_LOGE("ImageSourceNapiCreateFromRawFile napi create failed");
|
||||
args->outVal = nullptr;
|
||||
return IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
HiLog::Debug(LABEL, "ImageSourceNapiCreateFromRawFile success");
|
||||
IMAGE_LOGD("ImageSourceNapiCreateFromRawFile success");
|
||||
return IMAGE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t ImageSourceNapiCreateIncremental(struct ImageSourceArgs* args)
|
||||
{
|
||||
if (args == nullptr || args->inEnv == nullptr) {
|
||||
HiLog::Error(LABEL, "ImageSourceNapiCreateIncremental args or env is nullptr");
|
||||
IMAGE_LOGE("ImageSourceNapiCreateIncremental args or env is nullptr");
|
||||
return IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
IncrementalSourceOptions incOpts;
|
||||
if (args->sourceOps != nullptr) {
|
||||
HiLog::Debug(LABEL, "ImageSourceNapiCreate ParseImageSourceOps");
|
||||
IMAGE_LOGD("ImageSourceNapiCreate ParseImageSourceOps");
|
||||
ParseImageSourceOps(incOpts.sourceOptions, args->sourceOps);
|
||||
}
|
||||
incOpts.incrementalMode = IncrementalMode::INCREMENTAL_DATA;
|
||||
uint32_t errorCode = ERR_MEDIA_INVALID_VALUE;
|
||||
std::unique_ptr<ImageSource> imageSource = ImageSource::CreateIncrementalImageSource(incOpts, errorCode);
|
||||
if (imageSource == nullptr) {
|
||||
HiLog::Error(LABEL, "ImageSourceNapiCreateIncremental native imagesource failed");
|
||||
IMAGE_LOGE("ImageSourceNapiCreateIncremental native imagesource failed");
|
||||
return IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
if (args->dataArray.data != nullptr && args->dataArray.dataSize > SIZE_ZERO) {
|
||||
HiLog::Debug(LABEL, "ImageSourceNapiCreateIncremental update dataArray");
|
||||
IMAGE_LOGD("ImageSourceNapiCreateIncremental update dataArray");
|
||||
imageSource->UpdateData(args->dataArray.data, args->dataArray.dataSize, false);
|
||||
}
|
||||
DecodeOptions decodeOpts;
|
||||
@ -378,41 +381,41 @@ static int32_t ImageSourceNapiCreateIncremental(struct ImageSourceArgs* args)
|
||||
std::unique_ptr<IncrementalPixelMap> incPixelMap = imageSource->CreateIncrementalPixelMap(
|
||||
index, decodeOpts, errorCode);
|
||||
if (incPixelMap == nullptr) {
|
||||
HiLog::Error(LABEL, "ImageSourceNapiCreateIncremental native incremental pixelmap failed");
|
||||
IMAGE_LOGE("ImageSourceNapiCreateIncremental native incremental pixelmap failed");
|
||||
return IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
if (ImageSourceCreateNapi(args->inEnv, args->outVal,
|
||||
std::move(imageSource), std::move(incPixelMap), nullptr) != SUCCESS) {
|
||||
HiLog::Error(LABEL, "ImageSourceNapiCreateIncremental napi create failed");
|
||||
IMAGE_LOGE("ImageSourceNapiCreateIncremental napi create failed");
|
||||
args->outVal = nullptr;
|
||||
return IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
HiLog::Debug(LABEL, "ImageSourceNapiCreateIncremental success");
|
||||
IMAGE_LOGD("ImageSourceNapiCreateIncremental success");
|
||||
return IMAGE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t ImageSourceNapiGetSupportedFormats(struct ImageSourceArgs* args)
|
||||
{
|
||||
if (args == nullptr) {
|
||||
HiLog::Error(LABEL, "ImageSourceNapiGetSupportedFormats args is nullptr");
|
||||
IMAGE_LOGE("ImageSourceNapiGetSupportedFormats args is nullptr");
|
||||
return IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
auto formats = args->outFormats;
|
||||
if (formats == nullptr) {
|
||||
HiLog::Error(LABEL, "ImageSourceNapiGetSupportedFormats args or napi is nullptr");
|
||||
IMAGE_LOGE("ImageSourceNapiGetSupportedFormats args or napi is nullptr");
|
||||
return IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
std::set<std::string> formatSet;
|
||||
uint32_t errorCode = ImageSource::GetSupportedFormats(formatSet);
|
||||
if (errorCode != SUCCESS) {
|
||||
HiLog::Error(LABEL, "ImageSourceNapiGetSupportedFormats native failed");
|
||||
IMAGE_LOGE("ImageSourceNapiGetSupportedFormats native failed");
|
||||
return IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
|
||||
size_t formatCount = formatSet.size();
|
||||
if (formats->supportedFormatList == nullptr) {
|
||||
formats->size = formatCount;
|
||||
HiLog::Debug(LABEL, "ImageSourceNapiGetSupportedFormats get count only Success");
|
||||
IMAGE_LOGD("ImageSourceNapiGetSupportedFormats get count only Success");
|
||||
return IMAGE_RESULT_SUCCESS;
|
||||
} else {
|
||||
formatCount = formats->size;
|
||||
@ -425,7 +428,7 @@ static int32_t ImageSourceNapiGetSupportedFormats(struct ImageSourceArgs* args)
|
||||
break;
|
||||
}
|
||||
if (formatList[i] == nullptr || formatList[i]->format == nullptr) {
|
||||
HiLog::Debug(LABEL, "ImageSourceNapiGetSupportedFormats nullptr format out buffer");
|
||||
IMAGE_LOGD("ImageSourceNapiGetSupportedFormats nullptr format out buffer");
|
||||
return IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
memcpy_s(formatList[i]->format, formatList[i]->size, formatStr.c_str(), formatStr.size());
|
||||
@ -434,19 +437,19 @@ static int32_t ImageSourceNapiGetSupportedFormats(struct ImageSourceArgs* args)
|
||||
}
|
||||
i++;
|
||||
}
|
||||
HiLog::Debug(LABEL, "ImageSourceNapiGetSupportedFormats Success");
|
||||
IMAGE_LOGD("ImageSourceNapiGetSupportedFormats Success");
|
||||
return IMAGE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t ImageSourceNapiUnwrap(struct ImageSourceArgs* args)
|
||||
{
|
||||
if (args == nullptr || args->inEnv == nullptr || args->inVal == nullptr) {
|
||||
HiLog::Error(LABEL, "ImageSourceNapiUnwrap args or env is nullptr");
|
||||
IMAGE_LOGE("ImageSourceNapiUnwrap args or env is nullptr");
|
||||
return IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
args->napi = UnwrapNativeObject(args->inEnv, args->inVal);
|
||||
if (args->napi == nullptr) {
|
||||
HiLog::Error(LABEL, "ImageSourceNapiUnwrap UnwrapNativeObject failed");
|
||||
IMAGE_LOGE("ImageSourceNapiUnwrap UnwrapNativeObject failed");
|
||||
return IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
return IMAGE_RESULT_SUCCESS;
|
||||
@ -456,7 +459,7 @@ static int32_t ImageSourceNapiCreatePixelmap(struct ImageSourceArgs* args)
|
||||
{
|
||||
auto native = GetNativeImageSource(args);
|
||||
if (native == nullptr || args->inEnv == nullptr) {
|
||||
HiLog::Error(LABEL, "ImageSourceNapiCreatePixelmap args or napi is nullptr");
|
||||
IMAGE_LOGE("ImageSourceNapiCreatePixelmap args or napi is nullptr");
|
||||
return IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
std::shared_ptr<PixelMap> nativePixelMap = args->napi->GetIncrementalPixelMap();
|
||||
@ -468,22 +471,22 @@ static int32_t ImageSourceNapiCreatePixelmap(struct ImageSourceArgs* args)
|
||||
ParseDecodingOps(decOps, args->decodingOps);
|
||||
index = args->decodingOps->index;
|
||||
}
|
||||
HiLog::Debug(LABEL, "ImageSourceNapiCreatePixelmap CreatePixelMapEx");
|
||||
IMAGE_LOGD("ImageSourceNapiCreatePixelmap CreatePixelMapEx");
|
||||
auto tmpPixelmap = native->CreatePixelMapEx(index, decOps, errorCode);
|
||||
if (tmpPixelmap != nullptr) {
|
||||
nativePixelMap = std::move(tmpPixelmap);
|
||||
}
|
||||
}
|
||||
if (nativePixelMap == nullptr) {
|
||||
HiLog::Error(LABEL, "ImageSourceNapiCreatePixelmap native failed");
|
||||
IMAGE_LOGE("ImageSourceNapiCreatePixelmap native failed");
|
||||
return IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
*(args->outVal) = PixelMapNapi::CreatePixelMap(args->inEnv, nativePixelMap);
|
||||
if (*(args->outVal) == nullptr) {
|
||||
HiLog::Error(LABEL, "ImageSourceNapiCreatePixelmap create pixelmap failed");
|
||||
IMAGE_LOGE("ImageSourceNapiCreatePixelmap create pixelmap failed");
|
||||
return IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
HiLog::Debug(LABEL, "ImageSourceNapiCreatePixelmap Success");
|
||||
IMAGE_LOGD("ImageSourceNapiCreatePixelmap Success");
|
||||
return IMAGE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
@ -491,7 +494,7 @@ static int32_t ImageSourceNapiCreatePixelmapList(struct ImageSourceArgs* args)
|
||||
{
|
||||
auto native = GetNativeImageSource(args);
|
||||
if (native == nullptr || args->inEnv == nullptr) {
|
||||
HiLog::Error(LABEL, "ImageSourceNapiCreatePixelmapList args or napi is nullptr");
|
||||
IMAGE_LOGE("ImageSourceNapiCreatePixelmapList args or napi is nullptr");
|
||||
return IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
DecodeOptions decOps;
|
||||
@ -501,7 +504,7 @@ static int32_t ImageSourceNapiCreatePixelmapList(struct ImageSourceArgs* args)
|
||||
}
|
||||
auto pixelMapList = native->CreatePixelMapList(decOps, errorCode);
|
||||
if (pixelMapList == nullptr) {
|
||||
HiLog::Error(LABEL, "ImageSourceNapiCreatePixelmapList CreatePixelMapList failed");
|
||||
IMAGE_LOGE("ImageSourceNapiCreatePixelmapList CreatePixelMapList failed");
|
||||
return IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
napi_create_array(args->inEnv, args->outVal);
|
||||
@ -511,7 +514,7 @@ static int32_t ImageSourceNapiCreatePixelmapList(struct ImageSourceArgs* args)
|
||||
napi_set_element(args->inEnv, *(args->outVal), i, napiPixelMap);
|
||||
i++;
|
||||
}
|
||||
HiLog::Debug(LABEL, "ImageSourceNapiCreatePixelmapList Success");
|
||||
IMAGE_LOGD("ImageSourceNapiCreatePixelmapList Success");
|
||||
return IMAGE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
@ -519,19 +522,19 @@ static int32_t ImageSourceNapiGetDelayTime(struct ImageSourceArgs* args) __attri
|
||||
{
|
||||
auto native = GetNativeImageSource(args);
|
||||
if (native == nullptr || args->outDelayTimes == nullptr) {
|
||||
HiLog::Error(LABEL, "ImageSourceNapiGetDelayTime native image or out is nullptr");
|
||||
IMAGE_LOGE("ImageSourceNapiGetDelayTime native image or out is nullptr");
|
||||
return IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
auto outDelayTimes = args->outDelayTimes;
|
||||
uint32_t errorCode = ERR_MEDIA_INVALID_VALUE;
|
||||
auto delayTimes = native->GetDelayTime(errorCode);
|
||||
if (delayTimes == nullptr) {
|
||||
HiLog::Error(LABEL, "ImageSourceNapiGetDelayTime native failed");
|
||||
IMAGE_LOGE("ImageSourceNapiGetDelayTime native failed");
|
||||
return IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
size_t actCount = (*delayTimes).size();
|
||||
if (outDelayTimes->delayTimeList == nullptr) {
|
||||
HiLog::Error(LABEL, "ImageSourceNapiGetDelayTime get times count only");
|
||||
IMAGE_LOGE("ImageSourceNapiGetDelayTime get times count only");
|
||||
outDelayTimes->size = actCount;
|
||||
return IMAGE_RESULT_SUCCESS;
|
||||
}
|
||||
@ -541,7 +544,7 @@ static int32_t ImageSourceNapiGetDelayTime(struct ImageSourceArgs* args) __attri
|
||||
for (size_t i = SIZE_ZERO; i < actCount; i++) {
|
||||
outDelayTimes->delayTimeList[i] = (*delayTimes)[i];
|
||||
}
|
||||
HiLog::Debug(LABEL, "ImageSourceNapiGetDelayTime Success");
|
||||
IMAGE_LOGD("ImageSourceNapiGetDelayTime Success");
|
||||
return IMAGE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
@ -549,16 +552,16 @@ static int32_t ImageSourceNapiGetFrameCount(struct ImageSourceArgs* args)
|
||||
{
|
||||
auto native = GetNativeImageSource(args);
|
||||
if (native == nullptr || args->outUint32 == nullptr) {
|
||||
HiLog::Error(LABEL, "ImageSourceNapiGetFrameCount native image or out is nullptr");
|
||||
IMAGE_LOGE("ImageSourceNapiGetFrameCount native image or out is nullptr");
|
||||
return IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
uint32_t errorCode = ERR_MEDIA_INVALID_VALUE;
|
||||
*(args->outUint32) = native->GetFrameCount(errorCode);
|
||||
if (errorCode != SUCCESS) {
|
||||
HiLog::Error(LABEL, "ImageSourceNapiGetFrameCount native failed");
|
||||
IMAGE_LOGE("ImageSourceNapiGetFrameCount native failed");
|
||||
return IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
HiLog::Debug(LABEL, "ImageSourceNapiGetFrameCount Success");
|
||||
IMAGE_LOGD("ImageSourceNapiGetFrameCount Success");
|
||||
return IMAGE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
@ -566,22 +569,22 @@ static int32_t ImageSourceNapiGetImageInfo(struct ImageSourceArgs* args)
|
||||
{
|
||||
auto native = GetNativeImageSource(args);
|
||||
if (native == nullptr) {
|
||||
HiLog::Error(LABEL, "ImageSourceNapiGetImageInfo native image is nullptr");
|
||||
IMAGE_LOGE("ImageSourceNapiGetImageInfo native image is nullptr");
|
||||
return IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
auto imageSourceInfo = args->outInfo;
|
||||
if (imageSourceInfo == nullptr) {
|
||||
HiLog::Error(LABEL, "ImageSourceNapiGetImageInfo image info is nullptr");
|
||||
IMAGE_LOGE("ImageSourceNapiGetImageInfo image info is nullptr");
|
||||
return IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
ImageInfo imageInfo;
|
||||
uint32_t errorCode = native->GetImageInfo(args->inInt32, imageInfo);
|
||||
if (errorCode != SUCCESS) {
|
||||
HiLog::Error(LABEL, "ImageSourceNapiGetImageInfo native failed");
|
||||
IMAGE_LOGE("ImageSourceNapiGetImageInfo native failed");
|
||||
return IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
ParseImageSourceInfo(imageSourceInfo, imageInfo);
|
||||
HiLog::Debug(LABEL, "ImageSourceNapiGetImageInfo Success");
|
||||
IMAGE_LOGD("ImageSourceNapiGetImageInfo Success");
|
||||
return IMAGE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
@ -590,28 +593,28 @@ static int32_t ImageSourceNapiGetImageProperty(
|
||||
{
|
||||
auto native = GetNativeImageSource(args);
|
||||
if (native == nullptr) {
|
||||
HiLog::Error(LABEL, "ImageSourceNapiGetImageProperty native image is nullptr");
|
||||
IMAGE_LOGE("ImageSourceNapiGetImageProperty native image is nullptr");
|
||||
return IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
auto propertyKey = args->inPropertyKey;
|
||||
auto propertyVal = args->propertyVal;
|
||||
if (propertyKey == nullptr || propertyKey->value == nullptr || propertyKey->size == SIZE_ZERO) {
|
||||
HiLog::Error(LABEL, "ImageSourceNapiGetImageProperty key is empty");
|
||||
IMAGE_LOGE("ImageSourceNapiGetImageProperty key is empty");
|
||||
return IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
if (propertyVal == nullptr) {
|
||||
HiLog::Error(LABEL, "ImageSourceNapiGetImageProperty out val is nullptr");
|
||||
IMAGE_LOGE("ImageSourceNapiGetImageProperty out val is nullptr");
|
||||
return IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
std::string key(propertyKey->value, propertyKey->size);
|
||||
std::string val;
|
||||
uint32_t errorCode = native->GetImagePropertyString(DEFAULT_INDEX, key, val);
|
||||
if (errorCode != SUCCESS || val.empty()) {
|
||||
HiLog::Error(LABEL, "ImageSourceNapiGetImageProperty native failed");
|
||||
IMAGE_LOGE("ImageSourceNapiGetImageProperty native failed");
|
||||
return IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
if (propertyVal->value == nullptr) {
|
||||
HiLog::Debug(LABEL, "ImageSourceNapiGetImageProperty return size only");
|
||||
IMAGE_LOGD("ImageSourceNapiGetImageProperty return size only");
|
||||
propertyVal->size = val.size();
|
||||
return IMAGE_RESULT_SUCCESS;
|
||||
}
|
||||
@ -619,7 +622,7 @@ static int32_t ImageSourceNapiGetImageProperty(
|
||||
if (propertyVal->size > val.size()) {
|
||||
propertyVal->size = val.size();
|
||||
}
|
||||
HiLog::Debug(LABEL, "ImageSourceNapiGetImageProperty Success");
|
||||
IMAGE_LOGD("ImageSourceNapiGetImageProperty Success");
|
||||
return IMAGE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
@ -629,28 +632,28 @@ static uint32_t NativePropertyModify(ImageSource* native, ImageResource &imageRe
|
||||
auto type = imageResource.type;
|
||||
uint32_t errorCode = ERR_MEDIA_INVALID_VALUE;
|
||||
if (type == ImageResourceType::IMAGE_RESOURCE_INVAILD) {
|
||||
HiLog::Error(LABEL, "NativePropertyModify resource is invaild");
|
||||
IMAGE_LOGE("NativePropertyModify resource is invaild");
|
||||
return IMAGE_RESULT_BAD_PARAMETER;
|
||||
} else if (type == ImageResourceType::IMAGE_RESOURCE_FD && imageResource.fd != INVALID_FD) {
|
||||
HiLog::Debug(LABEL, "NativePropertyModify fd resource");
|
||||
IMAGE_LOGD("NativePropertyModify fd resource");
|
||||
errorCode = native->ModifyImageProperty(DEFAULT_INDEX, key, val, imageResource.fd);
|
||||
} else if (type == ImageResourceType::IMAGE_RESOURCE_PATH && !imageResource.path.empty()) {
|
||||
HiLog::Debug(LABEL, "NativePropertyModify path resource");
|
||||
IMAGE_LOGD("NativePropertyModify path resource");
|
||||
errorCode = native->ModifyImageProperty(DEFAULT_INDEX, key, val, imageResource.path);
|
||||
} else if (type == ImageResourceType::IMAGE_RESOURCE_BUFFER &&
|
||||
imageResource.buffer != nullptr && imageResource.bufferSize > SIZE_ZERO) {
|
||||
HiLog::Debug(LABEL, "NativePropertyModify buffer resource");
|
||||
IMAGE_LOGD("NativePropertyModify buffer resource");
|
||||
errorCode = native->ModifyImageProperty(DEFAULT_INDEX, key, val,
|
||||
imageResource.buffer, imageResource.bufferSize);
|
||||
} else {
|
||||
HiLog::Error(LABEL, "NativePropertyModify %{public}d resource error", type);
|
||||
IMAGE_LOGE("NativePropertyModify %{public}d resource error", type);
|
||||
return IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
if (errorCode == SUCCESS) {
|
||||
HiLog::Debug(LABEL, "NativePropertyModify Success");
|
||||
IMAGE_LOGD("NativePropertyModify Success");
|
||||
return IMAGE_RESULT_SUCCESS;
|
||||
}
|
||||
HiLog::Error(LABEL, "NativePropertyModify native failed");
|
||||
IMAGE_LOGE("NativePropertyModify native failed");
|
||||
return IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
|
||||
@ -658,17 +661,17 @@ static int32_t ImageSourceNapiModifyImageProperty(struct ImageSourceArgs* args)
|
||||
{
|
||||
auto native = GetNativeImageSource(args);
|
||||
if (native == nullptr) {
|
||||
HiLog::Error(LABEL, "ImageSourceNapiModifyImageProperty native image is nullptr");
|
||||
IMAGE_LOGE("ImageSourceNapiModifyImageProperty native image is nullptr");
|
||||
return IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
auto propertyKey = args->inPropertyKey;
|
||||
auto propertyVal = args->propertyVal;
|
||||
if (propertyKey == nullptr || propertyKey->value == nullptr || propertyKey->size == SIZE_ZERO) {
|
||||
HiLog::Error(LABEL, "ImageSourceNapiModifyImageProperty key is empty");
|
||||
IMAGE_LOGE("ImageSourceNapiModifyImageProperty key is empty");
|
||||
return IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
if (propertyVal == nullptr || propertyVal->value == nullptr || propertyVal->size == SIZE_ZERO) {
|
||||
HiLog::Error(LABEL, "ImageSourceNapiModifyImageProperty val is nullptr");
|
||||
IMAGE_LOGE("ImageSourceNapiModifyImageProperty val is nullptr");
|
||||
return IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
std::string key(propertyKey->value, propertyKey->size);
|
||||
@ -682,7 +685,7 @@ static int32_t ProcessIncrementalPixelMap(struct ImageSourceArgs* args, bool com
|
||||
{
|
||||
auto incPixelMap = args->napi->GetIncrementalPixelMap();
|
||||
if (incPixelMap == nullptr) {
|
||||
HiLog::Error(LABEL, "ProcessIncrementalPixelMap incremental pixelmap is nullptr");
|
||||
IMAGE_LOGE("ProcessIncrementalPixelMap incremental pixelmap is nullptr");
|
||||
return IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
uint8_t tmpProgress = 0;
|
||||
@ -691,7 +694,7 @@ static int32_t ProcessIncrementalPixelMap(struct ImageSourceArgs* args, bool com
|
||||
incPixelMap->DetachFromDecoding();
|
||||
}
|
||||
if (errCode != SUCCESS || (errCode == ERR_IMAGE_SOURCE_DATA_INCOMPLETE && !completed)) {
|
||||
HiLog::Error(LABEL, "ProcessIncrementalPixelMap promote decoding failed");
|
||||
IMAGE_LOGE("ProcessIncrementalPixelMap promote decoding failed");
|
||||
return IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
return IMAGE_RESULT_SUCCESS;
|
||||
@ -709,20 +712,20 @@ static int32_t ImageSourceNapiUpdateData(struct ImageSourceArgs* args)
|
||||
{
|
||||
auto native = GetNativeImageSource(args);
|
||||
if (native == nullptr) {
|
||||
HiLog::Error(LABEL, "ImageSourceNapiUpdateData native image is nullptr");
|
||||
IMAGE_LOGE("ImageSourceNapiUpdateData native image is nullptr");
|
||||
return IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
auto data = args->inUpdateData;
|
||||
if (data == nullptr || data->buffer == nullptr || data->bufferSize == SIZE_ZERO ||
|
||||
data->offset >= data->bufferSize) {
|
||||
HiLog::Error(LABEL, "ImageSourceNapiUpdateData update data is empty");
|
||||
IMAGE_LOGE("ImageSourceNapiUpdateData update data is empty");
|
||||
return IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
uint32_t actSize = MathMin((data->bufferSize - data->offset), data->updateLength);
|
||||
bool completed = data->isCompleted == INT8_TRUE;
|
||||
uint32_t errCode = native->UpdateData((data->buffer + data->offset), actSize, completed);
|
||||
if (errCode != SUCCESS) {
|
||||
HiLog::Error(LABEL, "ImageSourceNapiUpdateData update native failed");
|
||||
IMAGE_LOGE("ImageSourceNapiUpdateData update native failed");
|
||||
return IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
return ProcessIncrementalPixelMap(args, completed);
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -110,17 +110,17 @@ do \
|
||||
|
||||
#define DECORATOR_HILOG(op, fmt, args...) \
|
||||
do { \
|
||||
op(LABEL, fmt, ##args); \
|
||||
op(LOG_CORE, fmt, ##args); \
|
||||
} while (0)
|
||||
|
||||
#define IMAGE_ERR(fmt, ...) DECORATOR_HILOG(HiLog::Error, fmt, ##__VA_ARGS__)
|
||||
#define IMAGE_ERR(fmt, ...) DECORATOR_HILOG(HILOG_ERROR, fmt, ##__VA_ARGS__)
|
||||
#ifdef IMAGE_DEBUG_FLAG
|
||||
#define IMAGE_INFO(fmt, ...) DECORATOR_HILOG(HiLog::Info, fmt, ##__VA_ARGS__)
|
||||
#define IMAGE_DEBUG(fmt, ...) DECORATOR_HILOG(HiLog::Debug, fmt, ##__VA_ARGS__)
|
||||
#define IMAGE_FUNCTION_IN(fmt, ...) DECORATOR_HILOG(HiLog::Debug, fmt "%{public}s IN", __FUNCTION__, ##__VA_ARGS__)
|
||||
#define IMAGE_FUNCTION_OUT(fmt, ...) DECORATOR_HILOG(HiLog::Debug, fmt "%{public}s OUT", __FUNCTION__, ##__VA_ARGS__)
|
||||
#define IMAGE_LINE_IN(fmt, ...) DECORATOR_HILOG(HiLog::Debug, fmt "%{public}d IN", __LINE__, ##__VA_ARGS__)
|
||||
#define IMAGE_LINE_OUT(fmt, ...) DECORATOR_HILOG(HiLog::Debug, fmt "%{public}d OUT", __LINE__, ##__VA_ARGS__)
|
||||
#define IMAGE_INFO(fmt, ...) DECORATOR_HILOG(HILOG_INFO, fmt, ##__VA_ARGS__)
|
||||
#define IMAGE_DEBUG(fmt, ...) DECORATOR_HILOG(HILOG_DEBUG, fmt, ##__VA_ARGS__)
|
||||
#define IMAGE_FUNCTION_IN(fmt, ...) DECORATOR_HILOG(HILOG_DEBUG, fmt "%{public}s IN", ##__VA_ARGS__, __FUNCTION__)
|
||||
#define IMAGE_FUNCTION_OUT(fmt, ...) DECORATOR_HILOG(HILOG_DEBUG, fmt "%{public}s OUT", ##__VA_ARGS__, __FUNCTION__)
|
||||
#define IMAGE_LINE_IN(fmt, ...) DECORATOR_HILOG(HILOG_DEBUG, fmt "%{public}d IN", ##__VA_ARGS__, __LINE__)
|
||||
#define IMAGE_LINE_OUT(fmt, ...) DECORATOR_HILOG(HILOG_DEBUG, fmt "%{public}d OUT", ##__VA_ARGS__, __LINE__)
|
||||
#else
|
||||
#define IMAGE_INFO(fmt, ...)
|
||||
#define IMAGE_DEBUG(fmt, ...)
|
||||
|
@ -14,13 +14,15 @@
|
||||
*/
|
||||
|
||||
#include "native_module_ohos_image.h"
|
||||
#include "hilog/log.h"
|
||||
#include "log_tags.h"
|
||||
|
||||
using OHOS::HiviewDFX::HiLog;
|
||||
namespace {
|
||||
constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_TAG_DOMAIN_ID_IMAGE, "NAPITEST"};
|
||||
}
|
||||
#include "image_log.h"
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_IMAGE
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "NAPITEST"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media{
|
||||
/*
|
||||
@ -28,18 +30,18 @@ namespace Media{
|
||||
*/
|
||||
static napi_value Export(napi_env env, napi_value exports)
|
||||
{
|
||||
HiLog::Info(LABEL, "ImagePackerNapi CALL");
|
||||
IMAGE_LOGD("ImagePackerNapi CALL");
|
||||
ImagePackerNapi::Init(env, exports);
|
||||
HiLog::Info(LABEL, "PixelMapNapi CALL");
|
||||
IMAGE_LOGD("PixelMapNapi CALL");
|
||||
PixelMapNapi::Init(env, exports);
|
||||
HiLog::Info(LABEL, "ImageSourceNapi CALL");
|
||||
IMAGE_LOGD("ImageSourceNapi CALL");
|
||||
ImageSourceNapi::Init(env, exports);
|
||||
#if !defined(IOS_PLATFORM) && !defined(A_PLATFORM)
|
||||
HiLog::Info(LABEL, "ImageReceiverNapi CALL");
|
||||
IMAGE_LOGD("ImageReceiverNapi CALL");
|
||||
ImageReceiverNapi::Init(env, exports);
|
||||
HiLog::Info(LABEL, "ImageCreatorNapi CALL");
|
||||
IMAGE_LOGD("ImageCreatorNapi CALL");
|
||||
ImageCreatorNapi::Init(env, exports);
|
||||
HiLog::Info(LABEL, "ImageNapi CALL");
|
||||
IMAGE_LOGD("ImageNapi CALL");
|
||||
ImageNapi::Init(env, exports);
|
||||
#endif
|
||||
return exports;
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -223,6 +223,7 @@ if (use_clang_android) {
|
||||
"c_utils:utils",
|
||||
"graphic_2d:color_manager",
|
||||
"graphic_surface:surface",
|
||||
"hilog:libhilog",
|
||||
"hitrace:hitrace_meter",
|
||||
"ipc:ipc_core",
|
||||
"napi:ace_napi",
|
||||
@ -356,6 +357,7 @@ ohos_static_library("image_static") {
|
||||
"c_utils:utils",
|
||||
"graphic_2d:color_manager",
|
||||
"graphic_surface:surface",
|
||||
"hilog:libhilog",
|
||||
]
|
||||
}
|
||||
subsystem_name = "multimedia"
|
||||
|
@ -175,7 +175,10 @@ if (use_clang_ios) {
|
||||
"$image_subsystem/frameworks/innerkitsimpl/pixelconverter:pixelconvertadapter",
|
||||
]
|
||||
|
||||
external_deps = [ "napi:ace_napi" ]
|
||||
external_deps = [
|
||||
"hilog:libhilog",
|
||||
"napi:ace_napi",
|
||||
]
|
||||
|
||||
output_name = "libimage"
|
||||
relative_install_dir = "module/multimedia"
|
||||
@ -211,6 +214,7 @@ if (use_clang_ios) {
|
||||
"-DIMAGE_DEBUG_FLAG",
|
||||
"-DIMAGE_COLORSPACE_FLAG",
|
||||
]
|
||||
external_deps = []
|
||||
|
||||
if (use_clang_android) {
|
||||
defines = image_decode_android_defines
|
||||
@ -239,9 +243,10 @@ if (use_clang_ios) {
|
||||
"$image_subsystem/frameworks/innerkitsimpl/utils:image_utils",
|
||||
"$image_subsystem/interfaces/innerkits:image_native",
|
||||
]
|
||||
external_deps += [ "hilog:libhilog" ]
|
||||
}
|
||||
|
||||
external_deps = [
|
||||
external_deps += [
|
||||
"c_utils:utils",
|
||||
"graphic_2d:color_manager",
|
||||
"graphic_2d:color_space_object_convertor",
|
||||
|
@ -15,14 +15,17 @@
|
||||
|
||||
#include "my_pixel_map.h"
|
||||
#include "media_errors.h"
|
||||
#include "hilog/log.h"
|
||||
#include "image_log.h"
|
||||
#include "image_napi_utils.h"
|
||||
#include "image_pixel_map_napi.h"
|
||||
#include "log_tags.h"
|
||||
|
||||
using OHOS::HiviewDFX::HiLog;
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_IMAGE
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "MyPixelMapNapiTest"
|
||||
|
||||
namespace {
|
||||
constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_TAG_DOMAIN_ID_IMAGE, "MyPixelMapNapiTest"};
|
||||
constexpr uint32_t TEST_ARG_SUM = 1;
|
||||
}
|
||||
namespace OHOS {
|
||||
@ -52,32 +55,32 @@ napi_value MyPixelMap::Init(napi_env env, napi_value exports)
|
||||
|
||||
if (napi_define_class(env, CLASS_NAME.c_str(), NAPI_AUTO_LENGTH, Constructor, nullptr, IMG_ARRAY_SIZE(props),
|
||||
props, &constructor) != napi_ok) {
|
||||
HiLog::Error(LABEL, "define class fail");
|
||||
IMAGE_LOGE("define class fail");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (napi_create_reference(env, constructor, 1, &sConstructor_) != napi_ok) {
|
||||
HiLog::Error(LABEL, "create reference fail");
|
||||
IMAGE_LOGE("create reference fail");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (napi_set_named_property(env, exports, CLASS_NAME.c_str(), constructor) != napi_ok) {
|
||||
HiLog::Error(LABEL, "set named property fail");
|
||||
IMAGE_LOGE("set named property fail");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (napi_define_properties(env, exports, IMG_ARRAY_SIZE(static_prop), static_prop) != napi_ok) {
|
||||
HiLog::Error(LABEL, "define properties fail");
|
||||
IMAGE_LOGE("define properties fail");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
HiLog::Debug(LABEL, "Init success");
|
||||
IMAGE_LOGD("Init success");
|
||||
return exports;
|
||||
}
|
||||
|
||||
napi_value MyPixelMap::Constructor(napi_env env, napi_callback_info info)
|
||||
{
|
||||
HiLog::Debug(LABEL, "Constructor IN");
|
||||
IMAGE_LOGD("Constructor IN");
|
||||
napi_value undefineVar = nullptr;
|
||||
napi_get_undefined(env, &undefineVar);
|
||||
|
||||
@ -87,13 +90,13 @@ napi_value MyPixelMap::Constructor(napi_env env, napi_callback_info info)
|
||||
|
||||
napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr);
|
||||
|
||||
HiLog::Debug(LABEL, "Constructor OUT");
|
||||
IMAGE_LOGD("Constructor OUT");
|
||||
return thisVar;
|
||||
}
|
||||
|
||||
napi_value MyPixelMap::TestGetImageInfo(napi_env env, napi_callback_info info)
|
||||
{
|
||||
HiLog::Debug(LABEL, "TestGetImageInfo IN");
|
||||
IMAGE_LOGD("TestGetImageInfo IN");
|
||||
|
||||
napi_value result = nullptr;
|
||||
napi_get_undefined(env, &result);
|
||||
@ -105,23 +108,23 @@ napi_value MyPixelMap::TestGetImageInfo(napi_env env, napi_callback_info info)
|
||||
|
||||
status = napi_get_cb_info(env, info, &argCount, argValue, &thisVar, nullptr);
|
||||
if (status != napi_ok) {
|
||||
HiLog::Error(LABEL, "napi_get_cb_info fail");
|
||||
IMAGE_LOGE("napi_get_cb_info fail");
|
||||
}
|
||||
|
||||
HiLog::Debug(LABEL, "OH_GetImageInfo Test|Begin");
|
||||
IMAGE_LOGD("OH_GetImageInfo Test|Begin");
|
||||
OhosPixelMapInfo pixelMapInfo;
|
||||
int32_t res = OH_GetImageInfo(env, argValue[0], &pixelMapInfo);
|
||||
HiLog::Debug(LABEL, "OH_GetImageInfo Test|End, res=%{public}d", res);
|
||||
HiLog::Debug(LABEL, "OH_GetImageInfo, w=%{public}u, h=%{public}u, r=%{public}u, f=%{public}d",
|
||||
IMAGE_LOGD("OH_GetImageInfo Test|End, res=%{public}d", res);
|
||||
IMAGE_LOGD("OH_GetImageInfo, w=%{public}u, h=%{public}u, r=%{public}u, f=%{public}d",
|
||||
pixelMapInfo.width, pixelMapInfo.height, pixelMapInfo.rowSize, pixelMapInfo.pixelFormat);
|
||||
|
||||
HiLog::Debug(LABEL, "TestGetImageInfo OUT");
|
||||
IMAGE_LOGD("TestGetImageInfo OUT");
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value MyPixelMap::TestAccessPixels(napi_env env, napi_callback_info info)
|
||||
{
|
||||
HiLog::Debug(LABEL, "TestAccessPixels IN");
|
||||
IMAGE_LOGD("TestAccessPixels IN");
|
||||
|
||||
napi_value result = nullptr;
|
||||
napi_get_undefined(env, &result);
|
||||
@ -133,21 +136,21 @@ napi_value MyPixelMap::TestAccessPixels(napi_env env, napi_callback_info info)
|
||||
|
||||
status = napi_get_cb_info(env, info, &argCount, argValue, &thisVar, nullptr);
|
||||
if (status != napi_ok) {
|
||||
HiLog::Error(LABEL, "napi_get_cb_info fail");
|
||||
IMAGE_LOGE("napi_get_cb_info fail");
|
||||
}
|
||||
|
||||
HiLog::Debug(LABEL, "OH_AccessPixels Test|Begin");
|
||||
IMAGE_LOGD("OH_AccessPixels Test|Begin");
|
||||
void* addrPtr = nullptr;
|
||||
int32_t res = OH_AccessPixels(env, argValue[0], &addrPtr);
|
||||
HiLog::Debug(LABEL, "OH_AccessPixels Test|End, res=%{public}d", res);
|
||||
IMAGE_LOGD("OH_AccessPixels Test|End, res=%{public}d", res);
|
||||
|
||||
HiLog::Debug(LABEL, "TestAccessPixels OUT");
|
||||
IMAGE_LOGD("TestAccessPixels OUT");
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value MyPixelMap::TestUnAccessPixels(napi_env env, napi_callback_info info)
|
||||
{
|
||||
HiLog::Debug(LABEL, "TestUnAccessPixels IN");
|
||||
IMAGE_LOGD("TestUnAccessPixels IN");
|
||||
|
||||
napi_value result = nullptr;
|
||||
napi_get_undefined(env, &result);
|
||||
@ -159,14 +162,14 @@ napi_value MyPixelMap::TestUnAccessPixels(napi_env env, napi_callback_info info)
|
||||
|
||||
status = napi_get_cb_info(env, info, &argCount, argValue, &thisVar, nullptr);
|
||||
if (status != napi_ok) {
|
||||
HiLog::Error(LABEL, "napi_get_cb_info fail");
|
||||
IMAGE_LOGE("napi_get_cb_info fail");
|
||||
}
|
||||
|
||||
HiLog::Debug(LABEL, "OH_UnAccessPixels Test|Begin");
|
||||
IMAGE_LOGD("OH_UnAccessPixels Test|Begin");
|
||||
int32_t res = OH_UnAccessPixels(env, argValue[0]);
|
||||
HiLog::Debug(LABEL, "OH_UnAccessPixels Test|End, res=%{public}d", res);
|
||||
IMAGE_LOGD("OH_UnAccessPixels Test|End, res=%{public}d", res);
|
||||
|
||||
HiLog::Debug(LABEL, "TestUnAccessPixels OUT");
|
||||
IMAGE_LOGD("TestUnAccessPixels OUT");
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -175,7 +178,7 @@ napi_value MyPixelMap::TestUnAccessPixels(napi_env env, napi_callback_info info)
|
||||
*/
|
||||
static napi_value Export(napi_env env, napi_value exports)
|
||||
{
|
||||
HiLog::Info(LABEL, "MyPixelMap CALL");
|
||||
IMAGE_LOGI("MyPixelMap CALL");
|
||||
MyPixelMap::Init(env, exports);
|
||||
return exports;
|
||||
}
|
||||
|
@ -19,6 +19,11 @@
|
||||
#include "hilog/log_cpp.h"
|
||||
#include "ostream"
|
||||
|
||||
int HiLogPrint(LogType type, LogLevel level, unsigned int domain, const char *tag, const char *fmt, ...)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
namespace OHOS {
|
||||
namespace HiviewDFX {
|
||||
using namespace std;
|
||||
|
@ -43,6 +43,7 @@ ohos_shared_library("imageformatagent") {
|
||||
"//foundation/multimedia/image_framework/plugins/common/libs/image/formatagentplugin/include",
|
||||
"//foundation/multimedia/image_framework/plugins/manager/include/utils",
|
||||
"//foundation/multimedia/image_framework/interfaces/innerkits/include",
|
||||
"${image_subsystem}/frameworks/innerkitsimpl/utils/include",
|
||||
]
|
||||
|
||||
if (use_mingw_win) {
|
||||
@ -74,7 +75,6 @@ ohos_shared_library("imageformatagent") {
|
||||
"hilog:libhilog",
|
||||
]
|
||||
}
|
||||
|
||||
part_name = "image_framework"
|
||||
|
||||
subsystem_name = "multimedia"
|
||||
|
@ -14,18 +14,21 @@
|
||||
*/
|
||||
|
||||
#include "bmp_format_agent.h"
|
||||
#include "hilog/log_c.h"
|
||||
#include "hilog/log_cpp.h"
|
||||
#include "log_tags.h"
|
||||
|
||||
#include "image_log.h"
|
||||
#include "plugin_service.h"
|
||||
#include "sched.h"
|
||||
#include "string"
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_PLUGIN
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "BmpFormatAgent"
|
||||
|
||||
namespace OHOS {
|
||||
namespace ImagePlugin {
|
||||
using namespace OHOS::HiviewDFX;
|
||||
using namespace MultimediaPlugin;
|
||||
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_PLUGIN, "BmpFormatAgent" };
|
||||
namespace {
|
||||
const std::string FORMAT_TYPE = "image/bmp";
|
||||
constexpr uint8_t BMP_HEADER[] = { 0x42, 0x4D };
|
||||
@ -44,17 +47,17 @@ uint32_t BmpFormatAgent::GetHeaderSize()
|
||||
bool BmpFormatAgent::CheckFormat(const void *headerData, uint32_t dataSize)
|
||||
{
|
||||
if (headerData == nullptr) {
|
||||
HiLog::Error(LABEL, "check format failed: header data is null.");
|
||||
IMAGE_LOGE("check format failed: header data is null.");
|
||||
return false;
|
||||
}
|
||||
uint32_t headerSize = sizeof(BMP_HEADER);
|
||||
if (dataSize < headerSize) {
|
||||
HiLog::Error(LABEL, "read head size:[%{public}u] less than header size:[%{public}u].", dataSize, headerSize);
|
||||
IMAGE_LOGE("read head size:[%{public}u] less than header size:[%{public}u].", dataSize, headerSize);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (memcmp(headerData, BMP_HEADER, headerSize) != 0) {
|
||||
HiLog::Info(LABEL, "header stamp mismatch.");
|
||||
IMAGE_LOGI("header stamp mismatch.");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -14,23 +14,26 @@
|
||||
*/
|
||||
|
||||
#include "gif_format_agent.h"
|
||||
#include "hilog/log_c.h"
|
||||
#include "hilog/log_cpp.h"
|
||||
#include "log_tags.h"
|
||||
|
||||
#include "image_log.h"
|
||||
#include "plugin_service.h"
|
||||
#include "sched.h"
|
||||
#include "string"
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_PLUGIN
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "GifFormatAgent"
|
||||
|
||||
namespace OHOS {
|
||||
namespace ImagePlugin {
|
||||
using namespace OHOS::HiviewDFX;
|
||||
using namespace MultimediaPlugin;
|
||||
|
||||
static const std::string FORMAT_TYPE = "image/gif";
|
||||
static const char GIF87_STAMP[] = "GIF87a";
|
||||
static const char GIF89_STAMP[] = "GIF89a";
|
||||
static const uint8_t GIF_STAMP_LEN = 6;
|
||||
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_PLUGIN, "GifFormatAgent" };
|
||||
|
||||
std::string GifFormatAgent::GetFormatType()
|
||||
{
|
||||
@ -45,17 +48,17 @@ uint32_t GifFormatAgent::GetHeaderSize()
|
||||
bool GifFormatAgent::CheckFormat(const void *headerData, uint32_t dataSize)
|
||||
{
|
||||
if (headerData == nullptr) {
|
||||
HiLog::Error(LABEL, "check format failed: header data is null.");
|
||||
IMAGE_LOGE("check format failed: header data is null.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (dataSize < GIF_STAMP_LEN) {
|
||||
HiLog::Error(LABEL, "read head size:[%{public}u] less than header size:[%{public}u].", dataSize, GIF_STAMP_LEN);
|
||||
IMAGE_LOGE("read head size:[%{public}u] less than header size:[%{public}u].", dataSize, GIF_STAMP_LEN);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (memcmp(GIF87_STAMP, headerData, GIF_STAMP_LEN) != 0 && memcmp(GIF89_STAMP, headerData, GIF_STAMP_LEN) != 0) {
|
||||
HiLog::Info(LABEL, "header stamp mismatch.");
|
||||
IMAGE_LOGI("header stamp mismatch.");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -14,16 +14,20 @@
|
||||
*/
|
||||
|
||||
#include "heif_format_agent.h"
|
||||
#include "hilog/log_c.h"
|
||||
#include "hilog/log_cpp.h"
|
||||
#include "log_tags.h"
|
||||
|
||||
#include "image_log.h"
|
||||
#include "plugin_service.h"
|
||||
#include "string"
|
||||
#include "securec.h"
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_PLUGIN
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "HeifFormatAgent"
|
||||
|
||||
namespace OHOS {
|
||||
namespace ImagePlugin {
|
||||
using namespace OHOS::HiviewDFX;
|
||||
using namespace MultimediaPlugin;
|
||||
|
||||
const std::string FORMAT_TYPE = "image/heif";
|
||||
@ -37,7 +41,6 @@ constexpr uint32_t TIMES_SEVEN = 7;
|
||||
constexpr uint32_t TIMES_FIVE = 5;
|
||||
constexpr uint32_t TIMES_THREE = 3;
|
||||
constexpr uint32_t TIMES_TWO = 2;
|
||||
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_PLUGIN, "HeifFormatAgent" };
|
||||
|
||||
std::string HeifFormatAgent::GetFormatType()
|
||||
{
|
||||
@ -52,18 +55,18 @@ uint32_t HeifFormatAgent::GetHeaderSize()
|
||||
bool HeifFormatAgent::CheckFormat(const void *headerData, uint32_t dataSize)
|
||||
{
|
||||
if (headerData == nullptr) {
|
||||
HiLog::Error(LABEL, "check format failed: header data is null.");
|
||||
IMAGE_LOGE("check format failed: header data is null.");
|
||||
return false;
|
||||
}
|
||||
// Any valid ftyp box should have at least 8 bytes.
|
||||
if (dataSize < HEADER_LEAST_SIZE) {
|
||||
HiLog::Error(LABEL, "data size[%{public}u] less than eight.", dataSize);
|
||||
IMAGE_LOGE("data size[%{public}u] less than eight.", dataSize);
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t tmpBuff[HEADER_SIZE];
|
||||
if (memcpy_s(tmpBuff, HEADER_SIZE, headerData, dataSize) != 0) {
|
||||
HiLog::Error(LABEL, "memcpy headerData data size:[%{public}d] error.", dataSize);
|
||||
IMAGE_LOGE("memcpy headerData data size:[%{public}d] error.", dataSize);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -71,7 +74,7 @@ bool HeifFormatAgent::CheckFormat(const void *headerData, uint32_t dataSize)
|
||||
uint64_t chunkSize = EndianSwap32(ptr[0]); // first item
|
||||
uint32_t chunkType = EndianSwap32(ptr[1]); // second item
|
||||
if (chunkType != Fourcc('f', 't', 'y', 'p')) {
|
||||
HiLog::Error(LABEL, "head type is not ftyp.");
|
||||
IMAGE_LOGE("head type is not ftyp.");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -83,7 +86,7 @@ bool HeifFormatAgent::CheckFormat(const void *headerData, uint32_t dataSize)
|
||||
// It should at least have major brand (4-byte) and minor version (4-bytes).
|
||||
// The rest of the chunk (if any) is a list of (4-byte) compatible brands.
|
||||
if (chunkDataSize < HEADER_LEAST_SIZE) {
|
||||
HiLog::Error(LABEL, "chunk data size [%{public}lld] less than eight.", static_cast<long long>(chunkDataSize));
|
||||
IMAGE_LOGE("chunk data size [%{public}lld] less than eight.", static_cast<long long>(chunkDataSize));
|
||||
return false;
|
||||
}
|
||||
uint32_t numCompatibleBrands = (chunkDataSize - OFFSET_SIZE) / sizeof(uint32_t);
|
||||
@ -101,7 +104,7 @@ bool HeifFormatAgent::CheckFormat(const void *headerData, uint32_t dataSize)
|
||||
}
|
||||
}
|
||||
}
|
||||
HiLog::Info(LABEL, "check heif format failed.");
|
||||
IMAGE_LOGI("check heif format failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -112,21 +115,20 @@ bool HeifFormatAgent::IsHeif64(const void *buffer, const size_t bytesRead, int64
|
||||
// This indicates that the next 8 bytes represent the chunk size,
|
||||
// and chunk data comes after that.
|
||||
if (bytesRead < HEADER_NEXT_SIZE) {
|
||||
HiLog::Error(LABEL, "bytes read [%{public}zd] less than sixteen.", bytesRead);
|
||||
IMAGE_LOGE("bytes read [%{public}zd] less than sixteen.", bytesRead);
|
||||
return false;
|
||||
}
|
||||
auto *chunkSizePtr = static_cast<const uint64_t *>(buffer) + (offset / sizeof(uint64_t));
|
||||
chunkSize = EndianSwap64(*chunkSizePtr);
|
||||
if (chunkSize < HEADER_NEXT_SIZE) {
|
||||
// The smallest valid chunk is 16 bytes long in this case.
|
||||
HiLog::Error(LABEL, "chunk size [%{public}llu] less than sixteen.",
|
||||
static_cast<unsigned long long>(chunkSize));
|
||||
IMAGE_LOGE("chunk size [%{public}llu] less than sixteen.", static_cast<unsigned long long>(chunkSize));
|
||||
return false;
|
||||
}
|
||||
offset += OFFSET_SIZE;
|
||||
} else if (chunkSize < HEADER_LEAST_SIZE) {
|
||||
// The smallest valid chunk is 8 bytes long.
|
||||
HiLog::Error(LABEL, "chunk size [%{public}llu] less than eight.", static_cast<unsigned long long>(chunkSize));
|
||||
IMAGE_LOGE("chunk size [%{public}llu] less than eight.", static_cast<unsigned long long>(chunkSize));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -14,21 +14,24 @@
|
||||
*/
|
||||
|
||||
#include "jpeg_format_agent.h"
|
||||
#include "hilog/log_c.h"
|
||||
#include "hilog/log_cpp.h"
|
||||
#include "log_tags.h"
|
||||
|
||||
#include "image_log.h"
|
||||
#include "plugin_service.h"
|
||||
#include "sched.h"
|
||||
#include "string"
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_PLUGIN
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "JpegFormatAgent"
|
||||
|
||||
namespace OHOS {
|
||||
namespace ImagePlugin {
|
||||
using namespace OHOS::HiviewDFX;
|
||||
using namespace MultimediaPlugin;
|
||||
|
||||
static const std::string FORMAT_TYPE = "image/jpeg";
|
||||
static constexpr uint8_t JPEG_HEADER[] = { 0xFF, 0xD8, 0xFF };
|
||||
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_PLUGIN, "JpegFormatAgent" };
|
||||
|
||||
std::string JpegFormatAgent::GetFormatType()
|
||||
{
|
||||
@ -43,17 +46,17 @@ uint32_t JpegFormatAgent::GetHeaderSize()
|
||||
bool JpegFormatAgent::CheckFormat(const void *headerData, uint32_t dataSize)
|
||||
{
|
||||
if (headerData == nullptr) {
|
||||
HiLog::Error(LABEL, "check format failed: header data is null.");
|
||||
IMAGE_LOGE("check format failed: header data is null.");
|
||||
return false;
|
||||
}
|
||||
uint32_t headerSize = sizeof(JPEG_HEADER);
|
||||
if (dataSize < headerSize) {
|
||||
HiLog::Error(LABEL, "read head size:[%{public}u] less than header size:[%{public}u].", dataSize, headerSize);
|
||||
IMAGE_LOGE("read head size:[%{public}u] less than header size:[%{public}u].", dataSize, headerSize);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (memcmp(headerData, JPEG_HEADER, headerSize) != 0) {
|
||||
HiLog::Info(LABEL, "header stamp mismatch.");
|
||||
IMAGE_LOGI("header stamp mismatch.");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -14,14 +14,13 @@
|
||||
*/
|
||||
|
||||
#include "plugin_export.h"
|
||||
|
||||
#include "bmp_format_agent.h"
|
||||
#include "gif_format_agent.h"
|
||||
#include "heif_format_agent.h"
|
||||
#include "hilog/log_c.h"
|
||||
#include "hilog/log_cpp.h"
|
||||
#include "image_log.h"
|
||||
#include "iosfwd"
|
||||
#include "jpeg_format_agent.h"
|
||||
#include "log_tags.h"
|
||||
#include "map"
|
||||
#include "plugin_class_base.h"
|
||||
#include "plugin_utils.h"
|
||||
@ -33,6 +32,11 @@
|
||||
#include "wbmp_format_agent.h"
|
||||
#include "webp_format_agent.h"
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_PLUGIN
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "LibImageFormatAgent"
|
||||
|
||||
// plugin package name same as metadata.
|
||||
namespace {
|
||||
@ -53,32 +57,26 @@ PLUGIN_EXPORT_REGISTER_CLASS(OHOS::ImagePlugin::WbmpFormatAgent)
|
||||
PLUGIN_EXPORT_REGISTER_CLASS_END
|
||||
|
||||
using std::string;
|
||||
using namespace OHOS::HiviewDFX;
|
||||
|
||||
static constexpr HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_PLUGIN, "LibImageFormatAgent" };
|
||||
|
||||
#define PLUGIN_LOG_D(...) HiLog::Debug(LABEL, __VA_ARGS__)
|
||||
#define PLUGIN_LOG_E(...) HiLog::Error(LABEL, __VA_ARGS__)
|
||||
|
||||
// define the external interface of this plugin.
|
||||
PLUGIN_EXPORT_DEFAULT_EXTERNAL_START()
|
||||
PLUGIN_EXPORT_DEFAULT_EXTERNAL_STOP()
|
||||
OHOS::MultimediaPlugin::PluginClassBase *PluginExternalCreate(const string &className)
|
||||
{
|
||||
HiLog::Debug(LABEL, "PluginExternalCreate: create object for package: %{public}s, class: %{public}s.",
|
||||
PACKAGE_NAME.c_str(), className.c_str());
|
||||
IMAGE_LOGD("PluginExternalCreate: create object for package: %{public}s, class: %{public}s.",
|
||||
PACKAGE_NAME.c_str(), className.c_str());
|
||||
|
||||
auto iter = implClassMap.find(className);
|
||||
if (iter == implClassMap.end()) {
|
||||
HiLog::Error(LABEL, "PluginExternalCreate: failed to find class: %{public}s, in package: %{public}s.",
|
||||
className.c_str(), PACKAGE_NAME.c_str());
|
||||
IMAGE_LOGE("PluginExternalCreate: failed to find class: %{public}s, in package: %{public}s.",
|
||||
className.c_str(), PACKAGE_NAME.c_str());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto creator = iter->second;
|
||||
if (creator == nullptr) {
|
||||
HiLog::Error(LABEL, "PluginExternalCreate: null creator for class: %{public}s, in package: %{public}s.",
|
||||
className.c_str(), PACKAGE_NAME.c_str());
|
||||
IMAGE_LOGE("PluginExternalCreate: null creator for class: %{public}s, in package: %{public}s.",
|
||||
className.c_str(), PACKAGE_NAME.c_str());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -14,21 +14,24 @@
|
||||
*/
|
||||
|
||||
#include "png_format_agent.h"
|
||||
#include "hilog/log_c.h"
|
||||
#include "hilog/log_cpp.h"
|
||||
#include "log_tags.h"
|
||||
|
||||
#include "image_log.h"
|
||||
#include "plugin_service.h"
|
||||
#include "sched.h"
|
||||
#include "string"
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_PLUGIN
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "PngFormatAgent"
|
||||
|
||||
namespace OHOS {
|
||||
namespace ImagePlugin {
|
||||
using namespace OHOS::HiviewDFX;
|
||||
using namespace MultimediaPlugin;
|
||||
|
||||
static const std::string FORMAT_TYPE = "image/png";
|
||||
static constexpr uint8_t PNG_HEADER[] = { 137, 80, 78, 71, 13, 10, 26, 10 };
|
||||
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_PLUGIN, "PngFormatAgent" };
|
||||
|
||||
std::string PngFormatAgent::GetFormatType()
|
||||
{
|
||||
@ -43,12 +46,12 @@ uint32_t PngFormatAgent::GetHeaderSize()
|
||||
bool PngFormatAgent::CheckFormat(const void *headerData, uint32_t dataSize)
|
||||
{
|
||||
if (headerData == nullptr || dataSize == 0) {
|
||||
HiLog::Error(LABEL, "check format input parameter abnormal.");
|
||||
IMAGE_LOGE("check format input parameter abnormal.");
|
||||
return false;
|
||||
}
|
||||
uint32_t headerSize = sizeof(PNG_HEADER);
|
||||
if (dataSize < headerSize) {
|
||||
HiLog::Error(LABEL, "read head size:[%{public}u] less than header size:[%{public}u].", dataSize, headerSize);
|
||||
IMAGE_LOGE("read head size:[%{public}u] less than header size:[%{public}u].", dataSize, headerSize);
|
||||
return false;
|
||||
}
|
||||
return !memcmp(headerData, PNG_HEADER, headerSize);
|
||||
|
@ -14,16 +14,20 @@
|
||||
*/
|
||||
|
||||
#include "raw_format_agent.h"
|
||||
#include "hilog/log_c.h"
|
||||
#include "hilog/log_cpp.h"
|
||||
|
||||
#include "image_log.h"
|
||||
#include "image_plugin_type.h"
|
||||
#include "log_tags.h"
|
||||
#include "plugin_service.h"
|
||||
#include "string"
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_PLUGIN
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "RawFormatAgent"
|
||||
|
||||
namespace OHOS {
|
||||
namespace ImagePlugin {
|
||||
using namespace OHOS::HiviewDFX;
|
||||
using namespace ImagePlugin;
|
||||
using namespace MultimediaPlugin;
|
||||
|
||||
@ -41,7 +45,6 @@ using namespace MultimediaPlugin;
|
||||
*/
|
||||
const std::string FORMAT_TYPE = "image/x-raw";
|
||||
constexpr uint32_t HEADER_SIZE = 0;
|
||||
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_PLUGIN, "RawFormatAgent" };
|
||||
|
||||
std::string RawFormatAgent::GetFormatType()
|
||||
{
|
||||
@ -55,7 +58,7 @@ uint32_t RawFormatAgent::GetHeaderSize()
|
||||
|
||||
bool RawFormatAgent::CheckFormat(const void *headerData, uint32_t dataSize)
|
||||
{
|
||||
HiLog::Info(LABEL, "RawFormatAgent now pass all image format. dataSize = [%{public}d]", dataSize);
|
||||
IMAGE_LOGI("RawFormatAgent now pass all image format. dataSize = [%{public}d]", dataSize);
|
||||
return true;
|
||||
}
|
||||
} // namespace ImagePlugin
|
||||
|
@ -14,23 +14,26 @@
|
||||
*/
|
||||
|
||||
#include "svg_format_agent.h"
|
||||
#include "hilog/log_c.h"
|
||||
#include "hilog/log_cpp.h"
|
||||
#include "log_tags.h"
|
||||
|
||||
#include "image_log.h"
|
||||
#include "plugin_service.h"
|
||||
#include "sched.h"
|
||||
#include "string"
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_PLUGIN
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "SvgFormatAgent"
|
||||
|
||||
namespace OHOS {
|
||||
namespace ImagePlugin {
|
||||
using namespace OHOS::HiviewDFX;
|
||||
using namespace MultimediaPlugin;
|
||||
|
||||
namespace {
|
||||
static const std::string FORMAT_TYPE = "image/svg+xml";
|
||||
static const char SVG_STAMP[] = "<?xml";
|
||||
static constexpr uint8_t SVG_STAMP_LEN = 5;
|
||||
static constexpr HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_PLUGIN, "SvgFormatAgent" };
|
||||
}
|
||||
|
||||
std::string SvgFormatAgent::GetFormatType()
|
||||
@ -46,17 +49,17 @@ uint32_t SvgFormatAgent::GetHeaderSize()
|
||||
bool SvgFormatAgent::CheckFormat(const void *headerData, uint32_t dataSize)
|
||||
{
|
||||
if (headerData == nullptr) {
|
||||
HiLog::Error(LABEL, "check format failed: header data is null.");
|
||||
IMAGE_LOGE("check format failed: header data is null.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (dataSize < SVG_STAMP_LEN) {
|
||||
HiLog::Error(LABEL, "read head size:[%{public}u] less than header size:[%{public}u].", dataSize, SVG_STAMP_LEN);
|
||||
IMAGE_LOGE("read head size:[%{public}u] less than header size:[%{public}u].", dataSize, SVG_STAMP_LEN);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (memcmp(SVG_STAMP, headerData, SVG_STAMP_LEN) != 0) {
|
||||
HiLog::Info(LABEL, "header stamp mismatch.");
|
||||
IMAGE_LOGI("header stamp mismatch.");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -15,16 +15,20 @@
|
||||
|
||||
|
||||
#include "wbmp_format_agent.h"
|
||||
#include "hilog/log_c.h"
|
||||
#include "hilog/log_cpp.h"
|
||||
|
||||
#include "image_log.h"
|
||||
#include "image_plugin_type.h"
|
||||
#include "log_tags.h"
|
||||
#include "plugin_service.h"
|
||||
#include "string"
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_PLUGIN
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "WbmpFormatAgent"
|
||||
|
||||
namespace OHOS {
|
||||
namespace ImagePlugin {
|
||||
using namespace OHOS::HiviewDFX;
|
||||
using namespace ImagePlugin;
|
||||
using namespace MultimediaPlugin;
|
||||
|
||||
@ -33,12 +37,11 @@ constexpr uint32_t HEADER_SIZE = 32;
|
||||
constexpr uint8_t SHIF_BIT_MASK = 7;
|
||||
constexpr uint8_t LOW_BIT_MASK = 0x7F;
|
||||
constexpr uint8_t HIGH_BIT_MASK = 0x80;
|
||||
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_PLUGIN, "WbmpFormatAgent" };
|
||||
|
||||
bool WbmpFormatAgent::read_byte(uint8_t *stream, uint8_t &value, uint32_t &offset, uint32_t dataSize)
|
||||
{
|
||||
if (offset >= dataSize) {
|
||||
HiLog::Error(LABEL, "read_header data offset %{public}u. dataSize %{public}u", offset, dataSize);
|
||||
IMAGE_LOGE("read_header data offset %{public}u. dataSize %{public}u", offset, dataSize);
|
||||
return false;
|
||||
}
|
||||
value = *(stream + offset);
|
||||
@ -73,24 +76,24 @@ bool WbmpFormatAgent::read_header(const void *stream, uint32_t dataSize)
|
||||
if (!read_byte(pData, data, offset, dataSize) || data != 0) { // unknown type
|
||||
return false;
|
||||
}
|
||||
HiLog::Debug(LABEL, "read_header data %{public}d.", data);
|
||||
IMAGE_LOGD("read_header data %{public}d.", data);
|
||||
|
||||
if (!read_byte(pData, data, offset, dataSize) || (data & 0x9F)) { // skip fixed header
|
||||
return false;
|
||||
}
|
||||
HiLog::Debug(LABEL, "read_header data %{public}d.", data);
|
||||
IMAGE_LOGD("read_header data %{public}d.", data);
|
||||
|
||||
uint64_t width;
|
||||
uint64_t height;
|
||||
if (!read_mbf(pData, width, offset, dataSize) || width > 0xFFFF || !width) {
|
||||
return false;
|
||||
}
|
||||
HiLog::Debug(LABEL, "read_header width %{public}lld.", static_cast<long long>(width));
|
||||
IMAGE_LOGD("read_header width %{public}lld.", static_cast<long long>(width));
|
||||
|
||||
if (!read_mbf(pData, height, offset, dataSize) || height > 0xFFFF || !height) {
|
||||
return false;
|
||||
}
|
||||
HiLog::Debug(LABEL, "read_header height %{public}lld.", static_cast<long long>(height));
|
||||
IMAGE_LOGD("read_header height %{public}lld.", static_cast<long long>(height));
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -109,16 +112,16 @@ uint32_t WbmpFormatAgent::GetHeaderSize()
|
||||
bool WbmpFormatAgent::CheckFormat(const void *headerData, uint32_t dataSize)
|
||||
{
|
||||
if (headerData == nullptr) {
|
||||
HiLog::Error(LABEL, "check format failed: header data is null.");
|
||||
IMAGE_LOGE("check format failed: header data is null.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!read_header(headerData, dataSize)) {
|
||||
HiLog::Info(LABEL, "not wbmp image format.");
|
||||
IMAGE_LOGI("not wbmp image format.");
|
||||
return false;
|
||||
}
|
||||
|
||||
HiLog::Debug(LABEL, "wbmp image format ok.");
|
||||
IMAGE_LOGD("wbmp image format ok.");
|
||||
return true;
|
||||
}
|
||||
} // namespace ImagePlugin
|
||||
|
@ -14,21 +14,25 @@
|
||||
*/
|
||||
|
||||
#include "webp_format_agent.h"
|
||||
|
||||
#include <cstring>
|
||||
#include "hilog/log_c.h"
|
||||
#include "hilog/log_cpp.h"
|
||||
#include "log_tags.h"
|
||||
|
||||
#include "image_log.h"
|
||||
#include "plugin_service.h"
|
||||
#include "sched.h"
|
||||
#include "string"
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_PLUGIN
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "WebpFormatAgent"
|
||||
|
||||
namespace OHOS {
|
||||
namespace ImagePlugin {
|
||||
using namespace OHOS::HiviewDFX;
|
||||
using namespace MultimediaPlugin;
|
||||
|
||||
namespace {
|
||||
constexpr HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_PLUGIN, "WebpFormatAgent" };
|
||||
const std::string FORMAT_TYPE = "image/webp";
|
||||
constexpr size_t WEBP_MINIMUM_LENGTH = 14;
|
||||
const char *WEBP_HEADER_PRE = "RIFF";
|
||||
@ -50,7 +54,7 @@ uint32_t WebpFormatAgent::GetHeaderSize()
|
||||
bool WebpFormatAgent::CheckFormat(const void *headerData, uint32_t dataSize)
|
||||
{
|
||||
if (headerData == nullptr || dataSize == 0) {
|
||||
HiLog::Error(LABEL, "check format input parameter abnormal.");
|
||||
IMAGE_LOGE("check format input parameter abnormal.");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -36,6 +36,7 @@ ohos_shared_library("bmpplugin") {
|
||||
"//foundation/multimedia/image_framework/plugins/common/libs/image/libbmpplugin/include",
|
||||
"//foundation/multimedia/image_framework/interfaces/innerkits/include",
|
||||
"//foundation/multimedia/image_framework/frameworks/innerkitsimpl/utils/include",
|
||||
"${image_subsystem}/frameworks/innerkitsimpl/utils/include",
|
||||
"${graphic_subsystem}/interfaces/inner_api/surface",
|
||||
"$skia_root/skia/include/core",
|
||||
"$skia_root/skia/include/codec",
|
||||
|
@ -15,21 +15,24 @@
|
||||
|
||||
#include "bmp_decoder.h"
|
||||
|
||||
#include "hilog/log.h"
|
||||
#include "image_log.h"
|
||||
#include "image_utils.h"
|
||||
#include "log_tags.h"
|
||||
#include "media_errors.h"
|
||||
#include "securec.h"
|
||||
#if !defined(IOS_PLATFORM) && !defined(A_PLATFORM)
|
||||
#include "surface_buffer.h"
|
||||
#endif
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_PLUGIN
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "BmpDecoder"
|
||||
|
||||
namespace OHOS {
|
||||
namespace ImagePlugin {
|
||||
using namespace OHOS::HiviewDFX;
|
||||
using namespace Media;
|
||||
using namespace std;
|
||||
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_PLUGIN, "BmpDecoder" };
|
||||
namespace {
|
||||
constexpr uint32_t BMP_IMAGE_NUM = 1;
|
||||
}
|
||||
@ -53,11 +56,11 @@ void BmpDecoder::Reset()
|
||||
uint32_t BmpDecoder::GetImageSize(uint32_t index, PlSize &size)
|
||||
{
|
||||
if (index >= BMP_IMAGE_NUM) {
|
||||
HiLog::Error(LABEL, "GetImageSize failed, invalid index:%{public}u, range:%{public}u", index, BMP_IMAGE_NUM);
|
||||
IMAGE_LOGE("GetImageSize failed, invalid index:%{public}u, range:%{public}u", index, BMP_IMAGE_NUM);
|
||||
return ERR_IMAGE_INVALID_PARAMETER;
|
||||
}
|
||||
if (state_ < BmpDecodingState::SOURCE_INITED) {
|
||||
HiLog::Error(LABEL, "GetImageSize failed, invalid state:%{public}d", state_);
|
||||
IMAGE_LOGE("GetImageSize failed, invalid state:%{public}d", state_);
|
||||
return ERR_MEDIA_INVALID_OPERATION;
|
||||
}
|
||||
if (state_ >= BmpDecodingState::BASE_INFO_PARSED) {
|
||||
@ -66,7 +69,7 @@ uint32_t BmpDecoder::GetImageSize(uint32_t index, PlSize &size)
|
||||
return SUCCESS;
|
||||
}
|
||||
if (!DecodeHeader()) {
|
||||
HiLog::Error(LABEL, "GetImageSize failed, decode header failed, state=%{public}d", state_);
|
||||
IMAGE_LOGE("GetImageSize failed, decode header failed, state=%{public}d", state_);
|
||||
return ERR_IMAGE_DECODE_HEAD_ABNORMAL;
|
||||
}
|
||||
size.width = info_.width();
|
||||
@ -78,12 +81,12 @@ uint32_t BmpDecoder::GetImageSize(uint32_t index, PlSize &size)
|
||||
uint32_t BmpDecoder::SetDecodeOptions(uint32_t index, const PixelDecodeOptions &opts, PlImageInfo &info)
|
||||
{
|
||||
if (index >= BMP_IMAGE_NUM) {
|
||||
HiLog::Error(LABEL, "SetDecodeOptions failed, invalid index:%{public}u, range:%{public}u", index,
|
||||
BMP_IMAGE_NUM);
|
||||
IMAGE_LOGE("SetDecodeOptions failed, invalid index:%{public}u, range:%{public}u", index,
|
||||
BMP_IMAGE_NUM);
|
||||
return ERR_IMAGE_INVALID_PARAMETER;
|
||||
}
|
||||
if (state_ < BmpDecodingState::SOURCE_INITED) {
|
||||
HiLog::Error(LABEL, "SetDecodeOptions failed, invalid state %{public}d", state_);
|
||||
IMAGE_LOGE("SetDecodeOptions failed, invalid state %{public}d", state_);
|
||||
return ERR_MEDIA_INVALID_OPERATION;
|
||||
}
|
||||
if (state_ >= BmpDecodingState::IMAGE_DECODING) {
|
||||
@ -92,7 +95,7 @@ uint32_t BmpDecoder::SetDecodeOptions(uint32_t index, const PixelDecodeOptions &
|
||||
}
|
||||
if (state_ < BmpDecodingState::BASE_INFO_PARSED) {
|
||||
if (!DecodeHeader()) {
|
||||
HiLog::Error(LABEL, "GetImageSize failed, decode header failed, state=%{public}d", state_);
|
||||
IMAGE_LOGE("GetImageSize failed, decode header failed, state=%{public}d", state_);
|
||||
return ERR_IMAGE_DECODE_HEAD_ABNORMAL;
|
||||
}
|
||||
state_ = BmpDecodingState::BASE_INFO_PARSED;
|
||||
@ -145,7 +148,7 @@ uint32_t BmpDecoder::SetShareMemBuffer(uint64_t byteCount, DecodeContext &contex
|
||||
static uint32_t DmaMemAlloc(uint64_t count, DecodeContext &context, SkImageInfo &dstInfo)
|
||||
{
|
||||
#if defined(_WIN32) || defined(_APPLE) || defined(A_PLATFORM) || defined(IOS_PLATFORM)
|
||||
HiLog::Error(LABEL, "Unsupport dma mem alloc");
|
||||
IMAGE_LOGE("Unsupport dma mem alloc");
|
||||
return ERR_IMAGE_DATA_UNSUPPORT;
|
||||
#else
|
||||
sptr<SurfaceBuffer> sb = SurfaceBuffer::Create();
|
||||
@ -161,13 +164,13 @@ static uint32_t DmaMemAlloc(uint64_t count, DecodeContext &context, SkImageInfo
|
||||
};
|
||||
GSError ret = sb->Alloc(requestConfig);
|
||||
if (ret != GSERROR_OK) {
|
||||
HiLog::Error(LABEL, "SurfaceBuffer Alloc failed, %{public}s", GSErrorStr(ret).c_str());
|
||||
IMAGE_LOGE("SurfaceBuffer Alloc failed, %{public}s", GSErrorStr(ret).c_str());
|
||||
return ERR_DMA_NOT_EXIST;
|
||||
}
|
||||
void* nativeBuffer = sb.GetRefPtr();
|
||||
int32_t err = ImageUtils::SurfaceBuffer_Reference(nativeBuffer);
|
||||
if (err != OHOS::GSERROR_OK) {
|
||||
HiLog::Error(LABEL, "NativeBufferReference failed");
|
||||
IMAGE_LOGE("NativeBufferReference failed");
|
||||
return ERR_DMA_DATA_ABNORMAL;
|
||||
}
|
||||
context.pixelsBuffer.buffer = static_cast<uint8_t*>(sb->GetVirAddr());
|
||||
@ -183,25 +186,25 @@ uint32_t SetBuffer(uint64_t byteCount, DecodeContext &context)
|
||||
{
|
||||
#if !defined(_WIN32) && !defined(_APPLE) && !defined(A_PLATFORM) && !defined(IOS_PLATFORM)
|
||||
if (byteCount == 0) {
|
||||
HiLog::Error(LABEL, "Decode failed, byteCount is invalid value");
|
||||
IMAGE_LOGE("Decode failed, byteCount is invalid value");
|
||||
return ERR_MEDIA_INVALID_VALUE;
|
||||
}
|
||||
void *outputBuffer = malloc(byteCount);
|
||||
if (outputBuffer == nullptr) {
|
||||
HiLog::Error(LABEL, "Decode failed, alloc output buffer size:[%{public}llu] error",
|
||||
static_cast<unsigned long long>(byteCount));
|
||||
IMAGE_LOGE("Decode failed, alloc output buffer size:[%{public}llu] error",
|
||||
static_cast<unsigned long long>(byteCount));
|
||||
return ERR_IMAGE_MALLOC_ABNORMAL;
|
||||
}
|
||||
#ifdef _WIN32
|
||||
if (memset_s(outputBuffer, 0, byteCount) != EOK) {
|
||||
HiLog::Error(LABEL, "Decode failed, memset buffer failed", backRet);
|
||||
IMAGE_LOGE("Decode failed, memset buffer failed", backRet);
|
||||
free(outputBuffer);
|
||||
outputBuffer = nullptr;
|
||||
return ERR_IMAGE_DECODE_FAILED;
|
||||
}
|
||||
#else
|
||||
if (memset_s(outputBuffer, byteCount, 0, byteCount) != EOK) {
|
||||
HiLog::Error(LABEL, "Decode failed, memset buffer failed");
|
||||
IMAGE_LOGE("Decode failed, memset buffer failed");
|
||||
free(outputBuffer);
|
||||
outputBuffer = nullptr;
|
||||
return ERR_IMAGE_DECODE_FAILED;
|
||||
@ -220,25 +223,25 @@ uint32_t SetBuffer(uint64_t byteCount, DecodeContext &context)
|
||||
uint32_t SetBufferForPlatform(uint64_t byteCount, DecodeContext &context)
|
||||
{
|
||||
if (byteCount == 0) {
|
||||
HiLog::Error(LABEL, "Decode failed, byteCount is invalid value");
|
||||
IMAGE_LOGE("Decode failed, byteCount is invalid value");
|
||||
return ERR_MEDIA_INVALID_VALUE;
|
||||
}
|
||||
void *outputBuffer = malloc(byteCount);
|
||||
if (outputBuffer == nullptr) {
|
||||
HiLog::Error(LABEL, "Decode failed, alloc output buffer size:[%{public}llu] error",
|
||||
static_cast<unsigned long long>(byteCount));
|
||||
IMAGE_LOGE("Decode failed, alloc output buffer size:[%{public}llu] error",
|
||||
static_cast<unsigned long long>(byteCount));
|
||||
return ERR_IMAGE_MALLOC_ABNORMAL;
|
||||
}
|
||||
#ifdef _WIN32
|
||||
if (memset_s(outputBuffer, 0, byteCount) != EOK) {
|
||||
HiLog::Error(LABEL, "Decode failed, memset buffer failed", backRet);
|
||||
IMAGE_LOGE("Decode failed, memset buffer failed", backRet);
|
||||
free(outputBuffer);
|
||||
outputBuffer = nullptr;
|
||||
return ERR_IMAGE_DECODE_FAILED;
|
||||
}
|
||||
#else
|
||||
if (memset_s(outputBuffer, byteCount, 0, byteCount) != EOK) {
|
||||
HiLog::Error(LABEL, "Decode failed, memset buffer failed");
|
||||
IMAGE_LOGE("Decode failed, memset buffer failed");
|
||||
free(outputBuffer);
|
||||
outputBuffer = nullptr;
|
||||
return ERR_IMAGE_DECODE_FAILED;
|
||||
@ -283,22 +286,22 @@ uint32_t BmpDecoder::SetContextPixelsBuffer(uint64_t byteCount, DecodeContext &c
|
||||
uint32_t BmpDecoder::Decode(uint32_t index, DecodeContext &context)
|
||||
{
|
||||
if (index >= BMP_IMAGE_NUM) {
|
||||
HiLog::Error(LABEL, "Decode failed, invalid index:%{public}u, range:%{public}u", index, BMP_IMAGE_NUM);
|
||||
IMAGE_LOGE("Decode failed, invalid index:%{public}u, range:%{public}u", index, BMP_IMAGE_NUM);
|
||||
return ERR_IMAGE_INVALID_PARAMETER;
|
||||
}
|
||||
if (codec_ == nullptr) {
|
||||
HiLog::Error(LABEL, "Decode failed, codec is null");
|
||||
IMAGE_LOGE("Decode failed, codec is null");
|
||||
return ERR_IMAGE_DECODE_FAILED;
|
||||
}
|
||||
if (state_ != BmpDecodingState::IMAGE_DECODING) {
|
||||
HiLog::Error(LABEL, "Decode failed, invalid state %{public}d", state_);
|
||||
IMAGE_LOGE("Decode failed, invalid state %{public}d", state_);
|
||||
return ERR_MEDIA_INVALID_OPERATION;
|
||||
}
|
||||
|
||||
SkImageInfo dstInfo = info_.makeColorType(desireColor_);
|
||||
if (ImageUtils::CheckMulOverflow(dstInfo.width(), dstInfo.height(), dstInfo.bytesPerPixel())) {
|
||||
HiLog::Error(LABEL, "Decode failed, width:%{public}d, height:%{public}d is too large",
|
||||
dstInfo.width(), dstInfo.height());
|
||||
IMAGE_LOGE("Decode failed, width:%{public}d, height:%{public}d is too large",
|
||||
dstInfo.width(), dstInfo.height());
|
||||
return ERR_IMAGE_DECODE_FAILED;
|
||||
}
|
||||
if (context.pixelsBuffer.buffer == nullptr) {
|
||||
@ -312,7 +315,7 @@ uint32_t BmpDecoder::Decode(uint32_t index, DecodeContext &context)
|
||||
size_t rowBytes = dstInfo.width() * dstInfo.bytesPerPixel();
|
||||
SkCodec::Result ret = codec_->getPixels(dstInfo, dstBuffer, rowBytes);
|
||||
if (ret != SkCodec::kSuccess) {
|
||||
HiLog::Error(LABEL, "Decode failed, get pixels failed, ret=%{public}d", ret);
|
||||
IMAGE_LOGE("Decode failed, get pixels failed, ret=%{public}d", ret);
|
||||
state_ = BmpDecodingState::IMAGE_ERROR;
|
||||
return ERR_IMAGE_DECODE_ABNORMAL;
|
||||
}
|
||||
@ -330,7 +333,7 @@ bool BmpDecoder::DecodeHeader()
|
||||
{
|
||||
codec_ = SkCodec::MakeFromStream(make_unique<BmpStream>(stream_));
|
||||
if (codec_ == nullptr) {
|
||||
HiLog::Error(LABEL, "create codec from stream failed");
|
||||
IMAGE_LOGE("create codec from stream failed");
|
||||
return false;
|
||||
}
|
||||
info_ = codec_->getInfo();
|
||||
@ -347,7 +350,7 @@ PlAlphaType BmpDecoder::ConvertToAlphaType(SkAlphaType alphaType)
|
||||
case kUnpremul_SkAlphaType:
|
||||
return PlAlphaType::IMAGE_ALPHA_TYPE_UNPREMUL;
|
||||
default:
|
||||
HiLog::Error(LABEL, "unknown alpha type:%{public}d", alphaType);
|
||||
IMAGE_LOGE("unknown alpha type:%{public}d", alphaType);
|
||||
break;
|
||||
}
|
||||
return PlAlphaType::IMAGE_ALPHA_TYPE_UNKNOWN;
|
||||
@ -384,7 +387,7 @@ SkColorType BmpDecoder::ConvertToColorType(PlPixelFormat format, PlPixelFormat &
|
||||
break;
|
||||
}
|
||||
}
|
||||
HiLog::Debug(LABEL, "unsupported convert to format:%{public}d, set default RGBA", format);
|
||||
IMAGE_LOGD("unsupported convert to format:%{public}d, set default RGBA", format);
|
||||
outputFormat = PlPixelFormat::RGBA_8888;
|
||||
return kRGBA_8888_SkColorType;
|
||||
}
|
||||
|
@ -15,25 +15,28 @@
|
||||
|
||||
#include "bmp_stream.h"
|
||||
|
||||
#include "hilog/log.h"
|
||||
#include "log_tags.h"
|
||||
#include "image_log.h"
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_PLUGIN
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "BmpStream"
|
||||
|
||||
namespace OHOS {
|
||||
namespace ImagePlugin {
|
||||
using namespace OHOS::HiviewDFX;
|
||||
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_PLUGIN, "BmpStream" };
|
||||
BmpStream::BmpStream(InputDataStream *stream) : inputStream_(stream) {}
|
||||
|
||||
size_t BmpStream::read(void *buffer, size_t size)
|
||||
{
|
||||
if (inputStream_ == nullptr) {
|
||||
HiLog::Error(LABEL, "read failed, inputStream_ is null");
|
||||
IMAGE_LOGE("read failed, inputStream_ is null");
|
||||
return 0;
|
||||
}
|
||||
if (buffer == nullptr) {
|
||||
size_t curPosition = static_cast<size_t>(inputStream_->Tell());
|
||||
if (!inputStream_->Seek(curPosition + size)) {
|
||||
HiLog::Error(LABEL, "read failed, curpositon=%{public}zu, skip size=%{public}zu", curPosition, size);
|
||||
IMAGE_LOGE("read failed, curpositon=%{public}zu, skip size=%{public}zu", curPosition, size);
|
||||
return 0;
|
||||
}
|
||||
return size;
|
||||
@ -42,7 +45,7 @@ size_t BmpStream::read(void *buffer, size_t size)
|
||||
uint32_t bufferSize = desireSize;
|
||||
uint32_t readSize = desireSize;
|
||||
if (!inputStream_->Read(desireSize, static_cast<uint8_t *>(buffer), bufferSize, readSize)) {
|
||||
HiLog::Error(LABEL, "read failed, desire read size=%{public}u", desireSize);
|
||||
IMAGE_LOGE("read failed, desire read size=%{public}u", desireSize);
|
||||
return 0;
|
||||
}
|
||||
return readSize;
|
||||
@ -51,18 +54,18 @@ size_t BmpStream::read(void *buffer, size_t size)
|
||||
size_t BmpStream::peek(void *buffer, size_t size) const
|
||||
{
|
||||
if (inputStream_ == nullptr) {
|
||||
HiLog::Error(LABEL, "peek failed, inputStream_ is null");
|
||||
IMAGE_LOGE("peek failed, inputStream_ is null");
|
||||
return 0;
|
||||
}
|
||||
if (buffer == nullptr) {
|
||||
HiLog::Error(LABEL, "peek failed, output buffer is null");
|
||||
IMAGE_LOGE("peek failed, output buffer is null");
|
||||
return 0;
|
||||
}
|
||||
uint32_t desireSize = static_cast<uint32_t>(size);
|
||||
uint32_t bufferSize = desireSize;
|
||||
uint32_t readSize = desireSize;
|
||||
if (!inputStream_->Peek(desireSize, static_cast<uint8_t *>(buffer), bufferSize, readSize)) {
|
||||
HiLog::Error(LABEL, "peek failed, desire peek size=%{public}u", desireSize);
|
||||
IMAGE_LOGE("peek failed, desire peek size=%{public}u", desireSize);
|
||||
return 0;
|
||||
}
|
||||
return readSize;
|
||||
@ -71,7 +74,7 @@ size_t BmpStream::peek(void *buffer, size_t size) const
|
||||
bool BmpStream::isAtEnd() const
|
||||
{
|
||||
if (inputStream_ == nullptr) {
|
||||
HiLog::Error(LABEL, "get stream status failed, inputStream_ is null.");
|
||||
IMAGE_LOGE("get stream status failed, inputStream_ is null.");
|
||||
return false;
|
||||
}
|
||||
size_t size = inputStream_->GetStreamSize();
|
||||
|
@ -15,10 +15,15 @@
|
||||
|
||||
#include "plugin_export.h"
|
||||
#include "bmp_decoder.h"
|
||||
#include "hilog/log.h"
|
||||
#include "log_tags.h"
|
||||
#include "image_log.h"
|
||||
#include "plugin_utils.h"
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_PLUGIN
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "LibBmpPlugin"
|
||||
|
||||
// plugin package name same as metadata.
|
||||
namespace {
|
||||
const std::string PACKAGE_NAME = ("LibBmpPlugin");
|
||||
@ -30,32 +35,26 @@ PLUGIN_EXPORT_REGISTER_CLASS(OHOS::ImagePlugin::BmpDecoder)
|
||||
PLUGIN_EXPORT_REGISTER_CLASS_END
|
||||
|
||||
using std::string;
|
||||
using namespace OHOS::HiviewDFX;
|
||||
|
||||
static constexpr HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_PLUGIN, "LibBmpPlugin" };
|
||||
|
||||
#define PLUGIN_LOG_D(...) HiLog::Debug(LABEL, __VA_ARGS__)
|
||||
#define PLUGIN_LOG_E(...) HiLog::Error(LABEL, __VA_ARGS__)
|
||||
|
||||
// define the external interface of this plugin.
|
||||
PLUGIN_EXPORT_DEFAULT_EXTERNAL_START()
|
||||
PLUGIN_EXPORT_DEFAULT_EXTERNAL_STOP()
|
||||
OHOS::MultimediaPlugin::PluginClassBase *PluginExternalCreate(const string &className)
|
||||
{
|
||||
HiLog::Debug(LABEL, "PluginExternalCreate: create object for package: %{public}s, class: %{public}s.",
|
||||
PACKAGE_NAME.c_str(), className.c_str());
|
||||
IMAGE_LOGD("PluginExternalCreate: create object for package: %{public}s, class: %{public}s.",
|
||||
PACKAGE_NAME.c_str(), className.c_str());
|
||||
|
||||
auto iter = implClassMap.find(className);
|
||||
if (iter == implClassMap.end()) {
|
||||
HiLog::Error(LABEL, "PluginExternalCreate: failed to find class: %{public}s, in package: %{public}s.",
|
||||
className.c_str(), PACKAGE_NAME.c_str());
|
||||
IMAGE_LOGE("PluginExternalCreate: failed to find class: %{public}s, in package: %{public}s.",
|
||||
className.c_str(), PACKAGE_NAME.c_str());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto creator = iter->second;
|
||||
if (creator == nullptr) {
|
||||
HiLog::Error(LABEL, "PluginExternalCreate: null creator for class: %{public}s, in package: %{public}s.",
|
||||
className.c_str(), PACKAGE_NAME.c_str());
|
||||
IMAGE_LOGE("PluginExternalCreate: null creator for class: %{public}s, in package: %{public}s.",
|
||||
className.c_str(), PACKAGE_NAME.c_str());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -33,6 +33,7 @@ ohos_static_library("exifhelper") {
|
||||
]
|
||||
include_dirs = [
|
||||
"../libjpegplugin/include",
|
||||
"${image_subsystem}/frameworks/innerkitsimpl/utils/include",
|
||||
"${image_subsystem}/interfaces/innerkits/include",
|
||||
"//third_party/libexif",
|
||||
]
|
||||
@ -106,6 +107,7 @@ ohos_shared_library("textureEncoderCL") {
|
||||
}
|
||||
sources = [ "src/texture_encode/image_compressor.cpp" ]
|
||||
include_dirs = [
|
||||
"${image_subsystem}/frameworks/innerkitsimpl/utils/include",
|
||||
"${image_subsystem}/interfaces/innerkits/include",
|
||||
"include/texture_encode",
|
||||
]
|
||||
|
@ -19,8 +19,6 @@
|
||||
#include <vector>
|
||||
|
||||
#include "abs_image_encoder.h"
|
||||
#include "hilog/log.h"
|
||||
#include "log_tags.h"
|
||||
#include "plugin_class_base.h"
|
||||
|
||||
namespace OHOS {
|
||||
|
@ -19,11 +19,10 @@
|
||||
#include <map>
|
||||
|
||||
#include "ext_pixel_convert.h"
|
||||
#include "hilog/log.h"
|
||||
#include "image_log.h"
|
||||
#include "hisysevent.h"
|
||||
#include "image_system_properties.h"
|
||||
#include "image_utils.h"
|
||||
#include "log_tags.h"
|
||||
#include "media_errors.h"
|
||||
#include "securec.h"
|
||||
#include "string_ex.h"
|
||||
@ -31,8 +30,13 @@
|
||||
#include "surface_buffer.h"
|
||||
#endif
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_PLUGIN
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "ExtDecoder"
|
||||
|
||||
namespace {
|
||||
constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_TAG_DOMAIN_ID_PLUGIN, "ExtDecoder"};
|
||||
constexpr static int32_t ZERO = 0;
|
||||
constexpr static int32_t NUM_3 = 3;
|
||||
constexpr static int32_t NUM_4 = 4;
|
||||
@ -63,7 +67,6 @@ namespace OHOS {
|
||||
namespace ImagePlugin {
|
||||
using namespace Media;
|
||||
using namespace OHOS::HDI::Base;
|
||||
using namespace OHOS::HiviewDFX;
|
||||
using namespace std;
|
||||
const static string DEFAULT_EXIF_VALUE = "default_exif_value";
|
||||
const static string CODEC_INITED_KEY = "CodecInited";
|
||||
@ -145,25 +148,25 @@ static void SetDecodeContextBuffer(DecodeContext &context,
|
||||
static uint32_t ShareMemAlloc(DecodeContext &context, uint64_t count)
|
||||
{
|
||||
#if defined(_WIN32) || defined(_APPLE) || defined(A_PLATFORM) || defined(IOS_PLATFORM)
|
||||
HiLog::Error(LABEL, "Unsupport share mem alloc");
|
||||
IMAGE_LOGE("Unsupport share mem alloc");
|
||||
return ERR_IMAGE_DATA_UNSUPPORT;
|
||||
#else
|
||||
auto fd = make_unique<int32_t>();
|
||||
*fd = AshmemCreate(EXT_SHAREMEM_NAME.c_str(), count);
|
||||
if (*fd < 0) {
|
||||
HiLog::Error(LABEL, "AshmemCreate failed");
|
||||
IMAGE_LOGE("AshmemCreate failed");
|
||||
return ERR_SHAMEM_DATA_ABNORMAL;
|
||||
}
|
||||
int result = AshmemSetProt(*fd, PROT_READ | PROT_WRITE);
|
||||
if (result < 0) {
|
||||
::close(*fd);
|
||||
HiLog::Error(LABEL, "AshmemSetProt failed");
|
||||
IMAGE_LOGE("AshmemSetProt failed");
|
||||
return ERR_SHAMEM_DATA_ABNORMAL;
|
||||
}
|
||||
void* ptr = ::mmap(nullptr, count, PROT_READ | PROT_WRITE, MAP_SHARED, *fd, ZERO);
|
||||
if (ptr == MAP_FAILED) {
|
||||
::close(*fd);
|
||||
HiLog::Error(LABEL, "::mmap failed");
|
||||
IMAGE_LOGE("::mmap failed");
|
||||
return ERR_SHAMEM_DATA_ABNORMAL;
|
||||
}
|
||||
SetDecodeContextBuffer(context,
|
||||
@ -175,7 +178,7 @@ static uint32_t ShareMemAlloc(DecodeContext &context, uint64_t count)
|
||||
static uint32_t DmaMemAlloc(DecodeContext &context, uint64_t count, SkImageInfo &dstInfo)
|
||||
{
|
||||
#if defined(_WIN32) || defined(_APPLE) || defined(A_PLATFORM) || defined(IOS_PLATFORM)
|
||||
HiLog::Error(LABEL, "Unsupport dma mem alloc");
|
||||
IMAGE_LOGE("Unsupport dma mem alloc");
|
||||
return ERR_IMAGE_DATA_UNSUPPORT;
|
||||
#else
|
||||
sptr<SurfaceBuffer> sb = SurfaceBuffer::Create();
|
||||
@ -191,13 +194,13 @@ static uint32_t DmaMemAlloc(DecodeContext &context, uint64_t count, SkImageInfo
|
||||
};
|
||||
GSError ret = sb->Alloc(requestConfig);
|
||||
if (ret != GSERROR_OK) {
|
||||
HiLog::Error(LABEL, "SurfaceBuffer Alloc failed, %{public}s", GSErrorStr(ret).c_str());
|
||||
IMAGE_LOGE("SurfaceBuffer Alloc failed, %{public}s", GSErrorStr(ret).c_str());
|
||||
return ERR_DMA_NOT_EXIST;
|
||||
}
|
||||
void* nativeBuffer = sb.GetRefPtr();
|
||||
int32_t err = ImageUtils::SurfaceBuffer_Reference(nativeBuffer);
|
||||
if (err != OHOS::GSERROR_OK) {
|
||||
HiLog::Error(LABEL, "NativeBufferReference failed");
|
||||
IMAGE_LOGE("NativeBufferReference failed");
|
||||
return ERR_DMA_DATA_ABNORMAL;
|
||||
}
|
||||
|
||||
@ -210,7 +213,7 @@ static uint32_t DmaMemAlloc(DecodeContext &context, uint64_t count, SkImageInfo
|
||||
static uint32_t HeapMemAlloc(DecodeContext &context, uint64_t count)
|
||||
{
|
||||
if (count == 0 || count > PIXEL_MAP_MAX_RAM_SIZE) {
|
||||
HiLog::Error(LABEL, "HeapMemAlloc Invalid value of bufferSize");
|
||||
IMAGE_LOGE("HeapMemAlloc Invalid value of bufferSize");
|
||||
return ERR_IMAGE_DATA_ABNORMAL;
|
||||
}
|
||||
auto out = static_cast<uint8_t *>(malloc(count));
|
||||
@ -219,7 +222,7 @@ static uint32_t HeapMemAlloc(DecodeContext &context, uint64_t count)
|
||||
#else
|
||||
if (memset_s(out, count, ZERO, count) != EOK) {
|
||||
#endif
|
||||
HiLog::Error(LABEL, "Decode failed, memset buffer failed");
|
||||
IMAGE_LOGE("Decode failed, memset buffer failed");
|
||||
free(out);
|
||||
return ERR_IMAGE_DECODE_FAILED;
|
||||
}
|
||||
@ -265,11 +268,11 @@ static inline float Max(float a, float b)
|
||||
bool ExtDecoder::GetScaledSize(int &dWidth, int &dHeight, float &scale)
|
||||
{
|
||||
if (info_.isEmpty() && !DecodeHeader()) {
|
||||
HiLog::Error(LABEL, "DecodeHeader failed in GetScaledSize!");
|
||||
IMAGE_LOGE("DecodeHeader failed in GetScaledSize!");
|
||||
return false;
|
||||
}
|
||||
if (info_.isEmpty()) {
|
||||
HiLog::Error(LABEL, "empty image info in GetScaledSize!");
|
||||
IMAGE_LOGE("empty image info in GetScaledSize!");
|
||||
return false;
|
||||
}
|
||||
float finalScale = scale;
|
||||
@ -281,19 +284,19 @@ bool ExtDecoder::GetScaledSize(int &dWidth, int &dHeight, float &scale)
|
||||
dWidth = scaledDimension.width();
|
||||
dHeight = scaledDimension.height();
|
||||
scale = finalScale;
|
||||
HiLog::Debug(LABEL, "IsSupportScaleOnDecode info [%{public}d x %{public}d]", info_.width(), info_.height());
|
||||
HiLog::Debug(LABEL, "IsSupportScaleOnDecode [%{public}d x %{public}d]", dWidth, dHeight);
|
||||
HiLog::Debug(LABEL, "IsSupportScaleOnDecode [%{public}f]", scale);
|
||||
IMAGE_LOGD("IsSupportScaleOnDecode info [%{public}d x %{public}d]", info_.width(), info_.height());
|
||||
IMAGE_LOGD("IsSupportScaleOnDecode [%{public}d x %{public}d]", dWidth, dHeight);
|
||||
IMAGE_LOGD("IsSupportScaleOnDecode [%{public}f]", scale);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ExtDecoder::GetHardwareScaledSize(int &dWidth, int &dHeight, float &scale) {
|
||||
if (info_.isEmpty() && !DecodeHeader()) {
|
||||
HiLog::Error(LABEL, "DecodeHeader failed in GetHardwareScaledSize!");
|
||||
IMAGE_LOGE("DecodeHeader failed in GetHardwareScaledSize!");
|
||||
return false;
|
||||
}
|
||||
if (info_.isEmpty()) {
|
||||
HiLog::Error(LABEL, "empty image info in GetHardwareScaledSize!");
|
||||
IMAGE_LOGE("empty image info in GetHardwareScaledSize!");
|
||||
return false;
|
||||
}
|
||||
float finalScale = scale;
|
||||
@ -371,15 +374,15 @@ bool ExtDecoder::HasProperty(string key)
|
||||
|
||||
uint32_t ExtDecoder::GetImageSize(uint32_t index, PlSize &size)
|
||||
{
|
||||
HiLog::Debug(LABEL, "GetImageSize index:%{public}u", index);
|
||||
IMAGE_LOGD("GetImageSize index:%{public}u", index);
|
||||
if (!CheckIndexValied(index)) {
|
||||
HiLog::Error(LABEL, "Invalid index:%{public}u, range:%{public}d", index, frameCount_);
|
||||
IMAGE_LOGE("Invalid index:%{public}u, range:%{public}d", index, frameCount_);
|
||||
return ERR_IMAGE_INVALID_PARAMETER;
|
||||
}
|
||||
HiLog::Debug(LABEL, "GetImageSize index:%{public}u, range:%{public}d", index, frameCount_);
|
||||
IMAGE_LOGD("GetImageSize index:%{public}u, range:%{public}d", index, frameCount_);
|
||||
// Info has been get in check process, or empty on get failed.
|
||||
if (info_.isEmpty()) {
|
||||
HiLog::Error(LABEL, "GetImageSize failed, decode header failed.");
|
||||
IMAGE_LOGE("GetImageSize failed, decode header failed.");
|
||||
return ERR_IMAGE_DECODE_HEAD_ABNORMAL;
|
||||
}
|
||||
size.width = info_.width();
|
||||
@ -419,13 +422,12 @@ static sk_sp<SkColorSpace> getDesiredColorSpace(SkImageInfo &srcInfo, const Pixe
|
||||
uint32_t ExtDecoder::CheckDecodeOptions(uint32_t index, const PixelDecodeOptions &opts)
|
||||
{
|
||||
if (ImageUtils::CheckMulOverflow(dstInfo_.width(), dstInfo_.height(), dstInfo_.bytesPerPixel())) {
|
||||
HiLog::Error(LABEL, "SetDecodeOptions failed, width:%{public}d, height:%{public}d is too large",
|
||||
IMAGE_LOGE("SetDecodeOptions failed, width:%{public}d, height:%{public}d is too large",
|
||||
dstInfo_.width(), dstInfo_.height());
|
||||
return ERR_IMAGE_INVALID_PARAMETER;
|
||||
}
|
||||
if (!IsValidCrop(opts.CropRect, info_, dstSubset_)) {
|
||||
HiLog::Error(LABEL,
|
||||
"Invalid crop rect xy [%{public}d x %{public}d], wh [%{public}d x %{public}d]",
|
||||
IMAGE_LOGE("Invalid crop rect xy [%{public}d x %{public}d], wh [%{public}d x %{public}d]",
|
||||
dstSubset_.left(), dstSubset_.top(), dstSubset_.width(), dstSubset_.height());
|
||||
return ERR_IMAGE_INVALID_PARAMETER;
|
||||
}
|
||||
@ -443,11 +445,11 @@ uint32_t ExtDecoder::CheckDecodeOptions(uint32_t index, const PixelDecodeOptions
|
||||
uint32_t ExtDecoder::SetDecodeOptions(uint32_t index, const PixelDecodeOptions &opts, PlImageInfo &info)
|
||||
{
|
||||
if (!CheckIndexValied(index)) {
|
||||
HiLog::Error(LABEL, "Invalid index:%{public}u, range:%{public}d", index, frameCount_);
|
||||
IMAGE_LOGE("Invalid index:%{public}u, range:%{public}d", index, frameCount_);
|
||||
return ERR_IMAGE_INVALID_PARAMETER;
|
||||
}
|
||||
if (opts.sampleSize != DEFAULT_SAMPLE_SIZE) {
|
||||
HiLog::Error(LABEL, "Do not support sample size now!");
|
||||
IMAGE_LOGE("Do not support sample size now!");
|
||||
return ERR_IMAGE_INVALID_PARAMETER;
|
||||
}
|
||||
auto desireColor = ConvertToColorType(opts.desiredPixelFormat, info.pixelFormat);
|
||||
@ -500,13 +502,13 @@ uint32_t ExtDecoder::SetContextPixelsBuffer(uint64_t byteCount, DecodeContext &c
|
||||
|
||||
static void DebugInfo(SkImageInfo &info, SkImageInfo &dstInfo, SkCodec::Options &opts)
|
||||
{
|
||||
HiLog::Debug(LABEL, "Decode source info: WH[%{public}d x %{public}d], A %{public}d, C %{public}d.",
|
||||
IMAGE_LOGD("Decode source info: WH[%{public}d x %{public}d], A %{public}d, C %{public}d.",
|
||||
info.width(), info.height(),
|
||||
info.alphaType(), info.colorType());
|
||||
HiLog::Debug(LABEL, "Decode dst info: WH[%{public}d x %{public}d], A %{public}d, C %{public}d.",
|
||||
IMAGE_LOGD("Decode dst info: WH[%{public}d x %{public}d], A %{public}d, C %{public}d.",
|
||||
dstInfo.width(), dstInfo.height(), dstInfo.alphaType(), dstInfo.colorType());
|
||||
if (opts.fSubset != nullptr) {
|
||||
HiLog::Debug(LABEL, "Decode dstOpts sub: (%{public}d, %{public}d), WH[%{public}d x %{public}d]",
|
||||
IMAGE_LOGD("Decode dstOpts sub: (%{public}d, %{public}d), WH[%{public}d x %{public}d]",
|
||||
opts.fSubset->fLeft, opts.fSubset->fTop,
|
||||
opts.fSubset->width(), opts.fSubset->height());
|
||||
}
|
||||
@ -519,7 +521,7 @@ static uint32_t RGBxToRGB(uint8_t* srcBuffer, size_t srsSize,
|
||||
ExtPixels dst = {dstBuffer, dstSize, pixelCount};
|
||||
auto res = ExtPixelConvert::RGBxToRGB(src, dst);
|
||||
if (res != SUCCESS) {
|
||||
HiLog::Error(LABEL, "RGBxToRGB failed %{public}d", res);
|
||||
IMAGE_LOGE("RGBxToRGB failed %{public}d", res);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
@ -527,15 +529,15 @@ static uint32_t RGBxToRGB(uint8_t* srcBuffer, size_t srsSize,
|
||||
uint32_t ExtDecoder::PreDecodeCheck(uint32_t index)
|
||||
{
|
||||
if (!CheckIndexValied(index)) {
|
||||
HiLog::Error(LABEL, "Decode failed, invalid index:%{public}u, range:%{public}d", index, frameCount_);
|
||||
IMAGE_LOGE("Decode failed, invalid index:%{public}u, range:%{public}d", index, frameCount_);
|
||||
return ERR_IMAGE_INVALID_PARAMETER;
|
||||
}
|
||||
if (codec_ == nullptr) {
|
||||
HiLog::Error(LABEL, "Decode failed, codec is null");
|
||||
IMAGE_LOGE("Decode failed, codec is null");
|
||||
return ERR_IMAGE_DECODE_FAILED;
|
||||
}
|
||||
if (dstInfo_.isEmpty()) {
|
||||
HiLog::Error(LABEL, "Decode failed, dst info is empty");
|
||||
IMAGE_LOGE("Decode failed, dst info is empty");
|
||||
return ERR_IMAGE_DECODE_FAILED;
|
||||
}
|
||||
return SUCCESS;
|
||||
@ -577,7 +579,7 @@ uint32_t ExtDecoder::Decode(uint32_t index, DecodeContext &context)
|
||||
byteCount = byteCount / NUM_4 * NUM_3;
|
||||
}
|
||||
if (context.pixelsBuffer.buffer == nullptr) {
|
||||
HiLog::Debug(LABEL, "Decode alloc byte count.");
|
||||
IMAGE_LOGD("Decode alloc byte count.");
|
||||
res = SetContextPixelsBuffer(byteCount, context);
|
||||
if (res != SUCCESS) {
|
||||
return res;
|
||||
@ -595,7 +597,7 @@ uint32_t ExtDecoder::Decode(uint32_t index, DecodeContext &context)
|
||||
}
|
||||
SkEncodedImageFormat skEncodeFormat = codec_->getEncodedFormat();
|
||||
ReportImageType(skEncodeFormat);
|
||||
HiLog::Debug(LABEL, "decode format %{public}d", skEncodeFormat);
|
||||
IMAGE_LOGD("decode format %{public}d", skEncodeFormat);
|
||||
if (skEncodeFormat == SkEncodedImageFormat::kGIF || skEncodeFormat == SkEncodedImageFormat::kWEBP) {
|
||||
return GifDecode(index, context, rowStride);
|
||||
}
|
||||
@ -605,7 +607,7 @@ uint32_t ExtDecoder::Decode(uint32_t index, DecodeContext &context)
|
||||
ret = codec_->getPixels(dstInfo_, dstBuffer, rowStride, &dstOptions_);
|
||||
}
|
||||
if (ret != SkCodec::kSuccess) {
|
||||
HiLog::Error(LABEL, "Decode failed, get pixels failed, ret=%{public}d", ret);
|
||||
IMAGE_LOGE("Decode failed, get pixels failed, ret=%{public}d", ret);
|
||||
return ERR_IMAGE_DECODE_ABNORMAL;
|
||||
}
|
||||
if (dstInfo_.colorType() == SkColorType::kRGB_888x_SkColorType) {
|
||||
@ -652,21 +654,21 @@ static std::string GetFormatStr(SkEncodedImageFormat format)
|
||||
|
||||
void ExtDecoder::ReportImageType(SkEncodedImageFormat skEncodeFormat)
|
||||
{
|
||||
HiLog::Debug(LABEL, "ExtDecoder::ReportImageType format %{public}d start", skEncodeFormat);
|
||||
IMAGE_LOGD("ExtDecoder::ReportImageType format %{public}d start", skEncodeFormat);
|
||||
static constexpr char IMAGE_FWK_UE[] = "IMAGE_FWK_UE";
|
||||
int32_t ret = HiSysEventWrite(
|
||||
IMAGE_FWK_UE,
|
||||
"DECODED_IMAGE_TYPE_STATISTICS",
|
||||
HiSysEvent::EventType::STATISTIC,
|
||||
HiviewDFX::HiSysEvent::EventType::STATISTIC,
|
||||
"PNAMEID", DEFAULT_PACKAGE_NAME,
|
||||
"PVERSIONID", DEFAULT_VERSION_ID,
|
||||
"IMAGE_TYPE", GetFormatStr(skEncodeFormat)
|
||||
);
|
||||
if (SUCCESS != ret) {
|
||||
HiLog::Debug(LABEL, "ExtDecoder::ReportImageType failed, ret = %{public}d", ret);
|
||||
IMAGE_LOGD("ExtDecoder::ReportImageType failed, ret = %{public}d", ret);
|
||||
return;
|
||||
}
|
||||
HiLog::Debug(LABEL, "ExtDecoder::ReportImageType format %{public}d success", skEncodeFormat);
|
||||
IMAGE_LOGD("ExtDecoder::ReportImageType format %{public}d success", skEncodeFormat);
|
||||
}
|
||||
#ifdef JPEG_HW_DECODE_ENABLE
|
||||
uint32_t ExtDecoder::AllocOutputBuffer(DecodeContext &context)
|
||||
@ -674,7 +676,7 @@ uint32_t ExtDecoder::AllocOutputBuffer(DecodeContext &context)
|
||||
uint64_t byteCount = static_cast<uint64_t>(dstInfo_.height()) * dstInfo_.width() * dstInfo_.bytesPerPixel();
|
||||
uint32_t ret = DmaMemAlloc(context, byteCount, info_);
|
||||
if (ret != SUCCESS) {
|
||||
HiLog::Error(LABEL, "Alloc OutputBuffer failed, ret=%{public}d", ret);
|
||||
IMAGE_LOGE("Alloc OutputBuffer failed, ret=%{public}d", ret);
|
||||
return ERR_IMAGE_DECODE_ABNORMAL;
|
||||
}
|
||||
BufferHandle *handle = (static_cast<SurfaceBuffer*>(context.pixelsBuffer.context))->GetBufferHandle();
|
||||
@ -692,7 +694,7 @@ uint32_t ExtDecoder::AllocOutputBuffer(DecodeContext &context)
|
||||
bool CheckContext(const SkImageInfo &dstInfo)
|
||||
{
|
||||
if (dstInfo.colorType() != kRGBA_8888_SkColorType) {
|
||||
HiLog::Error(LABEL, "hardware decode only support rgba_8888 format");
|
||||
IMAGE_LOGE("hardware decode only support rgba_8888 format");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -713,8 +715,8 @@ uint32_t ExtDecoder::HardWareDecode(DecodeContext &context)
|
||||
{
|
||||
// check if the hwDstInfo is equal to the dstInfo
|
||||
if (hwDstInfo_.width() != dstInfo_.width() || hwDstInfo_.height() != dstInfo_.height()) {
|
||||
HiLog::Info(LABEL, "hwDstInfo(%{public}d, %{public}d) != dstInfo(%{public}d, %{public}d)",
|
||||
hwDstInfo_.width(), hwDstInfo_.height(), dstInfo_.width(), dstInfo_.height());
|
||||
IMAGE_LOGI("hwDstInfo(%{public}d, %{public}d) != dstInfo(%{public}d, %{public}d)",
|
||||
hwDstInfo_.width(), hwDstInfo_.height(), dstInfo_.width(), dstInfo_.height());
|
||||
return ERROR;
|
||||
}
|
||||
JpegHardwareDecoder hwDecoder;
|
||||
@ -728,12 +730,12 @@ uint32_t ExtDecoder::HardWareDecode(DecodeContext &context)
|
||||
Media::AllocatorType tmpAllocatorType = context.allocatorType;
|
||||
uint32_t ret = AllocOutputBuffer(context);
|
||||
if (ret != SUCCESS) {
|
||||
HiLog::Error(LABEL, "Decode failed, Alloc OutputBuffer failed, ret=%{public}d", ret);
|
||||
IMAGE_LOGE("Decode failed, Alloc OutputBuffer failed, ret=%{public}d", ret);
|
||||
return ERR_IMAGE_DECODE_ABNORMAL;
|
||||
}
|
||||
ret = hwDecoder.Decode(codec_.get(), stream_, orgImgSize_, sampleSize_, outputBuffer_);
|
||||
if (ret != SUCCESS) {
|
||||
HiLog::Error(LABEL, "failed to do jpeg hardware decode, err=%{public}d", ret);
|
||||
IMAGE_LOGE("failed to do jpeg hardware decode, err=%{public}d", ret);
|
||||
ReleaseOutputBuffer(context, tmpAllocatorType);
|
||||
return ERR_IMAGE_DECODE_ABNORMAL;
|
||||
}
|
||||
@ -748,7 +750,7 @@ static uint32_t handleGifCache(uint8_t* src, uint8_t* dst, SkImageInfo& info, co
|
||||
for (int i = 0; i < dstHeight; i++) {
|
||||
errno_t err = memcpy_s(dstRow, rowStride, srcRow, rowStride);
|
||||
if (err != EOK) {
|
||||
HiLog::Error(LABEL, "handle gif memcpy failed. errno:%{public}d", err);
|
||||
IMAGE_LOGE("handle gif memcpy failed. errno:%{public}d", err);
|
||||
return ERR_IMAGE_DECODE_ABNORMAL;
|
||||
}
|
||||
srcRow += rowStride;
|
||||
@ -790,7 +792,7 @@ uint32_t ExtDecoder::GifDecode(uint32_t index, DecodeContext &context, const uin
|
||||
ret = codec_->getPixels(dstInfo_, dstBuffer, rowStride, &dstOptions_);
|
||||
}
|
||||
if (ret != SkCodec::kSuccess) {
|
||||
HiLog::Error(LABEL, "Gif decode failed, get pixels failed, ret=%{public}d", ret);
|
||||
IMAGE_LOGE("Gif decode failed, get pixels failed, ret=%{public}d", ret);
|
||||
return ERR_IMAGE_DECODE_ABNORMAL;
|
||||
}
|
||||
if (curInfo.fDisposalMethod != SkCodecAnimation::DisposalMethod::kRestorePrevious) {
|
||||
@ -812,15 +814,15 @@ bool ExtDecoder::CheckCodec()
|
||||
if (codec_ != nullptr) {
|
||||
return true;
|
||||
} else if (stream_ == nullptr) {
|
||||
HiLog::Error(LABEL, "create codec: input stream is nullptr.");
|
||||
IMAGE_LOGE("create codec: input stream is nullptr.");
|
||||
return false;
|
||||
} else if (stream_->GetStreamSize() == SIZE_ZERO) {
|
||||
HiLog::Error(LABEL, "create codec: input stream size is zero.");
|
||||
IMAGE_LOGE("create codec: input stream size is zero.");
|
||||
return false;
|
||||
}
|
||||
codec_ = SkCodec::MakeFromStream(make_unique<ExtStream>(stream_));
|
||||
if (codec_ == nullptr) {
|
||||
HiLog::Error(LABEL, "create codec from stream failed");
|
||||
IMAGE_LOGE("create codec from stream failed");
|
||||
return false;
|
||||
}
|
||||
return codec_ != nullptr;
|
||||
@ -829,12 +831,12 @@ bool ExtDecoder::CheckCodec()
|
||||
bool ExtDecoder::DecodeHeader()
|
||||
{
|
||||
if (!CheckCodec()) {
|
||||
HiLog::Error(LABEL, "Check codec failed");
|
||||
IMAGE_LOGE("Check codec failed");
|
||||
return false;
|
||||
}
|
||||
info_ = codec_->getInfo();
|
||||
frameCount_ = codec_->getFrameCount();
|
||||
HiLog::Debug(LABEL, "DecodeHeader: get frame count %{public}d.", frameCount_);
|
||||
IMAGE_LOGD("DecodeHeader: get frame count %{public}d.", frameCount_);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -851,11 +853,11 @@ static uint32_t GetFormatName(SkEncodedImageFormat format, std::string &name)
|
||||
auto formatNameIter = FORMAT_NAME.find(format);
|
||||
if (formatNameIter != FORMAT_NAME.end() && !formatNameIter->second.empty()) {
|
||||
name = formatNameIter->second;
|
||||
HiLog::Debug(LABEL, "GetFormatName: get encoded format name (%{public}d)=>[%{public}s].",
|
||||
IMAGE_LOGD("GetFormatName: get encoded format name (%{public}d)=>[%{public}s].",
|
||||
format, name.c_str());
|
||||
return SUCCESS;
|
||||
}
|
||||
HiLog::Error(LABEL, "GetFormatName: get encoded format name failed %{public}d.", format);
|
||||
IMAGE_LOGE("GetFormatName: get encoded format name failed %{public}d.", format);
|
||||
return ERR_IMAGE_DATA_UNSUPPORT;
|
||||
}
|
||||
|
||||
@ -904,13 +906,13 @@ SkAlphaType ExtDecoder::ConvertToAlphaType(PlAlphaType desiredType, PlAlphaType
|
||||
return alphaType->second;
|
||||
}
|
||||
}
|
||||
HiLog::Debug(LABEL, "Unknown alpha type:%{public}d", desiredType);
|
||||
IMAGE_LOGD("Unknown alpha type:%{public}d", desiredType);
|
||||
SkAlphaType res;
|
||||
if (ConvertInfoToAlphaType(res, outputType)) {
|
||||
HiLog::Debug(LABEL, "Using alpha type:%{public}d", outputType);
|
||||
IMAGE_LOGD("Using alpha type:%{public}d", outputType);
|
||||
return res;
|
||||
}
|
||||
HiLog::Debug(LABEL, "Using default alpha type:%{public}d", PlAlphaType::IMAGE_ALPHA_TYPE_PREMUL);
|
||||
IMAGE_LOGD("Using default alpha type:%{public}d", PlAlphaType::IMAGE_ALPHA_TYPE_PREMUL);
|
||||
outputType = PlAlphaType::IMAGE_ALPHA_TYPE_PREMUL;
|
||||
return SkAlphaType::kPremul_SkAlphaType;
|
||||
}
|
||||
@ -924,13 +926,13 @@ SkColorType ExtDecoder::ConvertToColorType(PlPixelFormat format, PlPixelFormat &
|
||||
return colorType->second.skFormat;
|
||||
}
|
||||
}
|
||||
HiLog::Debug(LABEL, "Unknown pixel format:%{public}d", format);
|
||||
IMAGE_LOGD("Unknown pixel format:%{public}d", format);
|
||||
SkColorType res;
|
||||
if (ConvertInfoToColorType(res, outputFormat)) {
|
||||
HiLog::Debug(LABEL, "Using pixel format:%{public}d", outputFormat);
|
||||
IMAGE_LOGD("Using pixel format:%{public}d", outputFormat);
|
||||
return res;
|
||||
}
|
||||
HiLog::Debug(LABEL, "Using default pixel format:%{public}d", PlPixelFormat::RGBA_8888);
|
||||
IMAGE_LOGD("Using default pixel format:%{public}d", PlPixelFormat::RGBA_8888);
|
||||
outputFormat = PlPixelFormat::RGBA_8888;
|
||||
return kRGBA_8888_SkColorType;
|
||||
}
|
||||
@ -976,7 +978,7 @@ static bool MatchColorSpaceName(const uint8_t* buf, uint32_t size, OHOS::ColorMa
|
||||
}
|
||||
}
|
||||
if (desc.size() <= SIZE_1) {
|
||||
HiLog::Info(LABEL, "empty buffer");
|
||||
IMAGE_LOGI("empty buffer");
|
||||
return false;
|
||||
}
|
||||
std::string descText(desc.begin() + OFFSET_1, desc.end());
|
||||
@ -987,14 +989,14 @@ static bool MatchColorSpaceName(const uint8_t* buf, uint32_t size, OHOS::ColorMa
|
||||
name = nameEnum.name;
|
||||
return true;
|
||||
}
|
||||
HiLog::Error(LABEL, "Failed to match desc [%{public}s]", descText.c_str());
|
||||
IMAGE_LOGE("Failed to match desc [%{public}s]", descText.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool GetColorSpaceName(const skcms_ICCProfile* profile, OHOS::ColorManager::ColorSpaceName &name)
|
||||
{
|
||||
if (profile == nullptr || profile->buffer == nullptr) {
|
||||
HiLog::Debug(LABEL, "profile is nullptr");
|
||||
IMAGE_LOGD("profile is nullptr");
|
||||
return false;
|
||||
}
|
||||
auto tags = reinterpret_cast<const ICCTag*>(profile->buffer + ICC_HEADER_SIZE);
|
||||
@ -1026,7 +1028,7 @@ OHOS::ColorManager::ColorSpace ExtDecoder::getGrColorSpace()
|
||||
if (codec_ != nullptr) {
|
||||
auto profile = codec_->getICCProfile();
|
||||
if (profile != nullptr) {
|
||||
HiLog::Debug(LABEL, "profile got !!!!");
|
||||
IMAGE_LOGD("profile got !!!!");
|
||||
GetColorSpaceName(profile, name);
|
||||
}
|
||||
}
|
||||
@ -1070,12 +1072,12 @@ static bool ParseExifData(InputDataStream *input, EXIFInfo &info)
|
||||
if (info.IsExifDataParsed()) {
|
||||
return true;
|
||||
}
|
||||
HiLog::Debug(LABEL, "ParseExifData enter");
|
||||
IMAGE_LOGD("ParseExifData enter");
|
||||
auto code = ProcessWithStreamData(input, [&info](uint8_t* buffer, size_t size) {
|
||||
return info.ParseExifData(buffer, size);
|
||||
});
|
||||
if (code != SUCCESS) {
|
||||
HiLog::Error(LABEL, "Error parsing EXIF: code %{public}d", code);
|
||||
IMAGE_LOGE("Error parsing EXIF: code %{public}d", code);
|
||||
}
|
||||
return code == SUCCESS;
|
||||
}
|
||||
@ -1105,22 +1107,22 @@ bool ExtDecoder::GetPropertyCheck(uint32_t index, const std::string &key, uint32
|
||||
static uint32_t GetDelayTime(SkCodec * codec, uint32_t index, int32_t &value)
|
||||
{
|
||||
if (codec->getEncodedFormat() != SkEncodedImageFormat::kGIF) {
|
||||
HiLog::Error(LABEL, "[GetDelayTime] Should not get delay time in %{public}d", codec->getEncodedFormat());
|
||||
IMAGE_LOGE("[GetDelayTime] Should not get delay time in %{public}d", codec->getEncodedFormat());
|
||||
return ERR_MEDIA_INVALID_PARAM;
|
||||
}
|
||||
auto frameInfos = codec->getFrameInfo();
|
||||
if (index > frameInfos.size() - 1) {
|
||||
HiLog::Error(LABEL, "[GetDelayTime] frame size %{public}zu, index:%{public}d", frameInfos.size(), index);
|
||||
IMAGE_LOGE("[GetDelayTime] frame size %{public}zu, index:%{public}d", frameInfos.size(), index);
|
||||
return ERR_MEDIA_INVALID_PARAM;
|
||||
}
|
||||
value = frameInfos[index].fDuration;
|
||||
HiLog::Debug(LABEL, "[GetDelayTime] index[%{public}d]:%{public}d", index, value);
|
||||
IMAGE_LOGD("[GetDelayTime] index[%{public}d]:%{public}d", index, value);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
uint32_t ExtDecoder::GetImagePropertyInt(uint32_t index, const std::string &key, int32_t &value)
|
||||
{
|
||||
HiLog::Debug(LABEL, "[GetImagePropertyInt] enter ExtDecoder plugin, key:%{public}s", key.c_str());
|
||||
IMAGE_LOGD("[GetImagePropertyInt] enter ExtDecoder plugin, key:%{public}s", key.c_str());
|
||||
uint32_t res = Media::ERR_IMAGE_DATA_ABNORMAL;
|
||||
if (!GetPropertyCheck(index, key, res)) {
|
||||
return res;
|
||||
@ -1142,13 +1144,13 @@ uint32_t ExtDecoder::GetImagePropertyInt(uint32_t index, const std::string &key,
|
||||
value = atoi(strValue.c_str());
|
||||
return res;
|
||||
}
|
||||
HiLog::Error(LABEL, "[GetImagePropertyInt] The key:%{public}s is not supported int32_t", key.c_str());
|
||||
IMAGE_LOGE("[GetImagePropertyInt] The key:%{public}s is not supported int32_t", key.c_str());
|
||||
return Media::ERR_MEDIA_VALUE_INVALID;
|
||||
}
|
||||
|
||||
uint32_t ExtDecoder::GetImagePropertyString(uint32_t index, const std::string &key, std::string &value)
|
||||
{
|
||||
HiLog::Debug(LABEL, "[GetImagePropertyString] enter jpeg plugin, key:%{public}s", key.c_str());
|
||||
IMAGE_LOGD("[GetImagePropertyString] enter jpeg plugin, key:%{public}s", key.c_str());
|
||||
uint32_t res = Media::ERR_IMAGE_DATA_ABNORMAL;
|
||||
if (!GetPropertyCheck(index, key, res)) {
|
||||
return res;
|
||||
@ -1171,12 +1173,12 @@ uint32_t ExtDecoder::GetImagePropertyString(uint32_t index, const std::string &k
|
||||
res = GetMakerImagePropertyString(key, value);
|
||||
if (value.length() == 0) {
|
||||
value = DEFAULT_EXIF_VALUE;
|
||||
HiLog::Error(LABEL, "[GetImagePropertyString]The image does not contain the %{public}s tag ", key.c_str());
|
||||
IMAGE_LOGE("[GetImagePropertyString]The image does not contain the %{public}s tag ", key.c_str());
|
||||
}
|
||||
return res;
|
||||
}
|
||||
res = exifInfo_.GetExifData(key, value);
|
||||
HiLog::Debug(LABEL, "[GetImagePropertyString] enter jpeg plugin, value:%{public}s", value.c_str());
|
||||
IMAGE_LOGD("[GetImagePropertyString] enter jpeg plugin, value:%{public}s", value.c_str());
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -1192,7 +1194,7 @@ uint32_t ExtDecoder::GetMakerImagePropertyString(const std::string &key, std::st
|
||||
uint32_t ExtDecoder::ModifyImageProperty(uint32_t index, const std::string &key,
|
||||
const std::string &value, const std::string &path)
|
||||
{
|
||||
HiLog::Debug(LABEL, "[ModifyImageProperty] with path:%{public}s, key:%{public}s, value:%{public}s",
|
||||
IMAGE_LOGD("[ModifyImageProperty] with path:%{public}s, key:%{public}s, value:%{public}s",
|
||||
path.c_str(), key.c_str(), value.c_str());
|
||||
return exifInfo_.ModifyExifData(key, value, path);
|
||||
}
|
||||
@ -1200,7 +1202,7 @@ uint32_t ExtDecoder::ModifyImageProperty(uint32_t index, const std::string &key,
|
||||
uint32_t ExtDecoder::ModifyImageProperty(uint32_t index, const std::string &key,
|
||||
const std::string &value, const int fd)
|
||||
{
|
||||
HiLog::Debug(LABEL, "[ModifyImageProperty] with fd:%{public}d, key:%{public}s, value:%{public}s",
|
||||
IMAGE_LOGD("[ModifyImageProperty] with fd:%{public}d, key:%{public}s, value:%{public}s",
|
||||
fd, key.c_str(), value.c_str());
|
||||
return exifInfo_.ModifyExifData(key, value, fd);
|
||||
}
|
||||
@ -1208,16 +1210,16 @@ uint32_t ExtDecoder::ModifyImageProperty(uint32_t index, const std::string &key,
|
||||
uint32_t ExtDecoder::ModifyImageProperty(uint32_t index, const std::string &key,
|
||||
const std::string &value, uint8_t *data, uint32_t size)
|
||||
{
|
||||
HiLog::Debug(LABEL, "[ModifyImageProperty] with key:%{public}s, value:%{public}s",
|
||||
IMAGE_LOGD("[ModifyImageProperty] with key:%{public}s, value:%{public}s",
|
||||
key.c_str(), value.c_str());
|
||||
return exifInfo_.ModifyExifData(key, value, data, size);
|
||||
}
|
||||
|
||||
uint32_t ExtDecoder::GetFilterArea(const int &privacyType, std::vector<std::pair<uint32_t, uint32_t>> &ranges)
|
||||
{
|
||||
HiLog::Debug(LABEL, "[GetFilterArea] with privacyType:%{public}d ", privacyType);
|
||||
IMAGE_LOGD("[GetFilterArea] with privacyType:%{public}d ", privacyType);
|
||||
if (!CheckCodec()) {
|
||||
HiLog::Error(LABEL, "Check codec failed");
|
||||
IMAGE_LOGE("Check codec failed");
|
||||
return NO_EXIF_TAG;
|
||||
}
|
||||
SkEncodedImageFormat format = codec_->getEncodedFormat();
|
||||
@ -1229,11 +1231,11 @@ uint32_t ExtDecoder::GetFilterArea(const int &privacyType, std::vector<std::pair
|
||||
constexpr size_t U8_SHIFT = 8;
|
||||
return ProcessWithStreamData(stream_, [this, &privacyType, &ranges](uint8_t* buffer, size_t size) {
|
||||
size_t appSize = (static_cast<size_t>(buffer[APP1_SIZE_H_OFF]) << U8_SHIFT) | buffer[APP1_SIZE_L_OFF];
|
||||
HiLog::Debug(LABEL, "[GetFilterArea]: get app1 area size");
|
||||
IMAGE_LOGD("[GetFilterArea]: get app1 area size");
|
||||
appSize += APP1_SIZE_H_OFF;
|
||||
auto ret = exifInfo_.GetFilterArea(buffer, (appSize < size) ? appSize : size, privacyType, ranges);
|
||||
if (ret != SUCCESS) {
|
||||
HiLog::Error(LABEL, "[GetFilterArea]: failed to get area %{public}d", ret);
|
||||
IMAGE_LOGE("[GetFilterArea]: failed to get area %{public}d", ret);
|
||||
}
|
||||
return ret;
|
||||
});
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "astc_codec.h"
|
||||
#include "ext_pixel_convert.h"
|
||||
#include "ext_wstream.h"
|
||||
#include "image_log.h"
|
||||
#include "image_type_converter.h"
|
||||
#include "image_utils.h"
|
||||
#include "media_errors.h"
|
||||
@ -33,13 +34,15 @@
|
||||
#include "surface_buffer.h"
|
||||
#endif
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_PLUGIN
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "ExtEncoder"
|
||||
|
||||
namespace OHOS {
|
||||
namespace ImagePlugin {
|
||||
using namespace OHOS::HiviewDFX;
|
||||
using namespace Media;
|
||||
namespace {
|
||||
constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_TAG_DOMAIN_ID_PLUGIN, "ExtEncoder"};
|
||||
}
|
||||
|
||||
static const std::map<SkEncodedImageFormat, std::string> FORMAT_NAME = {
|
||||
{SkEncodedImageFormat::kBMP, "image/bmp"},
|
||||
@ -120,7 +123,7 @@ static uint32_t BuildSkBitmap(Media::PixelMap *pixelMap, SkBitmap &bitmap,
|
||||
pixelMap->GetCapacity() < skInfo.computeMinByteSize()) {
|
||||
res = RGBToRGBx(pixelMap, skInfo, holder);
|
||||
if (res != SUCCESS) {
|
||||
HiLog::Error(LABEL, "ExtEncoder::BuildSkBitmap pixel convert failed %{public}d", res);
|
||||
IMAGE_LOGE("ExtEncoder::BuildSkBitmap pixel convert failed %{public}d", res);
|
||||
return res;
|
||||
}
|
||||
pixels = holder.buf.get();
|
||||
@ -133,7 +136,7 @@ static uint32_t BuildSkBitmap(Media::PixelMap *pixelMap, SkBitmap &bitmap,
|
||||
rowStride = sbBuffer->GetStride();
|
||||
}
|
||||
if (!bitmap.installPixels(skInfo, pixels, rowStride)) {
|
||||
HiLog::Error(LABEL, "ExtEncoder::BuildSkBitmap to skbitmap failed");
|
||||
IMAGE_LOGE("ExtEncoder::BuildSkBitmap to skbitmap failed");
|
||||
return ERR_IMAGE_INVALID_PARAMETER;
|
||||
}
|
||||
return res;
|
||||
@ -159,7 +162,7 @@ uint32_t ExtEncoder::FinalizeEncode()
|
||||
return IsSameTextStr(item.second, opts_.format);
|
||||
});
|
||||
if (iter == FORMAT_NAME.end()) {
|
||||
HiLog::Error(LABEL, "ExtEncoder::FinalizeEncode unsupported format %{public}s", opts_.format.c_str());
|
||||
IMAGE_LOGE("ExtEncoder::FinalizeEncode unsupported format %{public}s", opts_.format.c_str());
|
||||
return ERR_IMAGE_INVALID_PARAMETER;
|
||||
}
|
||||
auto encodeFormat = iter->first;
|
||||
@ -167,12 +170,12 @@ uint32_t ExtEncoder::FinalizeEncode()
|
||||
TmpBufferHolder holder;
|
||||
auto errorCode = BuildSkBitmap(pixelmap_, bitmap, encodeFormat, holder);
|
||||
if (errorCode != SUCCESS) {
|
||||
HiLog::Error(LABEL, "ExtEncoder::FinalizeEncode BuildSkBitmap failed");
|
||||
IMAGE_LOGE("ExtEncoder::FinalizeEncode BuildSkBitmap failed");
|
||||
return errorCode;
|
||||
}
|
||||
ExtWStream wStream(output_);
|
||||
if (!SkEncodeImage(&wStream, bitmap, iter->first, opts_.quality)) {
|
||||
HiLog::Error(LABEL, "ExtEncoder::FinalizeEncode encode failed");
|
||||
IMAGE_LOGE("ExtEncoder::FinalizeEncode encode failed");
|
||||
return ERR_IMAGE_ENCODE_FAILED;
|
||||
}
|
||||
return SUCCESS;
|
||||
|
@ -14,16 +14,19 @@
|
||||
*/
|
||||
|
||||
#include "ext_stream.h"
|
||||
#include "hilog/log.h"
|
||||
#include "log_tags.h"
|
||||
#include "image_log.h"
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_PLUGIN
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "ExtStream"
|
||||
|
||||
namespace {
|
||||
constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_TAG_DOMAIN_ID_PLUGIN, "ExtStream"};
|
||||
constexpr static size_t SIZE_ZERO = 0;
|
||||
}
|
||||
namespace OHOS {
|
||||
namespace ImagePlugin {
|
||||
using namespace OHOS::HiviewDFX;
|
||||
struct InputStream {
|
||||
uint8_t* buf;
|
||||
uint32_t size;
|
||||
@ -49,7 +52,7 @@ static size_t Skip(InputDataStream *stream, size_t size)
|
||||
uint32_t cur = stream->Tell();
|
||||
uint32_t seek = cur + static_cast<uint32_t>(size);
|
||||
if (!stream->Seek(seek)) {
|
||||
HiLog::Error(LABEL, "skip failed, curpositon, skip size.");
|
||||
IMAGE_LOGE("skip failed, curpositon, skip size.");
|
||||
return SIZE_ZERO;
|
||||
}
|
||||
return size;
|
||||
@ -71,7 +74,7 @@ size_t ExtStream::read(void *buffer, size_t size)
|
||||
desiredSize = stream_->GetStreamSize();
|
||||
}
|
||||
if (!stream_->Read(desiredSize, buf.buf, buf.size, buf.resSize)) {
|
||||
HiLog::Error(LABEL, "read failed, desire read size=%{public}u", buf.resSize);
|
||||
IMAGE_LOGE("read failed, desire read size=%{public}u", buf.resSize);
|
||||
return 0;
|
||||
}
|
||||
return static_cast<size_t>(buf.resSize);
|
||||
@ -83,13 +86,13 @@ size_t ExtStream::peek(void *buffer, size_t size) const
|
||||
return SIZE_ZERO;
|
||||
}
|
||||
if (buffer == nullptr) {
|
||||
HiLog::Error(LABEL, "peek failed, output buffer is null");
|
||||
IMAGE_LOGE("peek failed, output buffer is null");
|
||||
return SIZE_ZERO;
|
||||
}
|
||||
InputStream buf;
|
||||
InputStreamInit(buf, static_cast<uint8_t *>(buffer), size);
|
||||
if (!stream_->Peek(buf.size, buf.buf, buf.size, buf.resSize)) {
|
||||
HiLog::Error(LABEL, "peek failed, desire read size=%{public}u", buf.resSize);
|
||||
IMAGE_LOGE("peek failed, desire read size=%{public}u", buf.resSize);
|
||||
return 0;
|
||||
}
|
||||
return static_cast<size_t>(buf.resSize);
|
||||
|
@ -14,16 +14,19 @@
|
||||
*/
|
||||
|
||||
#include "ext_wstream.h"
|
||||
#include "hilog/log.h"
|
||||
#include "log_tags.h"
|
||||
#include "image_log.h"
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_PLUGIN
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "ExtWStream"
|
||||
|
||||
namespace {
|
||||
constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_TAG_DOMAIN_ID_PLUGIN, "ExtWStream"};
|
||||
constexpr static size_t SIZE_ZERO = 0;
|
||||
}
|
||||
namespace OHOS {
|
||||
namespace ImagePlugin {
|
||||
using namespace OHOS::HiviewDFX;
|
||||
|
||||
ExtWStream::ExtWStream(OutputDataStream *stream) : stream_(stream)
|
||||
{
|
||||
@ -32,7 +35,7 @@ ExtWStream::ExtWStream(OutputDataStream *stream) : stream_(stream)
|
||||
bool ExtWStream::write(const void* buffer, size_t size) __attribute__((no_sanitize("cfi")))
|
||||
{
|
||||
if (stream_ == nullptr) {
|
||||
HiLog::Error(LABEL, "ExtWStream::write stream is nullptr");
|
||||
IMAGE_LOGE("ExtWStream::write stream is nullptr");
|
||||
return false;
|
||||
}
|
||||
return stream_->Write(static_cast<const uint8_t*>(buffer), size);
|
||||
@ -41,7 +44,7 @@ bool ExtWStream::write(const void* buffer, size_t size) __attribute__((no_saniti
|
||||
void ExtWStream::flush()
|
||||
{
|
||||
if (stream_ == nullptr) {
|
||||
HiLog::Error(LABEL, "ExtWStream::flush stream is nullptr");
|
||||
IMAGE_LOGE("ExtWStream::flush stream is nullptr");
|
||||
return;
|
||||
}
|
||||
stream_->Flush();
|
||||
@ -50,7 +53,7 @@ void ExtWStream::flush()
|
||||
size_t ExtWStream::bytesWritten() const
|
||||
{
|
||||
if (stream_ == nullptr) {
|
||||
HiLog::Error(LABEL, "ExtWStream::bytesWritten stream is nullptr");
|
||||
IMAGE_LOGE("ExtWStream::bytesWritten stream is nullptr");
|
||||
return SIZE_ZERO;
|
||||
}
|
||||
size_t written = SIZE_ZERO;
|
||||
|
@ -16,10 +16,15 @@
|
||||
#include "plugin_export.h"
|
||||
#include "ext_decoder.h"
|
||||
#include "ext_encoder.h"
|
||||
#include "hilog/log.h"
|
||||
#include "log_tags.h"
|
||||
#include "image_log.h"
|
||||
#include "plugin_utils.h"
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_PLUGIN
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "LibExtPlugin"
|
||||
|
||||
// plugin package name same as metadata.
|
||||
namespace {
|
||||
const std::string PACKAGE_NAME = ("LibExtPlugin");
|
||||
@ -32,32 +37,26 @@ PLUGIN_EXPORT_REGISTER_CLASS(OHOS::ImagePlugin::ExtEncoder)
|
||||
PLUGIN_EXPORT_REGISTER_CLASS_END
|
||||
|
||||
using std::string;
|
||||
using namespace OHOS::HiviewDFX;
|
||||
|
||||
static constexpr HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_PLUGIN, "LibExtPlugin" };
|
||||
|
||||
#define PLUGIN_LOG_D(...) HiLog::Debug(LABEL, __VA_ARGS__)
|
||||
#define PLUGIN_LOG_E(...) HiLog::Error(LABEL, __VA_ARGS__)
|
||||
|
||||
// define the external interface of this plugin.
|
||||
PLUGIN_EXPORT_DEFAULT_EXTERNAL_START()
|
||||
PLUGIN_EXPORT_DEFAULT_EXTERNAL_STOP()
|
||||
OHOS::MultimediaPlugin::PluginClassBase *PluginExternalCreate(const string &className)
|
||||
{
|
||||
HiLog::Debug(LABEL, "PluginExternalCreate: create object for package: %{public}s, class: %{public}s.",
|
||||
PACKAGE_NAME.c_str(), className.c_str());
|
||||
IMAGE_LOGD("PluginExternalCreate: create object for package: %{public}s, class: %{public}s.",
|
||||
PACKAGE_NAME.c_str(), className.c_str());
|
||||
|
||||
auto iter = implClassMap.find(className);
|
||||
if (iter == implClassMap.end()) {
|
||||
HiLog::Error(LABEL, "PluginExternalCreate: failed to find class: %{public}s, in package: %{public}s.",
|
||||
className.c_str(), PACKAGE_NAME.c_str());
|
||||
IMAGE_LOGE("PluginExternalCreate: failed to find class: %{public}s, in package: %{public}s.",
|
||||
className.c_str(), PACKAGE_NAME.c_str());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto creator = iter->second;
|
||||
if (creator == nullptr) {
|
||||
HiLog::Error(LABEL, "PluginExternalCreate: null creator for class: %{public}s, in package: %{public}s.",
|
||||
className.c_str(), PACKAGE_NAME.c_str());
|
||||
IMAGE_LOGE("PluginExternalCreate: null creator for class: %{public}s, in package: %{public}s.",
|
||||
className.c_str(), PACKAGE_NAME.c_str());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -15,19 +15,20 @@
|
||||
|
||||
#include "astc_codec.h"
|
||||
#include "image_compressor.h"
|
||||
#include "image_log.h"
|
||||
#include "image_system_properties.h"
|
||||
#include "securec.h"
|
||||
#include "media_errors.h"
|
||||
#include "hilog/log.h"
|
||||
#include "log_tags.h"
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_PLUGIN
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "AstcCodec"
|
||||
|
||||
namespace OHOS {
|
||||
namespace ImagePlugin {
|
||||
using namespace OHOS::HiviewDFX;
|
||||
using namespace Media;
|
||||
namespace {
|
||||
constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_TAG_DOMAIN_ID_PLUGIN, "AstcCodec"};
|
||||
}
|
||||
|
||||
constexpr uint8_t TEXTURE_HEAD_BYTES = 16;
|
||||
constexpr uint8_t ASTC_MASK = 0xFF;
|
||||
@ -41,7 +42,7 @@ constexpr uint8_t HIGH_SPEED_PROFILE_MAP_QUALITY = 20; // quality level is 20 fo
|
||||
uint32_t AstcCodec::SetAstcEncode(OutputDataStream* outputStream, PlEncodeOptions &option, Media::PixelMap* pixelMap)
|
||||
{
|
||||
if (outputStream == nullptr || pixelMap == nullptr) {
|
||||
HiLog::Error(LABEL, "input data is nullptr.");
|
||||
IMAGE_LOGE("input data is nullptr.");
|
||||
return ERROR;
|
||||
}
|
||||
astcOutput_ = outputStream;
|
||||
@ -54,7 +55,7 @@ uint32_t AstcCodec::SetAstcEncode(OutputDataStream* outputStream, PlEncodeOption
|
||||
uint32_t GenAstcHeader(uint8_t *header, astcenc_image img, TextureEncodeOptions *encodeParams, size_t size)
|
||||
{
|
||||
if ((encodeParams == nullptr) || (header == nullptr) || size < ASTC_HEADER_SIZE) {
|
||||
HiLog::Error(LABEL, "header is nullptr or encodeParams is nullptr or header_size is error");
|
||||
IMAGE_LOGE("header is nullptr or encodeParams is nullptr or header_size is error");
|
||||
return ERROR;
|
||||
}
|
||||
uint8_t *tmp = header;
|
||||
@ -80,7 +81,7 @@ uint32_t GenAstcHeader(uint8_t *header, astcenc_image img, TextureEncodeOptions
|
||||
uint32_t InitAstcencConfig(AstcEncoder* work, TextureEncodeOptions* option)
|
||||
{
|
||||
if ((work == nullptr) || (option == nullptr)) {
|
||||
HiLog::Error(LABEL, "astc input work or option is nullptr.");
|
||||
IMAGE_LOGE("astc input work or option is nullptr.");
|
||||
return ERROR;
|
||||
}
|
||||
unsigned int blockX = option->blockX_;
|
||||
@ -92,13 +93,13 @@ uint32_t InitAstcencConfig(AstcEncoder* work, TextureEncodeOptions* option)
|
||||
astcenc_error status = astcenc_config_init(work->profile, blockX, blockY,
|
||||
blockZ, quality, flags, &work->config);
|
||||
if (status == ASTCENC_ERR_BAD_BLOCK_SIZE) {
|
||||
HiLog::Error(LABEL, "ERROR: block size is invalid");
|
||||
IMAGE_LOGE("ERROR: block size is invalid");
|
||||
return ERROR;
|
||||
} else if (status == ASTCENC_ERR_BAD_CPU_FLOAT) {
|
||||
HiLog::Error(LABEL, "ERROR: astcenc must not be compiled with fast-math");
|
||||
IMAGE_LOGE("ERROR: astcenc must not be compiled with fast-math");
|
||||
return ERROR;
|
||||
} else if (status != ASTCENC_SUCCESS) {
|
||||
HiLog::Error(LABEL, "ERROR: config failed");
|
||||
IMAGE_LOGE("ERROR: config failed");
|
||||
return ERROR;
|
||||
}
|
||||
work->config.privateProfile = option->privateProfile_;
|
||||
@ -170,7 +171,7 @@ bool CheckQuality(int32_t *mseIn[RGBA_COM], int blockNum, int blockXYZ)
|
||||
double mseRgb = static_cast<double>(mseTotal[RGBA_COM] / (blockNum * blockXYZ * (RGBA_COM - 1)));
|
||||
psnr[RGBA_COM] = LOG_BASE * log(static_cast<double>(MAX_VALUE * MAX_VALUE) / mseRgb) / log(LOG_BASE);
|
||||
}
|
||||
HiLog::Debug(LABEL, "astc psnr r%{public}f g%{public}f b%{public}f a%{public}f rgb%{public}f",
|
||||
IMAGE_LOGD("astc psnr r%{public}f g%{public}f b%{public}f a%{public}f rgb%{public}f",
|
||||
psnr[R_COM], psnr[G_COM], psnr[B_COM], psnr[A_COM],
|
||||
psnr[RGBA_COM]);
|
||||
return (psnr[R_COM] > threshold[R_COM]) && (psnr[G_COM] > threshold[G_COM])
|
||||
@ -225,7 +226,7 @@ static bool InitMem(AstcEncoder *work, TextureEncodeOptions param, bool enableQu
|
||||
for (int i = R_COM; i < RGBA_COM; i++) {
|
||||
work->mse[i] = (int32_t *)calloc(blockNum, sizeof(int32_t));
|
||||
if (!work->mse[i]) {
|
||||
HiLog::Error(LABEL, "quality control calloc failed");
|
||||
IMAGE_LOGE("quality control calloc failed");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -249,7 +250,7 @@ uint32_t AstcCodec::AstcSoftwareEncode(TextureEncodeOptions ¶m, bool enableQ
|
||||
return ERROR;
|
||||
}
|
||||
if (InitAstcencConfig(&work, ¶m) != SUCCESS) {
|
||||
HiLog::Error(LABEL, "astc InitAstcencConfig failed");
|
||||
IMAGE_LOGE("astc InitAstcencConfig failed");
|
||||
FreeMem(&work);
|
||||
return ERROR;
|
||||
}
|
||||
@ -258,7 +259,7 @@ uint32_t AstcCodec::AstcSoftwareEncode(TextureEncodeOptions ¶m, bool enableQ
|
||||
size_t size;
|
||||
astcOutput_->GetCapicity(size);
|
||||
if (GenAstcHeader(work.data_out_, work.image_, ¶m, size) != SUCCESS) {
|
||||
HiLog::Error(LABEL, "astc GenAstcHeader failed");
|
||||
IMAGE_LOGE("astc GenAstcHeader failed");
|
||||
FreeMem(&work);
|
||||
return ERROR;
|
||||
}
|
||||
@ -274,7 +275,7 @@ uint32_t AstcCodec::AstcSoftwareEncode(TextureEncodeOptions ¶m, bool enableQ
|
||||
#else
|
||||
if (ASTCENC_SUCCESS != work.error_) {
|
||||
#endif
|
||||
HiLog::Error(LABEL, "astc compress failed");
|
||||
IMAGE_LOGE("astc compress failed");
|
||||
FreeMem(&work);
|
||||
return ERROR;
|
||||
}
|
||||
@ -301,26 +302,26 @@ static bool TryAstcEncBasedOnCl(uint8_t *inData, int32_t stride, TextureEncodeOp
|
||||
{
|
||||
ClAstcHandle *astcClEncoder = nullptr;
|
||||
if ((inData == nullptr) || (param == nullptr) || (buffer == nullptr)) {
|
||||
HiLog::Error(LABEL, "astc Please check TryAstcEncBasedOnCl input!");
|
||||
IMAGE_LOGE("astc Please check TryAstcEncBasedOnCl input!");
|
||||
return false;
|
||||
}
|
||||
if (AstcClCreate(&astcClEncoder, clBinPath) != CL_ASTC_ENC_SUCCESS) {
|
||||
HiLog::Error(LABEL, "astc AstcClCreate failed!");
|
||||
IMAGE_LOGE("astc AstcClCreate failed!");
|
||||
return false;
|
||||
}
|
||||
ClAstcImageOption imageIn;
|
||||
if (AstcClFillImage(&imageIn, inData, stride, param->width_, param->height_) != CL_ASTC_ENC_SUCCESS) {
|
||||
HiLog::Error(LABEL, "astc AstcClFillImage failed!");
|
||||
IMAGE_LOGE("astc AstcClFillImage failed!");
|
||||
AstcClClose(astcClEncoder);
|
||||
return false;
|
||||
}
|
||||
if (AstcClEncImage(astcClEncoder, &imageIn, buffer) != CL_ASTC_ENC_SUCCESS) {
|
||||
HiLog::Error(LABEL, "astc AstcClEncImage failed!");
|
||||
IMAGE_LOGE("astc AstcClEncImage failed!");
|
||||
AstcClClose(astcClEncoder);
|
||||
return false;
|
||||
}
|
||||
if (AstcClClose(astcClEncoder) != CL_ASTC_ENC_SUCCESS) {
|
||||
HiLog::Error(LABEL, "astc AstcClClose failed!");
|
||||
IMAGE_LOGE("astc AstcClClose failed!");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -344,25 +345,25 @@ uint32_t AstcCodec::ASTCEncode()
|
||||
|
||||
if (ImageSystemProperties::GetAstcHardWareEncodeEnabled() &&
|
||||
(param.blockX_ == DEFAULT_DIM) && (param.blockY_ == DEFAULT_DIM)) { // HardWare only support 4x4 now
|
||||
HiLog::Info(LABEL, "astc hardware encode begin");
|
||||
IMAGE_LOGI("astc hardware encode begin");
|
||||
std::string clBinPath = "/data/local/tmp/astcKernelBin.bin";
|
||||
if (TryAstcEncBasedOnCl(static_cast<uint8_t *>(astcPixelMap_->GetWritablePixels()),
|
||||
astcPixelMap_->GetRowStride(), ¶m, astcOutput_->GetAddr(), clBinPath)) {
|
||||
hardwareFlag = true;
|
||||
HiLog::Info(LABEL, "astc hardware encode success!");
|
||||
IMAGE_LOGI("astc hardware encode success!");
|
||||
} else {
|
||||
HiLog::Info(LABEL, "astc hardware encode failed!");
|
||||
IMAGE_LOGI("astc hardware encode failed!");
|
||||
}
|
||||
}
|
||||
if (!hardwareFlag) {
|
||||
uint32_t res = AstcSoftwareEncode(param, enableQualityCheck, blocksNum, outSize);
|
||||
if (res != SUCCESS) {
|
||||
HiLog::Error(LABEL, "AstcSoftwareEncode failed");
|
||||
IMAGE_LOGE("AstcSoftwareEncode failed");
|
||||
return ERROR;
|
||||
}
|
||||
HiLog::Info(LABEL, "astc software encode success!");
|
||||
IMAGE_LOGI("astc software encode success!");
|
||||
}
|
||||
HiLog::Info(LABEL, "astc hardwareFlag %{public}d, enableQualityCheck %{public}d, privateProfile %{public}d",
|
||||
IMAGE_LOGI("astc hardwareFlag %{public}d, enableQualityCheck %{public}d, privateProfile %{public}d",
|
||||
hardwareFlag, enableQualityCheck, param.privateProfile_);
|
||||
astcOutput_->SetOffset(outSize);
|
||||
return SUCCESS;
|
||||
|
@ -19,11 +19,13 @@
|
||||
|
||||
#include "securec.h"
|
||||
#include "media_errors.h"
|
||||
#include "hilog/log.h"
|
||||
#include "log_tags.h"
|
||||
#include "image_log.h"
|
||||
|
||||
using namespace OHOS::HiviewDFX;
|
||||
constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_PLUGIN, "ClAstcEnc" };
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_PLUGIN
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "ClAstcEnc"
|
||||
|
||||
constexpr int MAX_WIDTH = 8192;
|
||||
constexpr int MAX_HEIGHT = 4096;
|
||||
@ -1267,14 +1269,14 @@ kernel void AstcCl(read_only image2d_t inputImage, __global uint4* astcArr, __gl
|
||||
CL_ASTC_SHARE_LIB_API CL_ASTC_STATUS AstcClClose(ClAstcHandle *clAstcHandle)
|
||||
{
|
||||
if (clAstcHandle == nullptr) {
|
||||
HiLog::Error(LABEL, "astc AstcClClose clAstcHandle is nullptr!");
|
||||
IMAGE_LOGE("astc AstcClClose clAstcHandle is nullptr!");
|
||||
return CL_ASTC_ENC_FAILED;
|
||||
}
|
||||
cl_int clRet;
|
||||
if (clAstcHandle->kernel != nullptr) {
|
||||
clRet = clReleaseKernel(clAstcHandle->kernel);
|
||||
if (clRet != CL_SUCCESS) {
|
||||
HiLog::Error(LABEL, "astc clReleaseKernel failed ret %{public}d!", clRet);
|
||||
IMAGE_LOGE("astc clReleaseKernel failed ret %{public}d!", clRet);
|
||||
return CL_ASTC_ENC_FAILED;
|
||||
}
|
||||
clAstcHandle->kernel = nullptr;
|
||||
@ -1282,7 +1284,7 @@ CL_ASTC_SHARE_LIB_API CL_ASTC_STATUS AstcClClose(ClAstcHandle *clAstcHandle)
|
||||
if (clAstcHandle->queue != nullptr) {
|
||||
clRet = clReleaseCommandQueue(clAstcHandle->queue);
|
||||
if (clRet != CL_SUCCESS) {
|
||||
HiLog::Error(LABEL, "astc clReleaseCommandQueue failed ret %{public}d!", clRet);
|
||||
IMAGE_LOGE("astc clReleaseCommandQueue failed ret %{public}d!", clRet);
|
||||
return CL_ASTC_ENC_FAILED;
|
||||
}
|
||||
clAstcHandle->queue = nullptr;
|
||||
@ -1290,7 +1292,7 @@ CL_ASTC_SHARE_LIB_API CL_ASTC_STATUS AstcClClose(ClAstcHandle *clAstcHandle)
|
||||
if (clAstcHandle->context != nullptr) {
|
||||
clRet = clReleaseContext(clAstcHandle->context);
|
||||
if (clRet != CL_SUCCESS) {
|
||||
HiLog::Error(LABEL, "astc clReleaseContext failed ret %{public}d!", clRet);
|
||||
IMAGE_LOGE("astc clReleaseContext failed ret %{public}d!", clRet);
|
||||
return CL_ASTC_ENC_FAILED;
|
||||
}
|
||||
clAstcHandle->context = nullptr;
|
||||
@ -1316,37 +1318,37 @@ static CL_ASTC_STATUS SaveClBin(cl_program program, const std::string clBinPath)
|
||||
size_t programBinarySizes;
|
||||
cl_int clRet = clGetProgramInfo(program, CL_PROGRAM_BINARY_SIZES, sizeof(size_t), &programBinarySizes, NULL);
|
||||
if (clRet != CL_SUCCESS) {
|
||||
HiLog::Error(LABEL, "astc clGetProgramInfo CL_PROGRAM_BINARY_SIZES failed ret %{public}d!", clRet);
|
||||
IMAGE_LOGE("astc clGetProgramInfo CL_PROGRAM_BINARY_SIZES failed ret %{public}d!", clRet);
|
||||
return CL_ASTC_ENC_FAILED;
|
||||
}
|
||||
if ((programBinarySizes == 0) || (programBinarySizes > MAX_MALLOC_BYTES)) {
|
||||
HiLog::Error(LABEL, "astc clGetProgramInfo programBinarySizes %{public}zu too big!", programBinarySizes);
|
||||
IMAGE_LOGE("astc clGetProgramInfo programBinarySizes %{public}zu too big!", programBinarySizes);
|
||||
return CL_ASTC_ENC_FAILED;
|
||||
}
|
||||
uint8_t *programBinaries = (uint8_t *)malloc(programBinarySizes);
|
||||
if (programBinaries == nullptr) {
|
||||
HiLog::Error(LABEL, "astc programBinaries malloc failed!");
|
||||
IMAGE_LOGE("astc programBinaries malloc failed!");
|
||||
return CL_ASTC_ENC_FAILED;
|
||||
}
|
||||
clRet = clGetProgramInfo(program, CL_PROGRAM_BINARIES, programBinarySizes, &programBinaries, NULL);
|
||||
if (clRet != CL_SUCCESS) {
|
||||
HiLog::Error(LABEL, "astc clGetProgramInfo CL_PROGRAM_BINARIES failed ret %{public}d!", clRet);
|
||||
IMAGE_LOGE("astc clGetProgramInfo CL_PROGRAM_BINARIES failed ret %{public}d!", clRet);
|
||||
free(programBinaries);
|
||||
return CL_ASTC_ENC_FAILED;
|
||||
}
|
||||
FILE *fp = fopen(clBinPath.c_str(), "wb");
|
||||
if (fp == nullptr) {
|
||||
HiLog::Error(LABEL, "astc create file: %{public}s failed!", clBinPath.c_str());
|
||||
IMAGE_LOGE("astc create file: %{public}s failed!", clBinPath.c_str());
|
||||
free(programBinaries);
|
||||
return CL_ASTC_ENC_FAILED;
|
||||
}
|
||||
CL_ASTC_STATUS ret = CL_ASTC_ENC_SUCCESS;
|
||||
if (fwrite(programBinaries, 1, programBinarySizes, fp) != programBinarySizes) {
|
||||
HiLog::Error(LABEL, "astc fwrite programBinaries file failed!");
|
||||
IMAGE_LOGE("astc fwrite programBinaries file failed!");
|
||||
ret = CL_ASTC_ENC_FAILED;
|
||||
}
|
||||
if (fclose(fp) != 0) {
|
||||
HiLog::Error(LABEL, "astc SaveClBin close file failed!");
|
||||
IMAGE_LOGE("astc SaveClBin close file failed!");
|
||||
ret = CL_ASTC_ENC_FAILED;
|
||||
}
|
||||
fp = nullptr;
|
||||
@ -1358,12 +1360,12 @@ static CL_ASTC_STATUS BuildProgramAndCreateKernel(cl_program program, ClAstcHand
|
||||
{
|
||||
cl_int clRet = clBuildProgram(program, 1, &clAstcHandle->deviceID, "-cl-std=CL3.0", nullptr, nullptr);
|
||||
if (clRet != CL_SUCCESS) {
|
||||
HiLog::Error(LABEL, "astc clBuildProgram failed ret %{public}d!", clRet);
|
||||
IMAGE_LOGE("astc clBuildProgram failed ret %{public}d!", clRet);
|
||||
return CL_ASTC_ENC_FAILED;
|
||||
}
|
||||
clAstcHandle->kernel = clCreateKernel(program, "AstcCl", &clRet);
|
||||
if (clRet != CL_SUCCESS) {
|
||||
HiLog::Error(LABEL, "astc clCreateKernel failed ret %{public}d!", clRet);
|
||||
IMAGE_LOGE("astc clCreateKernel failed ret %{public}d!", clRet);
|
||||
return CL_ASTC_ENC_FAILED;
|
||||
}
|
||||
return CL_ASTC_ENC_SUCCESS;
|
||||
@ -1377,41 +1379,41 @@ static CL_ASTC_STATUS AstcClBuildProgram(ClAstcHandle *clAstcHandle, const std::
|
||||
size_t sourceSize = strlen(g_programSource) + 1; // '\0' occupies 1 bytes
|
||||
program = clCreateProgramWithSource(clAstcHandle->context, 1, &g_programSource, &sourceSize, &clRet);
|
||||
if (clRet != CL_SUCCESS) {
|
||||
HiLog::Error(LABEL, "astc clCreateProgramWithSource failed ret %{public}d!", clRet);
|
||||
IMAGE_LOGE("astc clCreateProgramWithSource failed ret %{public}d!", clRet);
|
||||
return CL_ASTC_ENC_FAILED;
|
||||
}
|
||||
if (BuildProgramAndCreateKernel(program, clAstcHandle) != CL_ASTC_ENC_SUCCESS) {
|
||||
HiLog::Error(LABEL, "astc clCreateProgramWithSource failed ret %{public}d!", clRet);
|
||||
IMAGE_LOGE("astc clCreateProgramWithSource failed ret %{public}d!", clRet);
|
||||
clReleaseProgram(program);
|
||||
return CL_ASTC_ENC_FAILED;
|
||||
}
|
||||
if (SaveClBin(program, clBinPath) != CL_ASTC_ENC_SUCCESS) {
|
||||
HiLog::Info(LABEL, "astc SaveClBin failed!");
|
||||
IMAGE_LOGI("astc SaveClBin failed!");
|
||||
}
|
||||
} else {
|
||||
std::ifstream contents{clBinPath};
|
||||
std::string binaryContent{std::istreambuf_iterator<char>{contents}, {}};
|
||||
size_t binSize = binaryContent.length();
|
||||
if ((binSize == 0) || (binSize > MAX_MALLOC_BYTES)) {
|
||||
HiLog::Error(LABEL, "astc AstcClBuildProgram read CLbin file lenth error %{public}zu!", binSize);
|
||||
IMAGE_LOGE("astc AstcClBuildProgram read CLbin file lenth error %{public}zu!", binSize);
|
||||
return CL_ASTC_ENC_FAILED;
|
||||
}
|
||||
const char *binary = static_cast<const char *>(binaryContent.c_str());
|
||||
program = clCreateProgramWithBinary(clAstcHandle->context, 1, &clAstcHandle->deviceID, &binSize,
|
||||
(const unsigned char **)&binary, nullptr, &clRet);
|
||||
if (clRet != CL_SUCCESS) {
|
||||
HiLog::Error(LABEL, "astc clCreateProgramWithBinary failed ret %{public}d!", clRet);
|
||||
IMAGE_LOGE("astc clCreateProgramWithBinary failed ret %{public}d!", clRet);
|
||||
return CL_ASTC_ENC_FAILED;
|
||||
}
|
||||
if (BuildProgramAndCreateKernel(program, clAstcHandle) != CL_ASTC_ENC_SUCCESS) {
|
||||
HiLog::Error(LABEL, "astc BuildProgramAndCreateKernel with bin failed!");
|
||||
IMAGE_LOGE("astc BuildProgramAndCreateKernel with bin failed!");
|
||||
clReleaseProgram(program);
|
||||
return CL_ASTC_ENC_FAILED;
|
||||
}
|
||||
}
|
||||
clRet = clReleaseProgram(program);
|
||||
if (clRet != CL_SUCCESS) {
|
||||
HiLog::Error(LABEL, "astc clReleaseProgram failed ret %{public}d!", clRet);
|
||||
IMAGE_LOGE("astc clReleaseProgram failed ret %{public}d!", clRet);
|
||||
return CL_ASTC_ENC_FAILED;
|
||||
}
|
||||
return CL_ASTC_ENC_SUCCESS;
|
||||
@ -1420,35 +1422,35 @@ static CL_ASTC_STATUS AstcClBuildProgram(ClAstcHandle *clAstcHandle, const std::
|
||||
static CL_ASTC_STATUS AstcCreateClKernel(ClAstcHandle *clAstcHandle, const std::string clBinPath)
|
||||
{
|
||||
if (!OHOS::InitOpenCL()) {
|
||||
HiLog::Error(LABEL, "astc InitOpenCL error!");
|
||||
IMAGE_LOGE("astc InitOpenCL error!");
|
||||
return CL_ASTC_ENC_FAILED;
|
||||
}
|
||||
cl_int clRet;
|
||||
cl_platform_id platformID;
|
||||
clRet = clGetPlatformIDs(1, &platformID, NULL);
|
||||
if (clRet != CL_SUCCESS) {
|
||||
HiLog::Error(LABEL, "astc clGetPlatformIDs failed ret %{public}d!", clRet);
|
||||
IMAGE_LOGE("astc clGetPlatformIDs failed ret %{public}d!", clRet);
|
||||
return CL_ASTC_ENC_FAILED;
|
||||
}
|
||||
clRet = clGetDeviceIDs(platformID, CL_DEVICE_TYPE_GPU, 1, &clAstcHandle->deviceID, NULL);
|
||||
if (clRet != CL_SUCCESS) {
|
||||
HiLog::Error(LABEL, "astc clGetDeviceIDs failed ret %{public}d!", clRet);
|
||||
IMAGE_LOGE("astc clGetDeviceIDs failed ret %{public}d!", clRet);
|
||||
return CL_ASTC_ENC_FAILED;
|
||||
}
|
||||
clAstcHandle->context = clCreateContext(0, 1, &clAstcHandle->deviceID, NULL, NULL, &clRet);
|
||||
if (clRet != CL_SUCCESS) {
|
||||
HiLog::Error(LABEL, "astc clCreateContext failed ret %{public}d!", clRet);
|
||||
IMAGE_LOGE("astc clCreateContext failed ret %{public}d!", clRet);
|
||||
return CL_ASTC_ENC_FAILED;
|
||||
}
|
||||
cl_queue_properties props[] = {CL_QUEUE_PRIORITY_KHR, CL_QUEUE_PRIORITY_HIGH_KHR, 0};
|
||||
clAstcHandle->queue = clCreateCommandQueueWithProperties(clAstcHandle->context,
|
||||
clAstcHandle->deviceID, props, &clRet);
|
||||
if (clRet != CL_SUCCESS) {
|
||||
HiLog::Error(LABEL, "astc clCreateCommandQueueWithProperties failed ret %{public}d!", clRet);
|
||||
IMAGE_LOGE("astc clCreateCommandQueueWithProperties failed ret %{public}d!", clRet);
|
||||
return CL_ASTC_ENC_FAILED;
|
||||
}
|
||||
if (AstcClBuildProgram(clAstcHandle, clBinPath) != CL_ASTC_ENC_SUCCESS) {
|
||||
HiLog::Error(LABEL, "astc AstcClBuildProgram failed!");
|
||||
IMAGE_LOGE("astc AstcClBuildProgram failed!");
|
||||
return CL_ASTC_ENC_FAILED;
|
||||
}
|
||||
return CL_ASTC_ENC_SUCCESS;
|
||||
@ -1458,19 +1460,19 @@ CL_ASTC_SHARE_LIB_API CL_ASTC_STATUS AstcClCreate(ClAstcHandle **handle, const s
|
||||
{
|
||||
ClAstcHandle *clAstcHandle = (ClAstcHandle *)calloc(1, sizeof(ClAstcHandle));
|
||||
if (clAstcHandle == nullptr) {
|
||||
HiLog::Error(LABEL, "astc AstcClCreate handle calloc failed!");
|
||||
IMAGE_LOGE("astc AstcClCreate handle calloc failed!");
|
||||
return CL_ASTC_ENC_FAILED;
|
||||
}
|
||||
*handle = clAstcHandle;
|
||||
size_t numMaxBlocks = ((MAX_WIDTH + DIM - 1) / DIM) * ((MAX_HEIGHT + DIM - 1) / DIM);
|
||||
clAstcHandle->encObj.blockErrs_ = (uint32_t *)malloc(numMaxBlocks * sizeof(uint32_t)); // 8MB mem Max
|
||||
if (clAstcHandle->encObj.blockErrs_ == nullptr) {
|
||||
HiLog::Error(LABEL, "astc blockErrs_ malloc failed!");
|
||||
IMAGE_LOGE("astc blockErrs_ malloc failed!");
|
||||
AstcClClose(*handle);
|
||||
return CL_ASTC_ENC_FAILED;
|
||||
}
|
||||
if (AstcCreateClKernel(clAstcHandle, clBinPath) != CL_ASTC_ENC_SUCCESS) {
|
||||
HiLog::Error(LABEL, "astc AstcCreateClKernel failed!");
|
||||
IMAGE_LOGE("astc AstcCreateClKernel failed!");
|
||||
AstcClClose(*handle);
|
||||
return CL_ASTC_ENC_FAILED;
|
||||
}
|
||||
@ -1480,11 +1482,11 @@ CL_ASTC_SHARE_LIB_API CL_ASTC_STATUS AstcClCreate(ClAstcHandle **handle, const s
|
||||
static CL_ASTC_STATUS AstcClEncImageCheckImageOption(const ClAstcImageOption *imageIn)
|
||||
{
|
||||
if ((imageIn->width <= 0) || (imageIn->height <= 0) || (imageIn->stride < imageIn->width)) {
|
||||
HiLog::Error(LABEL, "astc AstcClEncImage width <= 0 or height <= 0 or stride < width!");
|
||||
IMAGE_LOGE("astc AstcClEncImage width <= 0 or height <= 0 or stride < width!");
|
||||
return CL_ASTC_ENC_FAILED;
|
||||
}
|
||||
if ((imageIn->width > MAX_WIDTH) || (imageIn->height > MAX_HEIGHT)) {
|
||||
HiLog::Error(LABEL, "astc AstcClEncImage width[%{public}d] \
|
||||
IMAGE_LOGE("astc AstcClEncImage width[%{public}d] \
|
||||
need be [1, %{public}d] and height[%{public}d] need be [1, %{public}d]", \
|
||||
imageIn->width, MAX_WIDTH, imageIn->height, MAX_HEIGHT);
|
||||
return CL_ASTC_ENC_FAILED;
|
||||
@ -1496,7 +1498,7 @@ CL_ASTC_SHARE_LIB_API CL_ASTC_STATUS AstcClFillImage(ClAstcImageOption *imageIn,
|
||||
int32_t width, int32_t height)
|
||||
{
|
||||
if (imageIn == nullptr) {
|
||||
HiLog::Error(LABEL, "astc AstcClFillImage imageIn is nullptr!");
|
||||
IMAGE_LOGE("astc AstcClFillImage imageIn is nullptr!");
|
||||
return CL_ASTC_ENC_FAILED;
|
||||
}
|
||||
imageIn->data = data;
|
||||
@ -1504,7 +1506,7 @@ CL_ASTC_SHARE_LIB_API CL_ASTC_STATUS AstcClFillImage(ClAstcImageOption *imageIn,
|
||||
imageIn->width = width;
|
||||
imageIn->height = height;
|
||||
if (AstcClEncImageCheckImageOption(imageIn)) {
|
||||
HiLog::Error(LABEL, "astc AstcClEncImageCheckImageOption failed!");
|
||||
IMAGE_LOGE("astc AstcClEncImageCheckImageOption failed!");
|
||||
return CL_ASTC_ENC_FAILED;
|
||||
}
|
||||
return CL_ASTC_ENC_SUCCESS;
|
||||
@ -1538,21 +1540,21 @@ static void ReleaseClAstcObj(ClAstcObjEnc *obj)
|
||||
if (obj->inputImage != nullptr) {
|
||||
clRet = clReleaseMemObject(obj->inputImage);
|
||||
if (clRet != CL_SUCCESS) {
|
||||
HiLog::Error(LABEL, "astc inputImage release failed ret %{public}d!", clRet);
|
||||
IMAGE_LOGE("astc inputImage release failed ret %{public}d!", clRet);
|
||||
}
|
||||
obj->inputImage = nullptr;
|
||||
}
|
||||
if (obj->astcResult != nullptr) {
|
||||
clRet = clReleaseMemObject(obj->astcResult);
|
||||
if (clRet != CL_SUCCESS) {
|
||||
HiLog::Error(LABEL, "astc astcResult release failed ret %{public}d!", clRet);
|
||||
IMAGE_LOGE("astc astcResult release failed ret %{public}d!", clRet);
|
||||
}
|
||||
obj->astcResult = nullptr;
|
||||
}
|
||||
if (obj->errBuffer != nullptr) {
|
||||
clRet = clReleaseMemObject(obj->errBuffer);
|
||||
if (clRet != CL_SUCCESS) {
|
||||
HiLog::Error(LABEL, "astc errBuffer release failed ret %{public}d!", clRet);
|
||||
IMAGE_LOGE("astc errBuffer release failed ret %{public}d!", clRet);
|
||||
}
|
||||
obj->errBuffer = nullptr;
|
||||
}
|
||||
@ -1580,7 +1582,7 @@ static CL_ASTC_STATUS ClCreateBufferAndImage(const ClAstcImageOption *imageIn,
|
||||
size_t blockErrBytes = sizeof(uint32_t) * numBlocks;
|
||||
encObj->astcSize = numBlocks * TEXTURE_BLOCK_BYTES;
|
||||
if ((blockErrs == nullptr) || (memset_s(blockErrs, blockErrBytes, 0, blockErrBytes))) {
|
||||
HiLog::Error(LABEL, "astc blockErrs is nullptr or memset failed!");
|
||||
IMAGE_LOGE("astc blockErrs is nullptr or memset failed!");
|
||||
return CL_ASTC_ENC_FAILED;
|
||||
}
|
||||
cl_image_format imageFormat = { CL_RGBA, CL_UNORM_INT8 };
|
||||
@ -1589,18 +1591,18 @@ static CL_ASTC_STATUS ClCreateBufferAndImage(const ClAstcImageOption *imageIn,
|
||||
encObj->inputImage = clCreateImage(clAstcHandle->context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, &imageFormat,
|
||||
&desc, data, &clRet);
|
||||
if (clRet != CL_SUCCESS) {
|
||||
HiLog::Error(LABEL, "astc clCreateImage failed ret %{public}d!", clRet);
|
||||
IMAGE_LOGE("astc clCreateImage failed ret %{public}d!", clRet);
|
||||
return CL_ASTC_ENC_FAILED;
|
||||
}
|
||||
encObj->astcResult = clCreateBuffer(clAstcHandle->context,
|
||||
CL_MEM_ALLOC_HOST_PTR, encObj->astcSize, NULL, &clRet);
|
||||
if (clRet != CL_SUCCESS) {
|
||||
HiLog::Error(LABEL, "astc clCreateBuffer astcResult failed ret %{public}d!", clRet);
|
||||
IMAGE_LOGE("astc clCreateBuffer astcResult failed ret %{public}d!", clRet);
|
||||
return CL_ASTC_ENC_FAILED;
|
||||
}
|
||||
encObj->errBuffer = clCreateBuffer(clAstcHandle->context, CL_MEM_USE_HOST_PTR, blockErrBytes, blockErrs, &clRet);
|
||||
if (clRet != CL_SUCCESS) {
|
||||
HiLog::Error(LABEL, "astc clCreateBuffer errBuffer failed ret %{public}d!", clRet);
|
||||
IMAGE_LOGE("astc clCreateBuffer errBuffer failed ret %{public}d!", clRet);
|
||||
return CL_ASTC_ENC_FAILED;
|
||||
}
|
||||
return CL_ASTC_ENC_SUCCESS;
|
||||
@ -1611,27 +1613,27 @@ static CL_ASTC_STATUS ClKernelArgSet(ClAstcHandle *clAstcHandle, ClAstcObjEnc *e
|
||||
int32_t kernelId = 0;
|
||||
cl_int clRet = clSetKernelArg(clAstcHandle->kernel, kernelId++, sizeof(cl_mem), &encObj->inputImage);
|
||||
if (clRet != CL_SUCCESS) {
|
||||
HiLog::Error(LABEL, "astc clSetKernelArg inputImage failed ret %{public}d!", clRet);
|
||||
IMAGE_LOGE("astc clSetKernelArg inputImage failed ret %{public}d!", clRet);
|
||||
return CL_ASTC_ENC_FAILED;
|
||||
}
|
||||
clRet = clSetKernelArg(clAstcHandle->kernel, kernelId++, sizeof(cl_mem), &encObj->astcResult);
|
||||
if (clRet != CL_SUCCESS) {
|
||||
HiLog::Error(LABEL, "astc clSetKernelArg astcResult failed ret %{public}d!", clRet);
|
||||
IMAGE_LOGE("astc clSetKernelArg astcResult failed ret %{public}d!", clRet);
|
||||
return CL_ASTC_ENC_FAILED;
|
||||
}
|
||||
clRet = clSetKernelArg(clAstcHandle->kernel, kernelId++, sizeof(cl_mem), &encObj->errBuffer);
|
||||
if (clRet != CL_SUCCESS) {
|
||||
HiLog::Error(LABEL, "astc clSetKernelArg errBuffer failed ret %{public}d!", clRet);
|
||||
IMAGE_LOGE("astc clSetKernelArg errBuffer failed ret %{public}d!", clRet);
|
||||
return CL_ASTC_ENC_FAILED;
|
||||
}
|
||||
clRet = clSetKernelArg(clAstcHandle->kernel, kernelId++, sizeof(int), &width);
|
||||
if (clRet != CL_SUCCESS) {
|
||||
HiLog::Error(LABEL, "astc clSetKernelArg width failed ret %{public}d!", clRet);
|
||||
IMAGE_LOGE("astc clSetKernelArg width failed ret %{public}d!", clRet);
|
||||
return CL_ASTC_ENC_FAILED;
|
||||
}
|
||||
clRet = clSetKernelArg(clAstcHandle->kernel, kernelId++, sizeof(int), &height);
|
||||
if (clRet != CL_SUCCESS) {
|
||||
HiLog::Error(LABEL, "astc clSetKernelArg height failed ret %{public}d!", clRet);
|
||||
IMAGE_LOGE("astc clSetKernelArg height failed ret %{public}d!", clRet);
|
||||
return CL_ASTC_ENC_FAILED;
|
||||
}
|
||||
return CL_ASTC_ENC_SUCCESS;
|
||||
@ -1640,7 +1642,7 @@ static CL_ASTC_STATUS ClKernelArgSet(ClAstcHandle *clAstcHandle, ClAstcObjEnc *e
|
||||
static CL_ASTC_STATUS ClKernelArgSetAndRun(ClAstcHandle *clAstcHandle, ClAstcObjEnc *encObj, int width, int height)
|
||||
{
|
||||
if (ClKernelArgSet(clAstcHandle, encObj, width, height) != CL_ASTC_ENC_SUCCESS) {
|
||||
HiLog::Error(LABEL, "astc ClKernelArgSet failed!");
|
||||
IMAGE_LOGE("astc ClKernelArgSet failed!");
|
||||
return CL_ASTC_ENC_FAILED;
|
||||
}
|
||||
size_t local[] = {WORK_GROUP_SIZE, WORK_GROUP_SIZE};
|
||||
@ -1651,7 +1653,7 @@ static CL_ASTC_STATUS ClKernelArgSetAndRun(ClAstcHandle *clAstcHandle, ClAstcObj
|
||||
cl_int clRet = clGetKernelWorkGroupInfo(clAstcHandle->kernel, clAstcHandle->deviceID, CL_KERNEL_WORK_GROUP_SIZE,
|
||||
sizeof(size_t), &localMax, nullptr);
|
||||
if ((clRet != CL_SUCCESS) || localMax <= 0) {
|
||||
HiLog::Error(LABEL, "astc clGetKernelWorkGroupInfo failed ret %{public}d!", clRet);
|
||||
IMAGE_LOGE("astc clGetKernelWorkGroupInfo failed ret %{public}d!", clRet);
|
||||
return CL_ASTC_ENC_FAILED;
|
||||
}
|
||||
while (local[0] * local[1] > localMax) {
|
||||
@ -1659,18 +1661,18 @@ static CL_ASTC_STATUS ClKernelArgSetAndRun(ClAstcHandle *clAstcHandle, ClAstcObj
|
||||
local[1]--;
|
||||
}
|
||||
if ((local[0] < 1) || (local[1] < 1)) {
|
||||
HiLog::Error(LABEL, "astc ClKernelArgSetAndRun local set failed!");
|
||||
IMAGE_LOGE("astc ClKernelArgSetAndRun local set failed!");
|
||||
return CL_ASTC_ENC_FAILED;
|
||||
}
|
||||
clRet = clEnqueueNDRangeKernel(clAstcHandle->queue, clAstcHandle->kernel, GLOBAL_WH_NUM_CL, nullptr, global, local,
|
||||
0, nullptr, nullptr);
|
||||
if (clRet != CL_SUCCESS) {
|
||||
HiLog::Error(LABEL, "astc clEnqueueNDRangeKernel failed ret %{public}d!", clRet);
|
||||
IMAGE_LOGE("astc clEnqueueNDRangeKernel failed ret %{public}d!", clRet);
|
||||
return CL_ASTC_ENC_FAILED;
|
||||
}
|
||||
clRet = clFinish(clAstcHandle->queue);
|
||||
if (clRet != CL_SUCCESS) {
|
||||
HiLog::Error(LABEL, "astc clFinish failed ret %{public}d!", clRet);
|
||||
IMAGE_LOGE("astc clFinish failed ret %{public}d!", clRet);
|
||||
return CL_ASTC_ENC_FAILED;
|
||||
}
|
||||
return CL_ASTC_ENC_SUCCESS;
|
||||
@ -1682,7 +1684,7 @@ static CL_ASTC_STATUS ClReadAstcBufAndBlockError(ClAstcHandle *clAstcHandle, ClA
|
||||
cl_int clRet = clEnqueueReadBuffer(clAstcHandle->queue, encObj->astcResult, CL_TRUE,
|
||||
0, encObj->astcSize, buffer + TEXTURE_HEAD_BYTES, 0, NULL, NULL);
|
||||
if (clRet != CL_SUCCESS) {
|
||||
HiLog::Error(LABEL, "astc clEnqueueReadBuffer astcResult failed ret %{public}d!", clRet);
|
||||
IMAGE_LOGE("astc clEnqueueReadBuffer astcResult failed ret %{public}d!", clRet);
|
||||
return CL_ASTC_ENC_FAILED;
|
||||
}
|
||||
uint32_t maxVal = 0;
|
||||
@ -1691,7 +1693,7 @@ static CL_ASTC_STATUS ClReadAstcBufAndBlockError(ClAstcHandle *clAstcHandle, ClA
|
||||
clRet = clEnqueueReadBuffer(clAstcHandle->queue, encObj->errBuffer, CL_TRUE,
|
||||
0, sizeof(uint32_t) * numBlocks, encObj->blockErrs_, 0, NULL, NULL);
|
||||
if (clRet != CL_SUCCESS) {
|
||||
HiLog::Error(LABEL, "astc clEnqueueReadBuffer blockErrs failed ret %{public}d!", clRet);
|
||||
IMAGE_LOGE("astc clEnqueueReadBuffer blockErrs failed ret %{public}d!", clRet);
|
||||
return CL_ASTC_ENC_FAILED;
|
||||
}
|
||||
GetMaxAndSumVal(numBlocks, encObj->blockErrs_, maxVal, sumVal);
|
||||
@ -1702,28 +1704,28 @@ CL_ASTC_SHARE_LIB_API CL_ASTC_STATUS AstcClEncImage(ClAstcHandle *clAstcHandle,
|
||||
const ClAstcImageOption *imageIn, uint8_t *buffer)
|
||||
{
|
||||
if ((clAstcHandle == nullptr) || (imageIn == nullptr) || (buffer == nullptr)) {
|
||||
HiLog::Error(LABEL, "astc AstcClEncImage clAstcHandle or imageIn or buffer is nullptr!");
|
||||
IMAGE_LOGE("astc AstcClEncImage clAstcHandle or imageIn or buffer is nullptr!");
|
||||
return CL_ASTC_ENC_FAILED;
|
||||
}
|
||||
if (AstcClEncImageCheckImageOption(imageIn)) {
|
||||
HiLog::Error(LABEL, "astc AstcClEncImageCheckImageOption failed!");
|
||||
IMAGE_LOGE("astc AstcClEncImageCheckImageOption failed!");
|
||||
return CL_ASTC_ENC_FAILED;
|
||||
}
|
||||
GenAstcHeader(buffer, DIM, DIM, imageIn->width, imageIn->height);
|
||||
ClAstcObjEnc *encObj = &clAstcHandle->encObj;
|
||||
if (ClCreateBufferAndImage(imageIn, clAstcHandle, encObj) != CL_ASTC_ENC_SUCCESS) {
|
||||
ReleaseClAstcObj(encObj);
|
||||
HiLog::Error(LABEL, "astc ClCreateBufferAndImage failed!");
|
||||
IMAGE_LOGE("astc ClCreateBufferAndImage failed!");
|
||||
return CL_ASTC_ENC_FAILED;
|
||||
}
|
||||
if (ClKernelArgSetAndRun(clAstcHandle, encObj, imageIn->width, imageIn->height) != CL_ASTC_ENC_SUCCESS) {
|
||||
ReleaseClAstcObj(encObj);
|
||||
HiLog::Error(LABEL, "astc ClKernelArgSetAndRun failed!");
|
||||
IMAGE_LOGE("astc ClKernelArgSetAndRun failed!");
|
||||
return CL_ASTC_ENC_FAILED;
|
||||
}
|
||||
if (ClReadAstcBufAndBlockError(clAstcHandle, encObj, imageIn, buffer) != CL_ASTC_ENC_SUCCESS) {
|
||||
ReleaseClAstcObj(encObj);
|
||||
HiLog::Error(LABEL, "astc ClReadAstcBufAndBlockError failed!");
|
||||
IMAGE_LOGE("astc ClReadAstcBufAndBlockError failed!");
|
||||
return CL_ASTC_ENC_FAILED;
|
||||
}
|
||||
ReleaseClAstcObj(encObj);
|
||||
|
@ -21,8 +21,6 @@
|
||||
#include <string>
|
||||
#include "abs_image_decoder.h"
|
||||
#include "gif_lib.h"
|
||||
#include "hilog/log.h"
|
||||
#include "log_tags.h"
|
||||
#include "media_errors.h"
|
||||
#include "nocopyable.h"
|
||||
#include "plugin_class_base.h"
|
||||
|
@ -15,17 +15,22 @@
|
||||
|
||||
#include "gif_decoder.h"
|
||||
|
||||
#include "image_log.h"
|
||||
#include "image_utils.h"
|
||||
#if !defined(IOS_PLATFORM) && !defined(A_PLATFORM)
|
||||
#include "surface_buffer.h"
|
||||
#endif
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_PLUGIN
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "GifDecoder"
|
||||
|
||||
namespace OHOS {
|
||||
namespace ImagePlugin {
|
||||
using namespace OHOS::HiviewDFX;
|
||||
using namespace MultimediaPlugin;
|
||||
using namespace Media;
|
||||
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_PLUGIN, "GifDecoder" };
|
||||
|
||||
namespace {
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
@ -73,28 +78,28 @@ void GifDecoder::SetSource(InputDataStream &sourceStream)
|
||||
uint32_t GifDecoder::GetTopLevelImageNum(uint32_t &num)
|
||||
{
|
||||
if (inputStreamPtr_ == nullptr) {
|
||||
HiLog::Error(LABEL, "[GetTopLevelImageNum]set source need firstly");
|
||||
IMAGE_LOGE("[GetTopLevelImageNum]set source need firstly");
|
||||
return ERR_IMAGE_DATA_ABNORMAL;
|
||||
}
|
||||
if (!inputStreamPtr_->IsStreamCompleted()) {
|
||||
HiLog::Warn(LABEL, "[GetTopLevelImageNum]don't enough data to decode the frame number");
|
||||
IMAGE_LOGW("[GetTopLevelImageNum]don't enough data to decode the frame number");
|
||||
return ERR_IMAGE_SOURCE_DATA_INCOMPLETE;
|
||||
}
|
||||
uint32_t errorCode = CreateGifFileTypeIfNotExist();
|
||||
if (errorCode != SUCCESS) {
|
||||
HiLog::Error(LABEL, "[GetTopLevelImageNum]create GifFileType pointer failed %{public}u", errorCode);
|
||||
IMAGE_LOGE("[GetTopLevelImageNum]create GifFileType pointer failed %{public}u", errorCode);
|
||||
return ERR_IMAGE_DECODE_ABNORMAL;
|
||||
}
|
||||
if (!isLoadAllFrame_) {
|
||||
errorCode = UpdateGifFileType(INT_MAX);
|
||||
if (errorCode != SUCCESS) {
|
||||
HiLog::Error(LABEL, "[GetTopLevelImageNum]update GifFileType pointer failed %{public}u", errorCode);
|
||||
IMAGE_LOGE("[GetTopLevelImageNum]update GifFileType pointer failed %{public}u", errorCode);
|
||||
return ERR_IMAGE_DECODE_ABNORMAL;
|
||||
}
|
||||
}
|
||||
num = gifPtr_->ImageCount;
|
||||
if (num <= 0) {
|
||||
HiLog::Error(LABEL, "[GetTopLevelImageNum]image frame number must be larger than 0");
|
||||
IMAGE_LOGE("[GetTopLevelImageNum]image frame number must be larger than 0");
|
||||
return ERR_IMAGE_DATA_ABNORMAL;
|
||||
}
|
||||
return SUCCESS;
|
||||
@ -105,13 +110,13 @@ uint32_t GifDecoder::GetImageSize(uint32_t index, PlSize &size)
|
||||
{
|
||||
uint32_t errorCode = CheckIndex(index);
|
||||
if (errorCode != SUCCESS) {
|
||||
HiLog::Error(LABEL, "[GetImageSize]index %{public}u is invalid %{public}u", index, errorCode);
|
||||
IMAGE_LOGE("[GetImageSize]index %{public}u is invalid %{public}u", index, errorCode);
|
||||
return errorCode;
|
||||
}
|
||||
const int32_t bgWidth = gifPtr_->SWidth;
|
||||
const int32_t bgHeight = gifPtr_->SHeight;
|
||||
if (bgWidth <= 0 || bgHeight <= 0) {
|
||||
HiLog::Error(LABEL, "[GetImageSize]background size [%{public}d, %{public}d] is invalid", bgWidth, bgHeight);
|
||||
IMAGE_LOGE("[GetImageSize]background size [%{public}d, %{public}d] is invalid", bgWidth, bgHeight);
|
||||
return ERR_IMAGE_INVALID_PARAMETER;
|
||||
}
|
||||
size.width = bgWidth;
|
||||
@ -123,7 +128,7 @@ uint32_t GifDecoder::SetDecodeOptions(uint32_t index, const PixelDecodeOptions &
|
||||
{
|
||||
uint32_t errorCode = GetImageSize(index, info.size);
|
||||
if (errorCode != SUCCESS) {
|
||||
HiLog::Error(LABEL, "[SetDecodeOptions]get image size failed %{public}u", errorCode);
|
||||
IMAGE_LOGE("[SetDecodeOptions]get image size failed %{public}u", errorCode);
|
||||
return errorCode;
|
||||
}
|
||||
info.alphaType = PlAlphaType::IMAGE_ALPHA_TYPE_OPAQUE;
|
||||
@ -140,7 +145,7 @@ uint32_t GifDecoder::Decode(uint32_t index, DecodeContext &context)
|
||||
PlSize imageSize;
|
||||
uint32_t errorCode = GetImageSize(index, imageSize);
|
||||
if (errorCode != SUCCESS) {
|
||||
HiLog::Error(LABEL, "[Decode]index %{public}u is invalid %{public}u", index, errorCode);
|
||||
IMAGE_LOGE("[Decode]index %{public}u is invalid %{public}u", index, errorCode);
|
||||
return errorCode;
|
||||
}
|
||||
// compute start index and end index.
|
||||
@ -158,20 +163,20 @@ uint32_t GifDecoder::Decode(uint32_t index, DecodeContext &context)
|
||||
startIndex = 0;
|
||||
isOverlapped = false;
|
||||
}
|
||||
HiLog::Debug(LABEL, "[Decode]start frame: %{public}u, last frame: %{public}u,"
|
||||
"last pixelMapIndex: %{public}d, isOverlapped: %{public}d",
|
||||
startIndex, endIndex, lastPixelMapIndex_, isOverlapped);
|
||||
IMAGE_LOGD("[Decode]start frame: %{public}u, last frame: %{public}u,"
|
||||
"last pixelMapIndex: %{public}d, isOverlapped: %{public}d",
|
||||
startIndex, endIndex, lastPixelMapIndex_, isOverlapped);
|
||||
|
||||
if (!isOverlapped) {
|
||||
errorCode = OverlapFrame(startIndex, endIndex);
|
||||
if (errorCode != SUCCESS) {
|
||||
HiLog::Error(LABEL, "[Decode]overlap frame failed %{public}u", errorCode);
|
||||
IMAGE_LOGE("[Decode]overlap frame failed %{public}u", errorCode);
|
||||
return errorCode;
|
||||
}
|
||||
}
|
||||
errorCode = RedirectOutputBuffer(context);
|
||||
if (errorCode != SUCCESS) {
|
||||
HiLog::Error(LABEL, "[Decode]redirect output stream failed %{public}u", errorCode);
|
||||
IMAGE_LOGE("[Decode]redirect output stream failed %{public}u", errorCode);
|
||||
return errorCode;
|
||||
}
|
||||
return SUCCESS;
|
||||
@ -204,13 +209,13 @@ uint32_t GifDecoder::CreateGifFileTypeIfNotExist()
|
||||
if (gifPtr_ == nullptr) {
|
||||
int32_t errorCode = Media::ERROR;
|
||||
if (inputStreamPtr_ == nullptr) {
|
||||
HiLog::Error(LABEL, "[CreateGifFileTypeIfNotExist]set source need firstly");
|
||||
IMAGE_LOGE("[CreateGifFileTypeIfNotExist]set source need firstly");
|
||||
return ERR_IMAGE_GET_DATA_ABNORMAL;
|
||||
}
|
||||
// DGifOpen will create GifFileType pointer and set header and screen desc
|
||||
gifPtr_ = DGifOpen(inputStreamPtr_, InputStreamReader, &errorCode);
|
||||
if (gifPtr_ == nullptr) {
|
||||
HiLog::Error(LABEL, "[CreateGifFileTypeIfNotExist]open image error, %{public}d", errorCode);
|
||||
IMAGE_LOGE("[CreateGifFileTypeIfNotExist]open image error, %{public}d", errorCode);
|
||||
inputStreamPtr_->Seek(0);
|
||||
savedFrameIndex_ = -1;
|
||||
return ERR_IMAGE_SOURCE_DATA;
|
||||
@ -224,20 +229,20 @@ int32_t GifDecoder::InputStreamReader(GifFileType *gif, GifByteType *bytes, int3
|
||||
{
|
||||
uint32_t dataSize = 0;
|
||||
if (gif == nullptr) {
|
||||
HiLog::Error(LABEL, "[InputStreamReader]GifFileType pointer is null");
|
||||
IMAGE_LOGE("[InputStreamReader]GifFileType pointer is null");
|
||||
return dataSize;
|
||||
}
|
||||
InputDataStream *inputStream = static_cast<InputDataStream *>(gif->UserData);
|
||||
if (inputStream == nullptr) {
|
||||
HiLog::Error(LABEL, "[InputStreamReader]set source need firstly");
|
||||
IMAGE_LOGE("[InputStreamReader]set source need firstly");
|
||||
return dataSize;
|
||||
}
|
||||
if (size <= 0) {
|
||||
HiLog::Error(LABEL, "[InputStreamReader]callback size %{public}d is invalid", size);
|
||||
IMAGE_LOGE("[InputStreamReader]callback size %{public}d is invalid", size);
|
||||
return dataSize;
|
||||
}
|
||||
if (bytes == nullptr) {
|
||||
HiLog::Error(LABEL, "[InputStreamReader]callback buffer is null");
|
||||
IMAGE_LOGE("[InputStreamReader]callback buffer is null");
|
||||
return dataSize;
|
||||
}
|
||||
inputStream->Read(size, bytes, size, dataSize);
|
||||
@ -247,25 +252,25 @@ int32_t GifDecoder::InputStreamReader(GifFileType *gif, GifByteType *bytes, int3
|
||||
uint32_t GifDecoder::CheckIndex(uint32_t index)
|
||||
{
|
||||
if (!inputStreamPtr_->IsStreamCompleted()) {
|
||||
HiLog::Warn(LABEL, "[CheckIndex]don't enough data to decode the frame number");
|
||||
IMAGE_LOGW("[CheckIndex]don't enough data to decode the frame number");
|
||||
return ERR_IMAGE_SOURCE_DATA_INCOMPLETE;
|
||||
}
|
||||
uint32_t errorCode = CreateGifFileTypeIfNotExist();
|
||||
if (errorCode != SUCCESS) {
|
||||
HiLog::Error(LABEL, "[CheckIndex]create GifFileType failed %{public}u", errorCode);
|
||||
IMAGE_LOGE("[CheckIndex]create GifFileType failed %{public}u", errorCode);
|
||||
return errorCode;
|
||||
}
|
||||
int32_t updateFrameIndex = static_cast<int32_t>(index);
|
||||
if (!isLoadAllFrame_ && updateFrameIndex > savedFrameIndex_) {
|
||||
errorCode = UpdateGifFileType(updateFrameIndex);
|
||||
if (errorCode != SUCCESS) {
|
||||
HiLog::Error(LABEL, "[CheckIndex]update saved frame to index %{public}u failed", index);
|
||||
IMAGE_LOGE("[CheckIndex]update saved frame to index %{public}u failed", index);
|
||||
return errorCode;
|
||||
}
|
||||
}
|
||||
uint32_t frameNum = gifPtr_->ImageCount;
|
||||
if (index >= frameNum) {
|
||||
HiLog::Error(LABEL, "[CheckIndex]index %{public}u out of frame range %{public}u", index, frameNum);
|
||||
IMAGE_LOGE("[CheckIndex]index %{public}u out of frame range %{public}u", index, frameNum);
|
||||
return ERR_IMAGE_INVALID_PARAMETER;
|
||||
}
|
||||
return SUCCESS;
|
||||
@ -276,35 +281,33 @@ uint32_t GifDecoder::OverlapFrame(uint32_t startIndex, uint32_t endIndex)
|
||||
for (uint32_t frameIndex = startIndex; frameIndex <= endIndex; frameIndex++) {
|
||||
const SavedImage *savedImage = gifPtr_->SavedImages + frameIndex;
|
||||
if (savedImage == nullptr) {
|
||||
HiLog::Error(LABEL, "[OverlapFrame]image frame %{public}u data is invalid", frameIndex);
|
||||
IMAGE_LOGE("[OverlapFrame]image frame %{public}u data is invalid", frameIndex);
|
||||
return ERR_IMAGE_DECODE_ABNORMAL;
|
||||
}
|
||||
// acquire the frame graphices control information
|
||||
int32_t transColor = NO_TRANSPARENT_COLOR;
|
||||
int32_t disposalMode = DISPOSAL_UNSPECIFIED;
|
||||
GetTransparentAndDisposal(frameIndex, transColor, disposalMode);
|
||||
HiLog::Debug(LABEL,
|
||||
"[OverlapFrame]frameIndex = %{public}u, transColor = %{public}d, "
|
||||
"disposalMode = %{public}d",
|
||||
frameIndex, transColor, disposalMode);
|
||||
IMAGE_LOGD("[OverlapFrame]frameIndex = %{public}u, transColor = %{public}d, "
|
||||
"disposalMode = %{public}d", frameIndex, transColor, disposalMode);
|
||||
|
||||
if (frameIndex == 0 && AllocateLocalPixelMapBuffer() != SUCCESS) {
|
||||
HiLog::Error(LABEL, "[OverlapFrame]first frame allocate local pixelmap buffer failed");
|
||||
IMAGE_LOGE("[OverlapFrame]first frame allocate local pixelmap buffer failed");
|
||||
return ERR_IMAGE_DECODE_ABNORMAL;
|
||||
}
|
||||
if (localPixelMapBuffer_ == nullptr) {
|
||||
HiLog::Error(LABEL, "[OverlapFrame]local pixelmap is null, next frame can't overlap");
|
||||
IMAGE_LOGE("[OverlapFrame]local pixelmap is null, next frame can't overlap");
|
||||
return ERR_IMAGE_DECODE_ABNORMAL;
|
||||
}
|
||||
// current frame recover background
|
||||
if (frameIndex != 0 && disposalMode == DISPOSE_BACKGROUND &&
|
||||
DisposeBackground(frameIndex, savedImage) != SUCCESS) {
|
||||
HiLog::Error(LABEL, "[OverlapFrame]dispose frame %{public}d background failed", frameIndex);
|
||||
IMAGE_LOGE("[OverlapFrame]dispose frame %{public}d background failed", frameIndex);
|
||||
return ERR_IMAGE_DECODE_ABNORMAL;
|
||||
}
|
||||
if (disposalMode != DISPOSE_PREVIOUS &&
|
||||
PaddingData(savedImage, transColor) != SUCCESS) {
|
||||
HiLog::Error(LABEL, "[OverlapFrame]dispose frame %{public}u data color failed", frameIndex);
|
||||
IMAGE_LOGE("[OverlapFrame]dispose frame %{public}u data color failed", frameIndex);
|
||||
return ERR_IMAGE_DECODE_ABNORMAL;
|
||||
}
|
||||
}
|
||||
@ -322,7 +325,7 @@ uint32_t GifDecoder::DisposeBackground(uint32_t frameIndex, const SavedImage *cu
|
||||
return SUCCESS;
|
||||
}
|
||||
if (PaddingBgColor(curSavedImage) != SUCCESS) {
|
||||
HiLog::Error(LABEL, "[DisposeBackground]padding frame %{public}u background color failed", frameIndex);
|
||||
IMAGE_LOGE("[DisposeBackground]padding frame %{public}u background color failed", frameIndex);
|
||||
return ERR_IMAGE_DECODE_ABNORMAL;
|
||||
}
|
||||
return SUCCESS;
|
||||
@ -346,25 +349,25 @@ uint32_t GifDecoder::AllocateLocalPixelMapBuffer()
|
||||
uint64_t pixelMapBufferSize = static_cast<uint64_t>(bgWidth * bgHeight * sizeof(uint32_t));
|
||||
// create local pixelmap buffer, next frame depends on the previous
|
||||
if (pixelMapBufferSize > PIXEL_MAP_MAX_RAM_SIZE) {
|
||||
HiLog::Error(LABEL, "[AllocateLocalPixelMapBuffer]pixelmap buffer size %{public}llu out of max size",
|
||||
static_cast<unsigned long long>(pixelMapBufferSize));
|
||||
IMAGE_LOGE("[AllocateLocalPixelMapBuffer]pixelmap buffer size %{public}llu out of max size",
|
||||
static_cast<unsigned long long>(pixelMapBufferSize));
|
||||
return ERR_IMAGE_TOO_LARGE;
|
||||
}
|
||||
localPixelMapBuffer_ = reinterpret_cast<uint32_t *>(malloc(pixelMapBufferSize));
|
||||
if (localPixelMapBuffer_ == nullptr) {
|
||||
HiLog::Error(LABEL, "[AllocateLocalPixelMapBuffer]allocate local pixelmap buffer memory error");
|
||||
IMAGE_LOGE("[AllocateLocalPixelMapBuffer]allocate local pixelmap buffer memory error");
|
||||
return ERR_IMAGE_MALLOC_ABNORMAL;
|
||||
}
|
||||
#ifdef _WIN32
|
||||
errno_t backRet = memset_s(localPixelMapBuffer_, bgColor_, pixelMapBufferSize);
|
||||
if (backRet != EOK) {
|
||||
HiLog::Error(LABEL, "[DisposeFirstPixelMap]memset local pixelmap buffer background failed", backRet);
|
||||
IMAGE_LOGE("[DisposeFirstPixelMap]memset local pixelmap buffer background failed", backRet);
|
||||
FreeLocalPixelMapBuffer();
|
||||
return ERR_IMAGE_MALLOC_ABNORMAL;
|
||||
}
|
||||
#else
|
||||
if (memset_s(localPixelMapBuffer_, pixelMapBufferSize, bgColor_, pixelMapBufferSize) != EOK) {
|
||||
HiLog::Error(LABEL, "[DisposeFirstPixelMap]memset local pixelmap buffer background failed");
|
||||
IMAGE_LOGE("[DisposeFirstPixelMap]memset local pixelmap buffer background failed");
|
||||
FreeLocalPixelMapBuffer();
|
||||
return ERR_IMAGE_MALLOC_ABNORMAL;
|
||||
}
|
||||
@ -396,10 +399,10 @@ uint32_t GifDecoder::PaddingBgColor(const SavedImage *savedImage)
|
||||
frameHeight = bgHeight - frameTop;
|
||||
}
|
||||
if (frameWidth < 0 || frameHeight < 0) {
|
||||
HiLog::Error(LABEL, "[PaddingBgColor]frameWidth || frameHeight is abnormal,"
|
||||
"bgWidth:%{public}d, bgHeight:%{public}d, "
|
||||
"frameTop:%{public}d, frameLeft:%{public}d",
|
||||
bgWidth, bgHeight, frameTop, frameLeft);
|
||||
IMAGE_LOGE("[PaddingBgColor]frameWidth || frameHeight is abnormal,"
|
||||
"bgWidth:%{public}d, bgHeight:%{public}d, "
|
||||
"frameTop:%{public}d, frameLeft:%{public}d",
|
||||
bgWidth, bgHeight, frameTop, frameLeft);
|
||||
return ERR_IMAGE_DECODE_ABNORMAL;
|
||||
}
|
||||
uint32_t *dstPixelMapBuffer = localPixelMapBuffer_ + frameTop * bgWidth + frameLeft;
|
||||
@ -408,12 +411,12 @@ uint32_t GifDecoder::PaddingBgColor(const SavedImage *savedImage)
|
||||
#ifdef _WIN32
|
||||
errno_t backRet = memset_s(dstPixelMapBuffer, bgColor_, lineBufferSize);
|
||||
if (backRet != EOK) {
|
||||
HiLog::Error(LABEL, "[PaddingBgColor]memset local pixelmap buffer failed", backRet);
|
||||
IMAGE_LOGE("[PaddingBgColor]memset local pixelmap buffer failed", backRet);
|
||||
return ERR_IMAGE_MALLOC_ABNORMAL;
|
||||
}
|
||||
#else
|
||||
if (memset_s(dstPixelMapBuffer, lineBufferSize, bgColor_, lineBufferSize) != EOK) {
|
||||
HiLog::Error(LABEL, "[PaddingBgColor]memset local pixelmap buffer failed");
|
||||
IMAGE_LOGE("[PaddingBgColor]memset local pixelmap buffer failed");
|
||||
return ERR_IMAGE_MALLOC_ABNORMAL;
|
||||
}
|
||||
#endif
|
||||
@ -429,14 +432,14 @@ uint32_t GifDecoder::PaddingData(const SavedImage *savedImage, int32_t transpare
|
||||
colorMap = savedImage->ImageDesc.ColorMap; // local color map
|
||||
}
|
||||
if (colorMap == nullptr) {
|
||||
HiLog::Error(LABEL, "[PaddingData]color map is null");
|
||||
IMAGE_LOGE("[PaddingData]color map is null");
|
||||
return ERR_IMAGE_DECODE_ABNORMAL;
|
||||
}
|
||||
int32_t colorCount = colorMap->ColorCount;
|
||||
int32_t bitsPerPixel = colorMap->BitsPerPixel;
|
||||
if ((bitsPerPixel < 0) || (colorCount != (1 << static_cast<uint32_t>(bitsPerPixel)))) {
|
||||
HiLog::Error(LABEL, "[PaddingData]colormap is invalid, bitsPerPixel: %{public}d, colorCount: %{public}d",
|
||||
bitsPerPixel, colorCount);
|
||||
IMAGE_LOGE("[PaddingData]colormap is invalid, bitsPerPixel: %{public}d, colorCount: %{public}d",
|
||||
bitsPerPixel, colorCount);
|
||||
return ERR_IMAGE_DECODE_ABNORMAL;
|
||||
}
|
||||
|
||||
@ -496,7 +499,7 @@ void GifDecoder::ParseBgColor()
|
||||
{
|
||||
const int32_t bgColorIndex = gifPtr_->SBackGroundColor;
|
||||
if (bgColorIndex < 0) {
|
||||
HiLog::Warn(LABEL, "[ParseBgColor]bgColor index %{public}d is invalid, use default bgColor", bgColorIndex);
|
||||
IMAGE_LOGW("[ParseBgColor]bgColor index %{public}d is invalid, use default bgColor", bgColorIndex);
|
||||
return;
|
||||
}
|
||||
const ColorMapObject *bgColorMap = gifPtr_->SColorMap;
|
||||
@ -510,18 +513,18 @@ constexpr size_t SIZE_ZERO = 0;
|
||||
|
||||
static uint32_t HeapMemoryCreate(PlImageBuffer &plBuffer)
|
||||
{
|
||||
HiLog::Debug(LABEL, "HeapMemoryCreate IN");
|
||||
IMAGE_LOGD("HeapMemoryCreate IN");
|
||||
if (plBuffer.buffer != nullptr) {
|
||||
HiLog::Debug(LABEL, "HeapMemoryCreate has created");
|
||||
IMAGE_LOGD("HeapMemoryCreate has created");
|
||||
return SUCCESS;
|
||||
}
|
||||
if (plBuffer.bufferSize == 0 || plBuffer.bufferSize > PIXEL_MAP_MAX_RAM_SIZE) {
|
||||
HiLog::Error(LABEL, "HeapMemoryCreate Invalid value of bufferSize");
|
||||
IMAGE_LOGE("HeapMemoryCreate Invalid value of bufferSize");
|
||||
return ERR_IMAGE_DATA_ABNORMAL;
|
||||
}
|
||||
auto dataPtr = static_cast<uint8_t *>(malloc(plBuffer.bufferSize));
|
||||
if (dataPtr == nullptr) {
|
||||
HiLog::Error(LABEL, "alloc buffer error");
|
||||
IMAGE_LOGE("alloc buffer error");
|
||||
return ERR_IMAGE_MALLOC_ABNORMAL;
|
||||
}
|
||||
plBuffer.buffer = dataPtr;
|
||||
@ -531,9 +534,9 @@ static uint32_t HeapMemoryCreate(PlImageBuffer &plBuffer)
|
||||
|
||||
static uint32_t HeapMemoryRelease(PlImageBuffer &plBuffer)
|
||||
{
|
||||
HiLog::Debug(LABEL, "HeapMemoryRelease IN");
|
||||
IMAGE_LOGD("HeapMemoryRelease IN");
|
||||
if (plBuffer.buffer == nullptr) {
|
||||
HiLog::Error(LABEL, "HeapMemory::Release nullptr data");
|
||||
IMAGE_LOGE("HeapMemory::Release nullptr data");
|
||||
return ERR_IMAGE_DATA_ABNORMAL;
|
||||
}
|
||||
free(plBuffer.buffer);
|
||||
@ -544,7 +547,7 @@ static uint32_t HeapMemoryRelease(PlImageBuffer &plBuffer)
|
||||
static uint32_t DmaMemoryCreate(PlImageBuffer &plBuffer, GifFileType *gifPtr)
|
||||
{
|
||||
#if defined(_WIN32) || defined(_APPLE) || defined(A_PLATFORM) || defined(IOS_PLATFORM)
|
||||
HiLog::Error(LABEL, "Unsupport dma mem alloc");
|
||||
IMAGE_LOGE("Unsupport dma mem alloc");
|
||||
return ERR_IMAGE_DATA_UNSUPPORT;
|
||||
#else
|
||||
sptr<SurfaceBuffer> sb = SurfaceBuffer::Create();
|
||||
@ -560,13 +563,13 @@ static uint32_t DmaMemoryCreate(PlImageBuffer &plBuffer, GifFileType *gifPtr)
|
||||
};
|
||||
GSError ret = sb->Alloc(requestConfig);
|
||||
if (ret != GSERROR_OK) {
|
||||
HiLog::Error(LABEL, "SurfaceBuffer Alloc failed, %{public}s", GSErrorStr(ret).c_str());
|
||||
IMAGE_LOGE("SurfaceBuffer Alloc failed, %{public}s", GSErrorStr(ret).c_str());
|
||||
return ERR_DMA_NOT_EXIST;
|
||||
}
|
||||
void* nativeBuffer = sb.GetRefPtr();
|
||||
int32_t err = ImageUtils::SurfaceBuffer_Reference(nativeBuffer);
|
||||
if (err != OHOS::GSERROR_OK) {
|
||||
HiLog::Error(LABEL, "NativeBufferReference failed");
|
||||
IMAGE_LOGE("NativeBufferReference failed");
|
||||
return ERR_DMA_DATA_ABNORMAL;
|
||||
}
|
||||
plBuffer.buffer = static_cast<uint8_t*>(sb->GetVirAddr());
|
||||
@ -579,13 +582,13 @@ static uint32_t DmaMemoryCreate(PlImageBuffer &plBuffer, GifFileType *gifPtr)
|
||||
static uint32_t DmaMemoryRelease(PlImageBuffer &plBuffer)
|
||||
{
|
||||
#if defined(_WIN32) || defined(_APPLE) || defined(A_PLATFORM) || defined(IOS_PLATFORM)
|
||||
HiLog::Error(LABEL, "Unsupport dma mem release");
|
||||
IMAGE_LOGE("Unsupport dma mem release");
|
||||
return ERR_IMAGE_DATA_UNSUPPORT;
|
||||
#else
|
||||
if (plBuffer.context != nullptr) {
|
||||
int32_t err = ImageUtils::SurfaceBuffer_Unreference(static_cast<SurfaceBuffer*>(plBuffer.context));
|
||||
if (err != OHOS::GSERROR_OK) {
|
||||
HiLog::Error(LABEL, "NativeBufferUnReference failed");
|
||||
IMAGE_LOGE("NativeBufferUnReference failed");
|
||||
return ERR_DMA_DATA_ABNORMAL;
|
||||
}
|
||||
plBuffer.buffer = nullptr;
|
||||
@ -608,24 +611,24 @@ static inline void ReleaseSharedMemory(int* fdPtr, uint8_t* ptr = nullptr, size_
|
||||
|
||||
static uint32_t SharedMemoryCreate(PlImageBuffer &plBuffer)
|
||||
{
|
||||
HiLog::Debug(LABEL, "SharedMemoryCreate IN data size %{public}u", plBuffer.bufferSize);
|
||||
IMAGE_LOGD("SharedMemoryCreate IN data size %{public}u", plBuffer.bufferSize);
|
||||
if (plBuffer.bufferSize == SIZE_ZERO) {
|
||||
return ERR_IMAGE_DATA_ABNORMAL;
|
||||
}
|
||||
auto fdPtr = std::make_unique<int>();
|
||||
*fdPtr = AshmemCreate("GIF RawData", plBuffer.bufferSize);
|
||||
if (*fdPtr < 0) {
|
||||
HiLog::Error(LABEL, "SharedMemoryCreate AshmemCreate fd:[%{public}d].", *fdPtr);
|
||||
IMAGE_LOGE("SharedMemoryCreate AshmemCreate fd:[%{public}d].", *fdPtr);
|
||||
return ERR_IMAGE_DATA_ABNORMAL;
|
||||
}
|
||||
if (AshmemSetProt(*fdPtr, PROT_READ | PROT_WRITE) < 0) {
|
||||
HiLog::Error(LABEL, "SharedMemoryCreate AshmemSetProt errno %{public}d.", errno);
|
||||
IMAGE_LOGE("SharedMemoryCreate AshmemSetProt errno %{public}d.", errno);
|
||||
ReleaseSharedMemory(fdPtr.get());
|
||||
return ERR_IMAGE_DATA_ABNORMAL;
|
||||
}
|
||||
plBuffer.buffer = ::mmap(nullptr, plBuffer.bufferSize, PROT_READ | PROT_WRITE, MAP_SHARED, *fdPtr, 0);
|
||||
if (plBuffer.buffer == MAP_FAILED) {
|
||||
HiLog::Error(LABEL, "SharedMemoryCreate mmap failed, errno:%{public}d", errno);
|
||||
IMAGE_LOGE("SharedMemoryCreate mmap failed, errno:%{public}d", errno);
|
||||
ReleaseSharedMemory(fdPtr.get(), static_cast<uint8_t*>(plBuffer.buffer), plBuffer.bufferSize);
|
||||
return ERR_IMAGE_DATA_ABNORMAL;
|
||||
}
|
||||
@ -636,7 +639,7 @@ static uint32_t SharedMemoryCreate(PlImageBuffer &plBuffer)
|
||||
|
||||
static uint32_t SharedMemoryRelease(PlImageBuffer &plBuffer)
|
||||
{
|
||||
HiLog::Debug(LABEL, "SharedMemoryRelease IN");
|
||||
IMAGE_LOGD("SharedMemoryRelease IN");
|
||||
std::unique_ptr<int> fdPtr = std::unique_ptr<int>(static_cast<int*>(plBuffer.context));
|
||||
ReleaseSharedMemory(fdPtr.get(), static_cast<uint8_t*>(plBuffer.buffer), plBuffer.bufferSize);
|
||||
plBuffer.buffer = nullptr;
|
||||
@ -659,7 +662,7 @@ static uint32_t SharedMemoryRelease(PlImageBuffer &plBuffer)
|
||||
static uint32_t AllocMemory(DecodeContext &context, GifFileType *gifPtr)
|
||||
{
|
||||
if (context.pixelsBuffer.buffer != nullptr) {
|
||||
HiLog::Debug(LABEL, "AllocMemory has created");
|
||||
IMAGE_LOGD("AllocMemory has created");
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
@ -677,7 +680,7 @@ static uint32_t AllocMemory(DecodeContext &context, GifFileType *gifPtr)
|
||||
static uint32_t FreeMemory(DecodeContext &context)
|
||||
{
|
||||
if (context.pixelsBuffer.buffer == nullptr) {
|
||||
HiLog::Debug(LABEL, "FreeMemory has freed");
|
||||
IMAGE_LOGD("FreeMemory has freed");
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
@ -694,7 +697,7 @@ static uint32_t FreeMemory(DecodeContext &context)
|
||||
uint32_t GifDecoder::RedirectOutputBuffer(DecodeContext &context)
|
||||
{
|
||||
if (localPixelMapBuffer_ == nullptr) {
|
||||
HiLog::Error(LABEL, "[RedirectOutputBuffer]local pixelmap buffer is null, redirect failed");
|
||||
IMAGE_LOGE("[RedirectOutputBuffer]local pixelmap buffer is null, redirect failed");
|
||||
return ERR_IMAGE_DECODE_ABNORMAL;
|
||||
}
|
||||
int32_t bgWidth = gifPtr_->SWidth;
|
||||
@ -710,7 +713,7 @@ uint32_t GifDecoder::RedirectOutputBuffer(DecodeContext &context)
|
||||
}
|
||||
if (memcpy_s(context.pixelsBuffer.buffer, context.pixelsBuffer.bufferSize,
|
||||
localPixelMapBuffer_, imageBufferSize) != 0) {
|
||||
HiLog::Error(LABEL, "[RedirectOutputBuffer]memory copy size %{public}llu failed",
|
||||
IMAGE_LOGE("[RedirectOutputBuffer]memory copy size %{public}llu failed",
|
||||
static_cast<unsigned long long>(imageBufferSize));
|
||||
FreeMemory(context);
|
||||
return ERR_IMAGE_DECODE_ABNORMAL;
|
||||
@ -722,7 +725,7 @@ uint32_t GifDecoder::GetImageDelayTime(uint32_t index, int32_t &value)
|
||||
{
|
||||
uint32_t errorCode = CheckIndex(index);
|
||||
if (errorCode != SUCCESS) {
|
||||
HiLog::Error(LABEL, "[GetImageDelayTime]index %{public}u is invalid", index);
|
||||
IMAGE_LOGE("[GetImageDelayTime]index %{public}u is invalid", index);
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
@ -754,10 +757,10 @@ uint32_t GifDecoder::GetImageLoopCount(uint32_t index, int32_t &value)
|
||||
|
||||
uint32_t GifDecoder::GetImagePropertyInt(uint32_t index, const std::string &key, int32_t &value)
|
||||
{
|
||||
HiLog::Debug(LABEL, "[GetImagePropertyInt] enter gif plugin, key:%{public}s", key.c_str());
|
||||
IMAGE_LOGD("[GetImagePropertyInt] enter gif plugin, key:%{public}s", key.c_str());
|
||||
uint32_t errorCode = CheckIndex(0);
|
||||
if (errorCode != SUCCESS) {
|
||||
HiLog::Error(LABEL, "[GetImagePropertyInt]index %{public}u is invalid", index);
|
||||
IMAGE_LOGE("[GetImagePropertyInt]index %{public}u is invalid", index);
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
@ -766,7 +769,7 @@ uint32_t GifDecoder::GetImagePropertyInt(uint32_t index, const std::string &key,
|
||||
} else if (key == GIF_IMAGE_LOOP_COUNT) {
|
||||
errorCode = GetImageLoopCount(0, value);
|
||||
} else {
|
||||
HiLog::Error(LABEL, "[GetImagePropertyInt]key(%{public}s) not supported", key.c_str());
|
||||
IMAGE_LOGE("[GetImagePropertyInt]key(%{public}s) not supported", key.c_str());
|
||||
return ERR_IMAGE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
@ -775,7 +778,7 @@ uint32_t GifDecoder::GetImagePropertyInt(uint32_t index, const std::string &key,
|
||||
|
||||
uint32_t GifDecoder::GetImagePropertyString(uint32_t index, const std::string &key, std::string &value)
|
||||
{
|
||||
HiLog::Debug(LABEL, "[GetImagePropertyString] enter, index:%{public}u, key:%{public}s", index, key.c_str());
|
||||
IMAGE_LOGD("[GetImagePropertyString] enter, index:%{public}u, key:%{public}s", index, key.c_str());
|
||||
|
||||
if (key != GIF_IMAGE_DELAY_TIME) {
|
||||
return AbsImageDecoder::GetImagePropertyString(index, key, value);
|
||||
@ -784,14 +787,14 @@ uint32_t GifDecoder::GetImagePropertyString(uint32_t index, const std::string &k
|
||||
int32_t intValue = 0;
|
||||
uint32_t errorCode = GetImagePropertyInt(index, key, intValue);
|
||||
if (errorCode != SUCCESS) {
|
||||
HiLog::Error(LABEL, "[GetImagePropertyString] errorCode:%{public}u,"
|
||||
IMAGE_LOGE("[GetImagePropertyString] errorCode:%{public}u,"
|
||||
" index:%{public}u, key:%{public}s", errorCode, index, key.c_str());
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
value = std::to_string(intValue);
|
||||
|
||||
HiLog::Debug(LABEL, "[GetImagePropertyString] leave, index:%{public}u, key:%{public}s, value:%{public}s",
|
||||
IMAGE_LOGD("[GetImagePropertyString] leave, index:%{public}u, key:%{public}s, value:%{public}s",
|
||||
index, key.c_str(), value.c_str());
|
||||
return SUCCESS;
|
||||
}
|
||||
@ -799,7 +802,7 @@ uint32_t GifDecoder::GetImagePropertyString(uint32_t index, const std::string &k
|
||||
uint32_t GifDecoder::ParseFrameDetail()
|
||||
{
|
||||
if (DGifGetImageDesc(gifPtr_) == GIF_ERROR) {
|
||||
HiLog::Error(LABEL, "[ParseFrameDetail]parse frame desc to gif pointer failed %{public}d", gifPtr_->Error);
|
||||
IMAGE_LOGE("[ParseFrameDetail]parse frame desc to gif pointer failed %{public}d", gifPtr_->Error);
|
||||
return ERR_IMAGE_DECODE_ABNORMAL;
|
||||
}
|
||||
// DGifGetImageDesc use malloc or reallocarray allocate savedImages memory and increase imageCount.
|
||||
@ -811,8 +814,8 @@ uint32_t GifDecoder::ParseFrameDetail()
|
||||
int32_t imageHeight = saveImagePtr->ImageDesc.Height;
|
||||
uint64_t imageSize = static_cast<uint64_t>(imageWidth * imageHeight);
|
||||
if (imageWidth <= 0 || imageHeight <= 0 || imageSize > SIZE_MAX) {
|
||||
HiLog::Error(LABEL, "[ParseFrameDetail]check frame size[%{public}d, %{public}d] failed", imageWidth,
|
||||
imageHeight);
|
||||
IMAGE_LOGE("[ParseFrameDetail]check frame size[%{public}d, %{public}d] failed", imageWidth,
|
||||
imageHeight);
|
||||
// if error, imageCount go back and next time DGifGetImageDesc will retry.
|
||||
gifPtr_->ImageCount--;
|
||||
return ERR_IMAGE_DECODE_ABNORMAL;
|
||||
@ -826,7 +829,7 @@ uint32_t GifDecoder::ParseFrameDetail()
|
||||
}
|
||||
// set savedImage rasterBits
|
||||
if (SetSavedImageRasterBits(saveImagePtr, frameIndex, imageSize, imageWidth, imageHeight) != SUCCESS) {
|
||||
HiLog::Error(LABEL, "[ParseFrameDetail] set saved image data failed");
|
||||
IMAGE_LOGE("[ParseFrameDetail] set saved image data failed");
|
||||
GifFreeExtensions(&saveImagePtr->ExtensionBlockCount, &saveImagePtr->ExtensionBlocks);
|
||||
return ERR_IMAGE_DECODE_ABNORMAL;
|
||||
}
|
||||
@ -838,12 +841,12 @@ uint32_t GifDecoder::SetSavedImageRasterBits(SavedImage *saveImagePtr, int32_t f
|
||||
{
|
||||
if (saveImagePtr->RasterBits == nullptr) {
|
||||
if (imageSize == 0 || imageSize > PIXEL_MAP_MAX_RAM_SIZE) {
|
||||
HiLog::Error(LABEL, "[SetSavedImageData]malloc frame %{public}d failed for invalid imagesize", frameIndex);
|
||||
IMAGE_LOGE("[SetSavedImageData]malloc frame %{public}d failed for invalid imagesize", frameIndex);
|
||||
return ERR_IMAGE_MALLOC_ABNORMAL;
|
||||
}
|
||||
saveImagePtr->RasterBits = static_cast<GifPixelType *>(malloc(imageSize * sizeof(GifPixelType)));
|
||||
if (saveImagePtr->RasterBits == nullptr) {
|
||||
HiLog::Error(LABEL, "[SetSavedImageData]malloc frame %{public}d rasterBits failed", frameIndex);
|
||||
IMAGE_LOGE("[SetSavedImageData]malloc frame %{public}d rasterBits failed", frameIndex);
|
||||
return ERR_IMAGE_MALLOC_ABNORMAL;
|
||||
}
|
||||
}
|
||||
@ -852,16 +855,16 @@ uint32_t GifDecoder::SetSavedImageRasterBits(SavedImage *saveImagePtr, int32_t f
|
||||
for (int32_t i = 0; i < INTERLACED_PASSES; i++) {
|
||||
for (int32_t j = INTERLACED_OFFSET[i]; j < imageHeight; j += INTERLACED_INTERVAL[i]) {
|
||||
if (DGifGetLine(gifPtr_, saveImagePtr->RasterBits + j * imageWidth, imageWidth) == GIF_ERROR) {
|
||||
HiLog::Error(LABEL, "[SetSavedImageData]interlace set frame %{public}d bits failed %{public}d",
|
||||
frameIndex, gifPtr_->Error);
|
||||
IMAGE_LOGE("[SetSavedImageData]interlace set frame %{public}d bits failed %{public}d",
|
||||
frameIndex, gifPtr_->Error);
|
||||
return ERR_IMAGE_DECODE_ABNORMAL;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (DGifGetLine(gifPtr_, saveImagePtr->RasterBits, imageSize) == GIF_ERROR) {
|
||||
HiLog::Error(LABEL, "[SetSavedImageData]normal set frame %{public}d bits failed %{public}d", frameIndex,
|
||||
gifPtr_->Error);
|
||||
IMAGE_LOGE("[SetSavedImageData]normal set frame %{public}d bits failed %{public}d", frameIndex,
|
||||
gifPtr_->Error);
|
||||
return ERR_IMAGE_DECODE_ABNORMAL;
|
||||
}
|
||||
}
|
||||
@ -873,25 +876,25 @@ uint32_t GifDecoder::ParseFrameExtension()
|
||||
GifByteType *extData = nullptr;
|
||||
int32_t extFunc = 0;
|
||||
if (DGifGetExtension(gifPtr_, &extFunc, &extData) == GIF_ERROR) {
|
||||
HiLog::Error(LABEL, "[ParseFrameExtension]get extension failed %{public}d", gifPtr_->Error);
|
||||
IMAGE_LOGE("[ParseFrameExtension]get extension failed %{public}d", gifPtr_->Error);
|
||||
return ERR_IMAGE_DECODE_ABNORMAL;
|
||||
}
|
||||
if (extData == nullptr) {
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
HiLog::Debug(LABEL, "[ParseFrameExtension] get extension:0x%{public}x", extFunc);
|
||||
IMAGE_LOGD("[ParseFrameExtension] get extension:0x%{public}x", extFunc);
|
||||
|
||||
if (GifAddExtensionBlock(&gifPtr_->ExtensionBlockCount, &gifPtr_->ExtensionBlocks, extFunc,
|
||||
extData[EXTENSION_LEN_INDEX], &extData[EXTENSION_DATA_INDEX]) == GIF_ERROR) {
|
||||
HiLog::Error(LABEL, "[ParseFrameExtension]set extension to gif pointer failed");
|
||||
IMAGE_LOGE("[ParseFrameExtension]set extension to gif pointer failed");
|
||||
// GifAddExtensionBlock will allocate memory, if error, free extension ready to retry
|
||||
GifFreeExtensions(&gifPtr_->ExtensionBlockCount, &gifPtr_->ExtensionBlocks);
|
||||
return ERR_IMAGE_DECODE_ABNORMAL;
|
||||
}
|
||||
while (true) {
|
||||
if (DGifGetExtensionNext(gifPtr_, &extData) == GIF_ERROR) {
|
||||
HiLog::Error(LABEL, "[ParseFrameExtension]get next extension failed %{public}d", gifPtr_->Error);
|
||||
IMAGE_LOGE("[ParseFrameExtension]get next extension failed %{public}d", gifPtr_->Error);
|
||||
return ERR_IMAGE_DECODE_ABNORMAL;
|
||||
}
|
||||
if (extData == nullptr) {
|
||||
@ -900,7 +903,7 @@ uint32_t GifDecoder::ParseFrameExtension()
|
||||
|
||||
if (GifAddExtensionBlock(&gifPtr_->ExtensionBlockCount, &gifPtr_->ExtensionBlocks, CONTINUE_EXT_FUNC_CODE,
|
||||
extData[EXTENSION_LEN_INDEX], &extData[EXTENSION_DATA_INDEX]) == GIF_ERROR) {
|
||||
HiLog::Error(LABEL, "[ParseFrameExtension]set next extension to gif pointer failed");
|
||||
IMAGE_LOGE("[ParseFrameExtension]set next extension to gif pointer failed");
|
||||
GifFreeExtensions(&gifPtr_->ExtensionBlockCount, &gifPtr_->ExtensionBlocks);
|
||||
return ERR_IMAGE_DECODE_ABNORMAL;
|
||||
}
|
||||
@ -910,14 +913,14 @@ uint32_t GifDecoder::ParseFrameExtension()
|
||||
|
||||
uint32_t GifDecoder::UpdateGifFileType(int32_t updateFrameIndex)
|
||||
{
|
||||
HiLog::Debug(LABEL, "[UpdateGifFileType]update %{public}d to %{public}d", savedFrameIndex_, updateFrameIndex);
|
||||
IMAGE_LOGD("[UpdateGifFileType]update %{public}d to %{public}d", savedFrameIndex_, updateFrameIndex);
|
||||
uint32_t startPosition = inputStreamPtr_->Tell();
|
||||
GifRecordType recordType;
|
||||
gifPtr_->ExtensionBlocks = nullptr;
|
||||
gifPtr_->ExtensionBlockCount = 0;
|
||||
do {
|
||||
if (DGifGetRecordType(gifPtr_, &recordType) == GIF_ERROR) {
|
||||
HiLog::Error(LABEL, "[UpdateGifFileType]parse file record type failed %{public}d", gifPtr_->Error);
|
||||
IMAGE_LOGE("[UpdateGifFileType]parse file record type failed %{public}d", gifPtr_->Error);
|
||||
inputStreamPtr_->Seek(startPosition);
|
||||
return ERR_IMAGE_DECODE_ABNORMAL;
|
||||
}
|
||||
@ -925,14 +928,14 @@ uint32_t GifDecoder::UpdateGifFileType(int32_t updateFrameIndex)
|
||||
switch (recordType) {
|
||||
case EXTENSION_RECORD_TYPE:
|
||||
if (ParseFrameExtension() != SUCCESS) {
|
||||
HiLog::Error(LABEL, "[UpdateGifFileType]parse frame extension failed");
|
||||
IMAGE_LOGE("[UpdateGifFileType]parse frame extension failed");
|
||||
inputStreamPtr_->Seek(startPosition);
|
||||
return ERR_IMAGE_DECODE_ABNORMAL;
|
||||
}
|
||||
break;
|
||||
case IMAGE_DESC_RECORD_TYPE:
|
||||
if (ParseFrameDetail() != SUCCESS) {
|
||||
HiLog::Error(LABEL, "[UpdateGifFileType]parse frame detail failed");
|
||||
IMAGE_LOGE("[UpdateGifFileType]parse frame detail failed");
|
||||
inputStreamPtr_->Seek(startPosition);
|
||||
return ERR_IMAGE_DECODE_ABNORMAL;
|
||||
}
|
||||
@ -940,7 +943,7 @@ uint32_t GifDecoder::UpdateGifFileType(int32_t updateFrameIndex)
|
||||
startPosition = inputStreamPtr_->Tell();
|
||||
break;
|
||||
case TERMINATE_RECORD_TYPE:
|
||||
HiLog::Debug(LABEL, "[UpdateGifFileType]parse gif completed");
|
||||
IMAGE_LOGD("[UpdateGifFileType]parse gif completed");
|
||||
isLoadAllFrame_ = true;
|
||||
break;
|
||||
default:
|
||||
@ -954,7 +957,7 @@ uint32_t GifDecoder::UpdateGifFileType(int32_t updateFrameIndex)
|
||||
|
||||
if (gifPtr_->ImageCount <= 0) {
|
||||
gifPtr_->Error = D_GIF_ERR_NO_IMAG_DSCR;
|
||||
HiLog::Error(LABEL, "[UpdateGifFileType]has no frame in gif block");
|
||||
IMAGE_LOGE("[UpdateGifFileType]has no frame in gif block");
|
||||
return ERR_IMAGE_DECODE_ABNORMAL;
|
||||
}
|
||||
return SUCCESS;
|
||||
|
@ -15,16 +15,20 @@
|
||||
|
||||
#include "plugin_export.h"
|
||||
#include "gif_decoder.h"
|
||||
#include "hilog/log_c.h"
|
||||
#include "hilog/log_cpp.h"
|
||||
#include "image_log.h"
|
||||
#include "iosfwd"
|
||||
#include "log_tags.h"
|
||||
#include "map"
|
||||
#include "plugin_class_base.h"
|
||||
#include "plugin_utils.h"
|
||||
#include "string"
|
||||
#include "utility"
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_PLUGIN
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "LibGifPlugin"
|
||||
|
||||
// plugin package name same as metadata.
|
||||
namespace {
|
||||
const std::string PACKAGE_NAME = ("LibGifPlugin");
|
||||
@ -36,31 +40,25 @@ PLUGIN_EXPORT_REGISTER_CLASS(OHOS::ImagePlugin::GifDecoder)
|
||||
PLUGIN_EXPORT_REGISTER_CLASS_END
|
||||
|
||||
using std::string;
|
||||
using namespace OHOS::HiviewDFX;
|
||||
|
||||
static constexpr HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_PLUGIN, "LibGifPlugin" };
|
||||
|
||||
#define PLUGIN_LOG_D(...) HiLog::Debug(LABEL, __VA_ARGS__)
|
||||
#define PLUGIN_LOG_E(...) HiLog::Error(LABEL, __VA_ARGS__)
|
||||
|
||||
// define the external interface of this plugin.
|
||||
PLUGIN_EXPORT_DEFAULT_EXTERNAL_START()
|
||||
PLUGIN_EXPORT_DEFAULT_EXTERNAL_STOP()
|
||||
OHOS::MultimediaPlugin::PluginClassBase *PluginExternalCreate(const string &className)
|
||||
{
|
||||
HiLog::Debug(LABEL, "PluginExternalCreate: create object for package: %{public}s, class: %{public}s.",
|
||||
IMAGE_LOGD("PluginExternalCreate: create object for package: %{public}s, class: %{public}s.",
|
||||
PACKAGE_NAME.c_str(), className.c_str());
|
||||
|
||||
auto iter = implClassMap.find(className);
|
||||
if (iter == implClassMap.end()) {
|
||||
HiLog::Error(LABEL, "PluginExternalCreate: failed to find class: %{public}s, in package: %{public}s.",
|
||||
IMAGE_LOGE("PluginExternalCreate: failed to find class: %{public}s, in package: %{public}s.",
|
||||
className.c_str(), PACKAGE_NAME.c_str());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto creator = iter->second;
|
||||
if (creator == nullptr) {
|
||||
HiLog::Error(LABEL, "PluginExternalCreate: null creator for class: %{public}s, in package: %{public}s.",
|
||||
IMAGE_LOGE("PluginExternalCreate: null creator for class: %{public}s, in package: %{public}s.",
|
||||
className.c_str(), PACKAGE_NAME.c_str());
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -19,8 +19,6 @@
|
||||
#include <memory>
|
||||
#include "abs_image_decoder.h"
|
||||
#include "heif_decoder_wrapper.h"
|
||||
#include "hilog/log.h"
|
||||
#include "log_tags.h"
|
||||
#include "nocopyable.h"
|
||||
#include "plugin_class_base.h"
|
||||
|
||||
|
@ -14,16 +14,22 @@
|
||||
*/
|
||||
|
||||
#include "heif_decoder.h"
|
||||
|
||||
#include "image_log.h"
|
||||
#include "media_errors.h"
|
||||
#include "securec.h"
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_PLUGIN
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "HeifDecoder"
|
||||
|
||||
namespace OHOS {
|
||||
namespace ImagePlugin {
|
||||
using namespace OHOS::HiviewDFX;
|
||||
using namespace MultimediaPlugin;
|
||||
using namespace Media;
|
||||
|
||||
constexpr HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_PLUGIN, "HeifDecoder" };
|
||||
constexpr uint32_t HEIF_IMAGE_NUM = 1;
|
||||
|
||||
void HeifDecoder::SetSource(InputDataStream &sourceStream)
|
||||
@ -43,7 +49,7 @@ uint32_t HeifDecoder::SetDecodeOptions(uint32_t index, const PixelDecodeOptions
|
||||
{
|
||||
uint32_t ret = GetImageSize(index, info.size);
|
||||
if (ret != SUCCESS) {
|
||||
HiLog::Error(LABEL, "get image size failed, ret=%{public}u", ret);
|
||||
IMAGE_LOGE("get image size failed, ret=%{public}u", ret);
|
||||
return ret;
|
||||
}
|
||||
heifSize_ = info.size;
|
||||
@ -70,17 +76,17 @@ uint32_t HeifDecoder::SetDecodeOptions(uint32_t index, const PixelDecodeOptions
|
||||
uint32_t HeifDecoder::Decode(uint32_t index, DecodeContext &context)
|
||||
{
|
||||
if (heifDecoderInterface_ == nullptr) {
|
||||
HiLog::Error(LABEL, "create heif interface object failed!");
|
||||
IMAGE_LOGE("create heif interface object failed!");
|
||||
return ERR_IMAGE_INIT_ABNORMAL;
|
||||
}
|
||||
|
||||
if (index >= HEIF_IMAGE_NUM) {
|
||||
HiLog::Error(LABEL, "decode image out of range, index:%{public}u, range:%{public}d.", index, HEIF_IMAGE_NUM);
|
||||
IMAGE_LOGE("decode image out of range, index:%{public}u, range:%{public}d.", index, HEIF_IMAGE_NUM);
|
||||
return ERR_IMAGE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
if (!AllocHeapBuffer(context)) {
|
||||
HiLog::Error(LABEL, "get pixels memory fail.");
|
||||
IMAGE_LOGE("get pixels memory fail.");
|
||||
return ERR_IMAGE_MALLOC_ABNORMAL;
|
||||
}
|
||||
return heifDecoderInterface_->OnGetPixels(heifSize_, heifSize_.width * bytesPerPixel_, context);
|
||||
@ -89,19 +95,19 @@ uint32_t HeifDecoder::Decode(uint32_t index, DecodeContext &context)
|
||||
uint32_t HeifDecoder::GetImageSize(uint32_t index, PlSize &size)
|
||||
{
|
||||
if (index >= HEIF_IMAGE_NUM) {
|
||||
HiLog::Error(LABEL, "decode image out of range, index:%{public}u, range:%{public}d.", index, HEIF_IMAGE_NUM);
|
||||
IMAGE_LOGE("decode image out of range, index:%{public}u, range:%{public}d.", index, HEIF_IMAGE_NUM);
|
||||
return ERR_IMAGE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
if (heifDecoderInterface_ == nullptr) {
|
||||
HiLog::Error(LABEL, "create heif interface object failed!");
|
||||
IMAGE_LOGE("create heif interface object failed!");
|
||||
return ERR_IMAGE_INIT_ABNORMAL;
|
||||
}
|
||||
|
||||
heifDecoderInterface_->GetHeifSize(size);
|
||||
if (size.width == 0 || size.height == 0) {
|
||||
HiLog::Error(LABEL, "get width and height fail, height:%{public}u, width:%{public}u.", size.height,
|
||||
size.height);
|
||||
IMAGE_LOGE("get width and height fail, height:%{public}u, width:%{public}u.", size.height,
|
||||
size.height);
|
||||
return ERR_IMAGE_GET_DATA_ABNORMAL;
|
||||
}
|
||||
return SUCCESS;
|
||||
@ -123,7 +129,7 @@ bool HeifDecoder::AllocHeapBuffer(DecodeContext &context)
|
||||
{
|
||||
if (context.pixelsBuffer.buffer == nullptr) {
|
||||
if (!IsHeifImageParaValid(heifSize_, bytesPerPixel_)) {
|
||||
HiLog::Error(LABEL, "check heif image para fail");
|
||||
IMAGE_LOGE("check heif image para fail");
|
||||
return false;
|
||||
}
|
||||
uint64_t byteCount = static_cast<uint64_t>(heifSize_.width) * heifSize_.height * bytesPerPixel_;
|
||||
@ -132,12 +138,12 @@ bool HeifDecoder::AllocHeapBuffer(DecodeContext &context)
|
||||
} else {
|
||||
void *outputBuffer = malloc(byteCount);
|
||||
if (outputBuffer == nullptr) {
|
||||
HiLog::Error(LABEL, "alloc output buffer size:[%{public}llu] error.",
|
||||
static_cast<unsigned long long>(byteCount));
|
||||
IMAGE_LOGE("alloc output buffer size:[%{public}llu] error.",
|
||||
static_cast<unsigned long long>(byteCount));
|
||||
return false;
|
||||
}
|
||||
if (memset_s(outputBuffer, byteCount, 0, byteCount) != EOK) {
|
||||
HiLog::Error(LABEL, "memset buffer failed.");
|
||||
IMAGE_LOGE("memset buffer failed.");
|
||||
free(outputBuffer);
|
||||
outputBuffer = nullptr;
|
||||
return false;
|
||||
@ -173,7 +179,7 @@ bool HeifDecoder::AllocShareMem(DecodeContext &context, uint64_t byteCount)
|
||||
context.pixelsBuffer.buffer = ptr;
|
||||
void *fdBuffer = new int32_t();
|
||||
if (fdBuffer == nullptr) {
|
||||
HiLog::Error(LABEL, "new fdBuffer fail");
|
||||
IMAGE_LOGE("new fdBuffer fail");
|
||||
::munmap(ptr, byteCount);
|
||||
::close(fd);
|
||||
context.pixelsBuffer.buffer = nullptr;
|
||||
@ -190,21 +196,21 @@ bool HeifDecoder::AllocShareMem(DecodeContext &context, uint64_t byteCount)
|
||||
bool HeifDecoder::IsHeifImageParaValid(PlSize heifSize, uint32_t bytesPerPixel)
|
||||
{
|
||||
if (heifSize.width == 0 || heifSize.height == 0 || bytesPerPixel == 0) {
|
||||
HiLog::Error(LABEL, "heif image para is 0");
|
||||
IMAGE_LOGE("heif image para is 0");
|
||||
return false;
|
||||
}
|
||||
uint64_t area = static_cast<uint64_t>(heifSize.width) * heifSize.height;
|
||||
if ((area / heifSize.width) != heifSize.height) {
|
||||
HiLog::Error(LABEL, "compute width*height overflow!");
|
||||
IMAGE_LOGE("compute width*height overflow!");
|
||||
return false;
|
||||
}
|
||||
uint64_t size = area * bytesPerPixel;
|
||||
if ((size / bytesPerPixel) != area) {
|
||||
HiLog::Error(LABEL, "compute area*bytesPerPixel overflow!");
|
||||
IMAGE_LOGE("compute area*bytesPerPixel overflow!");
|
||||
return false;
|
||||
}
|
||||
if (size > UINT32_MAX) {
|
||||
HiLog::Error(LABEL, "size is too large!");
|
||||
IMAGE_LOGE("size is too large!");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -15,10 +15,15 @@
|
||||
|
||||
#include "plugin_export.h"
|
||||
#include "heif_decoder.h"
|
||||
#include "hilog/log.h"
|
||||
#include "log_tags.h"
|
||||
#include "image_log.h"
|
||||
#include "plugin_utils.h"
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_PLUGIN
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "LibHeifPlugin"
|
||||
|
||||
// plugin package name same as metadata.
|
||||
namespace {
|
||||
const std::string PACKAGE_NAME = ("LibHeifPlugin");
|
||||
@ -30,31 +35,25 @@ PLUGIN_EXPORT_REGISTER_CLASS(OHOS::ImagePlugin::HeifDecoder)
|
||||
PLUGIN_EXPORT_REGISTER_CLASS_END
|
||||
|
||||
using std::string;
|
||||
using namespace OHOS::HiviewDFX;
|
||||
|
||||
static constexpr HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_PLUGIN, "LibHeifPlugin" };
|
||||
|
||||
#define PLUGIN_LOG_D(...) HiLog::Debug(LABEL, __VA_ARGS__)
|
||||
#define PLUGIN_LOG_E(...) HiLog::Error(LABEL, __VA_ARGS__)
|
||||
|
||||
// define the external interface of this plugin.
|
||||
PLUGIN_EXPORT_DEFAULT_EXTERNAL_START()
|
||||
PLUGIN_EXPORT_DEFAULT_EXTERNAL_STOP()
|
||||
OHOS::MultimediaPlugin::PluginClassBase *PluginExternalCreate(const string &className)
|
||||
{
|
||||
HiLog::Debug(LABEL, "PluginExternalCreate: create object for package: %{public}s, class: %{public}s.",
|
||||
IMAGE_LOGD("PluginExternalCreate: create object for package: %{public}s, class: %{public}s.",
|
||||
PACKAGE_NAME.c_str(), className.c_str());
|
||||
|
||||
auto iter = implClassMap.find(className);
|
||||
if (iter == implClassMap.end()) {
|
||||
HiLog::Error(LABEL, "PluginExternalCreate: failed to find class: %{public}s, in package: %{public}s.",
|
||||
IMAGE_LOGE("PluginExternalCreate: failed to find class: %{public}s, in package: %{public}s.",
|
||||
className.c_str(), PACKAGE_NAME.c_str());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto creator = iter->second;
|
||||
if (creator == nullptr) {
|
||||
HiLog::Error(LABEL, "PluginExternalCreate: null creator for class: %{public}s, in package: %{public}s.",
|
||||
IMAGE_LOGE("PluginExternalCreate: null creator for class: %{public}s, in package: %{public}s.",
|
||||
className.c_str(), PACKAGE_NAME.c_str());
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -20,7 +20,6 @@
|
||||
#ifdef IMAGE_COLORSPACE_FLAG
|
||||
#include "color_space.h"
|
||||
#endif
|
||||
#include "hilog/log.h"
|
||||
#include "image_plugin_type.h"
|
||||
#include "include/core/SkData.h"
|
||||
#include "include/core/SkColorSpace.h"
|
||||
@ -28,7 +27,6 @@
|
||||
#include "include/third_party/skcms/skcms.h"
|
||||
#include "jpeg_utils.h"
|
||||
#include "jpeglib.h"
|
||||
#include "log_tags.h"
|
||||
#include "media_errors.h"
|
||||
#include "src/images/SkImageEncoderFns.h"
|
||||
namespace OHOS {
|
||||
|
@ -23,11 +23,9 @@
|
||||
#ifdef IMAGE_COLORSPACE_FLAG
|
||||
#include "color_space.h"
|
||||
#endif
|
||||
#include "hilog/log.h"
|
||||
#include "icc_profile_info.h"
|
||||
#include "jpeg_utils.h"
|
||||
#include "jpeglib.h"
|
||||
#include "log_tags.h"
|
||||
#include "plugin_class_base.h"
|
||||
#include "plugin_server.h"
|
||||
#include "exif_info.h"
|
||||
|
@ -21,17 +21,20 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include "exif_maker_note.h"
|
||||
#include "hilog/log.h"
|
||||
#include "log_tags.h"
|
||||
#include "image_log.h"
|
||||
#include "media_errors.h"
|
||||
#include "securec.h"
|
||||
#include "string_ex.h"
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_PLUGIN
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "exifInfo"
|
||||
|
||||
namespace OHOS {
|
||||
namespace ImagePlugin {
|
||||
namespace {
|
||||
using namespace OHOS::HiviewDFX;
|
||||
constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_IMAGE, "exifInfo" };
|
||||
static constexpr int PARSE_EXIF_SUCCESS = 0;
|
||||
static constexpr int PARSE_EXIF_DATA_ERROR = 10001;
|
||||
static constexpr int PARSE_EXIF_IFD_ERROR = 10002;
|
||||
@ -427,18 +430,17 @@ static void inline DumpTagsMap(std::map<ExifTag, std::string> &tags)
|
||||
{
|
||||
for (auto i = tags.begin(); i != tags.end(); i++) {
|
||||
if (TAG_MAP.count(i->first) == 0) {
|
||||
HiLog::Debug(LABEL, "DumpTagsMap %{public}d -> %{public}s.", i->first, i->second.c_str());
|
||||
IMAGE_LOGD("DumpTagsMap %{public}d -> %{public}s.", i->first, i->second.c_str());
|
||||
continue;
|
||||
}
|
||||
std::string name = TAG_MAP.at(i->first);
|
||||
HiLog::Debug(LABEL,
|
||||
"DumpTagsMap %{public}s(%{public}d) -> %{public}s.", name.c_str(), i->first, i->second.c_str());
|
||||
IMAGE_LOGD("DumpTagsMap %{public}s(%{public}d) -> %{public}s.", name.c_str(), i->first, i->second.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
int EXIFInfo::ParseExifData(const unsigned char *buf, unsigned len)
|
||||
{
|
||||
HiLog::Debug(LABEL, "ParseExifData ENTER");
|
||||
IMAGE_LOGD("ParseExifData ENTER");
|
||||
if (exifData_ != nullptr) {
|
||||
exif_data_unref(exifData_);
|
||||
exifData_ = nullptr;
|
||||
@ -454,7 +456,7 @@ int EXIFInfo::ParseExifData(const unsigned char *buf, unsigned len)
|
||||
ExifIfd ifd = exif_content_get_ifd(ec);
|
||||
(static_cast<EXIFInfo*>(userData))->imageFileDirectory_ = ifd;
|
||||
if (ifd == EXIF_IFD_COUNT) {
|
||||
HiLog::Debug(LABEL, "GetIfd ERROR");
|
||||
IMAGE_LOGD("GetIfd ERROR");
|
||||
return;
|
||||
}
|
||||
exif_content_foreach_entry(ec,
|
||||
@ -578,7 +580,7 @@ void EXIFInfo::SetExifTagValuesEx(const ExifTag &tag, const std::string &value)
|
||||
} else if (tag == EXIF_TAG_FOCAL_LENGTH_IN_35MM_FILM) {
|
||||
focalLengthIn35mmFilm_ = value;
|
||||
} else {
|
||||
HiLog::Debug(LABEL, "No match tag name!");
|
||||
IMAGE_LOGD("No match tag name!");
|
||||
}
|
||||
}
|
||||
|
||||
@ -587,33 +589,33 @@ uint32_t EXIFInfo::GetFileInfoByPath(const std::string &path, FILE **file, unsig
|
||||
{
|
||||
*file = fopen(path.c_str(), "rb");
|
||||
if (*file == nullptr) {
|
||||
HiLog::Debug(LABEL, "Error creating file %{public}s", path.c_str());
|
||||
IMAGE_LOGD("Error creating file %{public}s", path.c_str());
|
||||
return Media::ERR_MEDIA_IO_ABNORMAL;
|
||||
}
|
||||
|
||||
// read jpeg file to buff
|
||||
fileLength = GetFileSize(*file);
|
||||
if (fileLength == 0 || fileLength > MAX_FILE_SIZE) {
|
||||
HiLog::Debug(LABEL, "Get file size failed.");
|
||||
IMAGE_LOGD("Get file size failed.");
|
||||
(void)fclose(*file);
|
||||
return Media::ERR_MEDIA_BUFFER_TOO_SMALL;
|
||||
}
|
||||
|
||||
*fileBuf = static_cast<unsigned char *>(malloc(fileLength));
|
||||
if (*fileBuf == nullptr) {
|
||||
HiLog::Debug(LABEL, "Allocate buf for %{public}s failed.", path.c_str());
|
||||
IMAGE_LOGD("Allocate buf for %{public}s failed.", path.c_str());
|
||||
(void)fclose(*file);
|
||||
return Media::ERR_IMAGE_MALLOC_ABNORMAL;
|
||||
}
|
||||
|
||||
if (fread(*fileBuf, fileLength, 1, *file) != 1) {
|
||||
HiLog::Debug(LABEL, "Read %{public}s failed.", path.c_str());
|
||||
IMAGE_LOGD("Read %{public}s failed.", path.c_str());
|
||||
ReleaseSource(fileBuf, file);
|
||||
return Media::ERR_MEDIA_READ_PARCEL_FAIL;
|
||||
}
|
||||
|
||||
if (!((*fileBuf)[0] == 0xFF && (*fileBuf)[1] == 0xD8)) {
|
||||
HiLog::Debug(LABEL, "%{public}s is not jpeg file.", path.c_str());
|
||||
IMAGE_LOGD("%{public}s is not jpeg file.", path.c_str());
|
||||
ReleaseSource(fileBuf, file);
|
||||
return Media::ERR_IMAGE_MISMATCHED_FORMAT;
|
||||
}
|
||||
@ -641,7 +643,7 @@ uint32_t EXIFInfo::ModifyExifData(const ExifTag &tag, const std::string &value,
|
||||
|
||||
unsigned int orginExifDataLength = GetOrginExifDataLength(isNewExifData, fileBuf);
|
||||
if (!isNewExifData && orginExifDataLength == 0) {
|
||||
HiLog::Debug(LABEL, "There is no orginExifDataLength node in %{public}s.", path.c_str());
|
||||
IMAGE_LOGD("There is no orginExifDataLength node in %{public}s.", path.c_str());
|
||||
exif_data_unref(ptrExifData);
|
||||
free(fileBuf);
|
||||
return Media::ERR_IMAGE_DECODE_EXIF_UNSUPPORT;
|
||||
@ -650,7 +652,7 @@ uint32_t EXIFInfo::ModifyExifData(const ExifTag &tag, const std::string &value,
|
||||
ExifByteOrder order = GetExifByteOrder(isNewExifData, fileBuf);
|
||||
FILE *newFile = fopen(path.c_str(), "wb+");
|
||||
if (newFile == nullptr) {
|
||||
HiLog::Debug(LABEL, "Error create new file %{public}s", path.c_str());
|
||||
IMAGE_LOGD("Error create new file %{public}s", path.c_str());
|
||||
ReleaseSource(&fileBuf, &newFile);
|
||||
return Media::ERR_MEDIA_IO_ABNORMAL;
|
||||
}
|
||||
@ -674,21 +676,21 @@ uint32_t EXIFInfo::GetFileInfoByFd(int localFd, FILE **file, unsigned long &file
|
||||
{
|
||||
*file = fdopen(localFd, "wb+");
|
||||
if (*file == nullptr) {
|
||||
HiLog::Debug(LABEL, "Error creating file %{public}d", localFd);
|
||||
IMAGE_LOGD("Error creating file %{public}d", localFd);
|
||||
return Media::ERR_MEDIA_IO_ABNORMAL;
|
||||
}
|
||||
|
||||
// read jpeg file to buff
|
||||
fileLength = GetFileSize(*file);
|
||||
if (fileLength == 0 || fileLength > MAX_FILE_SIZE) {
|
||||
HiLog::Debug(LABEL, "Get file size failed.");
|
||||
IMAGE_LOGD("Get file size failed.");
|
||||
(void)fclose(*file);
|
||||
return Media::ERR_MEDIA_BUFFER_TOO_SMALL;
|
||||
}
|
||||
|
||||
*fileBuf = static_cast<unsigned char *>(malloc(fileLength));
|
||||
if (*fileBuf == nullptr) {
|
||||
HiLog::Debug(LABEL, "Allocate buf for %{public}d failed.", localFd);
|
||||
IMAGE_LOGD("Allocate buf for %{public}d failed.", localFd);
|
||||
(void)fclose(*file);
|
||||
return Media::ERR_IMAGE_MALLOC_ABNORMAL;
|
||||
}
|
||||
@ -696,13 +698,13 @@ uint32_t EXIFInfo::GetFileInfoByFd(int localFd, FILE **file, unsigned long &file
|
||||
// Set current position to begin of file.
|
||||
(void)fseek(*file, 0L, 0);
|
||||
if (fread(*fileBuf, fileLength, 1, *file) != 1) {
|
||||
HiLog::Debug(LABEL, "Read %{public}d failed.", localFd);
|
||||
IMAGE_LOGD("Read %{public}d failed.", localFd);
|
||||
ReleaseSource(fileBuf, file);
|
||||
return Media::ERR_MEDIA_READ_PARCEL_FAIL;
|
||||
}
|
||||
|
||||
if (!((*fileBuf)[0] == 0xFF && (*fileBuf)[1] == 0xD8)) {
|
||||
HiLog::Debug(LABEL, "%{public}d is not jpeg file.", localFd);
|
||||
IMAGE_LOGD("%{public}d is not jpeg file.", localFd);
|
||||
ReleaseSource(fileBuf, file);
|
||||
return Media::ERR_IMAGE_MISMATCHED_FORMAT;
|
||||
}
|
||||
@ -729,7 +731,7 @@ uint32_t EXIFInfo::ModifyExifData(const ExifTag &tag, const std::string &value,
|
||||
|
||||
unsigned int orginExifDataLength = GetOrginExifDataLength(isNewExifData, fileBuf);
|
||||
if (!isNewExifData && orginExifDataLength == 0) {
|
||||
HiLog::Debug(LABEL, "There is no orginExifDataLength node in %{public}d.", localFd);
|
||||
IMAGE_LOGD("There is no orginExifDataLength node in %{public}d.", localFd);
|
||||
free(fileBuf);
|
||||
exif_data_unref(ptrExifData);
|
||||
return Media::ERR_IMAGE_DECODE_EXIF_UNSUPPORT;
|
||||
@ -766,17 +768,17 @@ void ReleaseExifDataBuffer(unsigned char* exifDataBuf)
|
||||
uint32_t EXIFInfo::CheckInputDataValid(unsigned char *data, uint32_t size)
|
||||
{
|
||||
if (data == nullptr) {
|
||||
HiLog::Debug(LABEL, "buffer is nullptr.");
|
||||
IMAGE_LOGD("buffer is nullptr.");
|
||||
return Media::ERR_IMAGE_SOURCE_DATA;
|
||||
}
|
||||
|
||||
if (size == 0) {
|
||||
HiLog::Debug(LABEL, "buffer size is 0.");
|
||||
IMAGE_LOGD("buffer size is 0.");
|
||||
return Media::ERR_MEDIA_BUFFER_TOO_SMALL;
|
||||
}
|
||||
|
||||
if (!(data[0] == 0xFF && data[1] == 0xD8)) {
|
||||
HiLog::Debug(LABEL, "This is not jpeg file.");
|
||||
IMAGE_LOGD("This is not jpeg file.");
|
||||
return Media::ERR_IMAGE_MISMATCHED_FORMAT;
|
||||
}
|
||||
return Media::SUCCESS;
|
||||
@ -798,7 +800,7 @@ uint32_t EXIFInfo::ModifyExifData(const ExifTag &tag, const std::string &value,
|
||||
|
||||
unsigned int orginExifDataLength = GetOrginExifDataLength(isNewExifData, data);
|
||||
if (!isNewExifData && orginExifDataLength == 0) {
|
||||
HiLog::Debug(LABEL, "There is no orginExifDataLength node in buffer.");
|
||||
IMAGE_LOGD("There is no orginExifDataLength node in buffer.");
|
||||
exif_data_unref(ptrExifData);
|
||||
return Media::ERR_IMAGE_DECODE_EXIF_UNSUPPORT;
|
||||
}
|
||||
@ -814,20 +816,20 @@ uint32_t EXIFInfo::ModifyExifData(const ExifTag &tag, const std::string &value,
|
||||
unsigned int exifDataBufLength = 0;
|
||||
exif_data_save_data(ptrExifData, &exifDataBuf, &exifDataBufLength);
|
||||
if (exifDataBuf == nullptr) {
|
||||
HiLog::Debug(LABEL, "Get Exif Data Buf failed!");
|
||||
IMAGE_LOGD("Get Exif Data Buf failed!");
|
||||
exif_data_unref(ptrExifData);
|
||||
return Media::ERR_IMAGE_DECODE_EXIF_UNSUPPORT;
|
||||
}
|
||||
|
||||
if (size == 0 || size > MAX_FILE_SIZE) {
|
||||
HiLog::Debug(LABEL, "Buffer size is out of range.");
|
||||
IMAGE_LOGD("Buffer size is out of range.");
|
||||
exif_data_unref(ptrExifData);
|
||||
ReleaseExifDataBuffer(exifDataBuf);
|
||||
return Media::ERR_IMAGE_DECODE_EXIF_UNSUPPORT;
|
||||
}
|
||||
unsigned char *tempBuf = static_cast<unsigned char *>(malloc(size));
|
||||
if (tempBuf == nullptr) {
|
||||
HiLog::Debug(LABEL, "Allocate temp buffer ailed.");
|
||||
IMAGE_LOGD("Allocate temp buffer ailed.");
|
||||
exif_data_unref(ptrExifData);
|
||||
ReleaseExifDataBuffer(exifDataBuf);
|
||||
return Media::ERR_IMAGE_MALLOC_ABNORMAL;
|
||||
@ -836,7 +838,7 @@ uint32_t EXIFInfo::ModifyExifData(const ExifTag &tag, const std::string &value,
|
||||
// Write EXIF header to buffer
|
||||
uint32_t index = 0;
|
||||
if (sizeof(EXIF_HEADER) >= size) {
|
||||
HiLog::Debug(LABEL, "There is not enough space for EXIF header!");
|
||||
IMAGE_LOGD("There is not enough space for EXIF header!");
|
||||
ReleaseExifData(tempBuf, ptrExifData, exifDataBuf);
|
||||
return Media::ERR_MEDIA_OUT_OF_RANGE;
|
||||
}
|
||||
@ -848,7 +850,7 @@ uint32_t EXIFInfo::ModifyExifData(const ExifTag &tag, const std::string &value,
|
||||
// Write EXIF block length in big-endian order
|
||||
unsigned char highBit = static_cast<unsigned char>((exifDataBufLength + LENGTH_OFFSET_2) >> MOVE_OFFSET_8);
|
||||
if (index >= size) {
|
||||
HiLog::Debug(LABEL, "There is not enough space for writing EXIF block length!");
|
||||
IMAGE_LOGD("There is not enough space for writing EXIF block length!");
|
||||
ReleaseExifData(tempBuf, ptrExifData, exifDataBuf);
|
||||
return Media::ERR_MEDIA_OUT_OF_RANGE;
|
||||
}
|
||||
@ -856,7 +858,7 @@ uint32_t EXIFInfo::ModifyExifData(const ExifTag &tag, const std::string &value,
|
||||
|
||||
unsigned char lowBit = static_cast<unsigned char>((exifDataBufLength + LENGTH_OFFSET_2) & 0xff);
|
||||
if (index >= size) {
|
||||
HiLog::Debug(LABEL, "There is not enough space for writing EXIF block length!");
|
||||
IMAGE_LOGD("There is not enough space for writing EXIF block length!");
|
||||
ReleaseExifData(tempBuf, ptrExifData, exifDataBuf);
|
||||
return Media::ERR_MEDIA_OUT_OF_RANGE;
|
||||
}
|
||||
@ -864,7 +866,7 @@ uint32_t EXIFInfo::ModifyExifData(const ExifTag &tag, const std::string &value,
|
||||
|
||||
// Write EXIF data block
|
||||
if ((index + exifDataBufLength) >= size) {
|
||||
HiLog::Debug(LABEL, "There is not enough space for writing EXIF data block!");
|
||||
IMAGE_LOGD("There is not enough space for writing EXIF data block!");
|
||||
ReleaseExifData(tempBuf, ptrExifData, exifDataBuf);
|
||||
return Media::ERR_MEDIA_OUT_OF_RANGE;
|
||||
}
|
||||
@ -874,7 +876,7 @@ uint32_t EXIFInfo::ModifyExifData(const ExifTag &tag, const std::string &value,
|
||||
|
||||
// Write JPEG image data, skipping the non-EXIF header
|
||||
if ((index + size - orginExifDataLength - sizeof(EXIF_HEADER) - MOVE_OFFSET_8) > size) {
|
||||
HiLog::Debug(LABEL, "There is not enough space for writing JPEG image data!");
|
||||
IMAGE_LOGD("There is not enough space for writing JPEG image data!");
|
||||
ReleaseExifData(tempBuf, ptrExifData, exifDataBuf);
|
||||
return Media::ERR_MEDIA_OUT_OF_RANGE;
|
||||
}
|
||||
@ -910,7 +912,7 @@ ExifEntry* EXIFInfo::InitExifTag(ExifData *exif, ExifIfd ifd, ExifTag tag)
|
||||
/* Allocate a new entry */
|
||||
entry = exif_entry_new();
|
||||
if (entry == nullptr) {
|
||||
HiLog::Debug(LABEL, "Create new entry failed!");
|
||||
IMAGE_LOGD("Create new entry failed!");
|
||||
return nullptr;
|
||||
}
|
||||
entry->tag = tag; // tag must be set before calling exif_content_add_entry
|
||||
@ -938,7 +940,7 @@ static void EXIFInfoBufferCheck(ExifEntry *exifEntry, size_t len)
|
||||
/* Create a memory allocator to manage this ExifEntry */
|
||||
ExifMem *exifMem = exif_mem_new_default();
|
||||
if (exifMem == nullptr) {
|
||||
HiLog::Debug(LABEL, "Create mem failed!");
|
||||
IMAGE_LOGD("Create mem failed!");
|
||||
return;
|
||||
}
|
||||
auto buf = exif_mem_realloc(exifMem, exifEntry->data, len);
|
||||
@ -963,21 +965,21 @@ ExifEntry* EXIFInfo::CreateExifTag(ExifData *exif, ExifIfd ifd, ExifTag tag,
|
||||
/* Create a memory allocator to manage this ExifEntry */
|
||||
ExifMem *exifMem = exif_mem_new_default();
|
||||
if (exifMem == nullptr) {
|
||||
HiLog::Debug(LABEL, "Create mem failed!");
|
||||
IMAGE_LOGD("Create mem failed!");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/* Create a new ExifEntry using our allocator */
|
||||
exifEntry = exif_entry_new_mem (exifMem);
|
||||
if (exifEntry == nullptr) {
|
||||
HiLog::Debug(LABEL, "Create entry by mem failed!");
|
||||
IMAGE_LOGD("Create entry by mem failed!");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/* Allocate memory to use for holding the tag data */
|
||||
buf = exif_mem_alloc(exifMem, len);
|
||||
if (buf == nullptr) {
|
||||
HiLog::Debug(LABEL, "Allocate memory failed!");
|
||||
IMAGE_LOGD("Allocate memory failed!");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -1034,15 +1036,15 @@ bool EXIFInfo::CreateExifData(unsigned char *buf, unsigned long length, ExifData
|
||||
buf[BUFFER_POSITION_8] == 'i' && buf[BUFFER_POSITION_9] == 'f')) {
|
||||
*ptrData = exif_data_new_from_data(buf, static_cast<unsigned int>(length));
|
||||
if (!(*ptrData)) {
|
||||
HiLog::Debug(LABEL, "Create exif data from file failed.");
|
||||
IMAGE_LOGD("Create exif data from file failed.");
|
||||
return false;
|
||||
}
|
||||
isNewExifData = false;
|
||||
HiLog::Debug(LABEL, "Create exif data from buffer.");
|
||||
IMAGE_LOGD("Create exif data from buffer.");
|
||||
} else {
|
||||
*ptrData = exif_data_new();
|
||||
if (!(*ptrData)) {
|
||||
HiLog::Debug(LABEL, "Create exif data failed.");
|
||||
IMAGE_LOGD("Create exif data failed.");
|
||||
return false;
|
||||
}
|
||||
/* Set the image options */
|
||||
@ -1053,7 +1055,7 @@ bool EXIFInfo::CreateExifData(unsigned char *buf, unsigned long length, ExifData
|
||||
/* Create the mandatory EXIF fields with default data */
|
||||
exif_data_fix(*ptrData);
|
||||
isNewExifData = true;
|
||||
HiLog::Debug(LABEL, "Create new exif data.");
|
||||
IMAGE_LOGD("Create new exif data.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -1099,7 +1101,7 @@ static bool GetFractionFromStr(const std::string &decimal, ExifRational &result)
|
||||
|
||||
int gcdVal = GCD(numerator, denominator);
|
||||
if (gcdVal == 0) {
|
||||
HiLog::Debug(LABEL, "gcdVal is zero");
|
||||
IMAGE_LOGD("gcdVal is zero");
|
||||
return false;
|
||||
}
|
||||
numerator /= gcdVal;
|
||||
@ -1133,7 +1135,7 @@ static void ExifIntValueByFormat(unsigned char *b, ExifByteOrder order, ExifForm
|
||||
case EXIF_FORMAT_ASCII:
|
||||
case EXIF_FORMAT_RATIONAL:
|
||||
default:
|
||||
HiLog::Debug(LABEL, "ExifIntValueByFormat unsupported format %{public}d.", format);
|
||||
IMAGE_LOGD("ExifIntValueByFormat unsupported format %{public}d.", format);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -1148,7 +1150,7 @@ static bool ConvertStringToDouble(const std::string &str, double &number)
|
||||
static bool IsValidGpsData(const std::vector<std::string> &dataVec, const ExifTag &tag)
|
||||
{
|
||||
if (dataVec.size() != SIZE_3 || (tag != EXIF_TAG_GPS_LATITUDE && tag != EXIF_TAG_GPS_LONGITUDE)) {
|
||||
HiLog::Debug(LABEL, "Gps dms data size is invalid.");
|
||||
IMAGE_LOGD("Gps dms data size is invalid.");
|
||||
return false;
|
||||
}
|
||||
double degree = 0.0;
|
||||
@ -1157,14 +1159,14 @@ static bool IsValidGpsData(const std::vector<std::string> &dataVec, const ExifTa
|
||||
if (!ConvertStringToDouble(dataVec[CONSTANT_0], degree) ||
|
||||
!ConvertStringToDouble(dataVec[CONSTANT_1], minute) ||
|
||||
!ConvertStringToDouble(dataVec[CONSTANT_2], second)) {
|
||||
HiLog::Error(LABEL, "Convert gps data to double type failed.");
|
||||
IMAGE_LOGE("Convert gps data to double type failed.");
|
||||
return false;
|
||||
}
|
||||
constexpr uint32_t timePeriod = 60;
|
||||
double latOrLong = degree + minute / timePeriod + second / (timePeriod * timePeriod);
|
||||
if ((tag == EXIF_TAG_GPS_LATITUDE && (latOrLong > GPS_MAX_LATITUDE || latOrLong < GPS_MIN_LATITUDE)) ||
|
||||
(tag == EXIF_TAG_GPS_LONGITUDE && (latOrLong > GPS_MAX_LONGITUDE || latOrLong < GPS_MIN_LONGITUDE))) {
|
||||
HiLog::Debug(LABEL, "Gps latitude or longitude is out of range.");
|
||||
IMAGE_LOGD("Gps latitude or longitude is out of range.");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -1174,7 +1176,7 @@ static bool ConvertGpsDataToRationals(const std::vector<std::string> &dataVec,
|
||||
std::vector<ExifRational> &exifRationals)
|
||||
{
|
||||
if (!(dataVec.size() == SIZE_3 && exifRationals.size() == SIZE_3)) {
|
||||
HiLog::Debug(LABEL, "Data size is invalid.");
|
||||
IMAGE_LOGD("Data size is invalid.");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1197,12 +1199,12 @@ bool EXIFInfo::SetGpsRationals(ExifData *data, ExifEntry **ptrEntry, ExifByteOrd
|
||||
const ExifTag &tag, const std::vector<ExifRational> &exifRationals)
|
||||
{
|
||||
if (exifRationals.size() != SIZE_3) {
|
||||
HiLog::Debug(LABEL, "ExifRationals size is invalid.");
|
||||
IMAGE_LOGD("ExifRationals size is invalid.");
|
||||
return false;
|
||||
}
|
||||
*ptrEntry = GetExifTag(data, EXIF_IFD_GPS, tag, MOVE_OFFSET_24);
|
||||
if ((*ptrEntry) == nullptr) {
|
||||
HiLog::Debug(LABEL, "Get exif entry failed.");
|
||||
IMAGE_LOGD("Get exif entry failed.");
|
||||
return false;
|
||||
}
|
||||
exif_set_rational((*ptrEntry)->data, order, exifRationals[CONSTANT_0]);
|
||||
@ -1215,7 +1217,7 @@ bool EXIFInfo::SetGpsDegreeRational(ExifData *data, ExifEntry **ptrEntry, ExifBy
|
||||
const std::vector<std::string> &dataVec)
|
||||
{
|
||||
if (dataVec.size() != SIZE_2) {
|
||||
HiLog::Debug(LABEL, "Gps degree data size is invalid.");
|
||||
IMAGE_LOGD("Gps degree data size is invalid.");
|
||||
return false;
|
||||
}
|
||||
ExifRational exifRational;
|
||||
@ -1223,7 +1225,7 @@ bool EXIFInfo::SetGpsDegreeRational(ExifData *data, ExifEntry **ptrEntry, ExifBy
|
||||
exifRational.denominator = static_cast<ExifSLong>(atoi(dataVec[CONSTANT_1].c_str()));
|
||||
*ptrEntry = CreateExifTag(data, EXIF_IFD_GPS, tag, MOVE_OFFSET_8, EXIF_FORMAT_RATIONAL);
|
||||
if ((*ptrEntry) == nullptr) {
|
||||
HiLog::Debug(LABEL, "Get exif entry failed.");
|
||||
IMAGE_LOGD("Get exif entry failed.");
|
||||
return false;
|
||||
}
|
||||
exif_set_rational((*ptrEntry)->data, order, exifRational);
|
||||
@ -1235,13 +1237,13 @@ bool EXIFInfo::CreateExifEntryOfBitsPerSample(const ExifTag &tag, ExifData *data
|
||||
{
|
||||
*ptrEntry = InitExifTag(data, EXIF_IFD_0, EXIF_TAG_BITS_PER_SAMPLE);
|
||||
if ((*ptrEntry) == nullptr) {
|
||||
HiLog::Debug(LABEL, "Get exif entry failed.");
|
||||
IMAGE_LOGD("Get exif entry failed.");
|
||||
return false;
|
||||
}
|
||||
std::vector<std::string> bitsVec;
|
||||
SplitStr(value, ",", bitsVec);
|
||||
if (bitsVec.size() > CONSTANT_4) {
|
||||
HiLog::Debug(LABEL, "BITS_PER_SAMPLE Invalid value %{public}s", value.c_str());
|
||||
IMAGE_LOGD("BITS_PER_SAMPLE Invalid value %{public}s", value.c_str());
|
||||
return false;
|
||||
}
|
||||
if (bitsVec.size() != 0) {
|
||||
@ -1311,7 +1313,7 @@ bool EXIFInfo::CreateExifEntryOfRationalExif(const ExifTag &tag, ExifData *data,
|
||||
std::vector<std::string> longVec;
|
||||
SplitStr(value, separator, longVec);
|
||||
if (longVec.size() != sepSize) {
|
||||
HiLog::Debug(LABEL, "%{public}s Invalid value %{public}s", GetExifNameByExifTag(tag).c_str(), value.c_str());
|
||||
IMAGE_LOGD("%{public}s Invalid value %{public}s", GetExifNameByExifTag(tag).c_str(), value.c_str());
|
||||
return false;
|
||||
}
|
||||
ExifRational longRational;
|
||||
@ -1319,7 +1321,7 @@ bool EXIFInfo::CreateExifEntryOfRationalExif(const ExifTag &tag, ExifData *data,
|
||||
longRational.denominator = static_cast<ExifSLong>(atoi(longVec[1].c_str()));
|
||||
*ptrEntry = CreateExifTag(data, GetExifIfdByExifTag(tag), tag, sizeof(longRational), GetExifFormatByExifTag(tag));
|
||||
if ((*ptrEntry) == nullptr) {
|
||||
HiLog::Debug(LABEL, "Get %{public}s exif entry failed.", GetExifNameByExifTag(tag).c_str());
|
||||
IMAGE_LOGD("Get %{public}s exif entry failed.", GetExifNameByExifTag(tag).c_str());
|
||||
return false;
|
||||
}
|
||||
exif_set_rational((*ptrEntry)->data, order, longRational);
|
||||
@ -1332,12 +1334,12 @@ bool EXIFInfo::CreateExifEntryOfGpsTimeStamp(const ExifTag &tag, ExifData *data,
|
||||
std::vector<std::string> longVec;
|
||||
SplitStr(value, ":", longVec);
|
||||
if (longVec.size() != CONSTANT_3) {
|
||||
HiLog::Debug(LABEL, "GPS time stamp Invalid value %{public}s", value.c_str());
|
||||
IMAGE_LOGD("GPS time stamp Invalid value %{public}s", value.c_str());
|
||||
return false;
|
||||
}
|
||||
*ptrEntry = CreateExifTag(data, EXIF_IFD_GPS, tag, MOVE_OFFSET_24, EXIF_FORMAT_SRATIONAL);
|
||||
if ((*ptrEntry) == nullptr) {
|
||||
HiLog::Debug(LABEL, "Get GPS time stamp exif entry failed.");
|
||||
IMAGE_LOGD("Get GPS time stamp exif entry failed.");
|
||||
return false;
|
||||
}
|
||||
exif_set_long((*ptrEntry)->data, order, static_cast<ExifSLong>(atoi(longVec[CONSTANT_0].c_str())));
|
||||
@ -1353,12 +1355,12 @@ bool EXIFInfo::CreateExifEntryOfCompressedBitsPerPixel(const ExifTag &tag, ExifD
|
||||
{
|
||||
*ptrEntry = InitExifTag(data, EXIF_IFD_EXIF, tag);
|
||||
if ((*ptrEntry) == nullptr) {
|
||||
HiLog::Debug(LABEL, "Get exif entry failed.");
|
||||
IMAGE_LOGD("Get exif entry failed.");
|
||||
return false;
|
||||
}
|
||||
ExifRational rat;
|
||||
if (!GetFractionFromStr(value, rat)) {
|
||||
HiLog::Debug(LABEL, "Get fraction from value failed.");
|
||||
IMAGE_LOGD("Get fraction from value failed.");
|
||||
return false;
|
||||
}
|
||||
exif_set_rational((*ptrEntry)->data, order, rat);
|
||||
@ -1374,7 +1376,7 @@ bool EXIFInfo::CreateExifEntryOfGpsLatitudeOrLongitude(const ExifTag &tag, ExifD
|
||||
return SetGpsDegreeRational(data, ptrEntry, order, tag, longVec);
|
||||
}
|
||||
if (longVec.size() != CONSTANT_3 || !IsValidGpsData(longVec, tag)) {
|
||||
HiLog::Debug(LABEL, "%{public}s Invalid value %{public}s", GetExifNameByExifTag(tag).c_str(),
|
||||
IMAGE_LOGD("%{public}s Invalid value %{public}s", GetExifNameByExifTag(tag).c_str(),
|
||||
value.c_str());
|
||||
return false;
|
||||
}
|
||||
@ -1400,7 +1402,7 @@ bool EXIFInfo::CreateExifEntry(const ExifTag &tag, ExifData *data, const std::st
|
||||
} else if (std::find(vector1.begin(), vector1.end(), tag) != vector1.end()) {
|
||||
*ptrEntry = InitExifTag(data, GetExifIfdByExifTag(tag), tag);
|
||||
if ((*ptrEntry) == nullptr) {
|
||||
HiLog::Debug(LABEL, "Get %{public}s exif entry failed.", GetExifNameByExifTag(tag).c_str());
|
||||
IMAGE_LOGD("Get %{public}s exif entry failed.", GetExifNameByExifTag(tag).c_str());
|
||||
return false;
|
||||
}
|
||||
ExifIntValueByFormat((*ptrEntry)->data, order, (*ptrEntry)->format, atoi(value.c_str()));
|
||||
@ -1408,11 +1410,11 @@ bool EXIFInfo::CreateExifEntry(const ExifTag &tag, ExifData *data, const std::st
|
||||
} else if (std::find(vector2.begin(), vector2.end(), tag) != vector2.end()) {
|
||||
*ptrEntry = CreateExifTag(data, GetExifIfdByExifTag(tag), tag, value.length(), GetExifFormatByExifTag(tag));
|
||||
if ((*ptrEntry) == nullptr || (*ptrEntry)->size < value.length()) {
|
||||
HiLog::Debug(LABEL, "Get %{public}s exif entry failed.", GetExifNameByExifTag(tag).c_str());
|
||||
IMAGE_LOGD("Get %{public}s exif entry failed.", GetExifNameByExifTag(tag).c_str());
|
||||
return false;
|
||||
}
|
||||
if (memcpy_s((*ptrEntry)->data, value.length(), value.c_str(), value.length()) != 0) {
|
||||
HiLog::Debug(LABEL, "%{public}s memcpy error", GetExifNameByExifTag(tag).c_str());
|
||||
IMAGE_LOGD("%{public}s memcpy error", GetExifNameByExifTag(tag).c_str());
|
||||
}
|
||||
return true;
|
||||
} else if (tag == EXIF_TAG_GPS_LATITUDE || tag == EXIF_TAG_GPS_LONGITUDE) {
|
||||
@ -1434,40 +1436,40 @@ bool EXIFInfo::WriteExifDataToFile(ExifData *data, unsigned int orginExifDataLen
|
||||
unsigned int exifDataBufLength = 0;
|
||||
exif_data_save_data(data, &exifDataBuf, &exifDataBufLength);
|
||||
if (exifDataBuf == nullptr) {
|
||||
HiLog::Debug(LABEL, "Get Exif Data Buf failed!");
|
||||
IMAGE_LOGD("Get Exif Data Buf failed!");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Write EXIF header
|
||||
if (fwrite(EXIF_HEADER, sizeof(EXIF_HEADER), 1, fp) != 1) {
|
||||
HiLog::Debug(LABEL, "Error writing EXIF header to file!");
|
||||
IMAGE_LOGD("Error writing EXIF header to file!");
|
||||
ReleaseExifDataBuffer(exifDataBuf);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Write EXIF block length in big-endian order
|
||||
if (fputc((exifDataBufLength + LENGTH_OFFSET_2) >> MOVE_OFFSET_8, fp) < 0) {
|
||||
HiLog::Debug(LABEL, "Error writing EXIF block length to file!");
|
||||
IMAGE_LOGD("Error writing EXIF block length to file!");
|
||||
ReleaseExifDataBuffer(exifDataBuf);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (fputc((exifDataBufLength + LENGTH_OFFSET_2) & 0xff, fp) < 0) {
|
||||
HiLog::Debug(LABEL, "Error writing EXIF block length to file!");
|
||||
IMAGE_LOGD("Error writing EXIF block length to file!");
|
||||
ReleaseExifDataBuffer(exifDataBuf);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Write EXIF data block
|
||||
if (fwrite(exifDataBuf, exifDataBufLength, 1, fp) != 1) {
|
||||
HiLog::Debug(LABEL, "Error writing EXIF data block to file!");
|
||||
IMAGE_LOGD("Error writing EXIF data block to file!");
|
||||
ReleaseExifDataBuffer(exifDataBuf);
|
||||
return false;
|
||||
}
|
||||
// Write JPEG image data, skipping the non-EXIF header
|
||||
unsigned int dataOffset = orginExifDataLength + sizeof(EXIF_HEADER);
|
||||
if (fwrite(buf + dataOffset, fileLength - dataOffset, 1, fp) != 1) {
|
||||
HiLog::Debug(LABEL, "Error writing JPEG image data to file!");
|
||||
IMAGE_LOGD("Error writing JPEG image data to file!");
|
||||
ReleaseExifDataBuffer(exifDataBuf);
|
||||
return false;
|
||||
}
|
||||
@ -1496,20 +1498,20 @@ void EXIFInfo::UpdateCacheExifData(FILE *fp)
|
||||
{
|
||||
unsigned long fileLength = GetFileSize(fp);
|
||||
if (fileLength == 0 || fileLength > MAX_FILE_SIZE) {
|
||||
HiLog::Debug(LABEL, "Get file size failed.");
|
||||
IMAGE_LOGD("Get file size failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned char *fileBuf = static_cast<unsigned char *>(malloc(fileLength));
|
||||
if (fileBuf == nullptr) {
|
||||
HiLog::Debug(LABEL, "Allocate buf failed.");
|
||||
IMAGE_LOGD("Allocate buf failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Set current position to begin of file.
|
||||
(void)fseek(fp, 0L, 0);
|
||||
if (fread(fileBuf, fileLength, 1, fp) != 1) {
|
||||
HiLog::Debug(LABEL, "Read new file failed.");
|
||||
IMAGE_LOGD("Read new file failed.");
|
||||
free(fileBuf);
|
||||
fileBuf = nullptr;
|
||||
return;
|
||||
@ -1528,13 +1530,13 @@ uint32_t EXIFInfo::GetFilterArea(const uint8_t *buf,
|
||||
std::unique_ptr<ByteOrderedBuffer> byteOrderedBuffer = std::make_unique<ByteOrderedBuffer>(buf, bufSize);
|
||||
byteOrderedBuffer->GenerateDEArray();
|
||||
if (byteOrderedBuffer->directoryEntryArray_.size() == 0) {
|
||||
HiLog::Debug(LABEL, "Read Exif info range failed.");
|
||||
IMAGE_LOGD("Read Exif info range failed.");
|
||||
return ERROR_PARSE_EXIF_FAILED;
|
||||
}
|
||||
|
||||
GetAreaFromExifEntries(privacyType, byteOrderedBuffer->directoryEntryArray_, ranges);
|
||||
if (ranges.size() == 0) {
|
||||
HiLog::Debug(LABEL, "There is no exif info need filtered in this image.");
|
||||
IMAGE_LOGD("There is no exif info need filtered in this image.");
|
||||
return ERROR_NO_EXIF_TAGS;
|
||||
}
|
||||
|
||||
@ -1576,7 +1578,7 @@ void ByteOrderedBuffer::GenerateDEArray()
|
||||
curPosition_ = TIFF_OFFSET_FROM_FILE_BEGIN + CONSTANT_4;
|
||||
int32_t ifd0Offset = ReadInt32();
|
||||
if (ifd0Offset < 0) {
|
||||
HiLog::Debug(LABEL, "Get IFD0 offset failed!");
|
||||
IMAGE_LOGD("Get IFD0 offset failed!");
|
||||
return;
|
||||
}
|
||||
// Transform tiff offset to position of file
|
||||
@ -1585,7 +1587,7 @@ void ByteOrderedBuffer::GenerateDEArray()
|
||||
curPosition_ = static_cast<uint32_t>(ifd0Offset);
|
||||
|
||||
if (curPosition_ + CONSTANT_2 > bufferLength_) {
|
||||
HiLog::Debug(LABEL, "There is no data from the offset: %{public}d.", curPosition_);
|
||||
IMAGE_LOGD("There is no data from the offset: %{public}d.", curPosition_);
|
||||
return;
|
||||
}
|
||||
GetDataRangeFromIFD(EXIF_IFD_0);
|
||||
@ -1596,7 +1598,7 @@ void ByteOrderedBuffer::GetDataRangeFromIFD(const ExifIfd &ifd)
|
||||
handledIfdOffsets_.push_back(curPosition_);
|
||||
int16_t entryCount = ReadShort();
|
||||
if (static_cast<uint32_t>(curPosition_ + BYTE_COUNTS_12 * entryCount) > bufferLength_ || entryCount <= 0) {
|
||||
HiLog::Debug(LABEL, " The size of entries is either too big or negative.");
|
||||
IMAGE_LOGD(" The size of entries is either too big or negative.");
|
||||
return;
|
||||
}
|
||||
GetDataRangeFromDE(ifd, entryCount);
|
||||
@ -1604,7 +1606,7 @@ void ByteOrderedBuffer::GetDataRangeFromIFD(const ExifIfd &ifd)
|
||||
if (Peek() + CONSTANT_4 <= bufferLength_) {
|
||||
int32_t nextIfdOffset = ReadInt32();
|
||||
if (nextIfdOffset == 0) {
|
||||
HiLog::Debug(LABEL, "Stop reading file since this IFD is finished");
|
||||
IMAGE_LOGD("Stop reading file since this IFD is finished");
|
||||
return;
|
||||
}
|
||||
// Transform tiff offset to position of file
|
||||
@ -1620,10 +1622,10 @@ void ByteOrderedBuffer::GetDataRangeFromIFD(const ExifIfd &ifd)
|
||||
ExifIfd nextIfd = GetNextIfdFromLinkList(ifd);
|
||||
GetDataRangeFromIFD(nextIfd);
|
||||
} else {
|
||||
HiLog::Debug(LABEL, "Stop reading buffer since re-reading an IFD at %{public}d.", nextIfdOffset);
|
||||
IMAGE_LOGD("Stop reading buffer since re-reading an IFD at %{public}d.", nextIfdOffset);
|
||||
}
|
||||
} else {
|
||||
HiLog::Debug(LABEL, "Stop reading file since a wrong offset at %{public}d.", nextIfdOffset);
|
||||
IMAGE_LOGD("Stop reading file since a wrong offset at %{public}d.", nextIfdOffset);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1656,7 +1658,7 @@ void ByteOrderedBuffer::GetDataRangeFromDE(const ExifIfd &ifd, const int16_t &co
|
||||
curPosition_ = static_cast<uint32_t>(offset);
|
||||
} else {
|
||||
// Skip if invalid data offset.
|
||||
HiLog::Info(LABEL, "Skip the tag entry since data offset is invalid: %{public}d.", offset);
|
||||
IMAGE_LOGI("Skip the tag entry since data offset is invalid: %{public}d.", offset);
|
||||
curPosition_ = nextEntryOffset;
|
||||
continue;
|
||||
}
|
||||
@ -1694,15 +1696,15 @@ bool ByteOrderedBuffer::SetDEDataByteCount(const uint16_t &tagNumber,
|
||||
uint32_t &count)
|
||||
{
|
||||
if (IsValidTagNumber(tagNumber)) {
|
||||
HiLog::Debug(LABEL, "Skip the tag entry since tag number is not defined: %{public}d.", tagNumber);
|
||||
IMAGE_LOGD("Skip the tag entry since tag number is not defined: %{public}d.", tagNumber);
|
||||
} else if (dataFormat <= 0 || exif_format_get_size(static_cast<ExifFormat>(dataFormat)) == 0) {
|
||||
HiLog::Debug(LABEL, "Skip the tag entry since data format is invalid: %{public}d.", dataFormat);
|
||||
IMAGE_LOGD("Skip the tag entry since data format is invalid: %{public}d.", dataFormat);
|
||||
} else {
|
||||
count = static_cast<uint32_t>(numberOfComponents) *
|
||||
static_cast<uint32_t>(exif_format_get_size(static_cast<ExifFormat>(dataFormat)));
|
||||
if (count < 0) {
|
||||
HiLog::Debug(LABEL, "Skip the tag entry since the number of components is invalid: %{public}d.",
|
||||
numberOfComponents);
|
||||
IMAGE_LOGD("Skip the tag entry since the number of components is invalid: %{public}d.",
|
||||
numberOfComponents);
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
@ -1746,10 +1748,10 @@ void ByteOrderedBuffer::ParseIFDPointerTag(const ExifIfd &ifd, const uint16_t &d
|
||||
curPosition_ = offset;
|
||||
GetDataRangeFromIFD(ifd);
|
||||
} else {
|
||||
HiLog::Debug(LABEL, "Skip jump into the IFD since it has already been read at %{public}d.", offset);
|
||||
IMAGE_LOGD("Skip jump into the IFD since it has already been read at %{public}d.", offset);
|
||||
}
|
||||
} else {
|
||||
HiLog::Debug(LABEL, "Skip jump into the IFD since its offset is invalid: %{public}d.", offset);
|
||||
IMAGE_LOGD("Skip jump into the IFD since its offset is invalid: %{public}d.", offset);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1766,7 +1768,7 @@ bool ByteOrderedBuffer::IsValidTagNumber(const uint16_t &tagNumber)
|
||||
bool ByteOrderedBuffer::IsIFDhandled(const uint32_t &position)
|
||||
{
|
||||
if (handledIfdOffsets_.size() == 0) {
|
||||
HiLog::Debug(LABEL, "There is no handled IFD!");
|
||||
IMAGE_LOGD("There is no handled IFD!");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1835,7 +1837,7 @@ int32_t ByteOrderedBuffer::ReadInt32()
|
||||
// Move current position to begin of next segment
|
||||
curPosition_ += CONSTANT_4;
|
||||
if (curPosition_ > bufferLength_) {
|
||||
HiLog::Debug(LABEL, "Current Position %{public}u out of range.", curPosition_);
|
||||
IMAGE_LOGD("Current Position %{public}u out of range.", curPosition_);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -1862,7 +1864,7 @@ int16_t ByteOrderedBuffer::ReadShort()
|
||||
// Move current position to begin of next segment
|
||||
curPosition_ += CONSTANT_2;
|
||||
if (curPosition_ > bufferLength_) {
|
||||
HiLog::Debug(LABEL, "Current Position %{public}u out of range.", curPosition_);
|
||||
IMAGE_LOGD("Current Position %{public}u out of range.", curPosition_);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -2022,7 +2024,7 @@ static uint32_t SpecialExifData(EXIFInfo* info, const std::string &name, std::st
|
||||
return res;
|
||||
}
|
||||
if (ORIENTATION_INT_MAP.count(orgValue) == 0) {
|
||||
HiLog::Debug(LABEL, "SpecialExifData %{public}s not found %{public}s.",
|
||||
IMAGE_LOGD("SpecialExifData %{public}s not found %{public}s.",
|
||||
name.c_str(), orgValue.c_str());
|
||||
return Media::ERR_IMAGE_DECODE_EXIF_UNSUPPORT;
|
||||
}
|
||||
@ -2053,23 +2055,23 @@ uint32_t EXIFInfo::GetExifData(const std::string name, std::string &value)
|
||||
{
|
||||
auto res = SpecialExifData(this, name, value);
|
||||
if (res == Media::SUCCESS || res != Media::ERR_MEDIA_STATUS_ABNORMAL) {
|
||||
HiLog::Debug(LABEL, "GetExifData %{public}s special result with %{public}d.", name.c_str(), res);
|
||||
IMAGE_LOGD("GetExifData %{public}s special result with %{public}d.", name.c_str(), res);
|
||||
return res;
|
||||
}
|
||||
ExifTag tag;
|
||||
if (!GetExifTagByName(name, tag)) {
|
||||
HiLog::Debug(LABEL, "GetExifData %{public}s not in the TAGs map.", name.c_str());
|
||||
IMAGE_LOGD("GetExifData %{public}s not in the TAGs map.", name.c_str());
|
||||
return Media::ERR_IMAGE_DECODE_EXIF_UNSUPPORT;
|
||||
}
|
||||
DumpTagsMap(exifTags_);
|
||||
if (exifTags_.count(tag) == 0) {
|
||||
HiLog::Debug(LABEL, "GetExifData has no tag %{public}s[%{public}d], tags Size: %{public}zu.",
|
||||
IMAGE_LOGD("GetExifData has no tag %{public}s[%{public}d], tags Size: %{public}zu.",
|
||||
name.c_str(), tag, exifTags_.size());
|
||||
return Media::ERR_IMAGE_DECODE_EXIF_UNSUPPORT;
|
||||
}
|
||||
value = exifTags_.at(tag);
|
||||
if (IsSameTextStr(value, DEFAULT_EXIF_VALUE)) {
|
||||
HiLog::Debug(LABEL, "GetExifData %{public}s[%{public}d] value is DEFAULT_EXIF_VALUE.",
|
||||
IMAGE_LOGD("GetExifData %{public}s[%{public}d] value is DEFAULT_EXIF_VALUE.",
|
||||
name.c_str(), tag);
|
||||
return Media::ERR_MEDIA_VALUE_INVALID;
|
||||
}
|
||||
@ -2080,7 +2082,7 @@ uint32_t EXIFInfo::ModifyExifData(const std::string name, const std::string &val
|
||||
{
|
||||
ExifTag tag;
|
||||
if (!GetExifTagByName(name, tag)) {
|
||||
HiLog::Debug(LABEL, "ModifyExifData %{public}s not in the TAGs map.", name.c_str());
|
||||
IMAGE_LOGD("ModifyExifData %{public}s not in the TAGs map.", name.c_str());
|
||||
return Media::ERR_IMAGE_DECODE_EXIF_UNSUPPORT;
|
||||
}
|
||||
return ModifyExifData(tag, value, path);
|
||||
@ -2090,7 +2092,7 @@ uint32_t EXIFInfo::ModifyExifData(const std::string name, const std::string &val
|
||||
{
|
||||
ExifTag tag;
|
||||
if (!GetExifTagByName(name, tag)) {
|
||||
HiLog::Debug(LABEL, "ModifyExifData %{public}s not in the TAGs map.", name.c_str());
|
||||
IMAGE_LOGD("ModifyExifData %{public}s not in the TAGs map.", name.c_str());
|
||||
return Media::ERR_IMAGE_DECODE_EXIF_UNSUPPORT;
|
||||
}
|
||||
return ModifyExifData(tag, value, fd);
|
||||
@ -2100,7 +2102,7 @@ uint32_t EXIFInfo::ModifyExifData(const std::string name, const std::string &val
|
||||
{
|
||||
ExifTag tag;
|
||||
if (!GetExifTagByName(name, tag)) {
|
||||
HiLog::Debug(LABEL, "ModifyExifData %{public}s not in the TAGs map.", name.c_str());
|
||||
IMAGE_LOGD("ModifyExifData %{public}s not in the TAGs map.", name.c_str());
|
||||
return Media::ERR_IMAGE_DECODE_EXIF_UNSUPPORT;
|
||||
}
|
||||
return ModifyExifData(tag, value, data, size);
|
||||
|
@ -15,17 +15,21 @@
|
||||
#include "exif_maker_note.h"
|
||||
#include <memory>
|
||||
#include "exif_info.h"
|
||||
#include "hilog/log.h"
|
||||
#include "log_tags.h"
|
||||
#include "image_log.h"
|
||||
#include "media_errors.h"
|
||||
#include "securec.h"
|
||||
#include "string_ex.h"
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_PLUGIN
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "ExifMakerNote"
|
||||
|
||||
namespace OHOS {
|
||||
namespace ImagePlugin {
|
||||
using namespace HiviewDFX;
|
||||
using namespace Media;
|
||||
namespace {
|
||||
constexpr HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_IMAGE, "ExifMakerNote" };
|
||||
constexpr unsigned char EXIF_HEADER[] = {'E', 'x', 'i', 'f', '\0', '\0'};
|
||||
constexpr unsigned char HW_MNOTE_HEADER[] = { 'H', 'U', 'A', 'W', 'E', 'I', '\0', '\0' };
|
||||
constexpr unsigned char HW_MNOTE_TIFF_II[] = { 'I', 'I', 0x2A, 0x00, 0x08, 0x00, 0x00, 0x00 };
|
||||
@ -114,7 +118,7 @@ bool ExifMakerNote::ExifItem::GetValue(std::string &value, const ExifByteOrder &
|
||||
{
|
||||
auto *exifData = exif_data_new();
|
||||
if (exifData == nullptr) {
|
||||
HiLog::Error(LABEL, "GetValue, data is null.");
|
||||
IMAGE_LOGE("GetValue, data is null.");
|
||||
return false;
|
||||
}
|
||||
exif_data_set_byte_order(exifData, order);
|
||||
@ -131,7 +135,7 @@ bool ExifMakerNote::ExifItem::GetValue(std::string &value, ExifData *exifData,
|
||||
{
|
||||
auto *exifContent = exif_content_new();
|
||||
if (exifContent == nullptr) {
|
||||
HiLog::Error(LABEL, "GetValue, content is null.");
|
||||
IMAGE_LOGE("GetValue, content is null.");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -153,7 +157,7 @@ bool ExifMakerNote::ExifItem::GetValue(std::string &value, ExifContent *exifCont
|
||||
{
|
||||
auto *exifEntry = exif_entry_new();
|
||||
if (exifEntry == nullptr) {
|
||||
HiLog::Error(LABEL, "GetValue, item is null.");
|
||||
IMAGE_LOGE("GetValue, item is null.");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -202,11 +206,11 @@ void ExifMakerNote::ExifItem::Dump(const std::string &info, const ExifMakerNote:
|
||||
{
|
||||
uint32_t dataOrOffset = 0;
|
||||
if (!ExifMakerNote::GetUInt32(item.data, order, 0, dataOrOffset)) {
|
||||
HiLog::Error(LABEL, "ExifMakerNote::ExifItem::Dump, GetUInt32 failed");
|
||||
IMAGE_LOGE("ExifMakerNote::ExifItem::Dump, GetUInt32 failed");
|
||||
return;
|
||||
}
|
||||
|
||||
HiLog::Debug(LABEL, "%{public}s, "
|
||||
IMAGE_LOGD("%{public}s, "
|
||||
"ifd=0x%{public}x, tag=0x%{public}04x, fmt=%{public}u, cnt=%{public}u, "
|
||||
"dataOrOffset=%{public}u(0x%{public}08x), data=[%{public}s]",
|
||||
info.c_str(),
|
||||
@ -226,24 +230,24 @@ ExifMakerNote::~ExifMakerNote()
|
||||
|
||||
uint32_t ExifMakerNote::Parser(ExifData *exif, const unsigned char *data, uint32_t size)
|
||||
{
|
||||
HiLog::Debug(LABEL, "Parser enter");
|
||||
IMAGE_LOGD("Parser enter");
|
||||
|
||||
bool moreCheck = false;
|
||||
uint32_t res = ParserMakerNote(exif, moreCheck);
|
||||
if ((res == Media::SUCCESS) || (!moreCheck)) {
|
||||
HiLog::Debug(LABEL, "Parser leave");
|
||||
IMAGE_LOGD("Parser leave");
|
||||
return Media::SUCCESS;
|
||||
}
|
||||
|
||||
if ((data == nullptr) || (size < sizeof(EXIF_HEADER))) {
|
||||
HiLog::Error(LABEL, "Parser leave. param invalid");
|
||||
IMAGE_LOGE("Parser leave. param invalid");
|
||||
return Media::ERROR;
|
||||
}
|
||||
|
||||
const unsigned char *newData = nullptr;
|
||||
uint32_t newSize = 0;
|
||||
if (!FindExifLocation(data, size, newData, newSize)) {
|
||||
HiLog::Error(LABEL, "Parser leave. findExifLocation failed");
|
||||
IMAGE_LOGE("Parser leave. findExifLocation failed");
|
||||
return Media::ERROR;
|
||||
}
|
||||
|
||||
@ -258,69 +262,69 @@ uint32_t ExifMakerNote::Parser(ExifData *exif, const unsigned char *data, uint32
|
||||
continue;
|
||||
}
|
||||
|
||||
HiLog::Debug(LABEL, "Parser, find, ifd=%{public}u, tag=0x%{public}04x, fmt=%{public}u, "
|
||||
IMAGE_LOGD("Parser, find, ifd=%{public}u, tag=0x%{public}04x, fmt=%{public}u, "
|
||||
"num=%{public}u, valueOffset=%{public}u, valueLength=%{public}u",
|
||||
de.ifd, de.tag, de.format, de.dataCounts, de.valueOffset, de.valueLength);
|
||||
|
||||
if (ParserMakerNote(data + de.valueOffset, de.valueLength) == Media::SUCCESS) {
|
||||
HiLog::Debug(LABEL, "Parser leave");
|
||||
IMAGE_LOGD("Parser leave");
|
||||
return Media::SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
HiLog::Debug(LABEL, "Parser leave");
|
||||
IMAGE_LOGD("Parser leave");
|
||||
return Media::ERROR;
|
||||
}
|
||||
|
||||
bool ExifMakerNote::FindExifLocation(const unsigned char *data, uint32_t size,
|
||||
const unsigned char *&newData, uint32_t &newSize)
|
||||
{
|
||||
HiLog::Debug(LABEL, "FindExifLocation enter");
|
||||
IMAGE_LOGD("FindExifLocation enter");
|
||||
|
||||
if (size < sizeof(EXIF_HEADER)) {
|
||||
HiLog::Error(LABEL, "FindExifLocation, small. size=%{public}u", size);
|
||||
IMAGE_LOGE("FindExifLocation, small. size=%{public}u", size);
|
||||
return false;
|
||||
}
|
||||
|
||||
const unsigned char *d = data;
|
||||
if (memcmp(d, EXIF_HEADER, sizeof(EXIF_HEADER)) != 0) {
|
||||
if (!FindJpegAPP1(d, size, d, size)) {
|
||||
HiLog::Error(LABEL, "FindExifLocation leave, findJpegAPP1.");
|
||||
IMAGE_LOGE("FindExifLocation leave, findJpegAPP1.");
|
||||
return false;
|
||||
}
|
||||
|
||||
d++;
|
||||
size--;
|
||||
unsigned int len = (d[0] << 8) | d[1];
|
||||
HiLog::Debug(LABEL, "FindExifLocation, len=%{public}u", len);
|
||||
IMAGE_LOGD("FindExifLocation, len=%{public}u", len);
|
||||
|
||||
d += JPEG_TAG_SIZE;
|
||||
size -= JPEG_TAG_SIZE;
|
||||
}
|
||||
|
||||
if (size < EXIF_MIN_SIZE) {
|
||||
HiLog::Error(LABEL, "FindExifLocation, small.");
|
||||
IMAGE_LOGE("FindExifLocation, small.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (memcmp(d, EXIF_HEADER, sizeof(EXIF_HEADER)) != 0) {
|
||||
HiLog::Error(LABEL, "FindExifLocation, no found EXIF header");
|
||||
IMAGE_LOGE("FindExifLocation, no found EXIF header");
|
||||
return false;
|
||||
}
|
||||
|
||||
HiLog::Debug(LABEL, "FindExifLocation, Found EXIF header");
|
||||
IMAGE_LOGD("FindExifLocation, Found EXIF header");
|
||||
|
||||
newData = d;
|
||||
newSize = size;
|
||||
|
||||
HiLog::Debug(LABEL, "FindExifLocation leave");
|
||||
IMAGE_LOGD("FindExifLocation leave");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ExifMakerNote::FindJpegAPP1(const unsigned char *data, uint32_t size,
|
||||
const unsigned char *&newData, uint32_t &newSize)
|
||||
{
|
||||
HiLog::Debug(LABEL, "FindJpegAPP1 enter");
|
||||
IMAGE_LOGD("FindJpegAPP1 enter");
|
||||
|
||||
while (size >= JPEG_CHECK_MIN_SIZE) {
|
||||
while (size && (data[0] == 0xff)) {
|
||||
@ -343,7 +347,7 @@ bool ExifMakerNote::FindJpegAPP1(const unsigned char *data, uint32_t size,
|
||||
size--;
|
||||
unsigned int l = (data[0] << 8) | data[1];
|
||||
if (l > size) {
|
||||
HiLog::Error(LABEL, "FindJpegAPP1, small.");
|
||||
IMAGE_LOGE("FindJpegAPP1, small.");
|
||||
return false;
|
||||
}
|
||||
data += l;
|
||||
@ -351,71 +355,71 @@ bool ExifMakerNote::FindJpegAPP1(const unsigned char *data, uint32_t size,
|
||||
continue;
|
||||
}
|
||||
|
||||
HiLog::Error(LABEL, "FindJpegAPP1, Unknown.");
|
||||
IMAGE_LOGE("FindJpegAPP1, Unknown.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (size < JPEG_CHECK_MIN_SIZE) {
|
||||
HiLog::Error(LABEL, "FindJpegAPP1, small2.");
|
||||
IMAGE_LOGE("FindJpegAPP1, small2.");
|
||||
return false;
|
||||
}
|
||||
|
||||
newData = data;
|
||||
newSize = size;
|
||||
|
||||
HiLog::Debug(LABEL, "FindJpegAPP1 leave");
|
||||
IMAGE_LOGD("FindJpegAPP1 leave");
|
||||
return true;
|
||||
}
|
||||
|
||||
uint32_t ExifMakerNote::ParserMakerNote(ExifData* exif, bool &moreCheck)
|
||||
{
|
||||
HiLog::Debug(LABEL, "ParserMakerNote enter");
|
||||
IMAGE_LOGD("ParserMakerNote enter");
|
||||
|
||||
moreCheck = false;
|
||||
|
||||
if (exif == nullptr) {
|
||||
HiLog::Fatal(LABEL, "ParserMakerNote, exif is null.");
|
||||
IMAGE_LOGF("ParserMakerNote, exif is null.");
|
||||
return Media::ERROR;
|
||||
}
|
||||
|
||||
auto *ee = exif_data_get_entry (exif, EXIF_TAG_MAKER_NOTE);
|
||||
auto *md = exif_data_get_mnote_data(exif);
|
||||
if ((ee == nullptr) || (md != nullptr)) {
|
||||
HiLog::Debug(LABEL, "ParserMakerNote leave");
|
||||
IMAGE_LOGD("ParserMakerNote leave");
|
||||
return Media::ERROR;
|
||||
}
|
||||
|
||||
HiLog::Info(LABEL, "need parser mnote.");
|
||||
IMAGE_LOGI("need parser mnote.");
|
||||
|
||||
if (ParserMakerNote(ee->data, ee->size) == Media::SUCCESS) {
|
||||
HiLog::Debug(LABEL, "ParserMakerNote leave");
|
||||
IMAGE_LOGD("ParserMakerNote leave");
|
||||
return Media::SUCCESS;
|
||||
}
|
||||
|
||||
moreCheck = true;
|
||||
|
||||
HiLog::Debug(LABEL, "ParserMakerNote leave");
|
||||
IMAGE_LOGD("ParserMakerNote leave");
|
||||
return Media::ERROR;
|
||||
}
|
||||
|
||||
uint32_t ExifMakerNote::ParserMakerNote(const unsigned char *data, uint32_t size)
|
||||
{
|
||||
HiLog::Debug(LABEL, "ParserMakerNote enter");
|
||||
IMAGE_LOGD("ParserMakerNote enter");
|
||||
|
||||
if (!IsHwMakerNote(data, size)) {
|
||||
HiLog::Debug(LABEL, "ParserMakerNote leave");
|
||||
IMAGE_LOGD("ParserMakerNote leave");
|
||||
return Media::ERROR;
|
||||
}
|
||||
|
||||
makerNote_.resize(size);
|
||||
if (memcpy_s(makerNote_.data(), makerNote_.size(), data, size) != 0) {
|
||||
HiLog::Error(LABEL, "memcpy error");
|
||||
IMAGE_LOGE("memcpy error");
|
||||
return Media::ERROR;
|
||||
}
|
||||
|
||||
ParserHwMakerNote();
|
||||
|
||||
HiLog::Debug(LABEL, "ParserMakerNote leave");
|
||||
IMAGE_LOGD("ParserMakerNote leave");
|
||||
return Media::SUCCESS;
|
||||
}
|
||||
|
||||
@ -426,22 +430,22 @@ bool ExifMakerNote::IsParsed() const
|
||||
|
||||
bool ExifMakerNote::IsHwMakerNote(const unsigned char *data, uint32_t size)
|
||||
{
|
||||
HiLog::Debug(LABEL, "IsHwMakerNote enter");
|
||||
IMAGE_LOGD("IsHwMakerNote enter");
|
||||
|
||||
tiff_offset_ = 0;
|
||||
ifd0_offset_ = 0;
|
||||
|
||||
if (sizeof(HW_MNOTE_TIFF_II) != sizeof(HW_MNOTE_TIFF_MM)) {
|
||||
HiLog::Fatal(LABEL, "IsHwMakerNote leave, same");
|
||||
IMAGE_LOGF("IsHwMakerNote leave, same");
|
||||
return false;
|
||||
}
|
||||
if (size < (sizeof(HW_MNOTE_HEADER) + sizeof(HW_MNOTE_TIFF_II))) {
|
||||
HiLog::Debug(LABEL, "IsHwMakerNote leave, size");
|
||||
IMAGE_LOGD("IsHwMakerNote leave, size");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (memcmp(data, HW_MNOTE_HEADER, sizeof(HW_MNOTE_HEADER)) != 0) {
|
||||
HiLog::Debug(LABEL, "IsHwMakerNote leave, hd");
|
||||
IMAGE_LOGD("IsHwMakerNote leave, hd");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -450,26 +454,26 @@ bool ExifMakerNote::IsHwMakerNote(const unsigned char *data, uint32_t size)
|
||||
if (memcmp((data + tiff_offset_), HW_MNOTE_TIFF_II, sizeof(HW_MNOTE_TIFF_II)) == 0) {
|
||||
order_ = ExifByteOrder::EXIF_BYTE_ORDER_INTEL;
|
||||
ifd0_offset_ = tiff_offset_ + sizeof(HW_MNOTE_TIFF_II);
|
||||
HiLog::Debug(LABEL, "IsHwMakerNote leave, ii, tiff=%{public}u, ifd0=%{public}u", tiff_offset_, ifd0_offset_);
|
||||
IMAGE_LOGD("IsHwMakerNote leave, ii, tiff=%{public}u, ifd0=%{public}u", tiff_offset_, ifd0_offset_);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (memcmp((data+ tiff_offset_), HW_MNOTE_TIFF_MM, sizeof(HW_MNOTE_TIFF_MM)) == 0) {
|
||||
order_ = ExifByteOrder::EXIF_BYTE_ORDER_MOTOROLA;
|
||||
ifd0_offset_ = tiff_offset_ + sizeof(HW_MNOTE_TIFF_MM);
|
||||
HiLog::Debug(LABEL, "IsHwMakerNote leave, mm, tiff=%{public}u, ifd0=%{public}u", tiff_offset_, ifd0_offset_);
|
||||
IMAGE_LOGD("IsHwMakerNote leave, mm, tiff=%{public}u, ifd0=%{public}u", tiff_offset_, ifd0_offset_);
|
||||
return true;
|
||||
}
|
||||
|
||||
HiLog::Error(LABEL, "byte order error");
|
||||
IMAGE_LOGE("byte order error");
|
||||
|
||||
HiLog::Debug(LABEL, "IsHwMakerNote leave, order");
|
||||
IMAGE_LOGD("IsHwMakerNote leave, order");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ExifMakerNote::ParserHwMakerNote()
|
||||
{
|
||||
HiLog::Debug(LABEL, "ParserHwMakerNote enter");
|
||||
IMAGE_LOGD("ParserHwMakerNote enter");
|
||||
|
||||
bool ret = ParserIFD(ifd0_offset_, HW_MNOTE_IFD_DEFAULT);
|
||||
|
||||
@ -485,20 +489,20 @@ bool ExifMakerNote::ParserHwMakerNote()
|
||||
SetValue(entry, value);
|
||||
}
|
||||
|
||||
HiLog::Debug(LABEL, "ParserHwMakerNote leave, ret=%{public}u", ret);
|
||||
IMAGE_LOGD("ParserHwMakerNote leave, ret=%{public}u", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool ExifMakerNote::ParserIFD(uint32_t offset, uint32_t ifd, uint32_t deep)
|
||||
{
|
||||
HiLog::Debug(LABEL, "ParserIFD enter, offset=%{public}u, ifd=%{public}u, deep=%{public}u", offset, ifd, deep);
|
||||
IMAGE_LOGD("ParserIFD enter, offset=%{public}u, ifd=%{public}u, deep=%{public}u", offset, ifd, deep);
|
||||
|
||||
uint16_t count = 0;
|
||||
if (!GetUInt16AndMove(offset, count)) {
|
||||
HiLog::Error(LABEL, "ParserIFD leave, count, false");
|
||||
IMAGE_LOGE("ParserIFD leave, count, false");
|
||||
return false;
|
||||
}
|
||||
HiLog::Debug(LABEL, "ParserIFD, count=%{public}u", count);
|
||||
IMAGE_LOGD("ParserIFD, count=%{public}u", count);
|
||||
|
||||
for (uint16_t i = 0; i < count; i++) {
|
||||
if (ParserItem(offset, ifd, deep)) {
|
||||
@ -506,22 +510,22 @@ bool ExifMakerNote::ParserIFD(uint32_t offset, uint32_t ifd, uint32_t deep)
|
||||
continue;
|
||||
}
|
||||
|
||||
HiLog::Error(LABEL, "ParserIFD leave, entry, false");
|
||||
IMAGE_LOGE("ParserIFD leave, entry, false");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (memcmp(makerNote_.data() + offset, HW_MNOTE_IFD_TAIL, sizeof(HW_MNOTE_IFD_TAIL)) != 0) {
|
||||
HiLog::Error(LABEL, "ParserIFD leave, tail, false");
|
||||
IMAGE_LOGE("ParserIFD leave, tail, false");
|
||||
return false;
|
||||
}
|
||||
|
||||
HiLog::Debug(LABEL, "ParserIFD leave, true");
|
||||
IMAGE_LOGD("ParserIFD leave, true");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ExifMakerNote::ParserItem(uint32_t offset, uint32_t ifd, uint32_t deep)
|
||||
{
|
||||
HiLog::Debug(LABEL, "ParserItem enter, offset=%{public}u, deep=%{public}u, data=[%{public}s]",
|
||||
IMAGE_LOGD("ParserItem enter, offset=%{public}u, deep=%{public}u, data=[%{public}s]",
|
||||
offset, deep, ExifMakerNote::Dump(makerNote_, offset, ENTRY_SIZE).c_str());
|
||||
|
||||
uint16_t tag = 0;
|
||||
@ -529,19 +533,19 @@ bool ExifMakerNote::ParserItem(uint32_t offset, uint32_t ifd, uint32_t deep)
|
||||
uint32_t components = 0;
|
||||
uint32_t dataOrOffset = 0;
|
||||
if (!GetUInt16AndMove(offset, tag)) {
|
||||
HiLog::Error(LABEL, "ParserItem leave, tag, false");
|
||||
IMAGE_LOGE("ParserItem leave, tag, false");
|
||||
return false;
|
||||
}
|
||||
if (!GetUInt16AndMove(offset, format)) {
|
||||
HiLog::Error(LABEL, "ParserItem leave, format, false");
|
||||
IMAGE_LOGE("ParserItem leave, format, false");
|
||||
return false;
|
||||
}
|
||||
if (!GetUInt32AndMove(offset, components)) {
|
||||
HiLog::Error(LABEL, "ParserItem leave, components, false");
|
||||
IMAGE_LOGE("ParserItem leave, components, false");
|
||||
return false;
|
||||
}
|
||||
if (!GetUInt32(offset, dataOrOffset)) {
|
||||
HiLog::Error(LABEL, "ParserItem leave, data, false");
|
||||
IMAGE_LOGE("ParserItem leave, data, false");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -555,18 +559,18 @@ bool ExifMakerNote::ParserItem(uint32_t offset, uint32_t ifd, uint32_t deep)
|
||||
back.Dump("ParserItem", order_);
|
||||
|
||||
if (deep > 0) {
|
||||
HiLog::Debug(LABEL, "ParserItem leave, deep=%{public}u", deep);
|
||||
IMAGE_LOGD("ParserItem leave, deep=%{public}u", deep);
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((back.tag == HW_MNOTE_TAG_SCENE_INFO_OFFSET) || (back.tag == HW_MNOTE_TAG_FACE_INFO_OFFSET)) {
|
||||
if (!ParserIFD((tiff_offset_ + dataOrOffset), back.tag, (deep + 1))) {
|
||||
HiLog::Error(LABEL, "ParserItem leave, ifd, false");
|
||||
IMAGE_LOGE("ParserItem leave, ifd, false");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
HiLog::Debug(LABEL, "ParserItem leave");
|
||||
IMAGE_LOGD("ParserItem leave");
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -627,7 +631,7 @@ bool ExifMakerNote::GetUInt16(const std::vector<unsigned char> &buffer, ExifByte
|
||||
size_t offset, uint16_t &value)
|
||||
{
|
||||
if ((offset + sizeof(uint16_t)) > buffer.size()) {
|
||||
HiLog::Error(LABEL, "GetUInt16 check error.");
|
||||
IMAGE_LOGE("GetUInt16 check error.");
|
||||
return false;
|
||||
}
|
||||
value = exif_get_short(buffer.data() + offset, order);
|
||||
@ -638,7 +642,7 @@ bool ExifMakerNote::GetUInt32(const std::vector<unsigned char> &buffer, ExifByte
|
||||
size_t offset, uint32_t &value)
|
||||
{
|
||||
if ((offset + sizeof(uint32_t)) > buffer.size()) {
|
||||
HiLog::Error(LABEL, "GetUInt32 check error.");
|
||||
IMAGE_LOGE("GetUInt32 check error.");
|
||||
return false;
|
||||
}
|
||||
value = exif_get_long(buffer.data() + offset, order);
|
||||
@ -649,13 +653,13 @@ bool ExifMakerNote::GetData(const std::vector<unsigned char> &buffer, size_t off
|
||||
std::vector<unsigned char> &value)
|
||||
{
|
||||
if ((offset + count) > buffer.size()) {
|
||||
HiLog::Error(LABEL, "GetData check error.");
|
||||
IMAGE_LOGE("GetData check error.");
|
||||
return false;
|
||||
}
|
||||
|
||||
value.resize(count);
|
||||
if (memcpy_s(value.data(), count, buffer.data() + offset, count) != 0) {
|
||||
HiLog::Error(LABEL, "GetData memcpy error.");
|
||||
IMAGE_LOGE("GetData memcpy error.");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -671,12 +675,12 @@ std::string ExifMakerNote::Dump(const std::vector<unsigned char> &data, uint32_t
|
||||
for (size_t loc = 0, cur = offset; ((loc < sum) && (cur < size)); loc++, cur++) {
|
||||
if (loc == 0) {
|
||||
if (sprintf_s(buffer, sizeof(buffer), "%02X", data[cur]) == -1) {
|
||||
HiLog::Error(LABEL, "Dump sprintf error.");
|
||||
IMAGE_LOGE("Dump sprintf error.");
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (sprintf_s(buffer, sizeof(buffer), " %02X", data[cur]) == -1) {
|
||||
HiLog::Error(LABEL, "Dump sprintf error.");
|
||||
IMAGE_LOGE("Dump sprintf error.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -13,18 +13,25 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "icc_profile_info.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdio>
|
||||
#include <cstddef>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "image_log.h"
|
||||
#include "securec.h"
|
||||
#include "jerror.h"
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_PLUGIN
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "IccProfile"
|
||||
|
||||
namespace OHOS {
|
||||
namespace ImagePlugin {
|
||||
namespace {
|
||||
using namespace OHOS::HiviewDFX;
|
||||
constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_IMAGE, "IccProfile" };
|
||||
static constexpr uint32_t ICC_MARKER = JPEG_APP0 + 2;
|
||||
static constexpr uint32_t ICC_MARKER_HEADER_SIZE = 14;
|
||||
static constexpr uint8_t ICC_SIGNATURE[] = {
|
||||
@ -42,7 +49,7 @@ ICCProfileInfo::~ICCProfileInfo()
|
||||
#ifdef IMAGE_COLORSPACE_FLAG
|
||||
sk_sp<SkData> ICCProfileInfo::GetICCData(j_decompress_ptr cinfo)
|
||||
{
|
||||
HiLog::Info(LABEL, "%{public}s begin", __func__);
|
||||
IMAGE_LOGI("%{public}s begin", __func__);
|
||||
unsigned char *icc_profile = NULL;
|
||||
unsigned int icc_data_len = 0;
|
||||
bool isReadIccProfile = false;
|
||||
@ -52,7 +59,7 @@ sk_sp<SkData> ICCProfileInfo::GetICCData(j_decompress_ptr cinfo)
|
||||
// copy ICC profile data
|
||||
data = SkData::MakeWithCopy(icc_profile, icc_data_len);
|
||||
} else {
|
||||
HiLog::Error(LABEL, "ERROR: jpeg_read_icc_profile failed!");
|
||||
IMAGE_LOGE("ERROR: jpeg_read_icc_profile failed!");
|
||||
}
|
||||
|
||||
// clean up
|
||||
@ -62,7 +69,7 @@ sk_sp<SkData> ICCProfileInfo::GetICCData(j_decompress_ptr cinfo)
|
||||
|
||||
uint32_t ICCProfileInfo::ParsingICCProfile(j_decompress_ptr cinfo)
|
||||
{
|
||||
HiLog::Info(LABEL, "%{public}s begin", __func__);
|
||||
IMAGE_LOGI("%{public}s begin", __func__);
|
||||
|
||||
// read icc data to skdata
|
||||
sk_sp<SkData> profile = GetICCData(cinfo);
|
||||
@ -81,7 +88,7 @@ uint32_t ICCProfileInfo::ParsingICCProfile(j_decompress_ptr cinfo)
|
||||
if (skColorSpace != nullptr) {
|
||||
parseResult = OHOS::Media::SUCCESS;
|
||||
} else {
|
||||
HiLog::Error(LABEL, "ERROR: ParsingICCProfile skColorSpace is Null!");
|
||||
IMAGE_LOGE("ERROR: ParsingICCProfile skColorSpace is Null!");
|
||||
}
|
||||
grColorSpace_ = OHOS::ColorManager::ColorSpace(skColorSpace);
|
||||
return parseResult;
|
||||
@ -99,7 +106,7 @@ bool ICCProfileInfo::IsSupportICCProfile()
|
||||
|
||||
uint32_t ICCProfileInfo::PackingICCProfile(j_compress_ptr cinfo, const SkImageInfo& info)
|
||||
{
|
||||
HiLog::Info(LABEL, "%{public}s begin", __func__);
|
||||
IMAGE_LOGI("%{public}s begin", __func__);
|
||||
uint32_t packingResult = OHOS::Media::ERR_IMAGE_ENCODE_ICC_FAILED;
|
||||
|
||||
// write colorspace to SKData
|
||||
@ -120,7 +127,7 @@ uint32_t ICCProfileInfo::PackingICCProfile(j_compress_ptr cinfo, const SkImageIn
|
||||
jpeg_write_marker(cinfo, ICC_MARKER, jpegMarkerData->bytes(), jpegMarkerData->size());
|
||||
packingResult = OHOS::Media::SUCCESS;
|
||||
} else {
|
||||
HiLog::Error(LABEL, "ERROR: PackingICCProfile icc profile is Null!");
|
||||
IMAGE_LOGE("ERROR: PackingICCProfile icc profile is Null!");
|
||||
}
|
||||
return packingResult;
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user