diff --git a/frameworks/innerkitsimpl/receiver/include/image_receiver.h b/frameworks/innerkitsimpl/receiver/include/image_receiver.h new file mode 100644 index 0000000000000000000000000000000000000000..cbd1098854710d0c48788341f51e77ac1c85f59d --- /dev/null +++ b/frameworks/innerkitsimpl/receiver/include/image_receiver.h @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2021 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 IMAGE_RECEIVER_H +#define IMAGE_RECEIVER_H + +#include +#include +#include +#include +#include "hilog/log.h" +#include "image_format.h" +#include "image_type.h" +#include "log_tags.h" +#include "media_errors.h" +#include "pixel_map.h" +#include "display_type.h" +#include "image_receiver_context.h" + +namespace OHOS { + namespace Media { + class ImageReceiver { + public: + std::shared_ptr iraContext_ = nullptr; + sptr receiverConsumerSurface_ = nullptr; + sptr receiverProducerSurface_ = nullptr; + ImageReceiver() { + }; + ~ImageReceiver() + { + receiverConsumerSurface_ = nullptr; + receiverProducerSurface_ = nullptr; + iraContext_ = nullptr; + }; + static inline int32_t pipeFd[2] = {}; + static inline std::string OPTION_FORMAT = "image/jpeg"; + static inline std::int32_t OPTION_QUALITY = 100; + static inline std::int32_t OPTION_NUMBERHINT = 1; + static std::shared_ptr CreateImageReceiver(int32_t width, + int32_t height); + sptr GetReceiverSurface(); + OHOS::sptr ReadNextImage(); + int32_t SaveBufferAsImage(std::string path, + OHOS::sptr buffer, + InitializationOptions initializationOpts); + int32_t SaveBufferAsImage(std::string path, InitializationOptions initializationOpts); + std::unique_ptr getSurfacePixelMap(InitializationOptions initializationOpts); + void ReleaseReceiver(); + }; + + class ImageReceiverSurfaceListener : public IBufferConsumerListener { + public: + std::shared_ptr irContext_; + void OnBufferAvailable() override; + }; + } // namespace Media +} // namespace OHOS + +#endif // IMAGE_RECEIVER_H \ No newline at end of file diff --git a/frameworks/innerkitsimpl/receiver/include/image_receiver_context.h b/frameworks/innerkitsimpl/receiver/include/image_receiver_context.h new file mode 100644 index 0000000000000000000000000000000000000000..7e9a32c04c1843110de30cbdc4a22221c97babe2 --- /dev/null +++ b/frameworks/innerkitsimpl/receiver/include/image_receiver_context.h @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2021 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 IMAGE_RECEIVER_PRIVATE_H +#define IMAGE_RECEIVER_PRIVATE_H + +#include +#include +#include "hilog/log.h" + + +namespace OHOS { + namespace Media { + class ImageReceiverContext { + public: + ImageReceiverContext() { + }; + ~ImageReceiverContext() + { + currentBuffer_ = nullptr; + }; + OHOS::sptr currentBuffer_; + static std::shared_ptr CreateImageReceiverContext(); + void SetReceiverBufferConsumer(sptr &consumer) + { + receiverConsumerSurface_ = consumer; + } + sptr GetReceiverBufferConsumer() + { + return receiverConsumerSurface_; + } + void SetReceiverBufferProducer(sptr &producer) + { + receiverProducerSurface_ = producer; + } + sptr GetReceiverBufferProducer() + { + return receiverProducerSurface_; + } + void SetWidth(int32_t width) + { + width_ = width; + } + int32_t GetWidth() const + { + return width_; + } + void SetHeight(int32_t height) + { + height_ = height; + } + int32_t GetrHeight() const + { + return height_; + } + OHOS::sptr GetCurrentBuffer() const + { + return currentBuffer_; + } + void SetCurrentBuffer(OHOS::sptr currentBuffer) + { + currentBuffer_ = currentBuffer; + } + + private: + static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { + LOG_CORE, LOG_TAG_DOMAIN_ID_IMAGE, "ImageReceiverContext"}; + OHOS::sptr receiverConsumerSurface_; + OHOS::sptr receiverProducerSurface_; + int32_t width_; + int32_t height_; + }; + } // namespace Media +} // namespace OHOS + +#endif // IMAGE_RECEIVER_PRIVATE_H \ No newline at end of file diff --git a/frameworks/innerkitsimpl/receiver/src/image_receiver.cpp b/frameworks/innerkitsimpl/receiver/src/image_receiver.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f051d111e7b245564499e5776ac75606859e2467 --- /dev/null +++ b/frameworks/innerkitsimpl/receiver/src/image_receiver.cpp @@ -0,0 +1,165 @@ +/* + * Copyright (C) 2021 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_receiver.h" +#include "image_packer.h" +#include "image_source.h" +#include "image_utils.h" +#include "hilog/log.h" + +namespace OHOS { +namespace Media { + constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_TAG_DOMAIN_ID_IMAGE, "imageReceiver"}; + using namespace OHOS::HiviewDFX; + enum class mode_ { + MODE_PREVIEW = 0, + MODE_PHOTO + }; + int64_t PackImage(const std::string &filePath, std::unique_ptr pixelMap) + { + HiLog::Error(LABEL, "PackImage"); + ImagePacker imagePacker; + PackOption option; + option.format = ImageReceiver::OPTION_FORMAT; + option.quality = ImageReceiver::OPTION_QUALITY; + option.numberHint = ImageReceiver::OPTION_NUMBERHINT; + std::set formats; + uint32_t ret = imagePacker.GetSupportedFormats(formats); + if (ret != SUCCESS) { + HiLog::Error(LABEL, "image packer get supported format failed, ret=%{public}u.", ret); + return 0; + } else { + HiLog::Error(LABEL, "SUCCESS"); + } + imagePacker.StartPacking(filePath, option); + imagePacker.AddImage(*pixelMap); + int64_t packedSize = 0; + imagePacker.FinalizePacking(packedSize); + HiLog::Debug(LABEL, "packedSize=%{public}lld.", static_cast(packedSize)); + return packedSize; + } + std::unique_ptr ImageReceiver::getSurfacePixelMap(InitializationOptions initializationOpts) + { + uint32_t *addr = (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, + std::string path, + InitializationOptions initializationOpts) + { + int64_t errorCode = -1; + std::unique_ptr 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(path, std::move(pixelMap)); + if (errorCode > 0) { + errorCode = SUCCESS; + } else { + errorCode = ERR_MEDIA_INVALID_VALUE; + } + return errorCode; + } + int32_t ImageReceiver::SaveBufferAsImage(std::string path, + OHOS::sptr buffer, + InitializationOptions initializationOpts) + { + int32_t errorcode = 0; + if (buffer != nullptr) { + uint32_t *addr = (uint32_t *)buffer->GetVirAddr(); + int32_t size = buffer->GetSize(); + errorcode = SaveSTP(addr, (uint32_t)size, path, initializationOpts); + (iraContext_->GetReceiverBufferConsumer())->ReleaseBuffer(buffer, -1); + } else { + HiLog::Debug(LABEL, "SaveBufferAsImage buffer == nullptr"); + } + return errorcode; + } + int32_t ImageReceiver::SaveBufferAsImage(std::string path, + InitializationOptions initializationOpts) + { + if (iraContext_->currentBuffer_ != nullptr) { + return SaveBufferAsImage(path, iraContext_->currentBuffer_, initializationOpts); + } else { + HiLog::Debug(LABEL, "iraContext_->GetCurrentBuffer() == nullptr"); + return 0; + } + return 0; + } + void ImageReceiverSurfaceListener ::OnBufferAvailable() + { + int32_t flushFence = 0; + int64_t timestamp = 0; + OHOS::Rect damage = {}; + OHOS::sptr buffer; + sptr listenerConsumerSerface = irContext_->GetReceiverBufferConsumer(); + listenerConsumerSerface->AcquireBuffer(buffer, flushFence, timestamp, damage); + if (buffer != nullptr) { + irContext_->currentBuffer_ = buffer; + } + } + std::shared_ptr ImageReceiverContext ::CreateImageReceiverContext() + { + std::shared_ptr irc = std::make_shared(); + return irc; + } + + std::shared_ptr ImageReceiver::CreateImageReceiver(int32_t width, + int32_t height) + { + std::shared_ptr iva = std::make_shared(); + iva->iraContext_ = ImageReceiverContext::CreateImageReceiverContext(); + iva->receiverConsumerSurface_ = Surface::CreateSurfaceAsConsumer(); + if (iva->receiverConsumerSurface_ == nullptr) { + HiLog::Debug(LABEL, "SurfaceAsConsumer == nullptr"); + } + iva->receiverConsumerSurface_->SetDefaultWidthAndHeight(width, height); + auto p = iva->receiverConsumerSurface_->GetProducer(); + iva->receiverProducerSurface_ = Surface::CreateSurfaceAsProducer(p); + if (iva->receiverProducerSurface_ == nullptr) { + HiLog::Debug(LABEL, "SurfaceAsProducer == nullptr"); + } + iva->iraContext_->SetReceiverBufferConsumer(iva->receiverConsumerSurface_); + iva->iraContext_->SetReceiverBufferProducer(iva->receiverProducerSurface_); + iva->iraContext_->SetWidth(width); + iva->iraContext_->SetHeight(height); + sptr listener = new ImageReceiverSurfaceListener(); + listener->irContext_ = iva->iraContext_; + iva->receiverConsumerSurface_-> + RegisterConsumerListener((sptr &)listener); + return iva; + } + OHOS::sptr ImageReceiver::ReadNextImage() + { + return iraContext_->GetCurrentBuffer(); + } + sptr ImageReceiver::GetReceiverSurface() + { + return iraContext_->GetReceiverBufferProducer(); + } + void ImageReceiver::ReleaseReceiver() + { + ImageReceiver::~ImageReceiver(); + } + } // namespace Media +} // namespace OHOS diff --git a/frameworks/innerkitsimpl/test/BUILD.gn b/frameworks/innerkitsimpl/test/BUILD.gn index 25372dba8a5eecc3e604dfb8ec4bf209f2072336..eb07f2283eec7c5a5c9999d0e9b9e86ede4d7e14 100644 --- a/frameworks/innerkitsimpl/test/BUILD.gn +++ b/frameworks/innerkitsimpl/test/BUILD.gn @@ -86,19 +86,17 @@ ohos_unittest("imagesourcetest") { "//foundation/multimedia/image_standard/plugins/manager/include", ] sources = [ - # "//foundation/multimedia/image_standard/frameworks/innerkitsimpl/test/unittest/image_source_gif_test.cpp", + "//foundation/multimedia/image_standard/frameworks/innerkitsimpl/test/unittest/image_source_gif_test.cpp", "//foundation/multimedia/image_standard/frameworks/innerkitsimpl/test/unittest/image_source_jpeg_test.cpp", - - # "//foundation/multimedia/image_standard/frameworks/innerkitsimpl/test/unittest/image_source_png_test.cpp", + "//foundation/multimedia/image_standard/frameworks/innerkitsimpl/test/unittest/image_source_png_test.cpp", "//foundation/multimedia/image_standard/frameworks/innerkitsimpl/test/unittest/image_source_util.cpp", - - # "//foundation/multimedia/image_standard/frameworks/innerkitsimpl/test/unittest/image_source_webp_test.cpp", + "//foundation/multimedia/image_standard/frameworks/innerkitsimpl/test/unittest/image_source_webp_test.cpp", ] if (DUAL_ADAPTER) { sources += [ "//foundation/multimedia/image_standard/frameworks/innerkitsimpl/test/unittest/image_source_bmp_test.cpp", - # "//foundation/multimedia/image_standard/frameworks/innerkitsimpl/test/unittest/image_source_raw_test.cpp", - # "//foundation/multimedia/image_standard/frameworks/innerkitsimpl/test/unittest/image_source_wbmp_test.cpp", + "//foundation/multimedia/image_standard/frameworks/innerkitsimpl/test/unittest/image_source_raw_test.cpp", + "//foundation/multimedia/image_standard/frameworks/innerkitsimpl/test/unittest/image_source_wbmp_test.cpp", ] } diff --git a/frameworks/innerkitsimpl/test/unittest/image_pixel_map_test.cpp b/frameworks/innerkitsimpl/test/unittest/image_pixel_map_test.cpp index dc3fd6dc0c9d09ac018e198e5ed15aff4c0b07f2..cbd34f6fd14f0c6196eeeda87563b77ea6c9b445 100644 --- a/frameworks/innerkitsimpl/test/unittest/image_pixel_map_test.cpp +++ b/frameworks/innerkitsimpl/test/unittest/image_pixel_map_test.cpp @@ -83,7 +83,7 @@ public: if (bufferSize <= 0) { return nullptr; } - void *buffer = malloc(bufferSize); + std::unique_ptr buffer = malloc(bufferSize); if (buffer == nullptr) { return nullptr; } diff --git a/frameworks/kits/js/common/image_packer_napi.cpp b/frameworks/kits/js/common/image_packer_napi.cpp index 5035968d49a8366b0cab3aa42c20b585a8916cc3..0f4eedfaad7f5571f77d6ab4dde37e2227ad76a2 100644 --- a/frameworks/kits/js/common/image_packer_napi.cpp +++ b/frameworks/kits/js/common/image_packer_napi.cpp @@ -24,6 +24,9 @@ using OHOS::HiviewDFX::HiLog; namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "ImagePackerNapi"}; + constexpr uint32_t NUM_0 = 0; + constexpr uint32_t NUM_1 = 1; + constexpr uint32_t NUM_2 = 2; } namespace OHOS { @@ -69,36 +72,36 @@ ImagePackerNapi::~ImagePackerNapi() } } -static void CommonCallbackRoutine(napi_env env, ImagePackerAsyncContext* &asyncContext, const napi_value &valueParam) +static void CommonCallbackRoutine(napi_env env, ImagePackerAsyncContext* &connect, const napi_value &valueParam) { HiLog::Debug(LABEL, "CommonCallbackRoutine enter"); - napi_value result[2] = {0}; + napi_value result[NUM_2] = {0}; napi_value retVal; napi_value callback = nullptr; - napi_get_undefined(env, &result[0]); - napi_get_undefined(env, &result[1]); + napi_get_undefined(env, &result[NUM_0]); + napi_get_undefined(env, &result[NUM_1]); - if (asyncContext->status == SUCCESS) { + if (connect->status == SUCCESS) { result[1] = valueParam; } - if (asyncContext->deferred) { - if (asyncContext->status == SUCCESS) { - napi_resolve_deferred(env, asyncContext->deferred, result[1]); + if (connect->deferred) { + if (connect->status == SUCCESS) { + napi_resolve_deferred(env, connect->deferred, result[NUM_1]); } else { - napi_reject_deferred(env, asyncContext->deferred, result[0]); + napi_reject_deferred(env, connect->deferred, result[NUM_0]); } } else { - napi_get_reference_value(env, asyncContext->callbackRef, &callback); + napi_get_reference_value(env, connect->callbackRef, &callback); napi_call_function(env, nullptr, callback, PARAM2, result, &retVal); - napi_delete_reference(env, asyncContext->callbackRef); + napi_delete_reference(env, connect->callbackRef); } - napi_delete_async_work(env, asyncContext->work); + napi_delete_async_work(env, connect->work); - delete asyncContext; - asyncContext = nullptr; + delete connect; + connect = nullptr; HiLog::Debug(LABEL, "CommonCallbackRoutine exit"); } @@ -165,6 +168,7 @@ napi_value ImagePackerNapi::Init(napi_env env, napi_value exports) napi_property_descriptor props[] = { DECLARE_NAPI_FUNCTION("packing", Packing), DECLARE_NAPI_FUNCTION("release", Release), + DECLARE_NAPI_GETTER("supportedFormats", GetSupportedFormats), }; napi_property_descriptor static_prop[] = { DECLARE_NAPI_STATIC_FUNCTION("createImagePacker", CreateImagePacker), @@ -353,26 +357,86 @@ napi_value ImagePackerNapi::Packing(napi_env env, napi_callback_info info) return result; } -napi_value ImagePackerNapi::Release(napi_env env, napi_callback_info info) +napi_value ImagePackerNapi::GetSupportedFormats(napi_env env, napi_callback_info info) { - HiLog::Debug(LABEL, "Release enter"); napi_value result = nullptr; napi_get_undefined(env, &result); napi_status status; napi_value thisVar = nullptr; size_t argCount = 0; + HiLog::Debug(LABEL, "GetSupportedFormats IN"); 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")); - std::unique_ptr imagePackerNapi = std::make_unique(); - status = napi_unwrap(env, thisVar, reinterpret_cast(&imagePackerNapi)); + std::unique_ptr context = std::make_unique(); + status = napi_unwrap(env, thisVar, reinterpret_cast(&context->constructor_)); + + IMG_NAPI_CHECK_RET_D(IMG_IS_READY(status, context->constructor_), + nullptr, HiLog::Error(LABEL, "fail to unwrap context")); + std::set 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")); + + napi_create_array(env, &result); + size_t i = 0; + for (const std::string& formatStr: formats) { + napi_value format = nullptr; + napi_create_string_latin1(env, formatStr.c_str(), formatStr.length(), &format); + napi_set_element(env, result, i, format); + i++; + } + return result; +} + +static void ReleaseComplete(napi_env env, napi_status status, void *data) +{ + HiLog::Debug(LABEL, "ReleaseComplete IN"); + napi_value result = nullptr; + napi_get_undefined(env, &result); + + auto context = static_cast(data); + context->constructor_->~ImagePackerNapi(); + HiLog::Debug(LABEL, "ReleaseComplete OUT"); + CommonCallbackRoutine(env, context, result); +} + +napi_value ImagePackerNapi::Release(napi_env env, napi_callback_info info) +{ + HiLog::Debug(LABEL, "Release enter"); + napi_value result = nullptr; + napi_get_undefined(env, &result); + + int32_t refCount = 1; + napi_status status; + napi_value thisVar = nullptr; + napi_value argValue[NUM_1] = {0}; + 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")); + + std::unique_ptr context = std::make_unique(); + status = napi_unwrap(env, thisVar, reinterpret_cast(&context->constructor_)); - IMG_NAPI_CHECK_RET_D(IMG_IS_READY(status, imagePackerNapi), result, HiLog::Error(LABEL, "fail to unwrap context")); + 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); + if (argCount == 1 && ImageNapiUtils::getType(env, argValue[NUM_0]) == napi_function) { + napi_create_reference(env, argValue[NUM_0], refCount, &context->callbackRef); + } + + if (context->callbackRef == nullptr) { + napi_create_promise(env, &(context->deferred), &result); + } - imagePackerNapi->~ImagePackerNapi(); + IMG_CREATE_CREATE_ASYNC_WORK(env, status, "Release", + [](napi_env env, void *data) {}, ReleaseComplete, context, context->work); HiLog::Debug(LABEL, "Release exit"); return result; } diff --git a/frameworks/kits/js/common/pixel_map_napi.cpp b/frameworks/kits/js/common/pixel_map_napi.cpp index 62bd9b83767c3b3731a6429fc74f012a8a403f73..054d428c7471726b124da9edba25c0709b0efc3a 100644 --- a/frameworks/kits/js/common/pixel_map_napi.cpp +++ b/frameworks/kits/js/common/pixel_map_napi.cpp @@ -278,7 +278,7 @@ napi_value PixelMapNapi::Init(napi_env env, napi_value exports) DECLARE_NAPI_FUNCTION("getImageInfo", GetImageInfo), DECLARE_NAPI_FUNCTION("getBytesNumberPerRow", GetBytesNumberPerRow), DECLARE_NAPI_FUNCTION("getPixelBytesNumber", GetPixelBytesNumber), - DECLARE_NAPI_FUNCTION("Release", Release), + DECLARE_NAPI_FUNCTION("release", Release), DECLARE_NAPI_GETTER("isEditable", GetIsEditable), }; diff --git a/interfaces/innerkits/BUILD.gn b/interfaces/innerkits/BUILD.gn index 0543d8531f90fb70dcdda9d51d770a98079f86e6..4d193f05932dd12e0515acb6bbf4987f23aa508c 100644 --- a/interfaces/innerkits/BUILD.gn +++ b/interfaces/innerkits/BUILD.gn @@ -17,6 +17,9 @@ import("//foundation/multimedia/image_standard/ide/image_decode_config.gni") config("image_external_config") { include_dirs = [ + "include", + "//utils/system/safwk/native/include", + "//foundation/multimedia/image_standard/frameworks/innerkitsimpl/receiver/include", "//foundation/multimedia/image_standard/frameworks/innerkitsimpl/pixelconverter/include", "//foundation/multimedia/image_standard/frameworks/innerkitsimpl/converter/include", "//foundation/multimedia/image_standard/frameworks/innerkitsimpl/codec/include", @@ -30,6 +33,12 @@ config("image_external_config") { "//foundation/multimedia/image_standard/interfaces/innerkits/include", "//utils/jni/jnikit/include", "//base/hiviewdfx/hilog/interfaces/native/innerkits/include", + "//foundation/graphic/standard/interfaces/innerkits/surface", + "//foundation/graphic/standard/interfaces/innerkits/common", + "//foundation/communication/ipc/interfaces/innerkits/ipc_core/include", + "//foundation/graphic/standard/utils/buffer_handle/export", + "//drivers/peripheral/display/interfaces/include", + "//drivers/peripheral/base", ] if (use_mingw_win) { @@ -75,6 +84,7 @@ ohos_shared_library("image") { deps = [ ":image_native", "//foundation/ace/napi:ace_napi", + "//foundation/graphic/standard:libsurface", "//foundation/multimedia/image_standard/frameworks/innerkitsimpl/pixelconverter:pixelconvertadapter", "//foundation/multimedia/image_standard/frameworks/innerkitsimpl/utils:image_utils", "//foundation/multimedia/image_standard/plugins/manager:pluginmanager", @@ -106,6 +116,7 @@ ohos_shared_library("image_native") { "//foundation/multimedia/image_standard/frameworks/innerkitsimpl/converter/src/pixel_convert.cpp", "//foundation/multimedia/image_standard/frameworks/innerkitsimpl/converter/src/post_proc.cpp", "//foundation/multimedia/image_standard/frameworks/innerkitsimpl/converter/src/scan_line_filter.cpp", + "//foundation/multimedia/image_standard/frameworks/innerkitsimpl/receiver/src/image_receiver.cpp", "//foundation/multimedia/image_standard/frameworks/innerkitsimpl/stream/src/buffer_packer_stream.cpp", "//foundation/multimedia/image_standard/frameworks/innerkitsimpl/stream/src/buffer_source_stream.cpp", "//foundation/multimedia/image_standard/frameworks/innerkitsimpl/stream/src/file_packer_stream.cpp", @@ -125,6 +136,7 @@ ohos_shared_library("image_native") { "//foundation/multimedia/image_standard/frameworks/innerkitsimpl/stream/src/ostream_packer_stream.cpp", ] deps = [ + "//foundation/graphic/standard:libsurface", "//foundation/multimedia/image_standard/frameworks/innerkitsimpl/pixelconverter:pixelconvertadapter_static", "//foundation/multimedia/image_standard/frameworks/innerkitsimpl/utils:image_utils_static", "//foundation/multimedia/image_standard/mock/native:log_mock_static", @@ -140,6 +152,7 @@ ohos_shared_library("image_native") { "//foundation/multimedia/image_standard/frameworks/innerkitsimpl/stream/src/ostream_packer_stream.cpp", ] deps = [ + "//foundation/graphic/standard:libsurface", "//foundation/multimedia/image_standard/frameworks/innerkitsimpl/pixelconverter:pixelconvertadapter_static", "//foundation/multimedia/image_standard/frameworks/innerkitsimpl/utils:image_utils_static", "//foundation/multimedia/image_standard/mock/native:log_mock_static", @@ -152,6 +165,7 @@ ohos_shared_library("image_native") { deps = [ "//foundation/ace/napi:ace_napi", + "//foundation/graphic/standard:libsurface", "//foundation/multimedia/image_standard/frameworks/innerkitsimpl/pixelconverter:pixelconvertadapter", "//foundation/multimedia/image_standard/frameworks/innerkitsimpl/utils:image_utils", "//foundation/multimedia/image_standard/plugins/manager:pluginmanager", @@ -189,6 +203,7 @@ ohos_static_library("image_static_napi") { deps = [ ":image_native", "//foundation/ace/napi:ace_napi", + "//foundation/graphic/standard:libsurface", "//foundation/multimedia/image_standard/frameworks/innerkitsimpl/pixelconverter:pixelconvertadapter", "//foundation/multimedia/image_standard/frameworks/innerkitsimpl/utils:image_utils", "//foundation/multimedia/image_standard/plugins/manager:pluginmanager", @@ -212,6 +227,7 @@ ohos_static_library("image_static") { "//foundation/multimedia/image_standard/frameworks/innerkitsimpl/converter/src/pixel_convert.cpp", "//foundation/multimedia/image_standard/frameworks/innerkitsimpl/converter/src/post_proc.cpp", "//foundation/multimedia/image_standard/frameworks/innerkitsimpl/converter/src/scan_line_filter.cpp", + "//foundation/multimedia/image_standard/frameworks/innerkitsimpl/receiver/src/image_receiver.cpp", "//foundation/multimedia/image_standard/frameworks/innerkitsimpl/stream/src/buffer_packer_stream.cpp", "//foundation/multimedia/image_standard/frameworks/innerkitsimpl/stream/src/buffer_source_stream.cpp", "//foundation/multimedia/image_standard/frameworks/innerkitsimpl/stream/src/file_packer_stream.cpp", @@ -231,6 +247,7 @@ ohos_static_library("image_static") { "//foundation/multimedia/image_standard/frameworks/innerkitsimpl/stream/src/ostream_packer_stream.cpp", ] deps = [ + "//foundation/graphic/standard:libsurface", "//foundation/multimedia/image_standard/frameworks/innerkitsimpl/pixelconverter:pixelconvertadapter_static", "//foundation/multimedia/image_standard/frameworks/innerkitsimpl/utils:image_utils_static", "//foundation/multimedia/image_standard/mock/native:log_mock_static", @@ -247,6 +264,7 @@ ohos_static_library("image_static") { ] deps = [ + "//foundation/graphic/standard:libsurface", "//foundation/multimedia/image_standard/frameworks/innerkitsimpl/pixelconverter:pixelconvertadapter_static", "//foundation/multimedia/image_standard/frameworks/innerkitsimpl/utils:image_utils_static", "//foundation/multimedia/image_standard/mock/native:log_mock_static", @@ -259,6 +277,7 @@ ohos_static_library("image_static") { deps = [ "//foundation/ace/napi:ace_napi", + "//foundation/graphic/standard:libsurface", "//foundation/multimedia/image_standard/frameworks/innerkitsimpl/pixelconverter:pixelconvertadapter", "//foundation/multimedia/image_standard/frameworks/innerkitsimpl/utils:image_utils", "//foundation/multimedia/image_standard/plugins/manager:pluginmanager", diff --git a/interfaces/kits/js/@ohos.multimedia.image.d.ts b/interfaces/kits/js/@ohos.multimedia.image.d.ts index 1636a5cc59bc3abbb679611b1d1f4a0dbc1b40a2..1c418d018ff4672ab22a130ac14383ce7d1456f5 100644 --- a/interfaces/kits/js/@ohos.multimedia.image.d.ts +++ b/interfaces/kits/js/@ohos.multimedia.image.d.ts @@ -15,200 +15,164 @@ import { AsyncCallback } from './basic'; -/** - * @name image - * @since 6 - * @SysCap SystemCapability.Multimedia.Image - * @import import image from '@ohos.multimedia.image'; - * @devices phone, tablet, tv, wearable, car - */ declare namespace image { /** * Enumerates pixel map formats. - * RGB 1 - 999 - * YUV 1000 - 1999 - * IMAGE ENCODING 2000 - 2999 - * VIDEO ENCODING 3000 - 3999 - * @since 7 */ enum PixelMapFormat { /** - * Indicates an unknown format. + * Indicates an unknown pixel map format. */ UNKNOWN = 0, /** - * Indicates that each pixel is stored on 16 bits. Only the R, G, and B components are encoded - * from the higher-order to the lower-order bits: red is stored with 5 bits of precision, - * green is stored with 6 bits of precision, and blue is stored with 5 bits of precision. + * Indicates that each pixel is stored on 32 bits. Components A, R, G, and B each occupies 8 bits + * and are stored from the higher-order to the lower-order bits. */ - RGB_565 = 2, + ARGB_8888 = 1, /** - * Indicates that each pixel is stored on 32 bits. Components R, G, B, and A each occupies 8 bits - * and are stored from the higher-order to the lower-order bits. + * Indicates that each pixel is stored on 16 bits. Only the R, G, and B components are encoded + * from the higher-order to the lower-order bits: red is stored with 5 bits of precision, + * green is stored with 6 bits of precision, and blue is stored with 5 bits of precision. */ - RGBA_8888 = 3, + RGB_565 = 2 } /** - * Enum for image formats. - * @since 8 + * Enumerates color spaces. */ - enum ImageFormat { + enum ColorSpace { /** - * YCBCR422 semi-planar format. - * @since 8 + * Indicates an unknown color space. */ - YCBCR_422_SP = 1000, + UNKNOWN = 0, /** - * JPEG encoding format. - * @since 8 + * Indicates the color space based on SMPTE RP 431-2-2007 and IEC 61966-2.1:1999. */ - JPEG = 2000 - } + DISPLAY_P3 = 1, - enum ComponentType { - YUV_Y = 1, - YUV_U = 2, - YUV_V = 3, - } + /** + * Indicates the standard red green blue (SRGB) color space based on IEC 61966-2.1:1999. + */ + SRGB = 2, - /** - * Describes the size of an image. - */ - interface Size { /** - * Height - * @since 6 - * @SysCap SystemCapability.Multimedia.Image - * @devices phone, tablet, tv, wearable, car + * Indicates the SRGB using a linear transfer function based on the IEC 61966-2.1:1999 standard. */ - height: number; + LINEAR_SRGB = 3, /** - * Width - * @since 6 - * @SysCap SystemCapability.Multimedia.Image - * @devices phone, tablet, tv, wearable, car + * Indicates the color space based on IEC 61966-2-2:2003. */ - width: number; - } + EXTENDED_SRGB = 4, - /** - * Enumerates exchangeable image file format (Exif) information types of an image. - * @since 7 - * @SysCap SystemCapability.Multimedia.Image - * @import import image from '@ohos.multimedia.image' - * @devices phone, tablet, tv, wearable, car - */ - enum PropertyKey { /** - * Number of bits in each pixel of an image. + * Indicates the color space based on IEC 61966-2-2:2003. */ - BITS_PER_SAMPLE = "BitsPerSample", + LINEAR_EXTENDED_SRGB = 5, /** - * Image rotation mode. + * Indicates the color space based on the standard illuminant with D50 as the white point. */ - ORIENTATION = "Orientation", + GENERIC_XYZ = 6, /** - * Image length. + * Indicates the color space using CIE XYZ D50 as the profile conversion space. */ - IMAGE_LENGTH = "ImageLength", + GENERIC_LAB = 7, /** - * Image width. + * Indicates the color space based on SMPTE ST 2065-1:2012. */ - IMAGE_WIDTH = "ImageWidth", + ACES = 8, /** - * GPS latitude. + * Indicates the color space based on Academy S-2014-004. */ - GPS_LATITUDE = "GPSLatitude", + ACES_CG = 9, /** - * GPS longitude. + * Indicates the color space based on Adobe RGB (1998). */ - GPS_LONGITUDE = "GPSLongitude", + ADOBE_RGB_1998 = 10, /** - * GPS latitude reference. For example, N indicates north latitude and S indicates south latitude. + * Indicates the color space based on SMPTE RP 431-2-2007. */ - GPS_LATITUDE_REF = "GPSLatitudeRef", + DCI_P3 = 11, /** - * GPS longitude reference. For example, E indicates east longitude and W indicates west longitude. + * Indicates the color space based on Rec.ITU-R BT.709-5. */ - GPS_LONGITUDE_REF = "GPSLongitudeRef" - } + ITU_709 = 12, - /** - * Describes region information. - */ - interface Region { /** - * Image size. - * @since 7 - * @SysCap SystemCapability.Multimedia.Image - * @devices phone, tablet, tv, wearable, car + * Indicates the color space based on Rec.ITU-R BT.2020-1. */ - size: Size; + ITU_2020 = 13, /** - * x-coordinate at the upper left corner of the image. - * @since 7 - * @SysCap SystemCapability.Multimedia.Image - * @devices phone, tablet, tv, wearable, car + * Indicates the color space based on ISO 22028-2:2013. */ - x: number; + ROMM_RGB = 14, /** - * y-coordinate at the upper left corner of the image. - * @since 7 - * @SysCap SystemCapability.Multimedia.Image - * @devices phone, tablet, tv, wearable, car + * Indicates the color space based on the NTSC 1953 standard. */ - y: number; + NTSC_1953 = 15, + + /** + * Indicates the color space based on SMPTE C. + */ + SMPTE_C = 16 } /** - * Describes area information in an image. + * Enumerates alpha types. */ - interface PositionArea { + enum AlphaType { /** - * Image data that will be read or written. - * @since 7 - * @SysCap SystemCapability.Multimedia.Image - * @devices phone, tablet, tv, wearable, car + * Indicates an unknown alpha type. */ - pixels: ArrayBuffer; + UNKNOWN = 0, /** - * Offset for data reading. - * @since 7 - * @SysCap SystemCapability.Multimedia.Image - * @devices phone, tablet, tv, wearable, car + * Indicates that the image has no alpha channel, or all pixels in the image are fully opaque. */ - offset: number; + OPAQUE = 1, /** - * Number of bytes to read. - * @since 7 - * @SysCap SystemCapability.Multimedia.Image - * @devices phone, tablet, tv, wearable, car + * Indicates that RGB components of each pixel in the image are premultiplied by alpha. */ - stride: number; + PREMUL = 2, /** - * Region to read. - * @since 7 - * @SysCap SystemCapability.Multimedia.Image - * @devices phone, tablet, tv, wearable, car + * Indicates that RGB components of each pixel in the image are independent of alpha and are not premultiplied by alpha. */ + UNPREMUL = 3 + } + + /** + * Describes the size of an image. + */ + interface Size { + height: number; + width: number; + } + + interface Region { + size: Size; + x: number; + y: number; + } + + interface PositionArea { + pixels: ArrayBuffer; + offset: number; + stride: number; region: Region; } @@ -216,13 +180,10 @@ declare namespace image { * Describes image information. */ interface ImageInfo { - /** - * Indicates image dimensions specified by a {@link Size} interface. - * @since 6 - * @SysCap SystemCapability.Multimedia.Image - * @devices phone, tablet, tv, wearable, car - */ size: Size; + pixelFormat: PixelMapFormat; + colorSpace: ColorSpace; + alphaType: AlphaType; } /** @@ -231,626 +192,164 @@ declare namespace image { interface PackingOption { /** * Multipurpose Internet Mail Extensions (MIME) format of the target image, for example, image/jpeg. - * @since 6 - * @SysCap SystemCapability.Multimedia.Image - * @devices phone, tablet, tv, wearable, car */ format: string; /** * Quality of the target image. The value is an integer ranging from 0 to 100. A larger value indicates better - * image quality but larger space occupied. - * @since 6 - * @SysCap SystemCapability.Multimedia.Image - * @devices phone, tablet, tv, wearable, car */ quality: number; } - /** - * Describes image properties. - */ - interface GetImagePropertyOptions { - /** - * Index of an image. - * @since 7 - * @SysCap SystemCapability.Multimedia.Image - * @devices phone, tablet, tv, wearable, car - */ - index?: number; - - /** - * Default property value. - * @since 7 - * @SysCap SystemCapability.Multimedia.Image - * @devices phone, tablet, tv, wearable, car - */ - defaultValue?: string; - } - - /** - * Describes image decoding parameters. - */ interface DecodingOptions { - /** - * Number of image frames. - * @since 7 - * @SysCap SystemCapability.Multimedia.Image - * @devices phone, tablet, tv, wearable, car - */ - index?: number; + // Indicates the sampling size based on which an image is scaled down. + sampleSize: number; - /** - * Sampling ratio of the image pixel map. - * @since 7 - * @SysCap SystemCapability.Multimedia.Image - * @devices phone, tablet, tv, wearable, car - */ - sampleSize?: number; + // Indicates the rotation angle, ranging from 0 to 360 + rotateDegrees: number; - /** - * Rotation angle of the image pixel map. The value ranges from 0 to 360. - * @since 7 - * @SysCap SystemCapability.Multimedia.Image - * @devices phone, tablet, tv, wearable, car - */ - rotate?: number; + // Specifies whether pixel values of the pixel map to be decoded can be edited. + editable: boolean; - /** - * Whether the image pixel map is editable. - * @since 7 - * @SysCap SystemCapability.Multimedia.Image - * @devices phone, tablet, tv, wearable, car - */ - editable?: boolean; + // Indicates the expected output size + desiredSize: Size; - /** - * Width and height of the image pixel map. The value (0, 0) indicates that the pixels are decoded - * based on the original image size. - * @since 7 - * @SysCap SystemCapability.Multimedia.Image - * @devices phone, tablet, tv, wearable, car - */ - desiredSize?: Size; + // Indicates an image area to be decoded. + desiredRegion: Region; - /** - * Cropping region of the image pixel map. - * @since 7 - * @SysCap SystemCapability.Multimedia.Image - * @devices phone, tablet, tv, wearable, car - */ - desiredRegion?: Region; + // Indicates the pixel format of a decoded image, which is defined by PixelFormat. + desiredPixelFormat: PixelMapFormat; - /** - * Data format of the image pixel map. - * @since 7 - * @SysCap SystemCapability.Multimedia.Image - * @devices phone, tablet, tv, wearable, car - */ - desiredPixelFormat?: PixelMapFormat; + // reused current pixelmap buffer address for a new created pixelmap + reusedPixelMap: PixelMap; + } + + enum ScaleMode { + CENTER_CROP = 1, // Indicates the effect that scales an image to fill the target image area and center-crops the part outside the area. + FIT_TARGET_SIZE = 2, // Indicates the effect that fits the image into the target size. } - /** - * Options for pixelmap create. - * @since 8 - */ interface InitializationOptions { - /** - * Indicates the expected size of the pixel map to be created - * @since 8 - */ + // Indicates the expected alpha type of the pixel map to be created + alphaType: AlphaType; + + // Specifies whether pixel values of the pixel map to be created can be edited + editable: boolean; + + // Indicates the expected format of the pixel map to be created + pixelFormat: PixelMapFormat; + + // Indicates the scaling effect used when the aspect ratio of the original image is different from that of the target image + scaleMode: ScaleMode; + + // Indicates the expected size of the pixel map to be created size: Size; - /** - * Indicates the expected format of the pixel map to be created - * @since 8 - */ - pixelFormat?: PixelMapFormat; - /** - * Specifies whether pixel values of the pixel map to be created can be edited - * @since 8 - */ - editable?: boolean; } /** - * Creates an ImageSource instance based on the URI. - * @since 6 - * @SysCap SystemCapability.Multimedia.Image - * @devices phone, tablet, tv, wearable, car - * @import import image from '@ohos.multimedia.image' - * @param uri Image source URI. - * @return Returns the ImageSource instance if the operation is successful; returns null otherwise. + * Creates an ImageSource instance. */ function createImageSource(uri: string): ImageSource; - /** - * Creates an ImageSource instance based on the file descriptor. - * @since 7 - * @SysCap SystemCapability.Multimedia.Image - * @devices phone, tablet, tv, wearable, car - * @import import image from '@ohos.multimedia.image' - * @param fd ID of a file descriptor. - * @return Returns the ImageSource instance if the operation is successful; returns null otherwise. - */ + // create a imagesource based on fd function createImageSource(fd: number): ImageSource; - /** - * Creates an ImageSource instance based on the array buffer. - * @param data Image source data. - * @return Returns the ImageSource instance if the operation is successful; returns null otherwise. - * @since 8 - */ + // Creates an ImageSource based on a ArrayBuffer and source options. function createImageSource(data: ArrayBuffer): ImageSource; - /** - * Creates an empty PixelMap instance. - * @param data Image source data. - * @return Returns the ImageSource instance if the operation is successful; returns null otherwise. - * @since 8 - */ - function createPixelMap(options: InitializationOptions, callback: AsyncCallback): void; - function createPixelMap(options: InitializationOptions): Promise; + // Creates a pixel map based on initialization options (such as the image size, pixel format, and alpha type) + // and the data source described by a pixel color array, start offset, and number of pixels in a row. + function createPixelMap(colors: ArrayBuffer, opts: InitializationOptions): Promise; + function createPixelMap(colors: ArrayBuffer, opts: InitializationOptions, callback: AsyncCallback): void; - /** - * Creates a PixelMap instance based on the array buffer. - * @param data Image source data. - * @return Returns the ImageSource instance if the operation is successful; returns null otherwise. - * @since 8 - */ - function createPixelMap(colors: ArrayBuffer, options: InitializationOptions, callback: AsyncCallback): void; - function createPixelMap(colors: ArrayBuffer, options: InitializationOptions): Promise; + + function createIncrementalSource(data: ArrayBuffer): ImageSource; /** * Creates an ImagePacker instance. - * @since 6 - * @SysCap SystemCapability.Multimedia.Image - * @devices phone, tablet, tv, wearable, car - * @import import image from '@ohos.multimedia.image' - * @return Returns the ImagePacker instance if the operation is successful; returns null otherwise. */ function createImagePacker(): ImagePacker; - /** - * Creates an ImageReceiver instance. - * @param width The default width in pixels of the Images that this receiver will produce. - * @param height The default height in pixels of the Images that this receiver will produce. - * @param format The format of the Image that this receiver will produce. This must be one of the - * {@link ImageFormat} constants. Note that not all formats are supported, like ImageFormat.NV21. - * @param capacity The maximum number of images the user will want to access simultaneously. - */ - function createImageReceiver(width: number, height: number, format: number, capacity: number): ImageReceiver; - - /** - * Describes image color components. - * @Since 8 - */ - interface Component { - /** - * Component type. - * @Since 8 - */ - readonly componentType: ComponentType; - /** - * Row stride. - * @Since 8 - */ - readonly rowStride: number; - /** - * Pixel stride. - * @Since 8 - */ - readonly pixelStride: number; - /** - * Component buffer. - * @Since 8 - */ - readonly byteBuffer: ArrayBuffer; - } - - /** - * Provides basic image operations, including obtaining image information, and reading and writing image data. - * @Since 8 - */ - interface Image { - /** - * Sets or gets the image area to crop, default is size. - * @since 8 - */ - clipRect: Region; - - /** - * Image size. - * @since 8 - */ - readonly size: number; - - /** - * Image format. - * @since 8 - */ - readonly format: number; - - /** - * Get component buffer from image. - * @since 8 - */ - getComponent(componentType: ComponentType, callback: AsyncCallback): void; - getComponent(componentType: ComponentType): Promise; - - /** - * Release current image to receive another. - * @since 8 - */ - release(callback: AsyncCallback): void; - release(): Promise; - } - - /** - * Image receiver object. - * @Since 8 - */ - interface ImageReceiver { - /** - * Image size. - * @Since 8 - */ - readonly size: Size; - - /** - * Image capacity. - * @Since 8 - */ - readonly capacity: number; - - /** - * Image format. - * @Since 8 - */ - readonly format: ImageFormat; - - /** - * get an id which indicates a surface and can be used to set to Camera or other component can receive a surface - * @Since 8 - */ - getReceivingSurfaceId(callback: AsyncCallback): void; - getReceivingSurfaceId(): Promise; - - /** - * Get lasted image from receiver - * @since 8 - */ - readLatestImage(callback: AsyncCallback): void; - readLatestImage(): Promise; - - /** - * Get next image from receiver - * @since 8 - */ - readNextImage(callback: AsyncCallback): void; - readNextImage(): Promise; - - /** - * Subscribe callback when receiving an image - * @since 8 - */ - on(type: 'imageArrival', callback: AsyncCallback): void; - - /** - * Release instance. - * @since 8 - */ - release(callback: AsyncCallback): void; - release(): Promise; - } - - /** - * PixelMap object - * @since 7 - */ interface PixelMap { - /** - * Whether the image pixel map can be edited. - * @since 7 - * @SysCap SystemCapability.Multimedia.Image - * @devices phone, tablet, tv, wearable, car - * @import import image from '@ohos.multimedia.image' - */ - readonly isEditable: boolean; - - /** - * Reads image pixel map data and writes the data to an ArrayBuffer. This method uses - * a promise to return the result. - * @since 7 - * @SysCap SystemCapability.Multimedia.Image - * @devices phone, tablet, tv, wearable, car - * @import import image from '@ohos.multimedia.image' - * @param dst A buffer to which the image pixel map data will be written. - * @return A Promise instance used to return the operation result. If the operation fails, an error message is returned. - */ + // read all pixels to an buffer readPixelsToBuffer(dst: ArrayBuffer): Promise; - - /** - * Reads image pixel map data and writes the data to an ArrayBuffer. This method uses - * a callback to return the result. - * @since 7 - * @SysCap SystemCapability.Multimedia.Image - * @devices phone, tablet, tv, wearable, car - * @import import image from '@ohos.multimedia.image' - * @param dst A buffer to which the image pixel map data will be written. - * @param callback Callback used to return the operation result. If the operation fails, an error message is returned. - */ readPixelsToBuffer(dst: ArrayBuffer, callback: AsyncCallback): void; - /** - * Reads image pixel map data in an area. This method uses a promise to return the data read. - * @since 7 - * @SysCap SystemCapability.Multimedia.Image - * @devices phone, tablet, tv, wearable, car - * @import import image from '@ohos.multimedia.image' - * @param area Area from which the image pixel map data will be read. - * @return A Promise instance used to return the operation result. If the operation fails, an error message is returned. - */ - readPixels(area: PositionArea): Promise; - - /** - * Reads image pixel map data in an area. This method uses a callback to return the data read. - * @since 7 - * @SysCap SystemCapability.Multimedia.Image - * @devices phone, tablet, tv, wearable, car - * @import import image from '@ohos.multimedia.image' - * @param area Area from which the image pixel map data will be read. - * @param callback Callback used to return the operation result. If the operation fails, an error message is returned. - */ - readPixels(area: PositionArea, callback: AsyncCallback): void; + // read pixels from a specified area into an buffer + readPixels(area: PositionArea): Promise>; + readPixels(area: PositionArea, callback: AsyncCallback>): void; - /** - * Writes image pixel map data to the specified area. This method uses a promise to return - * the operation result. - * @since 7 - * @SysCap SystemCapability.Multimedia.Image - * @devices phone, tablet, tv, wearable, car - * @import import image from '@ohos.multimedia.image' - * @param area Area to which the image pixel map data will be written. - * @return A Promise instance used to return the operation result. If the operation fails, an error message is returned. - */ + // write pixels to a specified area writePixels(area: PositionArea): Promise; - - /** - * Writes image pixel map data to the specified area. This method uses a callback to return - * the operation result. - * @since 7 - * @SysCap SystemCapability.Multimedia.Image - * @devices phone, tablet, tv, wearable, car - * @import import image from '@ohos.multimedia.image' - * @param area Area to which the image pixel map data will be written. - * @param callback Callback used to return the operation result. If the operation fails, an error message is returned. - */ writePixels(area: PositionArea, callback: AsyncCallback): void; - /** - * Reads image data in an ArrayBuffer and writes the data to a PixelMap object. This method - * uses a promise to return the result. - * @since 7 - * @SysCap SystemCapability.Multimedia.Image - * @devices phone, tablet, tv, wearable, car - * @import import image from '@ohos.multimedia.image' - * @param src A buffer from which the image data will be read. - * @return A Promise instance used to return the operation result. If the operation fails, an error message is returned. - */ + // write array buffer to pixelmap writeBufferToPixels(src: ArrayBuffer): Promise; - - /** - * Reads image data in an ArrayBuffer and writes the data to a PixelMap object. This method - * uses a callback to return the result. - * @since 7 - * @SysCap SystemCapability.Multimedia.Image - * @devices phone, tablet, tv, wearable, car - * @import import image from '@ohos.multimedia.image' - * @param src A buffer from which the image data will be read. - * @param callback Callback used to return the operation result. If the operation fails, an error message is returned. - */ writeBufferToPixels(src: ArrayBuffer, callback: AsyncCallback): void; - /** - * Obtains pixel map information about this image. This method uses a promise to return the information. - * @since 7 - * @SysCap SystemCapability.Multimedia.Image - * @devices phone, tablet, tv, wearable, car - * @import import image from '@ohos.multimedia.image' - * @return A Promise instance used to return the image pixel map information. If the operation fails, an error message is returned. - */ + // obtains basic image information. getImageInfo(): Promise; - - /** - * Obtains pixel map information about this image. This method uses a callback to return the information. - * @since 7 - * @SysCap SystemCapability.Multimedia.Image - * @devices phone, tablet, tv, wearable, car - * @import import image from '@ohos.multimedia.image' - * @param callback Callback used to return the image pixel map information. If the operation fails, an error message is returned. - */ getImageInfo(callback: AsyncCallback): void; - /** - * Obtains the number of bytes in each line of the image pixel map. - * @since 7 - * @SysCap SystemCapability.Multimedia.Image - * @devices phone, tablet, tv, wearable, car - * @import import image from '@ohos.multimedia.image' - * @return Number of bytes in each line. - */ - getBytesNumberPerRow(): number; - - /** - * Obtains the number of bytes capacity. - * @return Bytes capacity. - * @since 8 - */ - getPixelBytesCapacity(): number; + // get bytes number per row. + getBytesNumberPerRow(): Promise; + getBytesNumberPerRow(callback: AsyncCallback): void; - /** - * Obtains the total number of bytes of the image pixel map. - * @since 7 - * @SysCap SystemCapability.Multimedia.Image - * @devices phone, tablet, tv, wearable, car - * @import import image from '@ohos.multimedia.image' - * @return Total number of bytes. - */ - getPixelBytesNumber(): number; + // get bytes buffer for a pixelmap. + getPixelBytesNumber(): Promise; + getPixelBytesNumber(callback: AsyncCallback): void; - /** - * Releases this PixelMap object. This method uses a callback to return the result. - * @since 7 - * @SysCap SystemCapability.Multimedia.Image - * @devices phone, tablet, tv, wearable, car - * @import import image from '@ohos.multimedia.image' - * @param callback Callback invoked for instance release. If the operation fails, an error message is returned. - */ - release(callback: AsyncCallback): void; + // release pixelmap + release(): void; - /** - * Releases this PixelMap object. This method uses a promise to return the result. - * @since 7 - * @SysCap SystemCapability.Multimedia.Image - * @devices phone, tablet, tv, wearable, car - * @import import image from '@ohos.multimedia.image' - * @return A Promise instance used to return the instance release result. If the operation fails, an error message is returned. - */ - release(): Promise; + readonly isEditable: boolean; } interface ImageSource { /** - * Obtains information about an image with the specified sequence number and uses a callback - * to return the result. - * @since 6 - * @SysCap SystemCapability.Multimedia.Image - * @devices phone, tablet, tv, wearable, car - * @import import image from '@ohos.multimedia.image' - * @param index Sequence number of an image. - * @param callback Callback used to return the image information. + * Obtains information about an image with the specified sequence number and uses a callback to return the result. */ getImageInfo(index: number, callback: AsyncCallback): void; /** * Obtains information about this image and uses a callback to return the result. - * @since 6 - * @SysCap SystemCapability.Multimedia.Image - * @devices phone, tablet, tv, wearable, car - * @import import image from '@ohos.multimedia.image' - * @param callback Callback used to return the image information. */ getImageInfo(callback: AsyncCallback): void; /** * Get image information from image source. - * @since 6 - * @SysCap SystemCapability.Multimedia.Image - * @devices phone, tablet, tv, wearable, car - * @import import image from '@ohos.multimedia.image' - * @param index Sequence number of an image. If this parameter is not specified, the default value 0 is used. - * @return A Promise instance used to return the image information. */ getImageInfo(index?: number): Promise; - /** - * Creates a PixelMap object based on image decoding parameters. This method uses a promise to - * return the object. - * @since 7 - * @SysCap SystemCapability.Multimedia.Image - * @devices phone, tablet, tv, wearable, car - * @import import image from '@ohos.multimedia.image' - * @param options Image decoding parameters. - * @return A Promise instance used to return the PixelMap object. - */ - createPixelMap(options?: DecodingOptions): Promise; + // Obtains the integer value of a specified property key for an image at the given index in the ImageSource. + getImagePropertyInt(index:number, key: string, defaultValue: number): Promise; + getImagePropertyInt(index:number, key: string, defaultValue: number, callback: AsyncCallback): void; - /** - * Creates a PixelMap object. This method uses a callback to return the object. - * @since 7 - * @SysCap SystemCapability.Multimedia.Image - * @devices phone, tablet, tv, wearable, car - * @import import image from '@ohos.multimedia.image' - * @param callback Callback used to return the PixelMap object. - */ - createPixelMap(callback: AsyncCallback): void; - - /** - * Creates a PixelMap object based on image decoding parameters. This method uses a callback to - * return the object. - * @since 7 - * @SysCap SystemCapability.Multimedia.Image - * @devices phone, tablet, tv, wearable, car - * @import import image from '@ohos.multimedia.image' - * @param options Image decoding parameters. - * @param callback Callback used to return the PixelMap object. - */ - createPixelMap(options: DecodingOptions, callback: AsyncCallback): void; - - /** - * Obtains the value of a property in an image with the specified index. This method uses a - * promise to return the property value in a string. - * @since 7 - * @SysCap SystemCapability.Multimedia.Image - * @devices phone, tablet, tv, wearable, car - * @import import image from '@ohos.multimedia.image' - * @param key Name of the property whose value is to be obtained. - * @param options Index of the image. - * @return A Promise instance used to return the property value. If the operation fails, the default value is returned. - */ - getImageProperty(key:string, options?: GetImagePropertyOptions): Promise; + // Obtains the string value of a specified image property key. + getImagePropertyString(key: string): Promise; + getImagePropertyString(key: string, callback: AsyncCallback): void; - /** - * Obtains the value of a property in this image. This method uses a callback to return the - * property value in a string. - * @since 7 - * @SysCap SystemCapability.Multimedia.Image - * @devices phone, tablet, tv, wearable, car - * @import import image from '@ohos.multimedia.image' - * @param key Name of the property whose value is to be obtained. - * @param callback Callback used to return the property value. If the operation fails, an error message is returned. - */ - getImageProperty(key:string, callback: AsyncCallback): void; + // Decodes source image data based on a specified index location in the ImageSource and creates a pixel map. + createPixelMap(index: number, options: DecodingOptions, callback: AsyncCallback): void; + createPixelMap(opts: DecodingOptions, callback: AsyncCallback): void; - /** - * Obtains the value of a property in an image with the specified index. This method uses - * a callback to return the property value in a string. - * @since 7 - * @SysCap SystemCapability.Multimedia.Image - * @devices phone, tablet, tv, wearable, car - * @import import image from '@ohos.multimedia.image' - * @param key Name of the property whose value is to be obtained. - * @param options Index of the image. - * @param callback Callback used to return the property value. If the operation fails, the default value is returned. - */ - getImageProperty(key:string, options: GetImagePropertyOptions, callback: AsyncCallback): void; + // Updates incremental data to an image data source using a byte array with specified offset and length. + updateData(data: Array, isFinal: boolean, offset?: number, length?: number): Promise; + updateData(data: Array, isFinal: boolean, offset: number, length: number, callback: AsyncCallback): void; + updateData(data: Array, isFinal: boolean, callback: AsyncCallback): void; /** * Releases an ImageSource instance and uses a callback to return the result. - * @since 6 - * @SysCap SystemCapability.Multimedia.Image - * @devices phone, tablet, tv, wearable, car - * @import import image from '@ohos.multimedia.image' - * @param callback Callback to return the operation result. */ release(callback: AsyncCallback): void; /** * Releases an ImageSource instance and uses a promise to return the result. - * @since 6 - * @SysCap SystemCapability.Multimedia.Image - * @devices phone, tablet, tv, wearable, car - * @import import image from '@ohos.multimedia.image' - * @return A Promise instance used to return the operation result. */ release(): Promise; /** * Supported image formats. - * @since 6 - * @SysCap SystemCapability.Multimedia.Image - * @devices phone, tablet, tv, wearable, car - * @import import image from '@ohos.multimedia.image' */ readonly supportedFormats: Array; } @@ -858,64 +357,26 @@ declare namespace image { interface ImagePacker { /** * Compresses or packs an image and uses a callback to return the result. - * @since 6 - * @SysCap SystemCapability.Multimedia.Image - * @devices phone, tablet, tv, wearable, car - * @import import image from '@ohos.multimedia.image' - * @param source Image to be processed. - * @param option Option for image packing. - * @param callback Callback used to return the packed data. */ - packing(source: ImageSource, option: PackingOption, callback: AsyncCallback): void; + packing(source: ImageSource, option: PackingOption, callback: AsyncCallback>): void; /** * Compresses or packs an image and uses a promise to return the result. - * @since 6 - * @SysCap SystemCapability.Multimedia.Image - * @devices phone, tablet, tv, wearable, car - * @import import image from '@ohos.multimedia.image' - * @param source Image to be processed. - * @param option Option for image packing. - * @return A Promise instance used to return the compressed or packed data. - */ - packing(source: ImageSource, option: PackingOption): Promise; - - /** - * Compresses or packs a pixelmap. - * @param source PixelMap to be processed. - * @param option Option for image packing. - * @return Compressed or packed data. - * @since 8 */ - packing(source: PixelMap, option: PackingOption, callback: AsyncCallback): void; - packing(source: PixelMap, option: PackingOption): Promise; + packing(source: ImageSource, option: PackingOption): Promise>; /** * Releases an ImagePacker instance and uses a callback to return the result. - * @since 6 - * @SysCap SystemCapability.Multimedia.Image - * @devices phone, tablet, tv, wearable, car - * @import import image from '@ohos.multimedia.image' - * @param callback Callback to return the operation result. */ release(callback: AsyncCallback): void; /** * Releases an ImagePacker instance and uses a promise to return the result. - * @since 6 - * @SysCap SystemCapability.Multimedia.Image - * @devices phone, tablet, tv, wearable, car - * @import import image from '@ohos.multimedia.image' - * @return A Promise instance used to return the operation result. */ release(): Promise; /** * Supported image formats. - * @since 6 - * @SysCap SystemCapability.Multimedia.Image - * @devices phone, tablet, tv, wearable, car - * @import import image from '@ohos.multimedia.image' */ readonly supportedFormats: Array; } diff --git a/interfaces/kits/js/common/include/image_packer_napi.h b/interfaces/kits/js/common/include/image_packer_napi.h index 8d6b5f694b7729b9bdca3e6f893304caa0496f08..931b1bfc0a1092c02b4a9be387bdea7924f6c329 100644 --- a/interfaces/kits/js/common/include/image_packer_napi.h +++ b/interfaces/kits/js/common/include/image_packer_napi.h @@ -47,6 +47,7 @@ private: static void Destructor(napi_env env, void *nativeObject, void *finalize); static napi_value Packing(napi_env env, napi_callback_info info); static napi_value Release(napi_env env, napi_callback_info info); + static napi_value GetSupportedFormats(napi_env env, napi_callback_info info); static napi_ref sConstructor_; static std::shared_ptr sImgSource_;