mirror of
https://gitee.com/openharmony/multimedia_image_framework
synced 2024-11-23 06:59:52 +00:00
add DFT
Signed-off-by: Tombaugh <tangbo23@huawei.com> Change-Id: I85cdda78be38e772fc00346b13d15749c0223679
This commit is contained in:
parent
b5df8ec7b4
commit
48d1bd2a85
@ -24,7 +24,6 @@
|
||||
#include "media_errors.h"
|
||||
#include "ostream_packer_stream.h"
|
||||
#include "plugin_server.h"
|
||||
#include "image_data_statistics.h"
|
||||
#if defined(ANDROID_PLATFORM) || defined(IOS_PLATFORM)
|
||||
#include "include/jpeg_encoder.h"
|
||||
#endif
|
||||
@ -246,7 +245,6 @@ uint32_t ImagePacker::FinalizePacking()
|
||||
|
||||
uint32_t ImagePacker::FinalizePacking(int64_t &packedSize)
|
||||
{
|
||||
ImageDataStatistics imageDataStatistics("[ImagePacker]FinalizePacking.");
|
||||
uint32_t ret = FinalizePacking();
|
||||
if (packerStream_ != nullptr) {
|
||||
packerStream_->Flush();
|
||||
|
@ -47,6 +47,7 @@
|
||||
#include "post_proc.h"
|
||||
#include "securec.h"
|
||||
#include "source_stream.h"
|
||||
#include "image_dfx.h"
|
||||
#if defined(ANDROID_PLATFORM) || defined(IOS_PLATFORM)
|
||||
#include "include/jpeg_decoder.h"
|
||||
#else
|
||||
@ -214,14 +215,17 @@ unique_ptr<ImageSource> ImageSource::DoImageSourceCreate(std::function<unique_pt
|
||||
errorCode = ERR_IMAGE_SOURCE_DATA;
|
||||
auto streamPtr = stream();
|
||||
if (streamPtr == nullptr) {
|
||||
ReportCreateImageSourceFault(opts.size.width, opts.size.height, traceName, "stream failed");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto sourcePtr = new (std::nothrow) ImageSource(std::move(streamPtr), opts);
|
||||
if (sourcePtr == nullptr) {
|
||||
IMAGE_LOGE("[ImageSource]failed to create ImageSource.");
|
||||
ReportCreateImageSourceFault(opts.size.width, opts.size.height, traceName, "failed to create ImageSource");
|
||||
return nullptr;
|
||||
}
|
||||
sourcePtr->SetSource(traceName);
|
||||
errorCode = SUCCESS;
|
||||
return unique_ptr<ImageSource>(sourcePtr);
|
||||
}
|
||||
@ -563,6 +567,8 @@ uint64_t ImageSource::GetNowTimeMicroSeconds()
|
||||
|
||||
unique_ptr<PixelMap> ImageSource::CreatePixelMapExtended(uint32_t index, const DecodeOptions &opts, uint32_t &errorCode)
|
||||
{
|
||||
ImageEvent imageEvent;
|
||||
SetDecodeInfoOptions(index, opts, imageEvent);
|
||||
ImageDataStatistics imageDataStatistics("[ImageSource] CreatePixelMapExtended.");
|
||||
uint64_t decodeStartTime = GetNowTimeMicroSeconds();
|
||||
opts_ = opts;
|
||||
@ -571,6 +577,7 @@ unique_ptr<PixelMap> ImageSource::CreatePixelMapExtended(uint32_t index, const D
|
||||
ImageTrace imageTrace("CreatePixelMapExtended, info.size:(%d, %d)", info.size.width, info.size.height);
|
||||
if (errorCode != SUCCESS || !IsSizeVailed(info.size)) {
|
||||
IMAGE_LOGE("[ImageSource]get image info failed, ret:%{public}u.", errorCode);
|
||||
imageEvent.SetDecodeErrorMsg("get image info failed, ret:" + std::to_string(errorCode));
|
||||
errorCode = ERR_IMAGE_DATA_ABNORMAL;
|
||||
return nullptr;
|
||||
}
|
||||
@ -581,6 +588,7 @@ unique_ptr<PixelMap> ImageSource::CreatePixelMapExtended(uint32_t index, const D
|
||||
ImagePlugin::PlImageInfo plInfo;
|
||||
errorCode = SetDecodeOptions(mainDecoder_, index, opts_, plInfo);
|
||||
if (errorCode != SUCCESS) {
|
||||
imageEvent.SetDecodeErrorMsg("set decode options error.ret:" + std::to_string(errorCode));
|
||||
IMAGE_LOGE("[ImageSource]set decode options error (index:%{public}u), ret:%{public}u.", index, errorCode);
|
||||
return nullptr;
|
||||
}
|
||||
@ -591,6 +599,7 @@ unique_ptr<PixelMap> ImageSource::CreatePixelMapExtended(uint32_t index, const D
|
||||
if (context.ifPartialOutput) {
|
||||
NotifyDecodeEvent(decodeListeners_, DecodeEvent::EVENT_PARTIAL_DECODE, &guard);
|
||||
}
|
||||
SetDecodeInfoOptions(index, opts, context, imageEvent);
|
||||
imageDataStatistics.AddTitle("imageSize: [%d, %d], desireSize: [%d, %d], imageFormat: %s, desirePixelFormat: %d," \
|
||||
"memorySize: %d, memoryType: %d", context.outInfo.size.width, context.outInfo.size.height,
|
||||
info.size.width, info.size.height, sourceInfo_.encodedFormat.c_str(), context.pixelFormat,
|
||||
@ -601,6 +610,7 @@ unique_ptr<PixelMap> ImageSource::CreatePixelMapExtended(uint32_t index, const D
|
||||
guard.unlock();
|
||||
if (errorCode != SUCCESS) {
|
||||
IMAGE_LOGE("[ImageSource]decode source fail, ret:%{public}u.", errorCode);
|
||||
imageEvent.SetDecodeErrorMsg("decode source fail, ret:" + std::to_string(errorCode));
|
||||
FreeContextBuffer(context.freeFunc, context.allocatorType, context.pixelsBuffer);
|
||||
return nullptr;
|
||||
}
|
||||
@ -728,6 +738,60 @@ unique_ptr<PixelMap> ImageSource::CreatePixelMapByInfos(ImagePlugin::PlImageInfo
|
||||
return pixelMap;
|
||||
}
|
||||
|
||||
void ImageSource::SetDecodeInfoOptions(uint32_t index, const DecodeOptions &opts, ImageEvent &imageEvent)
|
||||
{
|
||||
DecodeInfoOptions options;
|
||||
options.sampleSize = opts.sampleSize;
|
||||
options.rotate = opts.rotateDegrees;
|
||||
options.editable = opts.editable;
|
||||
options.sourceWidth = opts.CropRect.width;
|
||||
options.sourceHeight = opts.CropRect.height;
|
||||
options.desireSizeWidth = opts.desiredSize.width;
|
||||
options.desireSizeHeight = opts.desiredSize.height;
|
||||
options.desireRegionWidth = opts.desiredRegion.width;
|
||||
options.desireRegionHeight = opts.desiredRegion.height;
|
||||
options.desireRegionX = opts.desiredRegion.left;
|
||||
options.desireRegionY = opts.desiredRegion.top;
|
||||
options.desirePixelFormat = static_cast<int32_t>(opts.desiredPixelFormat);
|
||||
options.index = index;
|
||||
options.fitDensity = opts.fitDensity;
|
||||
options.desireColorSpace = static_cast<int32_t>(opts.desiredColorSpace);
|
||||
options.mimeType = sourceInfo_.encodedFormat;
|
||||
options.memoryType = static_cast<int32_t>(opts.allocatorType);
|
||||
options.invokeType = opts.invokeType;
|
||||
options.imageSource = source_;
|
||||
imageEvent.SetDecodeInfoOptions(options);
|
||||
}
|
||||
|
||||
void ImageSource::SetDecodeInfoOptions(uint32_t index, const DecodeOptions &opts,
|
||||
const ImagePlugin::DecodeContext &context, ImageEvent &imageEvent)
|
||||
{
|
||||
DecodeInfoOptions options;
|
||||
options.sampleSize = opts.sampleSize;
|
||||
options.rotate = opts.rotateDegrees;
|
||||
options.editable = opts.editable;
|
||||
options.sourceWidth = context.info.size.width;
|
||||
options.sourceHeight = context.info.size.height;
|
||||
options.desireSizeWidth = context.outInfo.size.width;
|
||||
options.desireSizeHeight = context.outInfo.size.width;
|
||||
options.desireRegionWidth = opts.desiredRegion.width;
|
||||
options.desireRegionHeight = opts.desiredRegion.height;
|
||||
options.desireRegionX = opts.desiredRegion.left;
|
||||
options.desireRegionY = opts.desiredRegion.top;
|
||||
options.desirePixelFormat = static_cast<int32_t>(opts.desiredPixelFormat);
|
||||
options.index = index;
|
||||
options.fitDensity = opts.fitDensity;
|
||||
options.desireColorSpace = static_cast<int32_t>(opts.desiredColorSpace);
|
||||
options.mimeType = sourceInfo_.encodedFormat;
|
||||
options.memorySize = context.pixelsBuffer.bufferSize;
|
||||
options.memoryType = static_cast<int32_t>(context.allocatorType);
|
||||
options.invokeType = opts.invokeType;
|
||||
options.imageSource = source_;
|
||||
options.isHardDecode = context.isHardDecode;
|
||||
options.hardDecodeError = context.hardDecodeError;
|
||||
imageEvent.SetDecodeInfoOptions(options);
|
||||
}
|
||||
|
||||
unique_ptr<PixelMap> ImageSource::CreatePixelMap(uint32_t index, const DecodeOptions &opts, uint32_t &errorCode)
|
||||
{
|
||||
std::unique_lock<std::mutex> guard(decodingMutex_);
|
||||
@ -748,19 +812,25 @@ unique_ptr<PixelMap> ImageSource::CreatePixelMap(uint32_t index, const DecodeOpt
|
||||
return CreatePixelMapExtended(index, opts, errorCode);
|
||||
}
|
||||
}
|
||||
|
||||
ImageEvent imageEvent;
|
||||
SetDecodeInfoOptions(index, opts, imageEvent);
|
||||
if (opts.desiredPixelFormat == PixelFormat::NV12 || opts.desiredPixelFormat == PixelFormat::NV21) {
|
||||
IMAGE_LOGE("[ImageSource] get YUV420 not support without going through CreatePixelMapExtended");
|
||||
imageEvent.SetDecodeErrorMsg("get YUV420 not support without going through CreatePixelMapExtended");
|
||||
return nullptr;
|
||||
}
|
||||
// the mainDecoder_ may be borrowed by Incremental decoding, so needs to be checked.
|
||||
if (InitMainDecoder() != SUCCESS) {
|
||||
IMAGE_LOGE("[ImageSource]image decode plugin is null.");
|
||||
imageEvent.SetDecodeErrorMsg("image decode plugin is null.");
|
||||
errorCode = ERR_IMAGE_PLUGIN_CREATE_FAILED;
|
||||
return nullptr;
|
||||
}
|
||||
unique_ptr<PixelMap> pixelMap = make_unique<PixelMap>();
|
||||
if (pixelMap == nullptr || pixelMap.get() == nullptr) {
|
||||
IMAGE_LOGE("[ImageSource]create the pixel map unique_ptr fail.");
|
||||
imageEvent.SetDecodeErrorMsg("create the pixel map unique_ptr fail.");
|
||||
errorCode = ERR_IMAGE_MALLOC_ABNORMAL;
|
||||
return nullptr;
|
||||
}
|
||||
@ -769,6 +839,7 @@ unique_ptr<PixelMap> ImageSource::CreatePixelMap(uint32_t index, const DecodeOpt
|
||||
errorCode = SetDecodeOptions(mainDecoder_, index, opts_, plInfo);
|
||||
if (errorCode != SUCCESS) {
|
||||
IMAGE_LOGE("[ImageSource]set decode options error (index:%{public}u), ret:%{public}u.", index, errorCode);
|
||||
imageEvent.SetDecodeErrorMsg("set decode options error, ret:." + std::to_string(errorCode));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -786,6 +857,7 @@ unique_ptr<PixelMap> ImageSource::CreatePixelMap(uint32_t index, const DecodeOpt
|
||||
errorCode = UpdatePixelMapInfo(opts_, plInfo, *(pixelMap.get()));
|
||||
if (errorCode != SUCCESS) {
|
||||
IMAGE_LOGE("[ImageSource]update pixelmap info error ret:%{public}u.", errorCode);
|
||||
imageEvent.SetDecodeErrorMsg("update pixelmap info error, ret:." + std::to_string(errorCode));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -813,6 +885,7 @@ unique_ptr<PixelMap> ImageSource::CreatePixelMap(uint32_t index, const DecodeOpt
|
||||
guard.lock();
|
||||
}
|
||||
}
|
||||
SetDecodeInfoOptions(index, opts, context, imageEvent);
|
||||
if (!useSkia) {
|
||||
ninePatchInfo_.ninePatch = context.ninePatchContext.ninePatch;
|
||||
ninePatchInfo_.patchSize = context.ninePatchContext.patchSize;
|
||||
@ -820,6 +893,7 @@ unique_ptr<PixelMap> ImageSource::CreatePixelMap(uint32_t index, const DecodeOpt
|
||||
guard.unlock();
|
||||
if (errorCode != SUCCESS) {
|
||||
IMAGE_LOGE("[ImageSource]decode source fail, ret:%{public}u.", errorCode);
|
||||
imageEvent.SetDecodeErrorMsg("decode source fail, ret:." + std::to_string(errorCode));
|
||||
if (context.pixelsBuffer.buffer != nullptr) {
|
||||
if (context.freeFunc != nullptr) {
|
||||
context.freeFunc(context.pixelsBuffer.buffer, context.pixelsBuffer.context,
|
||||
@ -1148,7 +1222,6 @@ uint32_t ImageSource::GetImagePropertyCommon(uint32_t index, const std::string &
|
||||
uint32_t ImageSource::GetImagePropertyInt(uint32_t index, const std::string &key, int32_t &value)
|
||||
{
|
||||
std::unique_lock<std::mutex> guard(decodingMutex_);
|
||||
ImageDataStatistics imageDataStatistics("[ImageSource]GetImagePropertyInt.");
|
||||
|
||||
if (key.empty()) {
|
||||
return Media::ERR_IMAGE_DECODE_EXIF_UNSUPPORT;
|
||||
@ -1180,7 +1253,6 @@ uint32_t ImageSource::GetImagePropertyInt(uint32_t index, const std::string &key
|
||||
uint32_t ImageSource::GetImagePropertyString(uint32_t index, const std::string &key, std::string &value)
|
||||
{
|
||||
std::unique_lock<std::mutex> guard(decodingMutex_);
|
||||
ImageDataStatistics imageDataStatistics("[ImageSource]GetImagePropertyString.");
|
||||
return GetImagePropertyCommon(index, key, value);
|
||||
}
|
||||
|
||||
@ -1858,6 +1930,8 @@ uint32_t ImageSource::DoIncrementalDecoding(uint32_t index, const DecodeOptions
|
||||
IncrementalDecodingContext &recordContext)
|
||||
{
|
||||
IMAGE_LOGD("[ImageSource]do incremental decoding: begin.");
|
||||
ImageEvent imageEvent;
|
||||
imageEvent.SetIncrementalDecode();
|
||||
uint8_t *pixelAddr = static_cast<uint8_t *>(pixelMap.GetWritablePixels());
|
||||
ProgDecodeContext context;
|
||||
context.decodeContext.pixelsBuffer.buffer = pixelAddr;
|
||||
@ -1869,9 +1943,11 @@ uint32_t ImageSource::DoIncrementalDecoding(uint32_t index, const DecodeOptions
|
||||
}
|
||||
IMAGE_LOGD("[ImageSource]do incremental decoding progress:%{public}u.", context.totalProcessProgress);
|
||||
recordContext.decodingProgress = context.totalProcessProgress;
|
||||
SetDecodeInfoOptions(index, opts, context.decodeContext, imageEvent);
|
||||
if (ret != SUCCESS && ret != ERR_IMAGE_SOURCE_DATA_INCOMPLETE) {
|
||||
recordContext.IncrementalState = ImageDecodingState::IMAGE_ERROR;
|
||||
IMAGE_LOGE("[ImageSource]do incremental decoding source fail, ret:%{public}u.", ret);
|
||||
imageEvent.SetDecodeErrorMsg("do incremental decoding source fail, ret:" + std::to_string(ret));
|
||||
return ret;
|
||||
}
|
||||
if (ret == SUCCESS) {
|
||||
@ -2488,6 +2564,11 @@ uint32_t ImageSource::GetFrameCount(uint32_t &errorCode)
|
||||
return frameCount;
|
||||
}
|
||||
|
||||
void ImageSource::SetSource(const std::string &source)
|
||||
{
|
||||
source_ = source;
|
||||
}
|
||||
|
||||
void ImageSource::DumpInputData(const std::string &fileSuffix)
|
||||
{
|
||||
if (!ImageSystemProperties::GetDumpImageEnabled()) {
|
||||
|
@ -17,7 +17,6 @@
|
||||
#include "image_log.h"
|
||||
#include "media_errors.h"
|
||||
#include "native_image.h"
|
||||
#include "image_data_statistics.h"
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_IMAGE
|
||||
@ -309,7 +308,6 @@ int32_t NativeImage::GetTimestamp(int64_t ×tamp)
|
||||
|
||||
NativeComponent* NativeImage::GetComponent(int32_t type)
|
||||
{
|
||||
ImageDataStatistics imageDataStatistics("[NativeImage] GetComponent by type %d", type);
|
||||
if (buffer_ == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -19,7 +19,6 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include "image_log.h"
|
||||
#include "image_data_statistics.h"
|
||||
#include "image_system_properties.h"
|
||||
#include "image_trace.h"
|
||||
#include "image_type_converter.h"
|
||||
@ -327,21 +326,9 @@ int32_t PixelMap::GetAllocatedByteCount(const ImageInfo& info)
|
||||
}
|
||||
}
|
||||
|
||||
static PixelFormat SetPixelFormat(BUILD_PARAM &info, const InitializationOptions &opts)
|
||||
{
|
||||
PixelFormat format = PixelFormat::BGRA_8888;
|
||||
if (info.flag_) {
|
||||
format = ((opts.srcPixelFormat == PixelFormat::UNKNOWN) ? PixelFormat::BGRA_8888 : opts.srcPixelFormat);
|
||||
}
|
||||
|
||||
return format;
|
||||
}
|
||||
|
||||
unique_ptr<PixelMap> PixelMap::Create(const uint32_t *colors, uint32_t colorLength, BUILD_PARAM &info,
|
||||
const InitializationOptions &opts, int &errorCode)
|
||||
{
|
||||
ImageDataStatistics imageDataStatistics("[PixelMap]Create width = %d, height = %d, pixelformat = %d," \
|
||||
"alphaType = %d", info.width_, opts.size.height, opts.pixelFormat, opts.alphaType);
|
||||
int offset = info.offset_;
|
||||
if (!CheckParams(colors, colorLength, offset, info.width_, opts)) {
|
||||
return nullptr;
|
||||
@ -353,8 +340,10 @@ unique_ptr<PixelMap> PixelMap::Create(const uint32_t *colors, uint32_t colorLeng
|
||||
errorCode = IMAGE_RESULT_PLUGIN_REGISTER_FAILED;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PixelFormat format = SetPixelFormat(info, opts);
|
||||
PixelFormat format = PixelFormat::BGRA_8888;
|
||||
if (info.flag_) {
|
||||
format = ((opts.srcPixelFormat == PixelFormat::UNKNOWN) ? PixelFormat::BGRA_8888 : opts.srcPixelFormat);
|
||||
}
|
||||
ImageInfo srcImageInfo =
|
||||
MakeImageInfo(info.width_, opts.size.height, format, AlphaType::IMAGE_ALPHA_TYPE_UNPREMUL);
|
||||
PixelFormat dstPixelFormat = (opts.pixelFormat == PixelFormat::UNKNOWN ? PixelFormat::RGBA_8888 : opts.pixelFormat);
|
||||
@ -376,7 +365,6 @@ unique_ptr<PixelMap> PixelMap::Create(const uint32_t *colors, uint32_t colorLeng
|
||||
errorCode = IMAGE_RESULT_ERR_SHAMEM_NOT_EXIST;
|
||||
return nullptr;
|
||||
}
|
||||
imageDataStatistics.SetRequestMemory(bufferSize);
|
||||
int32_t dstLength = PixelConvert::PixelsConvert(reinterpret_cast<const void *>(colors + offset),
|
||||
colorLength, srcImageInfo, dstPixels, dstImageInfo);
|
||||
if (dstLength < 0) {
|
||||
@ -475,9 +463,6 @@ bool PixelMap::CheckParams(const uint32_t *colors, uint32_t colorLength, int32_t
|
||||
unique_ptr<PixelMap> PixelMap::Create(const InitializationOptions &opts)
|
||||
{
|
||||
IMAGE_LOGD("PixelMap::Create3 enter");
|
||||
ImageDataStatistics imageDataStatistics("[PixelMap]Create3 width = %d, height = %d, pixelformat = %d," \
|
||||
"alphaType = %d",
|
||||
opts.size.width, opts.size.height, opts.pixelFormat, opts.alphaType);
|
||||
unique_ptr<PixelMap> dstPixelMap = make_unique<PixelMap>();
|
||||
if (dstPixelMap == nullptr) {
|
||||
IMAGE_LOGE("create pixelMap pointer fail");
|
||||
@ -503,7 +488,6 @@ unique_ptr<PixelMap> PixelMap::Create(const InitializationOptions &opts)
|
||||
IMAGE_LOGE("allocate memory size %{public}u fail", bufferSize);
|
||||
return nullptr;
|
||||
}
|
||||
imageDataStatistics.SetRequestMemory(bufferSize);
|
||||
// update alpha opaque
|
||||
UpdatePixelsAlpha(dstImageInfo.alphaType, dstImageInfo.pixelFormat,
|
||||
static_cast<uint8_t *>(dstPixels), *dstPixelMap.get());
|
||||
@ -578,9 +562,6 @@ unique_ptr<PixelMap> PixelMap::Create(PixelMap &source, const Rect &srcRect, con
|
||||
int32_t &errorCode)
|
||||
{
|
||||
IMAGE_LOGD("PixelMap::Create5 enter");
|
||||
ImageDataStatistics imageDataStatistics("[PixelMap] Create5 width = %d, height = %d, pixelformat = %d," \
|
||||
"alphaType = %d",
|
||||
opts.size.width, opts.size.height, opts.pixelFormat, opts.alphaType);
|
||||
ImageInfo srcImageInfo;
|
||||
source.GetImageInfo(srcImageInfo);
|
||||
PostProc postProc;
|
||||
@ -627,10 +608,6 @@ unique_ptr<PixelMap> PixelMap::Create(PixelMap &source, const Rect &srcRect, con
|
||||
bool PixelMap::SourceCropAndConvert(PixelMap &source, const ImageInfo &srcImageInfo, const ImageInfo &dstImageInfo,
|
||||
const Rect &srcRect, PixelMap &dstPixelMap)
|
||||
{
|
||||
ImageDataStatistics imageDataStatistics("[PixelMap] SourceCropAndConvert width = %d, height = %d," \
|
||||
"pixelformat = %d, alphaType = %d",
|
||||
srcImageInfo.size.width, srcImageInfo.size.height, srcImageInfo.pixelFormat,
|
||||
srcImageInfo.alphaType);
|
||||
uint32_t bufferSize = dstPixelMap.GetByteCount();
|
||||
if (bufferSize == 0 || (source.GetAllocatorType() == AllocatorType::HEAP_ALLOC &&
|
||||
bufferSize > PIXEL_MAP_MAX_RAM_SIZE)) {
|
||||
@ -648,7 +625,6 @@ bool PixelMap::SourceCropAndConvert(PixelMap &source, const ImageInfo &srcImageI
|
||||
IMAGE_LOGE("source crop allocate memory fail allocatetype: %{public}d ", source.GetAllocatorType());
|
||||
return false;
|
||||
}
|
||||
imageDataStatistics.SetRequestMemory(bufferSize);
|
||||
if (memset_s(dstPixels, bufferSize, 0, bufferSize) != EOK) {
|
||||
IMAGE_LOGE("dstPixels memset_s failed.");
|
||||
}
|
||||
@ -747,10 +723,6 @@ bool PixelMap::CopyPixelMap(PixelMap &source, PixelMap &dstPixelMap)
|
||||
}
|
||||
bool PixelMap::CopyPixelMap(PixelMap &source, PixelMap &dstPixelMap, int32_t &error)
|
||||
{
|
||||
ImageDataStatistics imageDataStatistics("[PixelMap] CopyPixelMap width = %d, height = %d, pixelformat = %d" \
|
||||
"allocatorType = %d",
|
||||
source.GetWidth(), source.GetHeight(), source.GetPixelFormat(),
|
||||
source.GetAllocatorType());
|
||||
uint32_t bufferSize = source.GetByteCount();
|
||||
if (source.GetPixels() == nullptr) {
|
||||
IMAGE_LOGE("source pixelMap data invalid");
|
||||
@ -775,7 +747,6 @@ bool PixelMap::CopyPixelMap(PixelMap &source, PixelMap &dstPixelMap, int32_t &er
|
||||
error = IMAGE_RESULT_MALLOC_ABNORMAL;
|
||||
return false;
|
||||
}
|
||||
imageDataStatistics.SetRequestMemory(bufferSize);
|
||||
void *tmpDstPixels = dstPixels;
|
||||
if (!CopyPixMapToDst(source, tmpDstPixels, fd, bufferSize)) {
|
||||
error = IMAGE_RESULT_ERR_SHAMEM_DATA_ABNORMAL;
|
||||
@ -906,9 +877,6 @@ uint32_t PixelMap::SetRowDataSizeForImageInfo(ImageInfo info)
|
||||
|
||||
uint32_t PixelMap::SetImageInfo(ImageInfo &info, bool isReused)
|
||||
{
|
||||
ImageDataStatistics imageDataStatistics("[PixelMap]SetImageInfo width = %d, height = %d, pixelformat = %d" \
|
||||
"AlphaType = %d, ColorSpace = %d, encodedFormat = %s", info.size.width, info.size.height, info.pixelFormat,
|
||||
info.alphaType, info.colorSpace, info.encodedFormat.c_str());
|
||||
if (info.size.width <= 0 || info.size.height <= 0) {
|
||||
IMAGE_LOGE("pixel map image info invalid.");
|
||||
return ERR_IMAGE_DATA_ABNORMAL;
|
||||
@ -945,8 +913,6 @@ uint32_t PixelMap::SetImageInfo(ImageInfo &info, bool isReused)
|
||||
FreePixelMap();
|
||||
}
|
||||
imageInfo_ = info;
|
||||
imageDataStatistics.AddTitle("width = %d, high = %d, format = %d, colorsapce = %d, type = %d, density = %d",
|
||||
info.size.width, info.size.height, info.pixelFormat, info.colorSpace, info.alphaType, info.baseDensity);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
@ -1439,7 +1405,6 @@ uint32_t PixelMap::ResetConfig(const Size &size, const PixelFormat &format)
|
||||
|
||||
bool PixelMap::SetAlphaType(const AlphaType &alphaType)
|
||||
{
|
||||
ImageDataStatistics imageDataStatistics("[PixelMap]SetAlphaType. alphaType = %d", alphaType);
|
||||
AlphaType type = ImageUtils::GetValidAlphaTypeByFormat(alphaType, imageInfo_.pixelFormat);
|
||||
if (type == AlphaType::IMAGE_ALPHA_TYPE_UNKNOWN) {
|
||||
IMAGE_LOGE("SetAlphaType Failed to get validate alpha type.");
|
||||
@ -2667,7 +2632,6 @@ uint32_t PixelMap::ConvertAlphaFormat(PixelMap &wPixelMap, const bool isPremul)
|
||||
|
||||
uint32_t PixelMap::SetAlpha(const float percent)
|
||||
{
|
||||
ImageDataStatistics imageDataStatistics("[PixelMap]SetAlpha.");
|
||||
auto alphaType = GetAlphaType();
|
||||
if (alphaType == AlphaType::IMAGE_ALPHA_TYPE_UNKNOWN ||
|
||||
alphaType == AlphaType::IMAGE_ALPHA_TYPE_OPAQUE) {
|
||||
@ -2910,7 +2874,6 @@ bool PixelMap::DoTranslation(TransInfos &infos, const AntiAliasingOption &option
|
||||
void PixelMap::scale(float xAxis, float yAxis)
|
||||
{
|
||||
ImageTrace imageTrace("PixelMap scale xAxis = %f, yAxis = %f", xAxis, yAxis);
|
||||
ImageDataStatistics imageDataStatistics("[PixelMap]scale xAxis = %f, yAxis = %f", xAxis, yAxis);
|
||||
TransInfos infos;
|
||||
infos.matrix.setScale(xAxis, yAxis);
|
||||
if (!DoTranslation(infos)) {
|
||||
@ -2921,8 +2884,6 @@ void PixelMap::scale(float xAxis, float yAxis)
|
||||
void PixelMap::scale(float xAxis, float yAxis, const AntiAliasingOption &option)
|
||||
{
|
||||
ImageTrace imageTrace("PixelMap scale with option");
|
||||
ImageDataStatistics imageDataStatistics("[PixelMap]scale with option xAxis = %f, yAxis = %f, option = %d",
|
||||
xAxis, yAxis, option);
|
||||
TransInfos infos;
|
||||
infos.matrix.setScale(xAxis, yAxis);
|
||||
if (!DoTranslation(infos, option)) {
|
||||
@ -2949,7 +2910,6 @@ bool PixelMap::resize(float xAxis, float yAxis)
|
||||
void PixelMap::translate(float xAxis, float yAxis)
|
||||
{
|
||||
ImageTrace imageTrace("PixelMap translate");
|
||||
ImageDataStatistics imageDataStatistics("[PixelMap]translate xAxis = %f, yAxis = %f", xAxis, yAxis);
|
||||
TransInfos infos;
|
||||
infos.matrix.setTranslate(xAxis, yAxis);
|
||||
if (!DoTranslation(infos)) {
|
||||
@ -2960,7 +2920,6 @@ void PixelMap::translate(float xAxis, float yAxis)
|
||||
void PixelMap::rotate(float degrees)
|
||||
{
|
||||
ImageTrace imageTrace("PixelMap rotate");
|
||||
ImageDataStatistics imageDataStatistics("[PixelMap]rotate degree = %f", degrees);
|
||||
TransInfos infos;
|
||||
infos.matrix.setRotate(degrees);
|
||||
if (!DoTranslation(infos)) {
|
||||
@ -2971,7 +2930,6 @@ void PixelMap::rotate(float degrees)
|
||||
void PixelMap::flip(bool xAxis, bool yAxis)
|
||||
{
|
||||
ImageTrace imageTrace("PixelMap flip");
|
||||
ImageDataStatistics imageDataStatistics("[PixelMap]flip.");
|
||||
if (xAxis == false && yAxis == false) {
|
||||
return;
|
||||
}
|
||||
@ -2981,7 +2939,6 @@ void PixelMap::flip(bool xAxis, bool yAxis)
|
||||
uint32_t PixelMap::crop(const Rect &rect)
|
||||
{
|
||||
ImageTrace imageTrace("PixelMap crop");
|
||||
ImageDataStatistics imageDataStatistics("[PixelMap]crop");
|
||||
ImageInfo imageInfo;
|
||||
GetImageInfo(imageInfo);
|
||||
|
||||
|
@ -21,7 +21,6 @@
|
||||
#include "image_utils.h"
|
||||
#include "image_receiver_buffer_processor.h"
|
||||
#include "image_receiver_manager.h"
|
||||
#include "image_data_statistics.h"
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_IMAGE
|
||||
@ -240,7 +239,6 @@ OHOS::sptr<OHOS::SurfaceBuffer> ImageReceiver::ReadNextImage(int64_t ×tamp)
|
||||
|
||||
OHOS::sptr<OHOS::SurfaceBuffer> ImageReceiver::ReadNextImage()
|
||||
{
|
||||
ImageDataStatistics imageDataStatistics("[ImageReceiver]ReadNextImage.");
|
||||
int32_t flushFence = 0;
|
||||
int64_t timestamp = 0;
|
||||
OHOS::Rect damage = {};
|
||||
@ -276,7 +274,6 @@ OHOS::sptr<OHOS::SurfaceBuffer> ImageReceiver::ReadLastImage(int64_t ×tamp)
|
||||
|
||||
OHOS::sptr<OHOS::SurfaceBuffer> ImageReceiver::ReadLastImage()
|
||||
{
|
||||
ImageDataStatistics imageDataStatistics("[ImageReceiver]ReadLastImage.");
|
||||
int32_t flushFence = 0;
|
||||
int64_t timestamp = 0;
|
||||
OHOS::Rect damage = {};
|
||||
@ -317,7 +314,6 @@ std::shared_ptr<IBufferProcessor> ImageReceiver::GetBufferProcessor()
|
||||
|
||||
std::shared_ptr<NativeImage> ImageReceiver::NextNativeImage()
|
||||
{
|
||||
ImageDataStatistics imageDataStatistics("[ImageReceiver]NextNativeImage.");
|
||||
if (GetBufferProcessor() == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
@ -331,7 +327,6 @@ std::shared_ptr<NativeImage> ImageReceiver::NextNativeImage()
|
||||
|
||||
std::shared_ptr<NativeImage> ImageReceiver::LastNativeImage()
|
||||
{
|
||||
ImageDataStatistics imageDataStatistics("[ImageReceiver]LastNativeImage.");
|
||||
if (GetBufferProcessor() == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -1509,6 +1509,55 @@ ohos_unittest("image_receiver_native_test") {
|
||||
external_deps = [ "c_utils:utils" ]
|
||||
}
|
||||
|
||||
ohos_unittest("datastatisticstest") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
cflags = [
|
||||
"-DIMAGE_DEBUG_FLAG",
|
||||
"-DIMAGE_COLORSPACE_FLAG",
|
||||
]
|
||||
|
||||
include_dirs = [ "$image_subsystem/frameworks/innerkitsimpl/utils/include" ]
|
||||
sources = [ "$image_subsystem/frameworks/innerkitsimpl/test/unittest/image_data_statistics_test.cpp" ]
|
||||
|
||||
deps = [
|
||||
"$image_subsystem/frameworks/innerkitsimpl/utils:image_utils",
|
||||
"//third_party/googletest:gmock_main",
|
||||
"//third_party/googletest:gtest_main",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"hilog:libhilog",
|
||||
"ipc:ipc_core",
|
||||
]
|
||||
}
|
||||
|
||||
ohos_unittest("imageeventtest") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
cflags = [
|
||||
"-DIMAGE_DEBUG_FLAG",
|
||||
"-DIMAGE_COLORSPACE_FLAG",
|
||||
]
|
||||
|
||||
include_dirs = [ "$image_subsystem/frameworks/innerkitsimpl/utils/include" ]
|
||||
sources = [ "$image_subsystem/frameworks/innerkitsimpl/test/unittest/image_event_test.cpp" ]
|
||||
|
||||
deps = [
|
||||
"$image_subsystem/frameworks/innerkitsimpl/utils:image_utils",
|
||||
"//third_party/googletest:gmock_main",
|
||||
"//third_party/googletest:gtest_main",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"hilog:libhilog",
|
||||
"hisysevent:libhisysevent",
|
||||
"ipc:ipc_core",
|
||||
]
|
||||
}
|
||||
|
||||
################################################
|
||||
group("unittest") {
|
||||
testonly = true
|
||||
@ -1518,6 +1567,7 @@ group("unittest") {
|
||||
":colorconvertertest",
|
||||
":convertertest",
|
||||
":creatortest",
|
||||
":datastatisticstest",
|
||||
":eglimagetest",
|
||||
":exifmakernotetest",
|
||||
":exifmetadatatest",
|
||||
@ -1529,6 +1579,7 @@ group("unittest") {
|
||||
":image_receiver_native_test",
|
||||
":imageaccessortest",
|
||||
":imagecolorspacetest",
|
||||
":imageeventtest",
|
||||
":imagepixelmapparceltest",
|
||||
":imagepixelmaptest",
|
||||
":imagesourcetest",
|
||||
|
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <string>
|
||||
#include "image_data_statistics.h"
|
||||
|
||||
using namespace OHOS::Media;
|
||||
using namespace testing::ext;
|
||||
namespace OHOS {
|
||||
namespace Multimedia {
|
||||
static const uint32_t BUFFER = 1024 * 1024;
|
||||
static const std::string INPUT_STRING = "hello10,title";
|
||||
class ImageDataStatisticsTest : public testing::Test {
|
||||
public:
|
||||
ImageDataStatisticsTest() {}
|
||||
~ImageDataStatisticsTest() {}
|
||||
};
|
||||
|
||||
/**
|
||||
* @tc.name: DataStatistics001
|
||||
* @tc.desc: SetRequestMemory
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ImageDataStatisticsTest, DataStatistics001, TestSize.Level3)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "ImageDataStatisticsTest: StartPacking001 start";
|
||||
ImageDataStatistics imageDataStatistics(INPUT_STRING);
|
||||
imageDataStatistics.SetRequestMemory(BUFFER);
|
||||
GTEST_LOG_(INFO) << "ImagePackerTest: DataStatistics001 end";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: DataStatistics002
|
||||
* @tc.desc: AddTitle
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ImageDataStatisticsTest, DataStatistics002, TestSize.Level3)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "ImageDataStatisticsTest: StartPacking002 start";
|
||||
ImageDataStatistics imageDataStatistics("%s%d,%s", "hello", 10, "title");
|
||||
imageDataStatistics.AddTitle("datastatisticsTest");
|
||||
GTEST_LOG_(INFO) << "ImagePackerTest: StartPacking002 end";
|
||||
}
|
||||
} // namespace Multimedia
|
||||
} // namespace OHOS
|
83
frameworks/innerkitsimpl/test/unittest/image_event_test.cpp
Normal file
83
frameworks/innerkitsimpl/test/unittest/image_event_test.cpp
Normal file
@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <string>
|
||||
#include "image_dfx.h"
|
||||
|
||||
using namespace OHOS::Media;
|
||||
using namespace testing::ext;
|
||||
namespace OHOS {
|
||||
namespace Multimedia {
|
||||
static const std::string ERROR_MESSAGE = "ImageEventTest SetDecodeErrorMsg";
|
||||
class ImageEventTest : public testing::Test {
|
||||
public:
|
||||
ImageEventTest() {}
|
||||
~ImageEventTest() {}
|
||||
};
|
||||
|
||||
/**
|
||||
* @tc.name: ImageEvent001
|
||||
* @tc.desc: SetDecodeErrorMsg
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ImageEventTest, ImageEvent001, TestSize.Level3)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "ImageEventTest: ImageEvent001 start";
|
||||
ImageEvent imageEvent;
|
||||
imageEvent.SetDecodeErrorMsg(ERROR_MESSAGE);
|
||||
GTEST_LOG_(INFO) << "ImageEventTest: ImageEvent001 end";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ImageEvent002
|
||||
* @tc.desc: SetIncrementalDecode
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ImageEventTest, ImageEvent002, TestSize.Level3)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "ImageEventTest: ImageEvent002 start";
|
||||
ImageEvent imageEvent;
|
||||
imageEvent.SetIncrementalDecode();
|
||||
GTEST_LOG_(INFO) << "ImageEventTest: ImageEvent002 end";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ImageEvent003
|
||||
* @tc.desc: ReportDecodeInfo
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ImageEventTest, ImageEvent003, TestSize.Level3)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "ImageEventTest: ImageEvent003 start";
|
||||
ImageEvent imageEvent;
|
||||
imageEvent.ReportDecodeInfo();
|
||||
GTEST_LOG_(INFO) << "ImageEventTest: ImageEvent003 end";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ImageEvent004
|
||||
* @tc.desc: ReportDecodeFault
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ImageEventTest, ImageEvent004, TestSize.Level3)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "ImageEventTest: ImageEvent004 start";
|
||||
ImageEvent imageEvent;
|
||||
imageEvent.ReportDecodeFault();
|
||||
GTEST_LOG_(INFO) << "ImageEventTest: ImageEvent004 end";
|
||||
}
|
||||
} // namespace Multimedia
|
||||
} // namespace OHOS
|
@ -111,12 +111,14 @@ if (use_clang_ios) {
|
||||
"//foundation/multimedia/image_framework/plugins/manager:pluginmanager",
|
||||
]
|
||||
|
||||
sources += [ "src/image_dfx.cpp" ]
|
||||
sources += [ "src/image_data_statistics.cpp" ]
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"graphic_2d:color_manager",
|
||||
"graphic_surface:surface",
|
||||
"hilog:libhilog",
|
||||
"hisysevent:libhisysevent",
|
||||
"hitrace:hitrace_meter",
|
||||
]
|
||||
|
||||
@ -193,6 +195,7 @@ ohos_static_library("image_utils_static") {
|
||||
sources += [ "//foundation/multimedia/image_framework/frameworks/innerkitsimpl/utils/src/image_trace.cpp" ]
|
||||
} else {
|
||||
sources += [ "//foundation/multimedia/image_framework/frameworks/innerkitsimpl/utils/src/image_trace.cpp" ]
|
||||
sources += [ "src/image_dfx.cpp" ]
|
||||
sources += [ "src/image_data_statistics.cpp" ]
|
||||
deps = [
|
||||
"//foundation/multimedia/image_framework/plugins/manager:pluginmanager",
|
||||
@ -201,6 +204,7 @@ ohos_static_library("image_utils_static") {
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"hilog:libhilog",
|
||||
"hisysevent:libhisysevent",
|
||||
"hitrace:hitrace_meter",
|
||||
]
|
||||
|
||||
|
@ -30,7 +30,6 @@ public:
|
||||
void AddTitle(const std::string title);
|
||||
void AddTitle(const char *fmt, ...);
|
||||
private:
|
||||
uint64_t GetNowTimeMillSeconds();
|
||||
std::string title_;
|
||||
uint64_t startTime_;
|
||||
uint32_t memorySize_;
|
||||
|
76
frameworks/innerkitsimpl/utils/include/image_dfx.h
Normal file
76
frameworks/innerkitsimpl/utils/include/image_dfx.h
Normal file
@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef FRAMEWORKS_INNERKITSIMPL_UTILS_INCLUDE_IMAGE_DFX_H
|
||||
#define FRAMEWORKS_INNERKITSIMPL_UTILS_INCLUDE_IMAGE_DFX_H
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
const uint16_t INNER_INTERFACE = 0;
|
||||
const uint16_t JS_INTERFACE = 1;
|
||||
const uint16_t C_INTERFACE = 2;
|
||||
|
||||
struct DecodeInfoOptions {
|
||||
uint32_t sampleSize;
|
||||
float rotate;
|
||||
bool editable;
|
||||
int32_t sourceWidth;
|
||||
int32_t sourceHeight;
|
||||
int32_t desireSizeWidth;
|
||||
int32_t desireSizeHeight;
|
||||
int32_t desireRegionWidth;
|
||||
int32_t desireRegionHeight;
|
||||
int32_t desireRegionX;
|
||||
int32_t desireRegionY;
|
||||
int32_t desirePixelFormat;
|
||||
uint32_t index;
|
||||
int32_t fitDensity;
|
||||
int32_t desireColorSpace;
|
||||
std::string mimeType;
|
||||
uint32_t memorySize;
|
||||
int32_t memoryType;
|
||||
std::string imageSource;
|
||||
uint16_t invokeType;
|
||||
bool isIncrementalDecode = false;
|
||||
bool isHardDecode;
|
||||
std::string hardDecodeError;
|
||||
std::string errorMsg;
|
||||
};
|
||||
|
||||
class ImageEvent {
|
||||
public:
|
||||
ImageEvent();
|
||||
~ImageEvent();
|
||||
void SetDecodeInfoOptions(const DecodeInfoOptions &options);
|
||||
void SetDecodeErrorMsg(std::string msg);
|
||||
void ReportDecodeFault();
|
||||
void ReportDecodeInfo();
|
||||
void SetIncrementalDecode()
|
||||
{
|
||||
options_.isIncrementalDecode = true;
|
||||
}
|
||||
|
||||
private:
|
||||
DecodeInfoOptions options_;
|
||||
uint64_t startTime_;
|
||||
};
|
||||
|
||||
void ReportCreateImageSourceFault(uint32_t width, uint32_t height, std::string type, std::string message);
|
||||
void ReportEncodeFault(uint32_t width, uint32_t height, std::string mimeType, std::string message);
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
||||
#endif // FRAMEWORKS_INNERKITSIMPL_UTILS_INCLUDE_IMAGE_DFX_H
|
@ -50,6 +50,8 @@ public:
|
||||
static void DumpPixelMapBeforeEncode(PixelMap& pixelMap);
|
||||
static void DumpDataIfDumpEnabled(const char* data, const size_t& totalSize, const std::string& fileSuffix = "dat",
|
||||
uint64_t imageId = 0);
|
||||
static uint64_t GetNowTimeMilliSeconds();
|
||||
static std::string GetCurrentProcessName();
|
||||
|
||||
private:
|
||||
static uint32_t RegisterPluginServer();
|
||||
|
@ -13,10 +13,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <chrono>
|
||||
#include "image_data_statistics.h"
|
||||
|
||||
#include "securec.h"
|
||||
#include "image_log.h"
|
||||
#include "image_data_statistics.h"
|
||||
#include "image_utils.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
@ -26,7 +27,7 @@ static constexpr uint64_t TIME_THRESHOLD_MS = 500;
|
||||
|
||||
ImageDataStatistics::ImageDataStatistics(const std::string &title) : title_(title), memorySize_(0)
|
||||
{
|
||||
startTime_ = GetNowTimeMillSeconds();
|
||||
startTime_ = ImageUtils::GetNowTimeMilliSeconds();
|
||||
}
|
||||
|
||||
ImageDataStatistics::ImageDataStatistics(const char *fmt, ...) : memorySize_(0)
|
||||
@ -46,14 +47,14 @@ ImageDataStatistics::ImageDataStatistics(const char *fmt, ...) : memorySize_(0)
|
||||
title_ = "ImageDataTraceFmt Format Error";
|
||||
}
|
||||
}
|
||||
startTime_ = GetNowTimeMillSeconds();
|
||||
startTime_ = ImageUtils::GetNowTimeMilliSeconds();
|
||||
#endif
|
||||
}
|
||||
|
||||
ImageDataStatistics::~ImageDataStatistics()
|
||||
{
|
||||
#if !defined(_WIN32) && !defined(_APPLE)
|
||||
uint64_t endTime = GetNowTimeMillSeconds();
|
||||
uint64_t endTime = ImageUtils::GetNowTimeMilliSeconds();
|
||||
uint64_t timeInterval = endTime - startTime_;
|
||||
|
||||
if ((memorySize_ != 0) && (memorySize_ > MEMORY_THRESHOLD_BYTE)) {
|
||||
@ -70,12 +71,6 @@ ImageDataStatistics::~ImageDataStatistics()
|
||||
#endif
|
||||
}
|
||||
|
||||
uint64_t ImageDataStatistics::GetNowTimeMillSeconds()
|
||||
{
|
||||
auto now = std::chrono::system_clock::now();
|
||||
return std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count();
|
||||
}
|
||||
|
||||
void ImageDataStatistics::SetRequestMemory(uint32_t size)
|
||||
{
|
||||
memorySize_ = size;
|
||||
|
178
frameworks/innerkitsimpl/utils/src/image_dfx.cpp
Normal file
178
frameworks/innerkitsimpl/utils/src/image_dfx.cpp
Normal file
@ -0,0 +1,178 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "image_dfx.h"
|
||||
|
||||
#include <unistd.h>
|
||||
#include <fstream>
|
||||
#include <chrono>
|
||||
|
||||
#include "hisysevent.h"
|
||||
#include "image_utils.h"
|
||||
#include "image_log.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
static constexpr char IMAGE_FWK_UE[] = "IMAGE_FWK_UE";
|
||||
const static std::string DEFAULT_VERSION_ID = "1";
|
||||
|
||||
ImageEvent::ImageEvent()
|
||||
{
|
||||
startTime_ = ImageUtils::GetNowTimeMilliSeconds();
|
||||
}
|
||||
|
||||
ImageEvent::~ImageEvent()
|
||||
{
|
||||
if (!options_.errorMsg.empty()) {
|
||||
ReportDecodeFault();
|
||||
} else {
|
||||
ReportDecodeInfo();
|
||||
}
|
||||
}
|
||||
|
||||
void ImageEvent::SetDecodeInfoOptions(const DecodeInfoOptions &options)
|
||||
{
|
||||
options_ = options;
|
||||
}
|
||||
|
||||
void ImageEvent::SetDecodeErrorMsg(std::string msg)
|
||||
{
|
||||
options_.errorMsg = msg;
|
||||
}
|
||||
|
||||
void ImageEvent::ReportDecodeFault()
|
||||
{
|
||||
std::string packageName = ImageUtils::GetCurrentProcessName();
|
||||
std::string temp;
|
||||
switch (options_.invokeType) {
|
||||
case (JS_INTERFACE):
|
||||
temp = "js_interface";
|
||||
break;
|
||||
case (C_INTERFACE):
|
||||
temp = "c_interface";
|
||||
break;
|
||||
default:
|
||||
temp = "inner_interface";
|
||||
}
|
||||
|
||||
HiSysEventWrite(IMAGE_FWK_UE,
|
||||
"DECODE_FAULT",
|
||||
OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
|
||||
"PNAMEID", packageName,
|
||||
"PVERSIONID", DEFAULT_VERSION_ID,
|
||||
"APPLICATION_NAME", packageName,
|
||||
"ROTATE", options_.rotate,
|
||||
"EDITABLE", options_.editable,
|
||||
"SAMPLE_SIZE", options_.sampleSize,
|
||||
"SOURCE_WIDTH", options_.sourceWidth,
|
||||
"SOURCE_HEIGHT", options_.sourceHeight,
|
||||
"DESIRE_SIZE_WIDTH", options_.desireSizeWidth,
|
||||
"DESIRE_SIZE_HEIGHT", options_.desireSizeHeight,
|
||||
"DESIRE_REGION_WIDTH", options_.desireRegionWidth,
|
||||
"DESIRE_REGION_HEIGHT", options_.desireRegionHeight,
|
||||
"DESIRE_REGION_X", options_.desireRegionX,
|
||||
"DESIRE_REGION_Y", options_.desireRegionY,
|
||||
"DESIRE_DESIRE_PIXEL_FORMAT", options_.desirePixelFormat,
|
||||
"INDEX", options_.index,
|
||||
"FIT_DENSITY", options_.fitDensity,
|
||||
"DESIRE_COLOR_SPACE", options_.desireColorSpace,
|
||||
"MIMETYPE", options_.mimeType,
|
||||
"MEMORY_SIZE", options_.memorySize,
|
||||
"MEMORY_TYPE", options_.memoryType,
|
||||
"IMAGE_SOURCE", options_.imageSource,
|
||||
"INVOKE_TYPE", temp,
|
||||
"INCREMENTAL_DECODE", options_.isIncrementalDecode,
|
||||
"HARD_DECODE", options_.isHardDecode,
|
||||
"HARD_DECODE_ERROR", options_.hardDecodeError,
|
||||
"ERROR_MSG", options_.errorMsg);
|
||||
}
|
||||
|
||||
void ImageEvent::ReportDecodeInfo()
|
||||
{
|
||||
std::string packageName = ImageUtils::GetCurrentProcessName();
|
||||
uint64_t costTime = ImageUtils::GetNowTimeMilliSeconds() - startTime_;
|
||||
std::string temp;
|
||||
switch (options_.invokeType) {
|
||||
case (JS_INTERFACE):
|
||||
temp = "js_interface";
|
||||
break;
|
||||
case (C_INTERFACE):
|
||||
temp = "c_interface";
|
||||
break;
|
||||
default:
|
||||
temp = "inner_interface";
|
||||
}
|
||||
|
||||
HiSysEventWrite(IMAGE_FWK_UE,
|
||||
"DECODE_INFORMATION",
|
||||
OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
|
||||
"PNAMEID", packageName,
|
||||
"PVERSIONID", DEFAULT_VERSION_ID,
|
||||
"APPLICATION_NAME", packageName,
|
||||
"ROTATE", options_.rotate,
|
||||
"EDITABLE", options_.editable,
|
||||
"SAMPLE_SIZE", options_.sampleSize,
|
||||
"SOURCE_WIDTH", options_.sourceWidth,
|
||||
"SOURCE_HEIGHT", options_.sourceHeight,
|
||||
"DESIRE_SIZE_WIDTH", options_.desireSizeWidth,
|
||||
"DESIRE_SIZE_HEIGHT", options_.desireSizeHeight,
|
||||
"DESIRE_REGION_WIDTH", options_.desireRegionWidth,
|
||||
"DESIRE_REGION_HEIGHT", options_.desireRegionHeight,
|
||||
"DESIRE_REGION_X", options_.desireRegionX,
|
||||
"DESIRE_REGION_Y", options_.desireRegionY,
|
||||
"DESIRE_DESIRE_PIXEL_FORMAT", options_.desirePixelFormat,
|
||||
"INDEX", options_.index,
|
||||
"FIT_DENSITY", options_.fitDensity,
|
||||
"DESIRE_COLOR_SPACE", options_.desireColorSpace,
|
||||
"MIMETYPE", options_.mimeType,
|
||||
"MEMORY_SIZE", options_.memorySize,
|
||||
"MEMORY_TYPE", options_.memoryType,
|
||||
"IMAGE_SOURCE", options_.imageSource,
|
||||
"INVOKE_TYPE", temp,
|
||||
"INCREMENTAL_DECODE", options_.isIncrementalDecode,
|
||||
"HARD_DECODE", options_.isHardDecode,
|
||||
"HARD_DECODE_ERROR", options_.hardDecodeError,
|
||||
"COST_TIME", costTime);
|
||||
}
|
||||
|
||||
void ReportCreateImageSourceFault(uint32_t width, uint32_t height, std::string type, std::string message)
|
||||
{
|
||||
std::string packageName = ImageUtils::GetCurrentProcessName();
|
||||
HiSysEventWrite(IMAGE_FWK_UE,
|
||||
"CREATE_IMAGESOURCE_FAULT",
|
||||
OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
|
||||
"PNAMEID", packageName,
|
||||
"PVERSIONID", DEFAULT_VERSION_ID,
|
||||
"WIDTH", width,
|
||||
"HEIGHT", height,
|
||||
"TYPE", type,
|
||||
"ERROR_MSG", message);
|
||||
}
|
||||
|
||||
void ReportEncodeFault(uint32_t width, uint32_t height, std::string mimeType, std::string message)
|
||||
{
|
||||
std::string packageName = ImageUtils::GetCurrentProcessName();
|
||||
HiSysEventWrite(IMAGE_FWK_UE,
|
||||
"ENCODE_FAULT",
|
||||
OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
|
||||
"PNAMEID", packageName,
|
||||
"PVERSIONID", DEFAULT_VERSION_ID,
|
||||
"WIDTH", width,
|
||||
"HEIGHT", height,
|
||||
"MIME_TYPE", mimeType,
|
||||
"ERROR_MSG", message);
|
||||
}
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
@ -24,6 +24,7 @@
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <chrono>
|
||||
|
||||
#include "__config"
|
||||
#include "image_log.h"
|
||||
@ -422,6 +423,31 @@ void ImageUtils::DumpDataIfDumpEnabled(const char* data, const size_t& totalSize
|
||||
IMAGE_LOGI("ImageUtils::DumpDataIfDumpEnabled success, path = %{public}s", fileName.c_str());
|
||||
}
|
||||
|
||||
uint64_t ImageUtils::GetNowTimeMilliSeconds()
|
||||
{
|
||||
auto now = std::chrono::system_clock::now();
|
||||
return std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count();
|
||||
}
|
||||
|
||||
std::string ImageUtils::GetCurrentProcessName()
|
||||
{
|
||||
std::string processName;
|
||||
std::ifstream cmdlineFile("/proc/self/cmdline");
|
||||
if (cmdlineFile.is_open()) {
|
||||
std::ostringstream oss;
|
||||
oss << cmdlineFile.rdbuf();
|
||||
cmdlineFile.close();
|
||||
|
||||
//Extrace process name from the command line
|
||||
std::string cmdline = oss.str();
|
||||
size_t pos = cmdline.find_first_of('\0');
|
||||
if (pos != std::string::npos) {
|
||||
processName = cmdline.substr(0, pos);
|
||||
}
|
||||
}
|
||||
return processName;
|
||||
}
|
||||
|
||||
uint32_t ImageUtils::SaveDataToFile(const std::string& fileName, const char* data, const size_t& totalSize)
|
||||
{
|
||||
std::ofstream outFile(fileName, std::ofstream::out);
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include "image_log.h"
|
||||
#include "media_errors.h"
|
||||
#include "securec.h"
|
||||
#include "image_dfx.h"
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_IMAGE
|
||||
@ -472,6 +473,7 @@ static int32_t ImageSourceNapiCreatePixelmap(struct ImageSourceArgs* args)
|
||||
index = args->decodingOps->index;
|
||||
}
|
||||
IMAGE_LOGD("ImageSourceNapiCreatePixelmap CreatePixelMapEx");
|
||||
decOps.invokeType = C_INTERFACE;
|
||||
auto tmpPixelmap = native->CreatePixelMapEx(index, decOps, errorCode);
|
||||
if (tmpPixelmap != nullptr) {
|
||||
nativePixelMap = std::move(tmpPixelmap);
|
||||
@ -502,6 +504,7 @@ static int32_t ImageSourceNapiCreatePixelmapList(struct ImageSourceArgs* args)
|
||||
if (args->decodingOps != nullptr) {
|
||||
ParseDecodingOps(decOps, args->decodingOps);
|
||||
}
|
||||
decOps.invokeType = C_INTERFACE;
|
||||
auto pixelMapList = native->CreatePixelMapList(decOps, errorCode);
|
||||
if (pixelMapList == nullptr) {
|
||||
IMAGE_LOGE("ImageSourceNapiCreatePixelmapList CreatePixelMapList failed");
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "image_trace.h"
|
||||
#include "hitrace_meter.h"
|
||||
#include "exif_metadata_formatter.h"
|
||||
#include "image_dfx.h"
|
||||
#include "color_space_object_convertor.h"
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
@ -1331,6 +1332,7 @@ static std::shared_ptr<PixelMap> CreatePixelMapInner(ImageSourceNapi *thisPtr,
|
||||
IMAGE_LOGD("Get Incremental PixelMap!!!");
|
||||
pixelMap = incPixelMap;
|
||||
} else {
|
||||
decodeOpts.invokeType = JS_INTERFACE;
|
||||
pixelMap = imageSource->CreatePixelMapEx((index >= NUM_0) ? index : NUM_0,
|
||||
decodeOpts, status);
|
||||
}
|
||||
@ -2179,6 +2181,7 @@ STATIC_EXEC_FUNC(CreatePixelMapList)
|
||||
uint32_t errorCode = 0;
|
||||
uint32_t frameCount = context->rImageSource->GetFrameCount(errorCode);
|
||||
if ((errorCode == SUCCESS) && (context->index >= NUM_0) && (context->index < frameCount)) {
|
||||
context->decodeOpts.invokeType = JS_INTERFACE;
|
||||
context->pixelMaps = context->rImageSource->CreatePixelMapList(context->decodeOpts, errorCode);
|
||||
}
|
||||
if ((errorCode == SUCCESS) && IMG_NOT_NULL(context->pixelMaps)) {
|
||||
|
@ -18,3 +18,82 @@ DECODED_IMAGE_TYPE_STATISTICS:
|
||||
PNAMEID: {type: STRING, desc: package name}
|
||||
PVERSIONID: {type: STRING, desc: application version}
|
||||
IMAGE_TYPE: {type: STRING, desc: Type of the decoded image for example png jpeg bmp gif ico and wbmp}
|
||||
|
||||
CREATE_IMAGESOURCE_FAULT:
|
||||
__BASE: {type: BEHAVIOR, level: MINOR, desc: Image encoding and decoding cause of the create image source failure, preserve: true}
|
||||
PNAMEID: {type: STRING, desc: package name}
|
||||
PVERSIONID: {type: STRING, desc: application version}
|
||||
WIDTH: {type: UINT32, desc: image width}
|
||||
HEIGHT: {type: UINT32, desc: image height}
|
||||
TYPE: {type: STRING, desc: image formats jpeg png etc}
|
||||
ERROR_MSG: {type: STRING, desc: error message}
|
||||
|
||||
|
||||
ENCODE_FAULT:
|
||||
__BASE: {type: BEHAVIOR, level: MINOR, desc: Image encoding and decoding cause of the encode failure, preserve: true}
|
||||
PNAMEID: {type: STRING, desc: package name}
|
||||
PVERSIONID: {type: STRING, desc: application version}
|
||||
WIDTH: {type: UINT32, desc: image width}
|
||||
HEIGHT: {type: UINT32, desc: image height}
|
||||
MIME_TYPE: {type: STRING, desc: Image formats jpeg png etc}
|
||||
ERROR_MSG: {type: STRING, desc: error message}
|
||||
|
||||
DECODE_FAULT:
|
||||
__BASE: {type: BEHAVIOR, level: MINOR, desc: Image encoding and decoding cause of the decode failure, preserve: true}
|
||||
PNAMEID: {type: STRING, desc: package name}
|
||||
PVERSIONID: {type: STRING, desc: application version}
|
||||
APPLICATION_NAME: {type: STRING, desc: application name}
|
||||
ROTATE: {type: FLOAT, desc: image rorate}
|
||||
EDITABLE: {type: BOOL, desc: IsEditable 0 is No 1 is Yes}
|
||||
SAMPLE_SIZE: {type: UINT32, desc: sample}
|
||||
SOURCE_WIDTH: {type: INT32, desc: source image width}
|
||||
SOURCE_HEIGHT: {type: INT32, desc: source image height}
|
||||
DESIRE_SIZE_WIDTH: {type: INT32, desc: desire image width}
|
||||
DESIRE_SIZE_HEIGHT: {type: INT32, desc: desire image height}
|
||||
DESIRE_REGION_WIDTH: {type: INT32, desc: desire region width}
|
||||
DESIRE_REGION_HEIGHT: {type: INT32, desc: desire region height}
|
||||
DESIRE_REGION_X: {type: INT32, desc: desire region x}
|
||||
DESIRE_REGION_Y: {type: INT32, desc: desire region y}
|
||||
DESIRE_DESIRE_PIXEL_FORMAT: {type: INT32, desc: Expected image pixel format The options are as fol1ows 1 is ARGB_888 3 is RGBA_8888 4 is BGRA_8888 8 is NV21 9 is NV12}
|
||||
INDEX: {type: UINT32, desc: image index}
|
||||
FIT_DENSITY: {type: INT32, desc: fit density}
|
||||
DESIRE_COLOR_SPACE: {type: INT32, desc: Indicates the expected image color space 1 is DISLAY_P3 2 is SRGB 3 is LINEAR SRGB}
|
||||
MIMETYPE: {type: STRING, desc: Image formats jpeg png etc}
|
||||
MEMORY_SIZE: {type: UINT32, desc: memory size}
|
||||
MEMORY_TYPE: {type: INT32, desc: Memory type The options are as follows 1 is heap 2 is sharedMem 4 is Dma}
|
||||
IMAGE_SOURCE: {type: STRING, desc: Image source FD buffer etc}
|
||||
INVOKE_TYPE: {type: STRING, desc: Invocation type JS_inerface c_interface and inner}
|
||||
INCREMENTAL_DECODE: {type: BOOL, desc: Indicates whether to perform incremental decoding The options are as follows 0 is no 1 is yes}
|
||||
HARD_DECODE: {type: BOOL, desc: Whether to perform hard decoding 0 is no 1 is yes}
|
||||
HARD_DECODE_ERROR: {type: STRING, desc: hard decode error message}
|
||||
ERROR_MSG: {type: STRING, desc: error message}
|
||||
|
||||
DECODE_INFORMATION:
|
||||
__BASE: {type: BEHAVIOR, level: MINOR, desc: Image encoding and decoding information statistics. Each application reports data once a day in different formats, preserve: true}
|
||||
PNAMEID: {type: STRING, desc: package name}
|
||||
PVERSIONID: {type: STRING, desc: application version}
|
||||
APPLICATION_NAME: {type: STRING, desc: application name}
|
||||
ROTATE: {type: FLOAT, desc: image rorate}
|
||||
EDITABLE: {type: BOOL, desc: IsEditable 0 is No 1 is Yes}
|
||||
SAMPLE_SIZE: {type: UINT32, desc: sample}
|
||||
SOURCE_WIDTH: {type: INT32, desc: source image width}
|
||||
SOURCE_HEIGHT: {type: INT32, desc: source image height}
|
||||
DESIRE_SIZE_WIDTH: {type: INT32, desc: desire image width}
|
||||
DESIRE_SIZE_HEIGHT: {type: INT32, desc: desire image height}
|
||||
DESIRE_REGION_WIDTH: {type: INT32, desc: desire region width}
|
||||
DESIRE_REGION_HEIGHT: {type: INT32, desc: desire region height}
|
||||
DESIRE_REGION_X: {type: INT32, desc: desire region x}
|
||||
DESIRE_REGION_Y: {type: INT32, desc: desire region y}
|
||||
DESIRE_DESIRE_PIXEL_FORMAT: {type: INT32, desc: Expected image pixel format The options are as fol1ows 1 is ARGB_888 3 is RGBA_8888 4 is BGRA_8888 8 is NV21 9 is NV12}
|
||||
INDEX: {type: UINT32, desc: image index}
|
||||
FIT_DENSITY: {type: INT32, desc: fit density}
|
||||
DESIRE_COLOR_SPACE: {type: INT32, desc: Indicates the expected image color space 1 is DISLAY_P3 2 is SRGB 3 is LINEAR SRGB}
|
||||
MIMETYPE: {type: STRING, desc: Image formats jpeg png etc}
|
||||
MEMORY_SIZE: {type: UINT32, desc: memory size}
|
||||
MEMORY_TYPE: {type: INT32, desc: Memory type The options are as follows 1 is heap 2 is sharedMem 4 is Dma}
|
||||
IMAGE_SOURCE: {type: STRING, desc: Image source FD buffer etc}
|
||||
INVOKE_TYPE: {type: STRING, desc: Invocation type JS_inerface c_interface and inner}
|
||||
INCREMENTAL_DECODE: {type: BOOL, desc: Indicates whether to perform incremental decoding The options are as follows 0 is no 1 is yes}
|
||||
HARD_DECODE: {type: BOOL, desc: Whether to perform hard decoding 0 is no 1 is yes}
|
||||
HARD_DECODE_ERROR: {type: STRING, desc: hard decode error message}
|
||||
COST_TIME: {type: UINT64, desc: decode cost time}
|
@ -45,11 +45,13 @@ class AbsImageDecoder;
|
||||
struct DataStreamBuffer;
|
||||
struct PixelDecodeOptions;
|
||||
struct PlImageInfo;
|
||||
struct DecodeContext;
|
||||
} // namespace ImagePlugin
|
||||
} // namespace OHOS
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
class ImageEvent;
|
||||
struct SourceOptions {
|
||||
std::string formatHint;
|
||||
int32_t baseDensity = 0;
|
||||
@ -208,6 +210,7 @@ public:
|
||||
#ifdef IMAGE_PURGEABLE_PIXELMAP
|
||||
NATIVEEXPORT size_t GetSourceSize() const;
|
||||
#endif
|
||||
void SetSource(const std::string &source);
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_MOVE(ImageSource);
|
||||
@ -272,6 +275,9 @@ private:
|
||||
const std::string &key, const std::string &value);
|
||||
uint32_t ModifyImageProperty(const std::string &key, const std::string &value);
|
||||
uint32_t CreatExifMetadataByImageSource(bool addFlag = false);
|
||||
void SetDecodeInfoOptions(uint32_t index, const DecodeOptions &opts, ImageEvent &imageEvent);
|
||||
void SetDecodeInfoOptions(uint32_t index, const DecodeOptions &opts, const ImagePlugin::DecodeContext &context,
|
||||
ImageEvent &imageEvent);
|
||||
const std::string NINE_PATCH = "ninepatch";
|
||||
const std::string SKIA_DECODER = "SKIA_DECODER";
|
||||
static MultimediaPlugin::PluginServer &pluginServer_;
|
||||
@ -300,6 +306,7 @@ private:
|
||||
std::optional<bool> isAstc_;
|
||||
uint64_t imageId_; // generated from the last six bits of the current timestamp
|
||||
std::shared_ptr<ExifMetadata> exifMetadata_ = nullptr;
|
||||
std::string source_; // Image source fd buffer etc
|
||||
bool isExifReadFailed = false;
|
||||
};
|
||||
} // namespace Media
|
||||
|
@ -213,6 +213,7 @@ struct DecodeOptions {
|
||||
std::shared_ptr<OHOS::ColorManager::ColorSpace> desiredColorSpaceInfo = nullptr;
|
||||
bool preferDma = false;
|
||||
bool fastAstc = false;
|
||||
uint16_t invokeType = 0;
|
||||
};
|
||||
|
||||
enum class ScaleMode : int32_t {
|
||||
|
@ -657,11 +657,14 @@ uint32_t ExtDecoder::Decode(uint32_t index, DecodeContext &context)
|
||||
{
|
||||
#ifdef JPEG_HW_DECODE_ENABLE
|
||||
if (IsSupportHardwareDecode() && DoHardWareDecode(context) == SUCCESS) {
|
||||
context.isHardDecode = true;
|
||||
return SUCCESS;
|
||||
}
|
||||
#endif
|
||||
context.outInfo.size.width = dstInfo_.width();
|
||||
context.outInfo.size.height = dstInfo_.height();
|
||||
context.info.size.width = info_.width();
|
||||
context.info.size.height = info_.height();
|
||||
if (IsHeifToYuvDecode(context)) {
|
||||
return DoHeifToYuvDecode(context);
|
||||
}
|
||||
@ -927,11 +930,13 @@ uint32_t ExtDecoder::HardWareDecode(DecodeContext &context)
|
||||
uint32_t ret = AllocOutputBuffer(context);
|
||||
if (ret != SUCCESS) {
|
||||
IMAGE_LOGE("Decode failed, Alloc OutputBuffer failed, ret=%{public}d", ret);
|
||||
context.hardDecodeError = "Decode failed, Alloc OutputBuffer failed, ret=" + std::to_string(ret);
|
||||
return ERR_IMAGE_DECODE_ABNORMAL;
|
||||
}
|
||||
ret = hwDecoder.Decode(codec_.get(), stream_, orgImgSize_, sampleSize_, outputBuffer_);
|
||||
if (ret != SUCCESS) {
|
||||
IMAGE_LOGE("failed to do jpeg hardware decode, err=%{public}d", ret);
|
||||
context.hardDecodeError = "failed to do jpeg hardware decode, err=" + std::to_string(ret);
|
||||
ReleaseOutputBuffer(context, tmpAllocatorType);
|
||||
return ERR_IMAGE_DECODE_ABNORMAL;
|
||||
}
|
||||
|
@ -37,6 +37,7 @@
|
||||
#include "media_errors.h"
|
||||
#include "string_ex.h"
|
||||
#include "image_data_statistics.h"
|
||||
#include "image_dfx.h"
|
||||
#if !defined(IOS_PLATFORM) && !defined(ANDROID_PLATFORM)
|
||||
#include "surface_buffer.h"
|
||||
#endif
|
||||
@ -159,7 +160,8 @@ bool IsAstc(const std::string &format)
|
||||
return format.find("image/astc") == 0;
|
||||
}
|
||||
|
||||
static uint32_t CreateAndWriteBlob(MetadataWStream &tStream, DataBuf &exifBlob, OutputDataStream* output)
|
||||
static uint32_t CreateAndWriteBlob(MetadataWStream &tStream, DataBuf &exifBlob, OutputDataStream* output,
|
||||
ImageInfo &imageInfo, PlEncodeOptions &opts)
|
||||
{
|
||||
if (output == nullptr) {
|
||||
return ERR_IMAGE_ENCODE_FAILED;
|
||||
@ -172,8 +174,12 @@ static uint32_t CreateAndWriteBlob(MetadataWStream &tStream, DataBuf &exifBlob,
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!output->Write(tStream.GetAddr(), tStream.bytesWritten())) {
|
||||
ReportEncodeFault(imageInfo.size.width, imageInfo.size.height, opts.format, "Failed to encode image");
|
||||
return ERR_IMAGE_ENCODE_FAILED;
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
uint32_t ExtEncoder::DoFinalizeEncode()
|
||||
{
|
||||
@ -185,6 +191,7 @@ uint32_t ExtEncoder::DoFinalizeEncode()
|
||||
});
|
||||
if (iter == FORMAT_NAME.end()) {
|
||||
IMAGE_LOGE("Unsupported format: %{public}s", opts_.format.c_str());
|
||||
ReportEncodeFault(0, 0, opts_.format, "Unsupported format:" + opts_.format);
|
||||
return ERR_IMAGE_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
@ -196,6 +203,7 @@ uint32_t ExtEncoder::DoFinalizeEncode()
|
||||
auto errorCode = BuildSkBitmap(pixelmap_, bitmap, iter->first, holder);
|
||||
if (errorCode != SUCCESS) {
|
||||
IMAGE_LOGE("Failed to build SkBitmap");
|
||||
ReportEncodeFault(imageInfo.size.width, imageInfo.size.height, opts_.format, "Failed to build SkBitmap");
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
@ -204,6 +212,7 @@ uint32_t ExtEncoder::DoFinalizeEncode()
|
||||
ExtWStream wStream(output_);
|
||||
if (!SkEncodeImage(&wStream, bitmap, iter->first, opts_.quality)) {
|
||||
IMAGE_LOGE("Failed to encode image");
|
||||
ReportEncodeFault(imageInfo.size.width, imageInfo.size.height, opts_.format, "Failed to encode image");
|
||||
return ERR_IMAGE_ENCODE_FAILED;
|
||||
}
|
||||
return SUCCESS;
|
||||
@ -217,17 +226,11 @@ uint32_t ExtEncoder::DoFinalizeEncode()
|
||||
MetadataWStream tStream;
|
||||
if (!SkEncodeImage(&tStream, bitmap, iter->first, opts_.quality)) {
|
||||
IMAGE_LOGE("Failed to encode image");
|
||||
ReportEncodeFault(imageInfo.size.width, imageInfo.size.height, opts_.format, "Failed to encode image");
|
||||
return ERR_IMAGE_ENCODE_FAILED;
|
||||
}
|
||||
|
||||
if (CreateAndWriteBlob(tStream, exifBlob, output_) == SUCCESS) {
|
||||
return SUCCESS;
|
||||
}
|
||||
if (!output_->Write(tStream.GetAddr(), tStream.bytesWritten())) {
|
||||
return ERR_IMAGE_ENCODE_FAILED;
|
||||
}
|
||||
|
||||
return SUCCESS;
|
||||
return CreateAndWriteBlob(tStream, exifBlob, output_, imageInfo, opts_);
|
||||
}
|
||||
|
||||
uint32_t ExtEncoder::FinalizeEncode()
|
||||
|
@ -73,6 +73,10 @@ struct DecodeContext {
|
||||
PlYuvDataInfo yuvInfo;
|
||||
// Out: output the final pixelMap Info, only size is used now.
|
||||
PlImageInfo outInfo;
|
||||
// Out: Whether to perform hard decoding 0 is no 1 is yes
|
||||
bool isHardDecode = false;
|
||||
// Out: hard decode error message
|
||||
std::string hardDecodeError;
|
||||
};
|
||||
|
||||
struct ProgDecodeContext {
|
||||
|
Loading…
Reference in New Issue
Block a user