From ddcd8549258328f16feea6a33bc357e50c371c04 Mon Sep 17 00:00:00 2001 From: yangfan Date: Fri, 12 Apr 2024 18:03:05 +0800 Subject: [PATCH 1/6] add ImageSource&imagePacker&PixelMap NDK Signed-off-by: yangfan Change-Id: I0541292b1cd77e7ee0933690807545b98f0d43eb --- bundle.json | 28 + frameworks/innerkitsimpl/test/BUILD.gn | 30 + .../unittest/image_packer_native_ndk_test.cpp | 189 +++ .../unittest/image_source_native_ndk_test.cpp | 396 ++++++ .../unittest/pixelmap_native_ndk_test.cpp | 397 ++++++ frameworks/kits/js/common/ndk/BUILD.gn | 58 + .../js/common/ndk/image_packer_native.cpp | 289 ++++ .../common/ndk/image_packer_native_impl.cpp | 154 ++ .../js/common/ndk/image_source_native.cpp | 554 ++++++++ .../common/ndk/image_source_native_impl.cpp | 91 ++ .../ndk/include/image_packer_native_impl.h | 54 + .../ndk/include/image_source_native_impl.h | 47 + .../common/ndk/include/pixelmap_native_impl.h | 41 + .../kits/js/common/pixelmap_ndk/BUILD.gn | 31 + .../common/pixelmap_ndk/pixelmap_native.cpp | 430 ++++++ .../pixelmap_ndk/pixelmap_native_impl.cpp | 67 + .../kits/native/include/image/image_common.h | 1251 +++++++++++++++++ .../include/image/image_packer_native.h | 238 ++++ .../include/image/image_source_native.h | 433 ++++++ .../native/include/image/pixelmap_native.h | 445 ++++++ 20 files changed, 5223 insertions(+) create mode 100644 frameworks/innerkitsimpl/test/unittest/image_packer_native_ndk_test.cpp create mode 100644 frameworks/innerkitsimpl/test/unittest/image_source_native_ndk_test.cpp create mode 100644 frameworks/innerkitsimpl/test/unittest/pixelmap_native_ndk_test.cpp create mode 100644 frameworks/kits/js/common/ndk/image_packer_native.cpp create mode 100644 frameworks/kits/js/common/ndk/image_packer_native_impl.cpp create mode 100644 frameworks/kits/js/common/ndk/image_source_native.cpp create mode 100644 frameworks/kits/js/common/ndk/image_source_native_impl.cpp create mode 100644 frameworks/kits/js/common/ndk/include/image_packer_native_impl.h create mode 100644 frameworks/kits/js/common/ndk/include/image_source_native_impl.h create mode 100644 frameworks/kits/js/common/ndk/include/pixelmap_native_impl.h create mode 100644 frameworks/kits/js/common/pixelmap_ndk/pixelmap_native.cpp create mode 100644 frameworks/kits/js/common/pixelmap_ndk/pixelmap_native_impl.cpp create mode 100644 interfaces/kits/native/include/image/image_common.h create mode 100644 interfaces/kits/native/include/image/image_packer_native.h create mode 100644 interfaces/kits/native/include/image/image_source_native.h create mode 100644 interfaces/kits/native/include/image/pixelmap_native.h diff --git a/bundle.json b/bundle.json index 7f8521022..fef9e2977 100644 --- a/bundle.json +++ b/bundle.json @@ -106,6 +106,16 @@ }, "name": "//foundation/multimedia/image_framework/interfaces/kits/js/common:image" }, + { + "header": { + "header_base": "//foundation/multimedia/image_framework/interfaces/kits/native/include/image/", + "header_files": [ + "image_common.h", + "pixelmap_native.h" + ] + }, + "name": "//foundation/multimedia/image_framework/frameworks/kits/js/common/pixelmap_ndk:pixelmap" + }, { "header": { "header_base": "//foundation/multimedia/image_framework/interfaces/kits/native/include/", @@ -154,6 +164,15 @@ }, "name": "//foundation/multimedia/image_framework/frameworks/kits/js/common/ndk:image_source_ndk" }, + { + "header": { + "header_base": "//foundation/multimedia/image_framework/interfaces/kits/native/include/image", + "header_files": [ + "image_source_native.h" + ] + }, + "name": "//foundation/multimedia/image_framework/frameworks/kits/js/common/ndk:image_source" + }, { "header": { "header_base": "//foundation/multimedia/image_framework/interfaces/kits/native/include/", @@ -163,6 +182,15 @@ }, "name": "//foundation/multimedia/image_framework/frameworks/kits/js/common/ndk:image_packer_ndk" }, + { + "header": { + "header_base": "//foundation/multimedia/image_framework/interfaces/kits/native/include/image", + "header_files": [ + "image_packer_native.h" + ] + }, + "name": "//foundation/multimedia/image_framework/frameworks/kits/js/common/ndk:image_packer" + }, { "header":{ "header_files":[ diff --git a/frameworks/innerkitsimpl/test/BUILD.gn b/frameworks/innerkitsimpl/test/BUILD.gn index e9538caf7..10685cfad 100644 --- a/frameworks/innerkitsimpl/test/BUILD.gn +++ b/frameworks/innerkitsimpl/test/BUILD.gn @@ -1037,6 +1037,35 @@ ohos_unittest("ndktest") { ] } +ohos_unittest("ndktest2") { + module_out_path = module_output_path + + include_dirs = [ + "$image_subsystem/frameworks/kits/js/common/ndk/include", + "/utils/include", + "/interfaces/innerkits/include", + "//third_party/googletest/googletest/include", + "../../../../../arkui/napi/interfaces/inner_api", + "../../../../../arkui/napi/interfaces/kits", + "//third_party/node/src", + "$resource_management_subsystem/interfaces/native/resource/include", + ] + sources = [ + "unittest/image_packer_native_ndk_test.cpp", + "unittest/image_source_native_ndk_test.cpp", + "unittest/pixelmap_native_ndk_test.cpp", + ] + + deps = [ + "$image_subsystem/frameworks/kits/js/common/ndk:image_ndk", + "$image_subsystem/frameworks/kits/js/common/ndk:image_packer", + "$image_subsystem/frameworks/kits/js/common/ndk:image_source", + "$image_subsystem/frameworks/kits/js/common/pixelmap_ndk:pixelmap", + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + ] +} + ohos_unittest("napitest") { module_out_path = module_output_path @@ -1491,6 +1520,7 @@ group("unittest") { ":jpegutilstest", ":jpgyuvtest", ":napitest", + ":ndktest2", ":pixelastctest", ":pixelconvertadaptertest", ":pixelmaptest", diff --git a/frameworks/innerkitsimpl/test/unittest/image_packer_native_ndk_test.cpp b/frameworks/innerkitsimpl/test/unittest/image_packer_native_ndk_test.cpp new file mode 100644 index 000000000..4f8a4ce00 --- /dev/null +++ b/frameworks/innerkitsimpl/test/unittest/image_packer_native_ndk_test.cpp @@ -0,0 +1,189 @@ +/* + * Copyright (C) 2023 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 +#include "image_packer_native.h" +#include "image_packer_native_impl.h" +#include "file_packer_stream.h" + +using namespace testing::ext; +using namespace OHOS::Media; + +namespace OHOS { +namespace Multimedia { +class ImagePackerNdk2Test : public testing::Test { +public: + ImagePackerNdk2Test() {} + ~ImagePackerNdk2Test() {} +}; + +/** + * @tc.name: OH_ImageSourceInfo_Create + * @tc.desc: test OH_ImageSourceInfo_Create + * @tc.type: FUNC + */ +HWTEST_F(ImagePackerNdk2Test, OH_PackingOptions_Create, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "ImagePackerNdk2Test: OH_ImageSourceInfo_Create start"; + OH_PackingOptions *ops = nullptr; + Image_ErrorCode ret = OH_PackingOptions_Create(&ops); + ASSERT_EQ(ret, IMAGE_SUCCESS); + OH_PackingOptions_Release(ops); + GTEST_LOG_(INFO) << "ImagePackerNdk2Test: OH_ImageSourceInfo_Create end"; +} + +/** + * @tc.name: OH_PackingOptions_SetGetMimeType + * @tc.desc: test OH_PackingOptions_SetGetMimeType + * @tc.type: FUNC + */ +HWTEST_F(ImagePackerNdk2Test, OH_PackingOptions_SetGetMimeType, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "ImagePackerNdk2Test: OH_PackingOptions_SetGetMimeType start"; + OH_PackingOptions *ops = nullptr; + char str[10] = ""; + char str2[10] = "12"; + Image_MimeType *mimeType = new Image_MimeType(); + mimeType->data = str; + mimeType->size = 0; + Image_MimeType *mimeType2 = new Image_MimeType(); + mimeType2->data = str2; + mimeType2->size = 2; + Image_ErrorCode ret = OH_PackingOptions_Create(&ops); + ASSERT_EQ(ret, IMAGE_SUCCESS); + OH_PackingOptions_SetMimeType(ops, mimeType2); + OH_PackingOptions_GetMimeType(ops, mimeType); + ASSERT_EQ(mimeType->size, 2); + string res(mimeType->data, mimeType->size); + ASSERT_EQ(res, "12"); + OH_PackingOptions_Release(ops); + GTEST_LOG_(INFO) << "ImagePackerNdk2Test: OH_PackingOptions_SetGetMimeType end"; +} + +/** + * @tc.name: OH_PackingOptions_Release + * @tc.desc: test OH_PackingOptions_Release + * @tc.type: FUNC + */ +HWTEST_F(ImagePackerNdk2Test, OH_PackingOptions_Release, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "ImagePackerNdk2Test: OH_PackingOptions_Release start"; + OH_PackingOptions *ops = nullptr; + Image_ErrorCode ret = OH_PackingOptions_Release(ops); + ASSERT_EQ(ret, IMAGE_BAD_PARAMETER); + GTEST_LOG_(INFO) << "ImagePackerNdk2Test: OH_PackingOptions_Release end"; +} + +/** + * @tc.name: OH_ImagePackerNative_Create + * @tc.desc: test OH_ImagePackerNative_Create + * @tc.type: FUNC + */ +HWTEST_F(ImagePackerNdk2Test, OH_ImagePackerNative_Create, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "ImagePackerNdk2Test: OH_ImagePackerNative_Create start"; + OH_ImagePackerNative *imagePacker = nullptr; + Image_ErrorCode ret = OH_ImagePackerNative_Create(&imagePacker); + ASSERT_EQ(ret, IMAGE_SUCCESS); + GTEST_LOG_(INFO) << "ImagePackerNdk2Test: OH_ImagePackerNative_Create end"; +} + +/** + * @tc.name: OH_ImagePackerNative_PackToDataFromImageSource + * @tc.desc: test OH_ImagePackerNative_PackToDataFromImageSource + * @tc.type: FUNC + */ +HWTEST_F(ImagePackerNdk2Test, OH_ImagePackerNative_PackToDataFromImageSource, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "ImagePackerNdk2Test: OH_ImagePackerNative_PackToDataFromImageSource start"; + OH_ImagePackerNative *imagePacker = nullptr; + OH_PackingOptions* option = nullptr; + OH_ImageSourceNative* imageSource = nullptr; + uint8_t* outData = nullptr; + size_t *size = 0; + Image_ErrorCode ret = OH_ImagePackerNative_PackToDataFromImageSource(imagePacker, option, imageSource, + outData, size); + ASSERT_EQ(ret, IMAGE_BAD_PARAMETER); + GTEST_LOG_(INFO) << "ImagePackerNdk2Test: OH_ImagePackerNative_PackToDataFromImageSource end"; +} + +/** + * @tc.name: OH_ImagePackerNative_PackToDataFromPixelmap + * @tc.desc: test OH_ImagePackerNative_PackToDataFromPixelmap + * @tc.type: FUNC + */ +HWTEST_F(ImagePackerNdk2Test, OH_ImagePackerNative_PackToDataFromPixelmap, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "ImagePackerNdk2Test: OH_ImagePackerNative_PackToDataFromPixelmap start"; + OH_ImagePackerNative *imagePacker = nullptr; + OH_PackingOptions* option = nullptr; + OH_PixelmapNative* pixelMap = nullptr; + uint8_t* outData = nullptr; + size_t *size = 0; + Image_ErrorCode ret = OH_ImagePackerNative_PackToDataFromPixelmap(imagePacker, option, pixelMap, outData, size); + ASSERT_EQ(ret, IMAGE_BAD_PARAMETER); + GTEST_LOG_(INFO) << "ImagePackerNdk2Test: OH_ImagePackerNative_PackToDataFromPixelmap end"; +} + +/** + * @tc.name: OH_ImagePackerNative_PackToFileFromImageSource + * @tc.desc: test OH_ImagePackerNative_PackToFileFromImageSource + * @tc.type: FUNC + */ +HWTEST_F(ImagePackerNdk2Test, OH_ImagePackerNative_PackToFileFromImageSource, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "ImagePackerNdk2Test: OH_ImagePackerNative_PackToFileFromImageSource start"; + OH_ImagePackerNative *imagePacker = nullptr; + OH_PackingOptions* option = nullptr; + OH_ImageSourceNative* imageSource = nullptr; + int32_t fd = 0; + Image_ErrorCode ret = OH_ImagePackerNative_PackToFileFromImageSource(imagePacker, option, imageSource, fd); + ASSERT_EQ(ret, IMAGE_BAD_PARAMETER); + GTEST_LOG_(INFO) << "ImagePackerNdk2Test: OH_ImagePackerNative_PackToFileFromImageSource end"; +} + +/** + * @tc.name: OH_ImagePackerNative_PackToFileFromPixelmap + * @tc.desc: test OH_ImagePackerNative_PackToFileFromPixelmap + * @tc.type: FUNC + */ +HWTEST_F(ImagePackerNdk2Test, OH_ImagePackerNative_PackToFileFromPixelmap, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "ImagePackerNdk2Test: OH_ImagePackerNative_PackToFileFromPixelmap start"; + OH_ImagePackerNative *imagePacker = nullptr; + OH_PackingOptions* option = nullptr; + OH_PixelmapNative* pixelMap = nullptr; + int32_t fd = 0; + Image_ErrorCode ret = OH_ImagePackerNative_PackToFileFromPixelmap(imagePacker, option, pixelMap, fd); + ASSERT_EQ(ret, IMAGE_BAD_PARAMETER); + GTEST_LOG_(INFO) << "ImagePackerNdk2Test: OH_ImagePackerNative_PackToFileFromPixelmap end"; +} + +/** + * @tc.name: OH_ImagePackerNative_Release + * @tc.desc: test OH_ImagePackerNative_Release + * @tc.type: FUNC + */ +HWTEST_F(ImagePackerNdk2Test, OH_ImagePackerNative_Release, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "ImagePackerNdk2Test: OH_ImagePackerNative_Release start"; + OH_ImagePackerNative *imagePacker = nullptr; + Image_ErrorCode ret = OH_ImagePackerNative_Release(imagePacker); + ASSERT_EQ(ret, IMAGE_BAD_PARAMETER); + GTEST_LOG_(INFO) << "ImagePackerNdk2Test: OH_ImagePackerNative_Release end"; +} + +} +} \ No newline at end of file diff --git a/frameworks/innerkitsimpl/test/unittest/image_source_native_ndk_test.cpp b/frameworks/innerkitsimpl/test/unittest/image_source_native_ndk_test.cpp new file mode 100644 index 000000000..c90a772f7 --- /dev/null +++ b/frameworks/innerkitsimpl/test/unittest/image_source_native_ndk_test.cpp @@ -0,0 +1,396 @@ +/* + * 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 +#include "common_utils.h" + +#include "image_source_native.h" +#include "image_source_native_impl.h" +#include "raw_file.h" + +using namespace testing::ext; +namespace OHOS { +namespace Media { +class ImagSourceNdk2Test : public testing::Test { +public: + ImagSourceNdk2Test() {} + ~ImagSourceNdk2Test() {} +}; + +/** + * @tc.name: OH_ImageSourceInfo_Create + * @tc.desc: test OH_ImageSourceInfo_Create + * @tc.type: FUNC + */ +HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceInfo_Create, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceInfo_Create start"; + OH_ImageSource_Info *ops = nullptr; + Image_ErrorCode ret = OH_ImageSourceInfo_Create(&ops); + ASSERT_EQ(ret, IMAGE_SUCCESS); + GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceInfo_Create end"; +} + +/** + * @tc.name: OH_ImageSourceInfo_GetWidth + * @tc.desc: test OH_ImageSourceInfo_GetWidth + * @tc.type: FUNC + */ +HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceInfo_GetWidth, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceInfo_GetWidth start"; + OH_ImageSource_Info *ops = nullptr; + uint32_t *width = nullptr; + Image_ErrorCode ret = OH_ImageSourceInfo_GetWidth(ops, width); + ASSERT_EQ(ret, IMAGE_BAD_PARAMETER); + GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceInfo_GetWidth end"; +} + +/** + * @tc.name: OH_ImageSourceInfo_GetHeight + * @tc.desc: test OH_ImageSourceInfo_GetHeight + * @tc.type: FUNC + */ +HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceInfo_GetHeight, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceInfo_GetHeight start"; + OH_ImageSource_Info *ops = nullptr; + uint32_t *width = nullptr; + Image_ErrorCode ret = OH_ImageSourceInfo_GetHeight(ops, width); + ASSERT_EQ(ret, IMAGE_BAD_PARAMETER); + GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceInfo_GetHeight end"; +} + +/** + * @tc.name: OH_ImageSourceInfo_Release + * @tc.desc: test OH_ImageSourceInfo_Release + * @tc.type: FUNC + */ +HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceInfo_Release, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceInfo_Release start"; + OH_ImageSource_Info *ops = nullptr; + Image_ErrorCode ret = OH_ImageSourceInfo_Release(ops); + ASSERT_EQ(ret, IMAGE_BAD_PARAMETER); + GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceInfo_Release end"; +} + +/** + * @tc.name: OH_DecodingOptions_Create + * @tc.desc: test OH_DecodingOptions_Create + * @tc.type: FUNC + */ +HWTEST_F(ImagSourceNdk2Test, OH_DecodingOptions_Create, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_DecodingOptions_Create start"; + OH_DecodingOptions *ops = nullptr; + Image_ErrorCode ret = OH_DecodingOptions_Create(&ops); + ASSERT_EQ(ret, IMAGE_SUCCESS); + GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_DecodingOptions_Create end"; +} + +/** + * @tc.name: OH_ImageSource_DecodingOptionsSetGetPixelFormat + * @tc.desc: test OH_ImageSource_DecodingOptionsSetGetPixelFormat + * @tc.type: FUNC + */ +HWTEST_F(ImagSourceNdk2Test, OH_ImageSource_DecodingOptionsSetGetPixelFormat, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSource_DecodingOptionsSetGetPixelFormat start"; + OH_DecodingOptions *ops = nullptr; + Image_ErrorCode ret = IMAGE_UNKNOWN_ERROR; + int32_t pixelFormat = 0; + ret = OH_DecodingOptions_Create(&ops); + ASSERT_EQ(ret, IMAGE_SUCCESS); + OH_DecodingOptions_SetPixelFormat(ops, 1); + OH_DecodingOptions_GetPixelFormat(ops, &pixelFormat); + ASSERT_EQ(pixelFormat, 1); + GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSource_DecodingOptionsSetGetPixelFormat end"; +} + +/** + * @tc.name: OH_ImageSource_DecodingOptionsSetGetIndex + * @tc.desc: test OH_ImageSource_DecodingOptionsSetGetIndex + * @tc.type: FUNC + */ +HWTEST_F(ImagSourceNdk2Test, OH_ImageSource_DecodingOptionsSetGetIndex, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSource_DecodingOptionsSetGetIndex start"; + OH_DecodingOptions *ops = nullptr; + Image_ErrorCode ret = IMAGE_UNKNOWN_ERROR; + uint32_t index = 0; + ret = OH_DecodingOptions_Create(&ops); + ASSERT_EQ(ret, IMAGE_SUCCESS); + OH_DecodingOptions_SetIndex(ops, 1); + OH_DecodingOptions_GetIndex(ops, &index); + ASSERT_EQ(index, 1); + GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSource_DecodingOptionsSetGetIndex end"; +} + +/** + * @tc.name: OH_ImageSource_DecodingOptionsSetGetRotate + * @tc.desc: test OH_ImageSource_DecodingOptionsSetGetRotate + * @tc.type: FUNC + */ +HWTEST_F(ImagSourceNdk2Test, OH_ImageSource_DecodingOptionsSetGetRotate, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSource_DecodingOptionsSetGetRotate start"; + OH_DecodingOptions *ops = nullptr; + Image_ErrorCode ret = IMAGE_UNKNOWN_ERROR; + float rotate = 0; + ret = OH_DecodingOptions_Create(&ops); + ASSERT_EQ(ret, IMAGE_SUCCESS); + OH_DecodingOptions_SetRotate(ops, 1); + OH_DecodingOptions_GetRotate(ops, &rotate); + ASSERT_EQ(rotate, 1); + GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSource_DecodingOptionsSetGetRotate end"; +} + +/** + * @tc.name: OH_ImageSource_DecodingOptionsSetGetDesiredSize + * @tc.desc: test OH_ImageSource_DecodingOptionsSetGetDesiredSize + * @tc.type: FUNC + */ +HWTEST_F(ImagSourceNdk2Test, OH_ImageSource_DecodingOptionsSetGetDesiredSize, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSource_DecodingOptionsSetGetDesiredSize start"; + OH_DecodingOptions *ops = nullptr; + Image_ErrorCode ret = IMAGE_UNKNOWN_ERROR; + Image_Size desiredSize = {0, 0}; + Image_Size desiredSize2 = {1, 2}; + ret = OH_DecodingOptions_Create(&ops); + ASSERT_EQ(ret, IMAGE_SUCCESS); + OH_DecodingOptions_SetDesiredSize(ops, &desiredSize2); + OH_DecodingOptions_GetDesiredSize(ops, &desiredSize); + ASSERT_EQ(desiredSize.width, desiredSize2.width); + ASSERT_EQ(desiredSize.height, desiredSize2.height); + GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSource_DecodingOptionsSetGetDesiredSize end"; +} + +/** + * @tc.name: OH_ImageSource_DecodingOptionsSetGetDesiredRegion + * @tc.desc: test OH_ImageSource_DecodingOptionsSetGetDesiredRegion + * @tc.type: FUNC + */ +HWTEST_F(ImagSourceNdk2Test, OH_ImageSource_DecodingOptionsSetGetDesiredRegion, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSource_DecodingOptionsSetGetDesiredRegion start"; + OH_DecodingOptions *ops = nullptr; + Image_ErrorCode ret = IMAGE_UNKNOWN_ERROR; + Image_Region desiredRegion = {0, 0, 0, 0}; + Image_Region desiredRegion2 = {1, 2, 3, 4}; + ret = OH_DecodingOptions_Create(&ops); + ASSERT_EQ(ret, IMAGE_SUCCESS); + OH_DecodingOptions_SetDesiredRegion(ops, &desiredRegion2); + OH_DecodingOptions_GetDesiredRegion(ops, &desiredRegion); + ASSERT_EQ(desiredRegion.x, 1); + ASSERT_EQ(desiredRegion.y, 2); + ASSERT_EQ(desiredRegion.width, 3); + ASSERT_EQ(desiredRegion.height, 4); + ret = OH_DecodingOptions_Release(ops); + ASSERT_EQ(ret, IMAGE_SUCCESS); + GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSource_DecodingOptionsSetGetDesiredRegion end"; +} + +/** + * @tc.name: OH_ImageSourceNative_CreateFromUri + * @tc.desc: test OH_ImageSourceNative_CreateFromUri + * @tc.type: FUNC + */ +HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreateFromUri, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreateFromUri start"; + OH_ImageSourceNative *imageSource = nullptr; + char *uri = nullptr; + size_t uriSize = 0; + Image_ErrorCode ret = OH_ImageSourceNative_CreateFromUri(uri, uriSize, &imageSource); + ASSERT_EQ(ret, IMAGE_BAD_PARAMETER); + GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreateFromUri end"; +} + +/** + * @tc.name: OH_ImageSourceNative_CreateFromFd + * @tc.desc: test OH_ImageSourceNative_CreateFromFd + * @tc.type: FUNC + */ +HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreateFromFd, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreateFromFd start"; + OH_ImageSourceNative *imageSource = nullptr; + int32_t fd = 0; + Image_ErrorCode ret = OH_ImageSourceNative_CreateFromFd(fd, &imageSource); + ASSERT_EQ(ret, IMAGE_BAD_PARAMETER); + GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreateFromFd end"; +} + +/** + * @tc.name: OH_ImageSourceNative_CreateFromData + * @tc.desc: test OH_ImageSourceNative_CreateFromData + * @tc.type: FUNC + */ +HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreateFromData, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreateFromData start"; + OH_ImageSourceNative *imageSource = nullptr; + uint8_t* data = nullptr; + size_t dataSize = 0; + Image_ErrorCode ret = OH_ImageSourceNative_CreateFromData(data, dataSize, &imageSource); + ASSERT_EQ(ret, IMAGE_BAD_PARAMETER); + GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreateFromData end"; +} + +/** + * @tc.name: OH_ImageSourceNative_CreateFromRawFile + * @tc.desc: test OH_ImageSourceNative_CreateFromRawFile + * @tc.type: FUNC + */ +HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreateFromRawFile, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreateFromRawFile start"; + OH_ImageSourceNative *imageSource = nullptr; + RawFileDescriptor *rawFile = nullptr; + Image_ErrorCode ret = OH_ImageSourceNative_CreateFromRawFile(rawFile, &imageSource); + ASSERT_EQ(ret, IMAGE_BAD_PARAMETER); + GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreateFromRawFile end"; +} + +/** + * @tc.name: OH_ImageSourceNative_CreatePixelmap + * @tc.desc: test OH_ImageSourceNative_CreatePixelmap + * @tc.type: FUNC + */ +HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmap, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreatePixelmap start"; + OH_ImageSourceNative *imageSource = nullptr; + OH_DecodingOptions* ops = nullptr; + OH_PixelmapNative* resPixMap = nullptr; + Image_ErrorCode ret = OH_ImageSourceNative_CreatePixelmap(imageSource, ops, &resPixMap); + ASSERT_EQ(ret, IMAGE_BAD_PARAMETER); + GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreatePixelmap end"; +} + +/** + * @tc.name: OH_ImageSourceNative_CreatePixelmapList + * @tc.desc: test OH_ImageSourceNative_CreatePixelmapList + * @tc.type: FUNC + */ +HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreatePixelmapList, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreatePixelmapList start"; + OH_DecodingOptions *ops = nullptr; + OH_ImageSourceNative *imageSource = nullptr; + OH_PixelmapNative** resVecPixMap = nullptr; + size_t outSize = 0; + Image_ErrorCode ret = OH_ImageSourceNative_CreatePixelmapList(imageSource, ops, resVecPixMap, outSize); + ASSERT_EQ(ret, IMAGE_BAD_PARAMETER); + GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreatePixelmapList end"; +} + +/** + * @tc.name: OH_ImageSourceNative_GetDelayTimeList + * @tc.desc: test OH_ImageSourceNative_GetDelayTimeList + * @tc.type: FUNC + */ +HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_GetDelayTimeList, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_GetDelayTimeList start"; + OH_ImageSourceNative *imageSource = nullptr; + int32_t* delayTimeList = nullptr; + size_t size = 0; + Image_ErrorCode ret = OH_ImageSourceNative_GetDelayTimeList(imageSource, delayTimeList, size); + ASSERT_EQ(ret, IMAGE_BAD_PARAMETER); + GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_GetDelayTimeList end"; +} + +/** + * @tc.name: OH_ImageSourceNative_GetImageInfo + * @tc.desc: test OH_ImageSourceNative_GetImageInfo + * @tc.type: FUNC + */ +HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_GetImageInfo, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_GetImageInfo start"; + OH_ImageSourceNative *imageSource = nullptr; + int32_t index = 0; + OH_ImageSource_Info* info = nullptr; + Image_ErrorCode ret = OH_ImageSourceNative_GetImageInfo(imageSource, index, info); + ASSERT_EQ(ret, IMAGE_BAD_PARAMETER); + GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_GetImageInfo end"; +} + +/** + * @tc.name: OH_ImageSourceNative_GetImageProperty + * @tc.desc: test OH_ImageSourceNative_GetImageProperty + * @tc.type: FUNC + */ +HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_GetImageProperty, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_GetImageProperty start"; + OH_ImageSourceNative *imageSource = nullptr; + Image_String* key = nullptr; + Image_String* value = nullptr; + Image_ErrorCode ret = OH_ImageSourceNative_GetImageProperty(imageSource, key, value); + ASSERT_EQ(ret, IMAGE_BAD_PARAMETER); + GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_GetImageProperty end"; +} + +/** + * @tc.name: OH_ImageSourceNative_ModifyImageProperty + * @tc.desc: test OH_ImageSourceNative_ModifyImageProperty + * @tc.type: FUNC + */ +HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_ModifyImageProperty, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_ModifyImageProperty start"; + OH_ImageSourceNative *imageSource = nullptr; + Image_String* key = nullptr; + Image_String* value = nullptr; + Image_ErrorCode ret = OH_ImageSourceNative_ModifyImageProperty(imageSource, key, value); + ASSERT_EQ(ret, IMAGE_BAD_PARAMETER); + GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_ModifyImageProperty end"; +} + +/** + * @tc.name: OH_ImageSourceNative_GetFrameCount + * @tc.desc: test OH_ImageSourceNative_GetFrameCount + * @tc.type: FUNC + */ +HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_GetFrameCount, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_GetFrameCount start"; + OH_ImageSourceNative *imageSource = nullptr; + uint32_t* res = nullptr; + Image_ErrorCode ret = OH_ImageSourceNative_GetFrameCount(imageSource, res); + ASSERT_EQ(ret, IMAGE_BAD_PARAMETER); + GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_GetFrameCount end"; +} + +/** + * @tc.name: OH_ImageSourceNative_Release + * @tc.desc: test OH_ImageSourceNative_Release + * @tc.type: FUNC + */ +HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_Release, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_Release start"; + OH_ImageSourceNative *imageSource = nullptr; + Image_ErrorCode ret = OH_ImageSourceNative_Release(imageSource); + ASSERT_EQ(ret, IMAGE_BAD_PARAMETER); + GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_Release end"; +} + +} +} diff --git a/frameworks/innerkitsimpl/test/unittest/pixelmap_native_ndk_test.cpp b/frameworks/innerkitsimpl/test/unittest/pixelmap_native_ndk_test.cpp new file mode 100644 index 000000000..e0056c111 --- /dev/null +++ b/frameworks/innerkitsimpl/test/unittest/pixelmap_native_ndk_test.cpp @@ -0,0 +1,397 @@ +/* + * 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 +#include "pixelmap_native.h" +#include "pixelmap_native_impl.h" +#include "common_utils.h" + +using namespace testing::ext; +using namespace OHOS::Media; +namespace OHOS { +namespace Media { +class PixelMapNdk2Test : public testing::Test { +public: + PixelMapNdk2Test() {} + ~PixelMapNdk2Test() {} +}; + +/** + * @tc.name: OH_PixelmapInitializationOptions_Create + * @tc.desc: OH_PixelmapInitializationOptions_Create + * @tc.type: FUNC + */ +HWTEST_F(PixelMapNdk2Test, OH_PixelmapInitializationOptions_Create, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "PixelMapNdk2Test: OH_PixelmapInitializationOptions_Create start"; + OH_Pixelmap_InitializationOptions *ops = nullptr; + Image_ErrorCode res = OH_PixelmapInitializationOptions_Create(&ops); + ASSERT_EQ(res, IMAGE_SUCCESS); + GTEST_LOG_(INFO) << "PixelMapNdk2Test: OH_PixelmapInitializationOptions_Create end"; +} + +/** + * @tc.name: OH_PixelmapInitializationOptions_SetGetWidth + * @tc.desc: OH_PixelmapInitializationOptions_SetGetWidth + * @tc.type: FUNC + */ +HWTEST_F(PixelMapNdk2Test, OH_PixelmapInitializationOptions_SetGetWidth, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "PixelMapNdk2Test: OH_PixelmapInitializationOptions_GetWidth start"; + OH_Pixelmap_InitializationOptions *ops = nullptr; + OH_PixelmapInitializationOptions_Create(&ops); + uint32_t width = 0; + OH_PixelmapInitializationOptions_SetWidth(ops, 1); + OH_PixelmapInitializationOptions_GetWidth(ops, &width); + ASSERT_EQ(width, 1); + GTEST_LOG_(INFO) << "PixelMapNdk2Test: OH_PixelmapInitializationOptions_GetWidth end"; +} + +/** + * @tc.name: OH_PixelmapInitializationOptions_SetGetHeight + * @tc.desc: OH_PixelmapInitializationOptions_SetGetHeight + * @tc.type: FUNC + */ +HWTEST_F(PixelMapNdk2Test, OH_PixelmapInitializationOptions_SetGetHeight, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "PixelMapNdk2Test: OH_PixelmapInitializationOptions_SetGetHeight start"; + OH_Pixelmap_InitializationOptions *ops = nullptr; + OH_PixelmapInitializationOptions_Create(&ops); + uint32_t height = 0; + OH_PixelmapInitializationOptions_SetHeight(ops, 1); + OH_PixelmapInitializationOptions_GetHeight(ops, &height); + ASSERT_EQ(height, 1); + GTEST_LOG_(INFO) << "PixelMapNdk2Test: OH_PixelmapInitializationOptions_SetGetHeight end"; +} + +/** + * @tc.name: OH_PixelmapInitializationOptions_SetGetPixelFormat + * @tc.desc: OH_PixelmapInitializationOptions_SetGetPixelFormat + * @tc.type: FUNC + */ +HWTEST_F(PixelMapNdk2Test, OH_PixelmapInitializationOptions_SetGetPixelFormat, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "PixelMapNdk2Test: OH_PixelmapNative_InitializationSetOptionsGetPixelFormat start"; + OH_Pixelmap_InitializationOptions *ops = nullptr; + OH_PixelmapInitializationOptions_Create(&ops); + int32_t pixelFormat = 0; + OH_PixelmapInitializationOptions_SetPixelFormat(ops, 1); + OH_PixelmapInitializationOptions_GetPixelFormat(ops, &pixelFormat); + ASSERT_EQ(pixelFormat, 1); + GTEST_LOG_(INFO) << "PixelMapNdk2Test: OH_PixelmapNative_InitializationSetOptionsGetPixelFormat end"; +} + +HWTEST_F(PixelMapNdk2Test, OH_PixelmapInitializationOptions_SetGetAlphaType, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "PixelMapNdk2Test: OH_PixelmapInitializationOptions_SetGetAlphaType start"; + OH_Pixelmap_InitializationOptions *ops = nullptr; + OH_PixelmapInitializationOptions_Create(&ops); + int32_t alphaType = 0; + OH_PixelmapInitializationOptions_SetAlphaType(ops, 1); + OH_PixelmapInitializationOptions_GetAlphaType(ops, &alphaType); + ASSERT_EQ(alphaType, 1); + GTEST_LOG_(INFO) << "PixelMapNdk2Test: OH_PixelmapInitializationOptions_SetGetAlphaType end"; +} + +/** + * @tc.name: OH_PixelmapInitializationOptions_Release + * @tc.desc: OH_PixelmapInitializationOptions_Release + * @tc.type: FUNC + */ +HWTEST_F(PixelMapNdk2Test, OH_PixelmapInitializationOptions_Release, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "PixelMapNdk2Test: OH_PixelmapInitializationOptions_Release start"; + OH_Pixelmap_InitializationOptions *ops = nullptr; + Image_ErrorCode ret = OH_PixelmapInitializationOptions_Release(ops); + ASSERT_EQ(ret, IMAGE_BAD_PARAMETER); + GTEST_LOG_(INFO) << "PixelMapNdk2Test: OH_PixelmapInitializationOptions_Release end"; +} + +/** + * @tc.name: OH_PixelmapImageInfo_Create + * @tc.desc: OH_PixelmapImageInfo_Create + * @tc.type: FUNC + */ +HWTEST_F(PixelMapNdk2Test, OH_PixelmapImageInfo_Create, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "PixelMapNdk2Test: OH_PixelmapImageInfo_Create start"; + OH_Pixelmap_ImageInfo *ImageInfo = nullptr; + Image_ErrorCode ret = OH_PixelmapImageInfo_Create(&ImageInfo); + ASSERT_EQ(ret, IMAGE_SUCCESS); + GTEST_LOG_(INFO) << "PixelMapNdk2Test: OH_PixelmapImageInfo_Create end"; +} + +/** + * @tc.name: OH_PixelmapImageInfo_GetWidth + * @tc.desc: OH_PixelmapImageInfo_GetWidth + * @tc.type: FUNC + */ +HWTEST_F(PixelMapNdk2Test, OH_PixelmapImageInfo_GetWidth, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "PixelMapNdk2Test: OH_PixelmapImageInfo_GetWidth start"; + OH_Pixelmap_ImageInfo *ImageInfo = nullptr; + uint32_t width = 0; + Image_ErrorCode ret = OH_PixelmapImageInfo_GetWidth(ImageInfo, &width); + ASSERT_EQ(ret, IMAGE_BAD_PARAMETER); + GTEST_LOG_(INFO) << "PixelMapNdk2Test: OH_PixelmapImageInfo_GetWidth end"; +} + +/** + * @tc.name: OH_PixelmapImageInfo_GetHeight + * @tc.desc: OH_PixelmapImageInfo_GetHeight + * @tc.type: FUNC + */ +HWTEST_F(PixelMapNdk2Test, OH_PixelmapImageInfo_GetHeight, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "PixelMapNdk2Test: OH_PixelmapImageInfo_GetHeight start"; + OH_Pixelmap_ImageInfo *ImageInfo = nullptr; + uint32_t height = 0; + Image_ErrorCode ret = OH_PixelmapImageInfo_GetHeight(ImageInfo, &height); + ASSERT_EQ(ret, IMAGE_BAD_PARAMETER); + GTEST_LOG_(INFO) << "PixelMapNdk2Test: OH_PixelmapImageInfo_GetHeight end"; +} + +/** + * @tc.name: OH_PixelmapImageInfo_GetRowStride + * @tc.desc: OH_PixelmapImageInfo_GetRowStride + * @tc.type: FUNC + */ +HWTEST_F(PixelMapNdk2Test, OH_PixelmapImageInfo_GetRowStride, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "PixelMapNdk2Test: OH_PixelmapImageInfo_GetRowStride start"; + OH_Pixelmap_ImageInfo *ImageInfo = nullptr; + uint32_t rowSize = 0; + Image_ErrorCode ret = OH_PixelmapImageInfo_GetRowStride(ImageInfo, &rowSize); + ASSERT_EQ(ret, IMAGE_BAD_PARAMETER); + GTEST_LOG_(INFO) << "PixelMapNdk2Test: OH_PixelmapImageInfo_GetRowStride end"; +} + +/** + * @tc.name: OH_PixelmapImageInfo_GetPixelFormat + * @tc.desc: OH_PixelmapImageInfo_GetPixelFormat + * @tc.type: FUNC + */ +HWTEST_F(PixelMapNdk2Test, OH_PixelmapImageInfo_GetPixelFormat, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "PixelMapNdk2Test: OH_PixelmapImageInfo_GetPixelFormat start"; + OH_Pixelmap_ImageInfo *ImageInfo = nullptr; + int32_t pixelFormat = 0; + Image_ErrorCode ret = OH_PixelmapImageInfo_GetPixelFormat(ImageInfo, &pixelFormat); + ASSERT_EQ(ret, IMAGE_BAD_PARAMETER); + GTEST_LOG_(INFO) << "PixelMapNdk2Test: OH_PixelmapImageInfo_GetPixelFormat end"; +} + +/** + * @tc.name: OH_PixelmapImageInfo_GetAlphaType + * @tc.desc: OH_PixelmapImageInfo_GetAlphaType + * @tc.type: FUNC + */ +HWTEST_F(PixelMapNdk2Test, OH_PixelmapImageInfo_GetAlphaType, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "PixelMapNdk2Test: OH_PixelmapImageInfo_GetAlphaType start"; + OH_Pixelmap_ImageInfo *ImageInfo = nullptr; + int32_t density = 0; + Image_ErrorCode ret = OH_PixelmapImageInfo_GetAlphaType(ImageInfo, &density); + ASSERT_EQ(ret, IMAGE_BAD_PARAMETER); + GTEST_LOG_(INFO) << "PixelMapNdk2Test: OH_PixelmapImageInfo_GetAlphaType end"; +} + +/** + * @tc.name: OH_PixelmapImageInfo_Release + * @tc.desc: OH_PixelmapImageInfo_Release + * @tc.type: FUNC + */ +HWTEST_F(PixelMapNdk2Test, OH_PixelmapImageInfo_Release, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "PixelMapNdk2Test: OH_PixelmapImageInfo_Release start"; + OH_Pixelmap_ImageInfo *ImageInfo = nullptr; + Image_ErrorCode ret = OH_PixelmapImageInfo_Release(ImageInfo); + ASSERT_EQ(ret, IMAGE_BAD_PARAMETER); + GTEST_LOG_(INFO) << "PixelMapNdk2Test: OH_PixelmapImageInfo_Release end"; +} + +/** + * @tc.name: OH_PixelmapNative_CreatePixelMap + * @tc.desc: OH_PixelmapNative_CreatePixelMap + * @tc.type: FUNC + */ +HWTEST_F(PixelMapNdk2Test, OH_PixelmapNative_CreatePixelMap, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "PixelMapNdk2Test: OH_PixelmapNative_CreatePixelMap start"; + uint8_t *colors = nullptr; + size_t colorLength = 0; + OH_Pixelmap_InitializationOptions *opts = nullptr; + OH_PixelmapNative *pixelMap = nullptr; + Image_ErrorCode ret = OH_PixelmapNative_CreatePixelmap(colors, colorLength, opts, &pixelMap); + ASSERT_EQ(ret, IMAGE_BAD_PARAMETER); + GTEST_LOG_(INFO) << "PixelMapNdk2Test: OH_PixelmapNative_CreatePixelMap end"; +} + +/** + * @tc.name: OH_PixelmapNative_ReadPixels + * @tc.desc: OH_PixelmapNative_ReadPixels + * @tc.type: FUNC + */ +HWTEST_F(PixelMapNdk2Test, OH_PixelmapNative_ReadPixels, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "PixelMapNdk2Test: OH_PixelmapNative_ReadPixels start"; + OH_PixelmapNative *pixelMap = nullptr; + uint8_t *buffer = nullptr; + size_t *bufferSize = nullptr; + Image_ErrorCode ret = OH_PixelmapNative_ReadPixels(pixelMap, buffer, bufferSize); + ASSERT_EQ(ret, IMAGE_BAD_PARAMETER); + GTEST_LOG_(INFO) << "PixelMapNdk2Test: OH_PixelmapNative_ReadPixels end"; +} + +/** + * @tc.name: OH_PixelmapNative_WritePixels + * @tc.desc: OH_PixelmapNative_WritePixels + * @tc.type: FUNC + */ +HWTEST_F(PixelMapNdk2Test, OH_PixelmapNative_WritePixels, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "PixelMapNdk2Test: OH_PixelmapNative_WritePixels start"; + OH_PixelmapNative *pixelMap = nullptr; + uint8_t *source = nullptr; + size_t bufferSize = 0; + Image_ErrorCode ret = OH_PixelmapNative_WritePixels(pixelMap, source, bufferSize); + ASSERT_EQ(ret, IMAGE_BAD_PARAMETER); + GTEST_LOG_(INFO) << "PixelMapNdk2Test: OH_PixelmapNative_WritePixels end"; +} + +/** + * @tc.name: OH_PixelmapNative_GetImageInfo + * @tc.desc: OH_PixelmapNative_GetImageInfo + * @tc.type: FUNC + */ +HWTEST_F(PixelMapNdk2Test, OH_PixelmapNative_GetImageInfo, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "PixelMapNdk2Test: OH_PixelmapNative_GetImageInfo start"; + OH_PixelmapNative *pixelMap = nullptr; + OH_Pixelmap_ImageInfo *imageInfo = nullptr; + Image_ErrorCode ret = OH_PixelmapNative_GetImageInfo(pixelMap, imageInfo); + ASSERT_EQ(ret, IMAGE_BAD_PARAMETER); + GTEST_LOG_(INFO) << "PixelMapNdk2Test: OH_PixelmapNative_GetImageInfo end"; +} + +/** + * @tc.name: OH_PixelmapNative_Opacity + * @tc.desc: OH_PixelmapNative_Opacity + * @tc.type: FUNC + */ +HWTEST_F(PixelMapNdk2Test, OH_PixelmapNative_Opacity, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "PixelMapNdk2Test: OH_PixelmapNative_Opacity start"; + OH_PixelmapNative *pixelMap = nullptr; + float rate = 0; + Image_ErrorCode ret = OH_PixelmapNative_Opacity(pixelMap, rate); + ASSERT_EQ(ret, IMAGE_BAD_PARAMETER); + GTEST_LOG_(INFO) << "PixelMapNdk2Test: OH_PixelmapNative_Opacity end"; +} + +/** + * @tc.name: OH_PixelmapNative_Scale + * @tc.desc: OH_PixelmapNative_Scale + * @tc.type: FUNC + */ +HWTEST_F(PixelMapNdk2Test, OH_PixelmapNative_Scale, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "PixelMapNdk2Test: OH_PixelmapNative_Scale start"; + OH_PixelmapNative *pixelMap = nullptr; + float x = 0; + float y = 0; + Image_ErrorCode ret = OH_PixelmapNative_Scale(pixelMap, x, y); + ASSERT_EQ(ret, IMAGE_BAD_PARAMETER); + GTEST_LOG_(INFO) << "PixelMapNdk2Test: OH_PixelmapNative_Scale end"; +} + +/** + * @tc.name: OH_PixelmapNative_Translate + * @tc.desc: OH_PixelmapNative_Translate + * @tc.type: FUNC + */ +HWTEST_F(PixelMapNdk2Test, OH_PixelmapNative_Translate, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "PixelMapNdk2Test: OH_PixelmapNative_Translate start"; + OH_PixelmapNative *pixelMap = nullptr; + float x = 0; + float y = 0; + Image_ErrorCode ret = OH_PixelmapNative_Translate(pixelMap, x, y); + ASSERT_EQ(ret, IMAGE_BAD_PARAMETER); + GTEST_LOG_(INFO) << "PixelMapNdk2Test: OH_PixelmapNative_Translate end"; +} + +/** + * @tc.name: OH_PixelmapNative_Rotate + * @tc.desc: OH_PixelmapNative_Rotate + * @tc.type: FUNC + */ +HWTEST_F(PixelMapNdk2Test, OH_PixelmapNative_Rotate, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "PixelMapNdk2Test: OH_PixelmapNative_Rotate start"; + OH_PixelmapNative *pixelMap = nullptr; + float angle = 0; + Image_ErrorCode ret = OH_PixelmapNative_Rotate(pixelMap, angle); + ASSERT_EQ(ret, IMAGE_BAD_PARAMETER); + GTEST_LOG_(INFO) << "PixelMapNdk2Test: OH_PixelmapNative_Rotate end"; +} + +/** + * @tc.name: OH_PixelmapNative_Flip + * @tc.desc: OH_PixelmapNative_Flip + * @tc.type: FUNC + */ +HWTEST_F(PixelMapNdk2Test, OH_PixelmapNative_Flip, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "PixelMapNdk2Test: OH_PixelmapNative_Flip start"; + OH_PixelmapNative *pixelMap = nullptr; + bool horizontal = 0; + bool vertical = 0; + Image_ErrorCode ret = OH_PixelmapNative_Flip(pixelMap, horizontal, vertical); + ASSERT_EQ(ret, IMAGE_BAD_PARAMETER); + GTEST_LOG_(INFO) << "PixelMapNdk2Test: OH_PixelmapNative_Flip end"; +} + +/** + * @tc.name: OH_PixelmapNative_Crop + * @tc.desc: OH_PixelmapNative_Crop + * @tc.type: FUNC + */ +HWTEST_F(PixelMapNdk2Test, OH_PixelmapNative_Crop, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "PixelMapNdk2Test: OH_PixelmapNative_Crop start"; + OH_PixelmapNative *pixelMap = nullptr; + Image_Region *region = nullptr; + Image_ErrorCode ret = OH_PixelmapNative_Crop(pixelMap, region); + ASSERT_EQ(ret, IMAGE_BAD_PARAMETER); + GTEST_LOG_(INFO) << "PixelMapNdk2Test: OH_PixelmapNative_Crop end"; +} + +/** + * @tc.name: OH_PixelmapNative_Release + * @tc.desc: OH_PixelmapNative_Release + * @tc.type: FUNC + */ +HWTEST_F(PixelMapNdk2Test, OH_PixelmapNative_Release, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "PixelMapNdk2Test: OH_PixelmapNative_Release start"; + OH_PixelmapNative *pixelMap = nullptr; + Image_ErrorCode ret = OH_PixelmapNative_Release(pixelMap); + ASSERT_EQ(ret, IMAGE_BAD_PARAMETER); + GTEST_LOG_(INFO) << "PixelMapNdk2Test: OH_PixelmapNative_Release end"; +} + +} +} diff --git a/frameworks/kits/js/common/ndk/BUILD.gn b/frameworks/kits/js/common/ndk/BUILD.gn index 5d1c3d31a..33a2001af 100644 --- a/frameworks/kits/js/common/ndk/BUILD.gn +++ b/frameworks/kits/js/common/ndk/BUILD.gn @@ -24,8 +24,11 @@ config("native_public_config") { "$BASE_DIR/arkui/napi/interfaces/inner_api", "$BASE_DIR/arkui/napi/interfaces/kits", "$BASE_DIR/multimedia/image_framework/interfaces/kits/native/include", + "$BASE_DIR/multimedia/image_framework/interfaces/kits/native/include/image", + "$BASE_DIR/multimedia/image_framework/interfaces/innerkits/include", "$THIRD_DIR/node/src", "$resource_management_subsystem/interfaces/native/resource/include", + "$BASE_DIR/multimedia/image_framework/frameworks/kits/js/common/pixelmap_ndk", ] } @@ -92,3 +95,58 @@ ohos_shared_library("image_packer_ndk") { subsystem_name = "multimedia" part_name = "image_framework" } + +ohos_shared_library("image_source") { + output_extension = "so" + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + + sources = [ + "image_source_native.cpp", + "image_source_native_impl.cpp", + ] + + public_configs = [ ":native_public_config" ] + + deps = [ + "$image_subsystem/frameworks/kits/js/common/pixelmap_ndk:pixelmap", + "$image_subsystem/interfaces/innerkits:image_native", + "$image_subsystem/interfaces/kits/js/common:image", + ] + + external_deps = [ "c_utils:utils" ] + + innerapi_tags = [ "ndk" ] + subsystem_name = "multimedia" + part_name = "image_framework" +} + +ohos_shared_library("image_packer") { + output_extension = "so" + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + + sources = [ + "image_packer_native.cpp", + "image_packer_native_impl.cpp", + ] + public_configs = [ ":native_public_config" ] + deps = [ + "$image_subsystem/frameworks/kits/js/common/ndk:image_source", + "$image_subsystem/frameworks/kits/js/common/pixelmap_ndk:pixelmap", + "$image_subsystem/interfaces/innerkits:image_native", + "$image_subsystem/interfaces/kits/js/common:image", + ] + + external_deps = [ "c_utils:utils" ] + + innerapi_tags = [ "ndk" ] + subsystem_name = "multimedia" + part_name = "image_framework" +} diff --git a/frameworks/kits/js/common/ndk/image_packer_native.cpp b/frameworks/kits/js/common/ndk/image_packer_native.cpp new file mode 100644 index 000000000..3f1093244 --- /dev/null +++ b/frameworks/kits/js/common/ndk/image_packer_native.cpp @@ -0,0 +1,289 @@ +/* + * 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 "image_packer_native.h" + +#include "common_utils.h" +#include "image_packer.h" +#include "image_packer_native_impl.h" +#include "image_source_native_impl.h" +#include "pixelmap_native_impl.h" +#ifndef _WIN32 +#include "securec.h" +#else +#include "memory.h" +#endif + +using namespace OHOS; +using namespace Media; +#ifdef __cplusplus +extern "C" { +#endif + +constexpr size_t SIZE_ZERO = 0; +constexpr int32_t IMAGE_BASE = 62980096; +static constexpr int32_t IMAGE_BASE_19 = 19; +static constexpr int32_t IMAGE_BASE_16 = 16; +static constexpr int32_t IMAGE_BASE_17 = 17; +static constexpr int32_t IMAGE_BASE_26 = 26; +static constexpr int32_t IMAGE_BASE_31 = 31; +static constexpr int32_t IMAGE_BASE_152 = 152; +static constexpr int32_t IMAGE_BASE_27 = 27; +static constexpr int32_t IMAGE_BASE_12 = 12; +static constexpr int32_t IMAGE_BASE_13 = 13; +static constexpr int32_t IMAGE_BASE_6 = 6; +static constexpr int32_t IMAGE_BASE_14 = 14; +static constexpr int32_t IMAGE_BASE_4 = 4; +static constexpr int32_t IMAGE_BASE_9 = 9; +static constexpr int32_t IMAGE_BASE_20 = 20; +static constexpr int32_t IMAGE_BASE_22 = 22; +static constexpr int32_t IMAGE_BASE_23 = 23; + +struct OH_PackingOptions { + Image_MimeType mimeType; + int quality; +}; + +static Image_ErrorCode ToNewErrorCode(int code) +{ + switch (code) { + case 0: + return IMAGE_SUCCESS; + case IMAGE_BASE + IMAGE_BASE_19: + return IMAGE_BAD_PARAMETER; + case IMAGE_BASE + IMAGE_BASE_16: + case IMAGE_BASE + IMAGE_BASE_17: + case IMAGE_BASE + IMAGE_BASE_26: + return IMAGE_UNKNOWN_MIME_TYPE; + case IMAGE_BASE + IMAGE_BASE_31: + return IMAGE_TOO_LARGE; + case IMAGE_BASE + IMAGE_BASE_152: + return IMAGE_UNSUPPORTED_OPERATION; + case IMAGE_BASE + IMAGE_BASE_27: + return IMAGE_UNSUPPORTED_METADATA; + case IMAGE_BASE + IMAGE_BASE_12: + return IMAGE_UNSUPPORTED_CONVERSION; + case IMAGE_BASE + IMAGE_BASE_13: + return IMAGE_INVALID_REGION; + case IMAGE_BASE + IMAGE_BASE_6: + return IMAGE_ALLOC_FAILED; + case IMAGE_BASE + IMAGE_BASE_14: + return IMAGE_BAD_SOURCE; + case IMAGE_BASE + IMAGE_BASE_4: + case IMAGE_BASE + IMAGE_BASE_9: + case IMAGE_BASE + IMAGE_BASE_20: + case IMAGE_BASE + IMAGE_BASE_22: + return IMAGE_DECODE_FAILED; + case IMAGE_BASE + IMAGE_BASE_23: + return IMAGE_ENCODE_FAILED; + default: + return IMAGE_UNKNOWN_ERROR; + } +}; + +MIDK_EXPORT +Image_ErrorCode OH_PackingOptions_Create(OH_PackingOptions **options) +{ + *options = new OH_PackingOptions(); + if (*options == nullptr) { + return IMAGE_BAD_PARAMETER; + } + return IMAGE_SUCCESS; +} + +MIDK_EXPORT +Image_ErrorCode OH_PackingOptions_GetMimeType(OH_PackingOptions *options, + Image_MimeType *format) +{ + if (options == nullptr || format == nullptr) { + return IMAGE_BAD_PARAMETER; + } + + if (format->size != SIZE_ZERO && format->size < options->mimeType.size) { + return IMAGE_BAD_PARAMETER; + } + + format->size = (format->size == SIZE_ZERO) ? options->mimeType.size : format->size; + format->data = static_cast(malloc(format->size)); + if (format->data == nullptr) { + return IMAGE_ALLOC_FAILED; + } + + if (memcpy_s(format->data, format->size, options->mimeType.data, options->mimeType.size) != 0) { + free(format->data); + format->data = nullptr; + format->size = 0; + return IMAGE_COPY_FAILED; + } + return IMAGE_SUCCESS; +} + +MIDK_EXPORT +Image_ErrorCode OH_PackingOptions_SetMimeType(OH_PackingOptions *options, + Image_MimeType *format) +{ + if (options == nullptr || format->data == nullptr || format->size == 0) { + return IMAGE_BAD_PARAMETER; + } + if (options->mimeType.data != nullptr) { + free(options->mimeType.data); + options->mimeType.data = nullptr; + } + options->mimeType.size = format->size; + options->mimeType.data = static_cast(malloc(options->mimeType.size)); + if (memcpy_s(options->mimeType.data, options->mimeType.size, format->data, format->size) != 0) { + free(options->mimeType.data); + options->mimeType.data = nullptr; + options->mimeType.size = 0; + return IMAGE_COPY_FAILED; + } + return IMAGE_SUCCESS; +} + +MIDK_EXPORT +Image_ErrorCode OH_PackingOptions_GetQuality(OH_PackingOptions *options, uint32_t *quality) +{ + if (options == nullptr || quality == nullptr) { + return IMAGE_BAD_PARAMETER; + } + *quality = options->quality; + return IMAGE_SUCCESS; +} + +MIDK_EXPORT +Image_ErrorCode OH_PackingOptions_SetQuality(OH_PackingOptions *options, uint32_t quality) +{ + if (options == nullptr) { + return IMAGE_BAD_PARAMETER; + } + options->quality = quality; + return IMAGE_SUCCESS; +} + +MIDK_EXPORT +Image_ErrorCode OH_PackingOptions_Release(OH_PackingOptions *options) +{ + if (options == nullptr) { + return IMAGE_BAD_PARAMETER; + } + if (options->mimeType.data) { + free(options->mimeType.data); + options->mimeType.data = nullptr; + } + delete options; + return IMAGE_SUCCESS; +} + +MIDK_EXPORT +Image_ErrorCode OH_ImagePackerNative_Create(OH_ImagePackerNative **imagePacker) +{ + auto imagePacker2 = new OH_ImagePackerNative(); + if (imagePacker2 == nullptr || imagePacker2->GetInnerImagePacker() == nullptr) { + if (imagePacker2) { + delete imagePacker2; + } + return IMAGE_BAD_PARAMETER; + } + *imagePacker = imagePacker2; + return IMAGE_SUCCESS; +} + +MIDK_EXPORT +Image_ErrorCode OH_ImagePackerNative_PackToDataFromImageSource(OH_ImagePackerNative *imagePacker, + OH_PackingOptions *options, OH_ImageSourceNative *imageSource, uint8_t *outData, size_t *size) +{ + if (imagePacker == nullptr || options == nullptr || imageSource == nullptr || outData == nullptr) { + return IMAGE_BAD_PARAMETER; + } + + PackOption packOption; + std::string format(options->mimeType.data, options->mimeType.size); + if (format.empty()) { + return IMAGE_BAD_PARAMETER; + } + packOption.format = format; + packOption.quality = options->quality; + return ToNewErrorCode(imagePacker->PackingFromImageSource(&packOption, imageSource, + outData, reinterpret_cast(size))); +} + +MIDK_EXPORT +Image_ErrorCode OH_ImagePackerNative_PackToDataFromPixelmap(OH_ImagePackerNative *imagePacker, + OH_PackingOptions *options, OH_PixelmapNative *pixelmap, uint8_t *outData, size_t *size) +{ + if (imagePacker == nullptr || options == nullptr || pixelmap == nullptr || outData == nullptr) { + return IMAGE_BAD_PARAMETER; + } + + PackOption packOption; + std::string format(options->mimeType.data, options->mimeType.size); + if (format.empty()) { + return IMAGE_BAD_PARAMETER; + } + packOption.format = format; + packOption.quality = options->quality; + return ToNewErrorCode(imagePacker->PackingFromPixelmap(&packOption, pixelmap, outData, + reinterpret_cast(size))); +} + +MIDK_EXPORT +Image_ErrorCode OH_ImagePackerNative_PackToFileFromImageSource(OH_ImagePackerNative *imagePacker, + OH_PackingOptions *options, OH_ImageSourceNative *imageSource, int32_t fd) +{ + if (imagePacker == nullptr || options == nullptr || imageSource == nullptr) { + return IMAGE_BAD_PARAMETER; + } + + PackOption packOption; + std::string format(options->mimeType.data, options->mimeType.size); + if (format.empty()) { + return IMAGE_BAD_PARAMETER; + } + packOption.format = format; + packOption.quality = options->quality; + return ToNewErrorCode(imagePacker->PackToFileFromImageSource(&packOption, imageSource, fd)); +} + +MIDK_EXPORT +Image_ErrorCode OH_ImagePackerNative_PackToFileFromPixelmap(OH_ImagePackerNative *imagePacker, + OH_PackingOptions *options, OH_PixelmapNative *pixelmap, int32_t fd) +{ + if (imagePacker == nullptr || options == nullptr || pixelmap == nullptr) { + return IMAGE_BAD_PARAMETER; + } + + PackOption packOption; + std::string format(options->mimeType.data, options->mimeType.size); + if (format.empty()) { + return IMAGE_BAD_PARAMETER; + } + packOption.format = format; + packOption.quality = options->quality; + return ToNewErrorCode(imagePacker->PackToFileFromPixelmap(&packOption, pixelmap, fd)); +} + +MIDK_EXPORT +Image_ErrorCode OH_ImagePackerNative_Release(OH_ImagePackerNative *imagePacker) +{ + if (imagePacker == nullptr) { + return IMAGE_BAD_PARAMETER; + } + delete imagePacker; + return IMAGE_SUCCESS; +} + +#ifdef __cplusplus +}; +#endif \ No newline at end of file diff --git a/frameworks/kits/js/common/ndk/image_packer_native_impl.cpp b/frameworks/kits/js/common/ndk/image_packer_native_impl.cpp new file mode 100644 index 000000000..fc4aadd52 --- /dev/null +++ b/frameworks/kits/js/common/ndk/image_packer_native_impl.cpp @@ -0,0 +1,154 @@ +/* + * 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 "image_packer_native_impl.h" +#include "image_source_native_impl.h" +#include "pixelmap_native_impl.h" + +using namespace OHOS; +using namespace Media; +#ifdef __cplusplus +extern "C" { +#endif + + +OH_ImagePackerNative::OH_ImagePackerNative() +{ + imagePacker_ = std::make_shared(); +} + +OH_ImagePackerNative::OH_ImagePackerNative(std::shared_ptr imagePacker) +{ + imagePacker_ = imagePacker; +} + +OH_ImagePackerNative::~OH_ImagePackerNative() +{ + if (imagePacker_) { + imagePacker_ = nullptr; + } +} + +int32_t OH_ImagePackerNative::PackingFromImageSource(OHOS::Media::PackOption *option, OH_ImageSourceNative *imageSource, + uint8_t *outData, int64_t *size) +{ + if (option == nullptr || imageSource == nullptr) { + return IMAGE_BAD_PARAMETER; + } + OHOS::Media::ImagePacker *imagePacker = imagePacker_.get(); + OHOS::Media::ImageSource *imageSourcePtr = imageSource->GetInnerImageSource().get(); + int64_t packedSize = 0; + uint32_t ret = IMAGE_SUCCESS; + const int64_t DEFAULT_BUFFER_SIZE = 25 * 1024 * 1024; + int64_t bufferSize = (*size <= 0) ? DEFAULT_BUFFER_SIZE : (*size); + ret = imagePacker->StartPacking(outData, bufferSize, *option); + if (ret != IMAGE_SUCCESS) { + return ret; + } + ret = imagePacker->AddImage(*imageSourcePtr); + if (ret != IMAGE_SUCCESS) { + return ret; + } + ret = imagePacker->FinalizePacking(packedSize); + if (ret != IMAGE_SUCCESS) { + return ret; + } + if (packedSize > 0 && (packedSize < bufferSize)) { + *size = packedSize; + return IMAGE_SUCCESS; + } + return IMAGE_ENCODE_FAILED; +} + +int32_t OH_ImagePackerNative::PackingFromPixelmap(OHOS::Media::PackOption *option, OH_PixelmapNative *pixelmap, + uint8_t *outData, int64_t *size) +{ + if (option == nullptr || pixelmap == nullptr) { + return IMAGE_BAD_PARAMETER; + } + OHOS::Media::ImagePacker *imagePacker = imagePacker_.get(); + OHOS::Media::PixelMap *pixelmapPtr = pixelmap->GetInnerPixelmap().get(); + int64_t packedSize = 0; + uint32_t ret = IMAGE_SUCCESS; + const int64_t DEFAULT_BUFFER_SIZE = 25 * 1024 * 1024; + int64_t bufferSize = (*size <= 0) ? DEFAULT_BUFFER_SIZE : (*size); + ret = imagePacker->StartPacking(outData, bufferSize, *option); + if (ret != IMAGE_SUCCESS) { + return ret; + } + ret = imagePacker->AddImage(*pixelmapPtr); + if (ret != IMAGE_SUCCESS) { + return ret; + } + ret = imagePacker->FinalizePacking(packedSize); + if (ret != IMAGE_SUCCESS) { + return ret; + } + if (packedSize > 0 && (packedSize < bufferSize)) { + *size = packedSize; + return IMAGE_SUCCESS; + } + return IMAGE_ENCODE_FAILED; +} + +int32_t OH_ImagePackerNative::PackToFileFromImageSource(OHOS::Media::PackOption *option, + OH_ImageSourceNative *imageSource, const int fd) +{ + if (option == nullptr || imageSource == nullptr) { + return IMAGE_BAD_PARAMETER; + } + OHOS::Media::ImagePacker *imagePacker = imagePacker_.get(); + OHOS::Media::ImageSource *imageSourcePtr = imageSource->GetInnerImageSource().get(); + int64_t packedSize = 0; + uint32_t ret = IMAGE_SUCCESS; + ret = imagePacker->StartPacking(fd, *option); + if (ret != IMAGE_SUCCESS) { + return ret; + } + ret = imagePacker->AddImage(*imageSourcePtr); + if (ret != IMAGE_SUCCESS) { + return ret; + } + return imagePacker->FinalizePacking(packedSize); +} + +int32_t OH_ImagePackerNative::PackToFileFromPixelmap(OHOS::Media::PackOption *option, OH_PixelmapNative *pixelmap, + int32_t fd) +{ + if (option == nullptr || pixelmap == nullptr) { + return IMAGE_BAD_PARAMETER; + } + OHOS::Media::ImagePacker *imagePacker = imagePacker_.get(); + OHOS::Media::PixelMap *pixelmapPtr = pixelmap->GetInnerPixelmap().get(); + int64_t packedSize = 0; + uint32_t ret = IMAGE_SUCCESS; + ret = imagePacker->StartPacking(fd, *option); + if (ret != IMAGE_SUCCESS) { + return ret; + } + ret = imagePacker->AddImage(*pixelmapPtr); + if (ret != IMAGE_SUCCESS) { + return ret; + } + return imagePacker->FinalizePacking(packedSize); +} + +std::shared_ptr OH_ImagePackerNative::GetInnerImagePacker() +{ + return imagePacker_; +} + +#ifdef __cplusplus +}; +#endif \ No newline at end of file diff --git a/frameworks/kits/js/common/ndk/image_source_native.cpp b/frameworks/kits/js/common/ndk/image_source_native.cpp new file mode 100644 index 000000000..f26a0b010 --- /dev/null +++ b/frameworks/kits/js/common/ndk/image_source_native.cpp @@ -0,0 +1,554 @@ +/* + * 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 "image_source_native.h" + +#include "common_utils.h" +#include "image_source.h" +#include "image_source_native_impl.h" +#include "pixelmap_native_impl.h" +#ifndef _WIN32 +#include "securec.h" +#else +#include "memory.h" +#endif + +using namespace OHOS; +using namespace Media; +#ifdef __cplusplus +extern "C" { +#endif + +const uint32_t DEFAULT_INDEX = 0; +constexpr size_t SIZE_ZERO = 0; +constexpr uint32_t INVALID_SAMPLE_SIZE = 0; +const int32_t INVALID_FD = -1; +static constexpr int32_t FORMAT_0 = 0; +static constexpr int32_t FORMAT_2 = 2; +static constexpr int32_t FORMAT_3 = 3; +static constexpr int32_t FORMAT_4 = 4; +static constexpr int32_t FORMAT_5 = 5; +static constexpr int32_t FORMAT_6 = 6; +static constexpr int32_t FORMAT_7 = 7; +static constexpr int32_t FORMAT_8 = 8; +static constexpr int32_t FORMAT_9 = 9; + +struct OH_DecodingOptions { + int32_t pixelFormat; + uint32_t index; + uint32_t sampleSize; + uint32_t rotate; + struct Image_Size desiredSize; + struct Image_Region desiredRegion; +}; + +struct OH_ImageSource_Info { + /** Image width, in pixels. */ + int32_t width; + /** Image height, in pixels. */ + int32_t height; +}; + +MIDK_EXPORT +Image_ErrorCode OH_DecodingOptions_Create(OH_DecodingOptions **options) +{ + *options = new OH_DecodingOptions(); + if (*options == nullptr) { + return IMAGE_BAD_PARAMETER; + } + return IMAGE_SUCCESS; +} + +MIDK_EXPORT +Image_ErrorCode OH_DecodingOptions_GetPixelFormat(OH_DecodingOptions *options, + int32_t *pixelFormat) +{ + if (options == nullptr || pixelFormat == nullptr) { + return IMAGE_BAD_PARAMETER; + } + *pixelFormat = options->pixelFormat; + return IMAGE_SUCCESS; +} + +MIDK_EXPORT +Image_ErrorCode OH_DecodingOptions_SetPixelFormat(OH_DecodingOptions *options, + int32_t pixelFormat) +{ + if (options == nullptr) { + return IMAGE_BAD_PARAMETER; + } + options->pixelFormat = pixelFormat; + return IMAGE_SUCCESS; +} + +MIDK_EXPORT +Image_ErrorCode OH_DecodingOptions_GetIndex(OH_DecodingOptions *options, uint32_t *index) +{ + if (options == nullptr || index == nullptr) { + return IMAGE_BAD_PARAMETER; + } + *index = options->index; + return IMAGE_SUCCESS; +} + +MIDK_EXPORT +Image_ErrorCode OH_DecodingOptions_SetIndex(OH_DecodingOptions *options, uint32_t index) +{ + if (options == nullptr) { + return IMAGE_BAD_PARAMETER; + } + options->index = index; + return IMAGE_SUCCESS; +} + +MIDK_EXPORT +Image_ErrorCode OH_DecodingOptions_GetRotate(OH_DecodingOptions *options, float *rotate) +{ + if (options == nullptr || rotate == nullptr) { + return IMAGE_BAD_PARAMETER; + } + *rotate = options->rotate; + return IMAGE_SUCCESS; +} + +MIDK_EXPORT +Image_ErrorCode OH_DecodingOptions_SetRotate(OH_DecodingOptions *options, float rotate) +{ + if (options == nullptr) { + return IMAGE_BAD_PARAMETER; + } + options->rotate = rotate; + return IMAGE_SUCCESS; +} + +MIDK_EXPORT +Image_ErrorCode OH_DecodingOptions_GetDesiredSize(OH_DecodingOptions *options, + Image_Size *desiredSize) +{ + if (options == nullptr || desiredSize == nullptr) { + return IMAGE_BAD_PARAMETER; + } + desiredSize->width = options->desiredSize.width; + desiredSize->height = options->desiredSize.height; + return IMAGE_SUCCESS; +} + +MIDK_EXPORT +Image_ErrorCode OH_DecodingOptions_SetDesiredSize(OH_DecodingOptions *options, + Image_Size *desiredSize) +{ + if (options == nullptr || desiredSize == nullptr) { + return IMAGE_BAD_PARAMETER; + } + options->desiredSize.width = desiredSize->width; + options->desiredSize.height = desiredSize->height; + return IMAGE_SUCCESS; +} + +MIDK_EXPORT +Image_ErrorCode OH_DecodingOptions_GetDesiredRegion(OH_DecodingOptions *options, + Image_Region *desiredRegion) +{ + if (options == nullptr || desiredRegion == nullptr) { + return IMAGE_BAD_PARAMETER; + } + desiredRegion->x = options->desiredRegion.x; + desiredRegion->y = options->desiredRegion.y; + desiredRegion->width = options->desiredRegion.width; + desiredRegion->height = options->desiredRegion.height; + return IMAGE_SUCCESS; +} + +MIDK_EXPORT +Image_ErrorCode OH_DecodingOptions_SetDesiredRegion(OH_DecodingOptions *options, + Image_Region *desiredRegion) +{ + if (options == nullptr || desiredRegion == nullptr) { + return IMAGE_BAD_PARAMETER; + } + options->desiredRegion.x = desiredRegion->x; + options->desiredRegion.y = desiredRegion->y; + options->desiredRegion.width = desiredRegion->width; + options->desiredRegion.height = desiredRegion->height; + return IMAGE_SUCCESS; +} + +MIDK_EXPORT +Image_ErrorCode OH_DecodingOptions_Release(OH_DecodingOptions *options) +{ + if (options == nullptr) { + return IMAGE_BAD_PARAMETER; + } + delete options; + return IMAGE_SUCCESS; +} + +MIDK_EXPORT +Image_ErrorCode OH_ImageSourceInfo_Create(OH_ImageSource_Info **info) +{ + *info = new OH_ImageSource_Info(); + if (*info == nullptr) { + return IMAGE_BAD_PARAMETER; + } + return IMAGE_SUCCESS; +} + +MIDK_EXPORT +Image_ErrorCode OH_ImageSourceInfo_GetWidth(OH_ImageSource_Info *info, uint32_t *width) +{ + if (info == nullptr || width == nullptr) { + return IMAGE_BAD_PARAMETER; + } + *width = info->width; + return IMAGE_SUCCESS; +} + +MIDK_EXPORT +Image_ErrorCode OH_ImageSourceInfo_GetHeight(OH_ImageSource_Info *info, uint32_t *height) +{ + if (info == nullptr || height == nullptr) { + return IMAGE_BAD_PARAMETER; + } + *height = info->height; + return IMAGE_SUCCESS; +} + +MIDK_EXPORT +Image_ErrorCode OH_ImageSourceInfo_Release(OH_ImageSource_Info *info) +{ + if (info == nullptr) { + return IMAGE_BAD_PARAMETER; + } + delete info; + return IMAGE_SUCCESS; +} + + +std::string OH_ImageSourceNative::UrlToPath(const std::string &path) +{ + const std::string filePrefix = "file://"; + if (path.size() > filePrefix.size() && + (path.compare(0, filePrefix.size(), filePrefix) == 0)) { + return path.substr(filePrefix.size()); + } + return path; +} + +static void ParseDecodingOps(DecodeOptions &decOps, struct OH_DecodingOptions *ops) +{ + if (ops->sampleSize != INVALID_SAMPLE_SIZE) { + decOps.sampleSize = ops->sampleSize; + } + decOps.rotateNewDegrees = ops->rotate; + decOps.desiredSize.width = ops->desiredSize.width; + decOps.desiredSize.height = ops->desiredSize.height; + decOps.desiredRegion.left = ops->desiredRegion.x; + decOps.desiredRegion.top = ops->desiredRegion.y; + decOps.desiredRegion.width = ops->desiredRegion.width; + decOps.desiredRegion.height = ops->desiredRegion.height; + switch (static_cast(ops->pixelFormat)) { + case FORMAT_0: + case FORMAT_2: + case FORMAT_3: + case FORMAT_4: + case FORMAT_5: + case FORMAT_6: + case FORMAT_7: + case FORMAT_8: + case FORMAT_9: + decOps.desiredPixelFormat = PixelFormat(ops->pixelFormat); + break; + default: + decOps.desiredPixelFormat = PixelFormat::UNKNOWN; + } +} + +static void ParseImageSourceInfo(struct OH_ImageSource_Info *source, ImageInfo &info) +{ + source->width = info.size.width; + source->height = info.size.height; +} + +MIDK_EXPORT +Image_ErrorCode OH_ImageSourceNative_CreateFromUri(char *uri, size_t uriSize, OH_ImageSourceNative **res) +{ + if (uri == nullptr) { + return IMAGE_BAD_PARAMETER; + } + SourceOptions options; + auto imageSource = new OH_ImageSourceNative(uri, uriSize, options); + if (imageSource == nullptr || imageSource->GetInnerImageSource() == nullptr) { + if (imageSource) { + delete imageSource; + } + *res = nullptr; + return IMAGE_BAD_PARAMETER; + } + std::string tmp(uri, uriSize); + if (tmp.empty()) { + return IMAGE_BAD_PARAMETER; + } + imageSource->filePath_ = tmp; + *res = imageSource; + return IMAGE_SUCCESS; +} + +MIDK_EXPORT +Image_ErrorCode OH_ImageSourceNative_CreateFromFd(int32_t fd, OH_ImageSourceNative **res) +{ + SourceOptions options; + auto imageSource = new OH_ImageSourceNative(fd, options); + if (imageSource == nullptr || imageSource->GetInnerImageSource() == nullptr) { + if (imageSource) { + delete imageSource; + } + *res = nullptr; + return IMAGE_BAD_PARAMETER; + } + imageSource->fileDescriptor_ = fd; + *res = imageSource; + return IMAGE_SUCCESS; +} + +MIDK_EXPORT +Image_ErrorCode OH_ImageSourceNative_CreateFromData(uint8_t *data, size_t dataSize, OH_ImageSourceNative **res) +{ + if (data == nullptr) { + return IMAGE_BAD_PARAMETER; + } + SourceOptions options; + auto imageSource = new OH_ImageSourceNative(data, dataSize, options); + if (imageSource == nullptr || imageSource->GetInnerImageSource() == nullptr) { + if (imageSource) { + delete imageSource; + } + *res = nullptr; + return IMAGE_BAD_PARAMETER; + } + imageSource->fileBuffer_ = (void*)data; + imageSource->fileBufferSize_ = dataSize; + *res = imageSource; + return IMAGE_SUCCESS; +} + +MIDK_EXPORT +Image_ErrorCode OH_ImageSourceNative_CreateFromRawFile(RawFileDescriptor *rawFile, OH_ImageSourceNative **res) +{ + if (rawFile == nullptr) { + return IMAGE_BAD_PARAMETER; + } + SourceOptions options; + auto imageSource = new OH_ImageSourceNative(*rawFile, options); + if (imageSource == nullptr || imageSource->GetInnerImageSource() == nullptr) { + if (imageSource) { + delete imageSource; + } + *res = nullptr; + return IMAGE_BAD_PARAMETER; + } + *res = imageSource; + return IMAGE_SUCCESS; +} + +MIDK_EXPORT +Image_ErrorCode OH_ImageSourceNative_CreatePixelmap(OH_ImageSourceNative *source, OH_DecodingOptions *ops, + OH_PixelmapNative **pixelmap) +{ + if (source == nullptr || ops == nullptr) { + return IMAGE_BAD_PARAMETER; + } + + DecodeOptions decOps; + uint32_t index = DEFAULT_INDEX; + uint32_t errorCode = IMAGE_BAD_PARAMETER; + ParseDecodingOps(decOps, ops); + index = ops->index; + std::unique_ptr tmpPixelmap = source->GetInnerImageSource()->CreatePixelMapEx(index, decOps, errorCode); + if (tmpPixelmap == nullptr || errorCode != IMAGE_SUCCESS) { + return IMAGE_UNSUPPORTED_OPERATION; + } + std::shared_ptr nativePixelmap = std::move(tmpPixelmap); + OH_PixelmapNative *stPixMap = new OH_PixelmapNative(nativePixelmap); + *pixelmap = stPixMap; + return IMAGE_SUCCESS; +} + +MIDK_EXPORT +Image_ErrorCode OH_ImageSourceNative_CreatePixelmapList(OH_ImageSourceNative *source, OH_DecodingOptions *ops, + OH_PixelmapNative *resVecPixMap[], size_t outSize) +{ + if (source == nullptr || ops == nullptr || resVecPixMap == nullptr || outSize <= SIZE_ZERO) { + return IMAGE_BAD_PARAMETER; + } + DecodeOptions decOps; + uint32_t errorCode = IMAGE_BAD_PARAMETER; + if (ops != nullptr) { + ParseDecodingOps(decOps, ops); + } + auto pixelmapList = source->GetInnerImageSource()->CreatePixelMapList(decOps, errorCode); + if (pixelmapList == nullptr || errorCode != IMAGE_SUCCESS) { + return IMAGE_BAD_PARAMETER; + } + if (outSize < (*pixelmapList).size()) { + return IMAGE_BAD_PARAMETER; + } + size_t index = 0; + for (auto &item : *pixelmapList) { + std::shared_ptr tempPixMap = std::move(item); + OH_PixelmapNative *stPixMap = new OH_PixelmapNative(tempPixMap); + resVecPixMap[index] = stPixMap; + index ++; + } + return IMAGE_SUCCESS; +} + +MIDK_EXPORT +Image_ErrorCode OH_ImageSourceNative_GetDelayTimeList(OH_ImageSourceNative *source, int32_t *delayTimeList, size_t size) +{ + if (source == nullptr || delayTimeList == nullptr) { + return IMAGE_BAD_PARAMETER; + } + uint32_t errorCode = IMAGE_SUCCESS; + auto delayTimes = source->GetInnerImageSource()->GetDelayTime(errorCode); + if (delayTimes == nullptr || errorCode != IMAGE_SUCCESS) { + return IMAGE_BAD_PARAMETER; + } + size_t actCount = (*delayTimes).size(); + if (size < actCount) { + return IMAGE_BAD_PARAMETER; + } + for (size_t i = SIZE_ZERO; i < actCount; i++) { + delayTimeList[i] = (*delayTimes)[i]; + } + return IMAGE_SUCCESS; +} + +MIDK_EXPORT +Image_ErrorCode OH_ImageSourceNative_GetImageInfo(OH_ImageSourceNative *source, int32_t index, + struct OH_ImageSource_Info *info) +{ + if (source == nullptr || info == nullptr) { + return IMAGE_BAD_PARAMETER; + } + ImageInfo imageInfo; + uint32_t errorCode = source->GetInnerImageSource()->GetImageInfo(index, imageInfo); + if (errorCode != IMAGE_SUCCESS) { + return IMAGE_BAD_PARAMETER; + } + ParseImageSourceInfo(info, imageInfo); + return IMAGE_SUCCESS; +} + +MIDK_EXPORT +Image_ErrorCode OH_ImageSourceNative_GetImageProperty(OH_ImageSourceNative *source, Image_String *key, + Image_String *value) +{ + if (source == nullptr) { + return IMAGE_BAD_PARAMETER; + } + if (key == nullptr || key->data == nullptr || key->size == SIZE_ZERO) { + return IMAGE_BAD_PARAMETER; + } + if (value == nullptr) { + return IMAGE_BAD_PARAMETER; + } + std::string keyString(key->data, key->size); + if (keyString.empty()) { + return IMAGE_BAD_PARAMETER; + } + std::string val; + uint32_t errorCode = source->GetInnerImageSource()->GetImagePropertyString(DEFAULT_INDEX, keyString, val); + if (errorCode != IMAGE_SUCCESS || val.empty()) { + return IMAGE_BAD_PARAMETER; + } + + if (value->size != SIZE_ZERO && value->size < val.size()) { + return IMAGE_BAD_PARAMETER; + } + value->size = (value->size == SIZE_ZERO) ? val.size() : value->size; + value->data = static_cast(malloc(value->size)); + if (value->data == nullptr) { + return IMAGE_ALLOC_FAILED; + } + memcpy_s(value->data, value->size, val.c_str(), val.size()); + return IMAGE_SUCCESS; +} + +MIDK_EXPORT +Image_ErrorCode OH_ImageSourceNative_ModifyImageProperty(OH_ImageSourceNative *source, Image_String *key, + Image_String *value) +{ + if (source == nullptr) { + return IMAGE_BAD_PARAMETER; + } + if (key == nullptr || key->data == nullptr || key->size == SIZE_ZERO) { + return IMAGE_BAD_PARAMETER; + } + if (value == nullptr || value->data == nullptr || value->size == SIZE_ZERO) { + return IMAGE_BAD_PARAMETER; + } + + std::string keyStr(key->data, key->size); + if (keyStr.empty()) { + return IMAGE_BAD_PARAMETER; + } + std::string val(value->data, value->size); + if (val.empty()) { + return IMAGE_BAD_PARAMETER; + } + uint32_t errorCode = IMAGE_BAD_PARAMETER; + if (!(source->filePath_.empty())) { + errorCode = source->GetInnerImageSource()->ModifyImageProperty(DEFAULT_INDEX, keyStr, val, source->filePath_); + } else if (source->fileDescriptor_ != INVALID_FD) { + errorCode = source->GetInnerImageSource()->ModifyImageProperty(DEFAULT_INDEX, keyStr, val, + source->fileDescriptor_); + } else if (source->fileBuffer_ != nullptr && source->fileBufferSize_ != 0) { + errorCode = source->GetInnerImageSource()->ModifyImageProperty(DEFAULT_INDEX, keyStr, val, + static_cast(source->fileBuffer_), source->fileBufferSize_); + } else { + return IMAGE_BAD_PARAMETER; + } + if (errorCode == IMAGE_SUCCESS) { + return IMAGE_SUCCESS; + } + return IMAGE_BAD_PARAMETER; +} + +MIDK_EXPORT +Image_ErrorCode OH_ImageSourceNative_GetFrameCount(OH_ImageSourceNative *source, uint32_t *frameCount) +{ + if (source == nullptr || frameCount == nullptr) { + return IMAGE_BAD_PARAMETER; + } + uint32_t errorCode = IMAGE_BAD_PARAMETER; + *frameCount = source->GetInnerImageSource()->GetFrameCount(errorCode); + if (errorCode != IMAGE_SUCCESS) { + return IMAGE_BAD_PARAMETER; + } + return IMAGE_SUCCESS; +} + +MIDK_EXPORT +Image_ErrorCode OH_ImageSourceNative_Release(OH_ImageSourceNative *source) +{ + if (source == nullptr) { + return IMAGE_BAD_PARAMETER; + } + source->~OH_ImageSourceNative(); + return IMAGE_SUCCESS; +} +#ifdef __cplusplus +}; +#endif \ No newline at end of file diff --git a/frameworks/kits/js/common/ndk/image_source_native_impl.cpp b/frameworks/kits/js/common/ndk/image_source_native_impl.cpp new file mode 100644 index 000000000..4e712c6b9 --- /dev/null +++ b/frameworks/kits/js/common/ndk/image_source_native_impl.cpp @@ -0,0 +1,91 @@ +/* + * 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 "image_source_native_impl.h" + +using namespace OHOS; +using namespace Media; +#ifdef __cplusplus +extern "C" { +#endif + +OH_ImageSourceNative::~OH_ImageSourceNative() +{ + if (innerImageSource_) { + innerImageSource_ = nullptr; + } +} + +std::shared_ptr OH_ImageSourceNative::GetInnerImageSource() +{ + return innerImageSource_; +} + +OH_ImageSourceNative::OH_ImageSourceNative(std::shared_ptr imageSource) +{ + innerImageSource_ = imageSource; +} + +OH_ImageSourceNative::OH_ImageSourceNative(char *uri, size_t size, SourceOptions opts) +{ + std::string strUri = std::string(uri, size); + std::string path = UrlToPath(strUri); + uint32_t errorCode = IMAGE_BAD_PARAMETER; + std::unique_ptr nativeImageSource = ImageSource::CreateImageSource(path, opts, errorCode); + if (nativeImageSource == nullptr) { + innerImageSource_ = nullptr; + return; + } + innerImageSource_ = std::move(nativeImageSource); +} + +OH_ImageSourceNative::OH_ImageSourceNative(int32_t fd, SourceOptions opts) +{ + uint32_t errorCode = IMAGE_BAD_PARAMETER; + std::unique_ptr nativeImageSource = ImageSource::CreateImageSource(fd, opts, errorCode); + if (nativeImageSource == nullptr) { + innerImageSource_ = nullptr; + return; + } + innerImageSource_ = std::move(nativeImageSource); +} + +OH_ImageSourceNative::OH_ImageSourceNative(uint8_t *data, size_t dataSize, SourceOptions opts) +{ + uint32_t errorCode = IMAGE_BAD_PARAMETER; + std::unique_ptr nativeImageSource = ImageSource::CreateImageSource( + data, dataSize, opts, errorCode); + if (nativeImageSource == nullptr) { + innerImageSource_ = nullptr; + return; + } + innerImageSource_ = std::move(nativeImageSource); +} + +OH_ImageSourceNative::OH_ImageSourceNative(RawFileDescriptor rawFile, SourceOptions opts) +{ + uint32_t errorCode = IMAGE_BAD_PARAMETER; + int32_t rawFileLength = rawFile.start + rawFile.length; + std::unique_ptr nativeImageSource = ImageSource::CreateImageSource( + rawFile.fd, rawFile.start, rawFileLength, opts, errorCode); + if (nativeImageSource == nullptr) { + innerImageSource_ = nullptr; + return; + } + innerImageSource_ = std::move(nativeImageSource); +} + +#ifdef __cplusplus +}; +#endif \ No newline at end of file diff --git a/frameworks/kits/js/common/ndk/include/image_packer_native_impl.h b/frameworks/kits/js/common/ndk/include/image_packer_native_impl.h new file mode 100644 index 000000000..5225e1060 --- /dev/null +++ b/frameworks/kits/js/common/ndk/include/image_packer_native_impl.h @@ -0,0 +1,54 @@ +/* + * 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 FRAMEWORKS_KITS_JS_COMMON_INCLUDE_IMAGE_PACKER_NATIVE_IMPL_H +#define FRAMEWORKS_KITS_JS_COMMON_INCLUDE_IMAGE_PACKER_NATIVE_IMPL_H +#include +#include "image_packer.h" +#include "image_source_native.h" +#include "pixelmap_native.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct OH_ImagePackerNative { +public: + OH_ImagePackerNative(); + OH_ImagePackerNative(std::shared_ptr imagePacker); + ~OH_ImagePackerNative(); + + int32_t PackingFromImageSource(OHOS::Media::PackOption *option, struct OH_ImageSourceNative *imageSource, + uint8_t *outData, int64_t *size); + + int32_t PackingFromPixelmap(OHOS::Media::PackOption *option, struct OH_PixelmapNative *pixelmap, + uint8_t *outData, int64_t *size); + + int32_t PackToFileFromImageSource(OHOS::Media::PackOption *option, struct OH_ImageSourceNative *imageSource, + const int fd); + + int32_t PackToFileFromPixelmap(OHOS::Media::PackOption *option, struct OH_PixelmapNative *pixelmap, + const int32_t fd); + + std::shared_ptr GetInnerImagePacker(); + +private: + std::shared_ptr imagePacker_; +}; + +#ifdef __cplusplus +}; +#endif +/** @} */ +#endif // FRAMEWORKS_KITS_JS_COMMON_INCLUDE_IMAGE_PACKER_NATIVE_IMPL_H \ No newline at end of file diff --git a/frameworks/kits/js/common/ndk/include/image_source_native_impl.h b/frameworks/kits/js/common/ndk/include/image_source_native_impl.h new file mode 100644 index 000000000..9701f3251 --- /dev/null +++ b/frameworks/kits/js/common/ndk/include/image_source_native_impl.h @@ -0,0 +1,47 @@ +/* + * 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 FRAMEWORKS_KITS_JS_COMMON_INCLUDE_IMAGE_SOURCE_NATIVE_IMPL_H +#define FRAMEWORKS_KITS_JS_COMMON_INCLUDE_IMAGE_SOURCE_NATIVE_IMPL_H +#include +#include "image_source.h" +#include "image_source_native.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct OH_ImageSourceNative { +public: + OH_ImageSourceNative(std::shared_ptr imageSource); + OH_ImageSourceNative(char *uri, size_t size, OHOS::Media::SourceOptions ops); + OH_ImageSourceNative(int32_t fd, OHOS::Media::SourceOptions ops); + OH_ImageSourceNative(uint8_t *data, size_t dataSize, OHOS::Media::SourceOptions ops); + OH_ImageSourceNative(RawFileDescriptor rawFile, OHOS::Media::SourceOptions ops); + ~OH_ImageSourceNative(); + std::shared_ptr GetInnerImageSource(); + std::string filePath_ = ""; + int fileDescriptor_ = -1; + void *fileBuffer_ = nullptr; + size_t fileBufferSize_ = 0; +private: + std::string UrlToPath(const std::string &path); + std::shared_ptr innerImageSource_; +}; + +#ifdef __cplusplus +}; +#endif +/** @} */ +#endif // FRAMEWORKS_KITS_JS_COMMON_INCLUDE_IMAGE_SOURCE_NATIVE_IMPL_H \ No newline at end of file diff --git a/frameworks/kits/js/common/ndk/include/pixelmap_native_impl.h b/frameworks/kits/js/common/ndk/include/pixelmap_native_impl.h new file mode 100644 index 000000000..1233ab2f7 --- /dev/null +++ b/frameworks/kits/js/common/ndk/include/pixelmap_native_impl.h @@ -0,0 +1,41 @@ +/* + * 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 FRAMEWORKS_KITS_JS_COMMON_INCLUDE_PIXELMAP_NATIVE_IMPL_H +#define FRAMEWORKS_KITS_JS_COMMON_INCLUDE_PIXELMAP_NATIVE_IMPL_H +#include +#include "pixel_map.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct OH_PixelmapNative { +public: + OH_PixelmapNative(std::shared_ptr pixelMap); + OH_PixelmapNative(const uint32_t *colors, uint32_t colorLength, const OHOS::Media::InitializationOptions &opts); + OH_PixelmapNative(OH_PixelmapNative *OH_PixelmapNative, const OHOS::Media::InitializationOptions &opts); + ~OH_PixelmapNative(); + + std::shared_ptr GetInnerPixelmap(); + +private: + std::shared_ptr pixelmap_; +}; + +#ifdef __cplusplus +}; +#endif +/** @} */ +#endif // FRAMEWORKS_KITS_JS_COMMON_INCLUDE_PIXELMAP_NATIVE_IMPL_H \ No newline at end of file diff --git a/frameworks/kits/js/common/pixelmap_ndk/BUILD.gn b/frameworks/kits/js/common/pixelmap_ndk/BUILD.gn index 51065b961..4371f0cba 100644 --- a/frameworks/kits/js/common/pixelmap_ndk/BUILD.gn +++ b/frameworks/kits/js/common/pixelmap_ndk/BUILD.gn @@ -44,3 +44,34 @@ ohos_shared_library("pixelmap_ndk") { subsystem_name = "multimedia" part_name = "image_framework" } + +ohos_shared_library("pixelmap") { + output_extension = "so" + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + include_dirs = [ + "${image_subsystem}/frameworks/innerkitsimpl/egl_image/include", + "$SUBSYSTEM_DIR/interfaces/kits/native/include/image", + "$SUBSYSTEM_DIR/frameworks/kits/js/common/ndk/include", + ] + + sources = [ + "pixelmap_native.cpp", + "pixelmap_native_impl.cpp", + ] + + public_configs = + [ "$SUBSYSTEM_DIR/interfaces/innerkits:image_external_config" ] + + deps = [ #"$SUBSYSTEM_DIR/interfaces/kits/js/common:image", + "$SUBSYSTEM_DIR/frameworks/innerkitsimpl/egl_image:egl_image", + "$SUBSYSTEM_DIR/interfaces/innerkits:image_native", + ] + + innerapi_tags = [ "ndk" ] + subsystem_name = "multimedia" + part_name = "image_framework" +} diff --git a/frameworks/kits/js/common/pixelmap_ndk/pixelmap_native.cpp b/frameworks/kits/js/common/pixelmap_ndk/pixelmap_native.cpp new file mode 100644 index 000000000..9162ff84a --- /dev/null +++ b/frameworks/kits/js/common/pixelmap_ndk/pixelmap_native.cpp @@ -0,0 +1,430 @@ +/* + * 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 "pixelmap_native.h" + +#include "common_utils.h" +#include "image_type.h" +#include "pixelmap_native_impl.h" + +using namespace OHOS::Media; +#ifdef __cplusplus +extern "C" { +#endif + +constexpr int32_t IMAGE_BASE = 62980096; +static constexpr int32_t IMAGE_BASE_19 = 19; +static constexpr int32_t IMAGE_BASE_16 = 16; +static constexpr int32_t IMAGE_BASE_17 = 17; +static constexpr int32_t IMAGE_BASE_26 = 26; +static constexpr int32_t IMAGE_BASE_31 = 31; +static constexpr int32_t IMAGE_BASE_152 = 152; +static constexpr int32_t IMAGE_BASE_27 = 27; +static constexpr int32_t IMAGE_BASE_12 = 12; +static constexpr int32_t IMAGE_BASE_13 = 13; +static constexpr int32_t IMAGE_BASE_6 = 6; +static constexpr int32_t IMAGE_BASE_14 = 14; +static constexpr int32_t IMAGE_BASE_4 = 4; +static constexpr int32_t IMAGE_BASE_9 = 9; +static constexpr int32_t IMAGE_BASE_20 = 20; +static constexpr int32_t IMAGE_BASE_22 = 22; +static constexpr int32_t IMAGE_BASE_23 = 23; + +struct OH_Pixelmap_InitializationOptions { + uint32_t width; + uint32_t height; + PIXEL_FORMAT pixelFormat = PIXEL_FORMAT::PIXEL_FORMAT_UNKNOWN; + uint32_t editable = false; + PIXELMAP_ALPHA_TYPE alphaType = PIXELMAP_ALPHA_TYPE::PIXELMAP_ALPHA_TYPE_UNKNOWN; +}; + +struct OH_Pixelmap_ImageInfo { + uint32_t width; + uint32_t height; + uint32_t rowStride; + int32_t pixelFormat = PIXEL_FORMAT::PIXEL_FORMAT_UNKNOWN; + PIXELMAP_ALPHA_TYPE alphaType = PIXELMAP_ALPHA_TYPE::PIXELMAP_ALPHA_TYPE_UNKNOWN; +}; + +static PIXEL_FORMAT ParsePixelForamt(int32_t val) +{ + if (val <= static_cast(PIXEL_FORMAT::PIXEL_FORMAT_NV12)) { + return PIXEL_FORMAT(val); + } + + return PIXEL_FORMAT::PIXEL_FORMAT_UNKNOWN; +} + +static PIXELMAP_ALPHA_TYPE ParseAlphaType(int32_t val) +{ + if (val <= static_cast(PIXELMAP_ALPHA_TYPE::PIXELMAP_ALPHA_TYPE_PREMULTIPLIED)) { + return PIXELMAP_ALPHA_TYPE(val); + } + + return PIXELMAP_ALPHA_TYPE::PIXELMAP_ALPHA_TYPE_UNKNOWN; +} + +static Image_ErrorCode ToNewErrorCode(int code) +{ + switch (code) { + case 0: + return IMAGE_SUCCESS; + case IMAGE_BASE + IMAGE_BASE_19: + return IMAGE_BAD_PARAMETER; + case IMAGE_BASE + IMAGE_BASE_16: + case IMAGE_BASE + IMAGE_BASE_17: + case IMAGE_BASE + IMAGE_BASE_26: + return IMAGE_UNKNOWN_MIME_TYPE; + case IMAGE_BASE + IMAGE_BASE_31: + return IMAGE_TOO_LARGE; + case IMAGE_BASE + IMAGE_BASE_152: + return IMAGE_UNSUPPORTED_OPERATION; + case IMAGE_BASE + IMAGE_BASE_27: + return IMAGE_UNSUPPORTED_METADATA; + case IMAGE_BASE + IMAGE_BASE_12: + return IMAGE_UNSUPPORTED_CONVERSION; + case IMAGE_BASE + IMAGE_BASE_13: + return IMAGE_INVALID_REGION; + case IMAGE_BASE + IMAGE_BASE_6: + return IMAGE_ALLOC_FAILED; + case IMAGE_BASE + IMAGE_BASE_14: + return IMAGE_BAD_SOURCE; + case IMAGE_BASE + IMAGE_BASE_4: + case IMAGE_BASE + IMAGE_BASE_9: + case IMAGE_BASE + IMAGE_BASE_20: + case IMAGE_BASE + IMAGE_BASE_22: + return IMAGE_DECODE_FAILED; + case IMAGE_BASE + IMAGE_BASE_23: + return IMAGE_ENCODE_FAILED; + default: + return IMAGE_UNKNOWN_ERROR; + } +}; + +MIDK_EXPORT +Image_ErrorCode OH_PixelmapInitializationOptions_Create(OH_Pixelmap_InitializationOptions **ops) +{ + *ops = new OH_Pixelmap_InitializationOptions(); + if (ops == nullptr) { + return IMAGE_BAD_PARAMETER; + } + return IMAGE_SUCCESS; +} + +MIDK_EXPORT +Image_ErrorCode OH_PixelmapInitializationOptions_GetWidth(OH_Pixelmap_InitializationOptions *ops, + uint32_t *width) +{ + if (ops == nullptr || width == nullptr) { + return IMAGE_BAD_PARAMETER; + } + *width = ops->width; + return IMAGE_SUCCESS; +} + +MIDK_EXPORT +Image_ErrorCode OH_PixelmapInitializationOptions_SetWidth(OH_Pixelmap_InitializationOptions *ops, + uint32_t width) +{ + if (ops == nullptr) { + return IMAGE_BAD_PARAMETER; + } + ops->width = width; + return IMAGE_SUCCESS; +} + +MIDK_EXPORT +Image_ErrorCode OH_PixelmapInitializationOptions_GetHeight(OH_Pixelmap_InitializationOptions *ops, + uint32_t *height) +{ + if (ops == nullptr || height == nullptr) { + return IMAGE_BAD_PARAMETER; + } + *height = ops->height; + return IMAGE_SUCCESS; +} + +MIDK_EXPORT +Image_ErrorCode OH_PixelmapInitializationOptions_SetHeight(OH_Pixelmap_InitializationOptions *ops, + uint32_t height) +{ + if (ops == nullptr) { + return IMAGE_BAD_PARAMETER; + } + ops->height = height; + return IMAGE_SUCCESS; +} + +MIDK_EXPORT +Image_ErrorCode OH_PixelmapInitializationOptions_GetPixelFormat(OH_Pixelmap_InitializationOptions *ops, + int32_t *pixelFormat) +{ + if (ops == nullptr || pixelFormat == nullptr) { + return IMAGE_BAD_PARAMETER; + } + *pixelFormat = static_cast(ops->pixelFormat); + return IMAGE_SUCCESS; +} + +MIDK_EXPORT +Image_ErrorCode OH_PixelmapInitializationOptions_SetPixelFormat(OH_Pixelmap_InitializationOptions *ops, + int32_t pixelFormat) +{ + if (ops == nullptr) { + return IMAGE_BAD_PARAMETER; + } + ops->pixelFormat = ParsePixelForamt(pixelFormat); + return IMAGE_SUCCESS; +} + +MIDK_EXPORT +Image_ErrorCode OH_PixelmapInitializationOptions_GetAlphaType(OH_Pixelmap_InitializationOptions *ops, + int32_t *alphaType) +{ + if (ops == nullptr || alphaType == nullptr) { + return IMAGE_BAD_PARAMETER; + } + *alphaType = static_cast(ops->alphaType); + return IMAGE_SUCCESS; +} + +MIDK_EXPORT +Image_ErrorCode OH_PixelmapInitializationOptions_SetAlphaType(OH_Pixelmap_InitializationOptions *ops, + int32_t alphaType) +{ + if (ops == nullptr) { + return IMAGE_BAD_PARAMETER; + } + ops->alphaType = ParseAlphaType(alphaType); + return IMAGE_SUCCESS; +} + +MIDK_EXPORT +Image_ErrorCode OH_PixelmapInitializationOptions_Release(OH_Pixelmap_InitializationOptions *ops) +{ + if (ops == nullptr) { + return IMAGE_BAD_PARAMETER; + } + delete ops; + return IMAGE_SUCCESS; +} + +MIDK_EXPORT +Image_ErrorCode OH_PixelmapImageInfo_Create(OH_Pixelmap_ImageInfo **info) +{ + *info = new OH_Pixelmap_ImageInfo(); + if (*info == nullptr) { + return IMAGE_BAD_PARAMETER; + } + return IMAGE_SUCCESS; +} + +MIDK_EXPORT +Image_ErrorCode OH_PixelmapImageInfo_GetWidth(OH_Pixelmap_ImageInfo *info, uint32_t *width) +{ + if (info == nullptr || width == nullptr) { + return IMAGE_BAD_PARAMETER; + } + *width = info->width; + return IMAGE_SUCCESS; +} + +MIDK_EXPORT +Image_ErrorCode OH_PixelmapImageInfo_GetHeight(OH_Pixelmap_ImageInfo *info, uint32_t *height) +{ + if (info == nullptr || height == nullptr) { + return IMAGE_BAD_PARAMETER; + } + *height = info->height; + return IMAGE_SUCCESS; +} + +MIDK_EXPORT +Image_ErrorCode OH_PixelmapImageInfo_GetRowStride(OH_Pixelmap_ImageInfo *info, uint32_t *rowStride) +{ + if (info == nullptr || rowStride == nullptr) { + return IMAGE_BAD_PARAMETER; + } + *rowStride = info->rowStride; + return IMAGE_SUCCESS; +} + +MIDK_EXPORT +Image_ErrorCode OH_PixelmapImageInfo_GetPixelFormat(OH_Pixelmap_ImageInfo *info, int32_t *pixelFormat) +{ + if (info == nullptr || pixelFormat == nullptr) { + return IMAGE_BAD_PARAMETER; + } + *pixelFormat = info->pixelFormat; + return IMAGE_SUCCESS; +} + +MIDK_EXPORT +Image_ErrorCode OH_PixelmapImageInfo_GetAlphaType(OH_Pixelmap_ImageInfo *info, int32_t *alphaType) +{ + if (info == nullptr || alphaType == nullptr) { + return IMAGE_BAD_PARAMETER; + } + *alphaType = static_cast(info->alphaType); + return IMAGE_SUCCESS; +} + +MIDK_EXPORT +Image_ErrorCode OH_PixelmapImageInfo_Release(OH_Pixelmap_ImageInfo *info) +{ + if (info == nullptr) { + return IMAGE_BAD_PARAMETER; + } + delete info; + return IMAGE_SUCCESS; +} + +MIDK_EXPORT +Image_ErrorCode OH_PixelmapNative_CreatePixelmap(uint8_t *data, size_t dataLength, + OH_Pixelmap_InitializationOptions *options, OH_PixelmapNative **pixelmap) +{ + if (data == nullptr || options == nullptr) { + return IMAGE_BAD_PARAMETER; + } + InitializationOptions info; + info.editable = true; + info.alphaType = static_cast(options->alphaType); + info.pixelFormat = static_cast(options->pixelFormat); + info.size.height = options->height; + info.size.width = options->width; + + auto pixelmap2 = new OH_PixelmapNative(reinterpret_cast(data), static_cast(dataLength), info); + if (pixelmap2 == nullptr || pixelmap2->GetInnerPixelmap() == nullptr) { + if (pixelmap2) { + delete pixelmap2; + } + return IMAGE_BAD_PARAMETER; + } + *pixelmap = pixelmap2; + return IMAGE_SUCCESS; +} + +MIDK_EXPORT +Image_ErrorCode OH_PixelmapNative_ReadPixels(OH_PixelmapNative *pixelmap, uint8_t *destination, size_t *bufferSize) +{ + if (pixelmap == nullptr || destination == nullptr) { + return IMAGE_BAD_PARAMETER; + } + return ToNewErrorCode(pixelmap->GetInnerPixelmap()->ReadPixels(*bufferSize, destination)); +} + +MIDK_EXPORT +Image_ErrorCode OH_PixelmapNative_WritePixels(OH_PixelmapNative *pixelmap, uint8_t *source, size_t bufferSize) +{ + if (pixelmap == nullptr || source == nullptr) { + return IMAGE_BAD_PARAMETER; + } + return ToNewErrorCode(pixelmap->GetInnerPixelmap()->WritePixels(source, bufferSize)); +} + +MIDK_EXPORT +Image_ErrorCode OH_PixelmapNative_GetImageInfo(OH_PixelmapNative *pixelmap, OH_Pixelmap_ImageInfo *imageInfo) +{ + if (pixelmap == nullptr || imageInfo == nullptr) { + return IMAGE_BAD_PARAMETER; + } + ImageInfo srcInfo; + pixelmap->GetInnerPixelmap()->GetImageInfo(srcInfo); + imageInfo->width = srcInfo.size.width; + imageInfo->height = srcInfo.size.height; + imageInfo->rowStride = pixelmap->GetInnerPixelmap()->GetRowStride(); + imageInfo->pixelFormat = static_cast(srcInfo.pixelFormat); + return IMAGE_SUCCESS; +} + +MIDK_EXPORT +Image_ErrorCode OH_PixelmapNative_Opacity(OH_PixelmapNative *pixelmap, float rate) +{ + if (pixelmap == nullptr) { + return IMAGE_BAD_PARAMETER; + } + pixelmap->GetInnerPixelmap()->SetAlpha(rate); + return IMAGE_SUCCESS; +} + +MIDK_EXPORT +Image_ErrorCode OH_PixelmapNative_Scale(OH_PixelmapNative *pixelmap, float scaleX, float scaleY) +{ + if (pixelmap == nullptr) { + return IMAGE_BAD_PARAMETER; + } + pixelmap->GetInnerPixelmap()->scale(scaleX, scaleY); + return IMAGE_SUCCESS; +} + +MIDK_EXPORT +Image_ErrorCode OH_PixelmapNative_Translate(OH_PixelmapNative *pixelmap, float x, float y) +{ + if (pixelmap == nullptr) { + return IMAGE_BAD_PARAMETER; + } + pixelmap->GetInnerPixelmap()->translate(x, y); + return IMAGE_SUCCESS; +} + +MIDK_EXPORT +Image_ErrorCode OH_PixelmapNative_Rotate(OH_PixelmapNative *pixelmap, float angle) +{ + if (pixelmap == nullptr) { + return IMAGE_BAD_PARAMETER; + } + pixelmap->GetInnerPixelmap()->rotate(angle); + return IMAGE_SUCCESS; +} + +MIDK_EXPORT +Image_ErrorCode OH_PixelmapNative_Flip(OH_PixelmapNative *pixelmap, bool shouldFilpHorizontally, + bool shouldFilpVertically) +{ + if (pixelmap == nullptr) { + return IMAGE_BAD_PARAMETER; + } + pixelmap->GetInnerPixelmap()->flip(shouldFilpHorizontally, shouldFilpVertically); + return IMAGE_SUCCESS; +} + +MIDK_EXPORT +Image_ErrorCode OH_PixelmapNative_Crop(OH_PixelmapNative *pixelmap, Image_Region *region) +{ + if (pixelmap == nullptr) { + return IMAGE_BAD_PARAMETER; + } + Rect rect; + rect.left = region->x; + rect.top = region->y; + rect.width = region->width; + rect.height = region->height; + pixelmap->GetInnerPixelmap()->crop(rect); + return IMAGE_SUCCESS; +} + +MIDK_EXPORT +Image_ErrorCode OH_PixelmapNative_Release(OH_PixelmapNative *pixelmap) +{ + if (pixelmap == nullptr) { + return IMAGE_BAD_PARAMETER; + } + pixelmap->~OH_PixelmapNative(); + return IMAGE_SUCCESS; +} + +#ifdef __cplusplus +}; +#endif \ No newline at end of file diff --git a/frameworks/kits/js/common/pixelmap_ndk/pixelmap_native_impl.cpp b/frameworks/kits/js/common/pixelmap_ndk/pixelmap_native_impl.cpp new file mode 100644 index 000000000..4f93dc56e --- /dev/null +++ b/frameworks/kits/js/common/pixelmap_ndk/pixelmap_native_impl.cpp @@ -0,0 +1,67 @@ +/* + * 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 "pixelmap_native_impl.h" + +#include "pixel_map.h" + +using namespace OHOS::Media; +#ifdef __cplusplus +extern "C" { +#endif + +OH_PixelmapNative::OH_PixelmapNative(std::shared_ptr pixelmap) +{ + if (pixelmap == nullptr) { + pixelmap_ = nullptr; + return; + } + pixelmap_ = pixelmap; +} + +OH_PixelmapNative::OH_PixelmapNative(const uint32_t *colors, uint32_t colorLength, const InitializationOptions &opts) +{ + auto tmpPixelmap = PixelMap::Create(colors, colorLength, opts); + pixelmap_ = std::move(tmpPixelmap); +} + +OH_PixelmapNative::OH_PixelmapNative(OH_PixelmapNative *OH_PixelmapNative, const InitializationOptions &opts) +{ + if (OH_PixelmapNative == nullptr) { + pixelmap_ = nullptr; + return; + } + auto pixelmapPtr = OH_PixelmapNative->GetInnerPixelmap().get(); + auto tmpPixelmap = PixelMap::Create(*pixelmapPtr, opts); + pixelmap_ = std::move(tmpPixelmap); +} + +std::shared_ptr OH_PixelmapNative::GetInnerPixelmap() +{ + return pixelmap_; +} + +OH_PixelmapNative::~OH_PixelmapNative() +{ + if (pixelmap_) { + pixelmap_ = nullptr; + } +} + +#ifdef __cplusplus +}; +#endif + +// } +// } \ No newline at end of file diff --git a/interfaces/kits/native/include/image/image_common.h b/interfaces/kits/native/include/image/image_common.h new file mode 100644 index 000000000..d05235c54 --- /dev/null +++ b/interfaces/kits/native/include/image/image_common.h @@ -0,0 +1,1251 @@ +/* + * Copyright (C) 2023 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. + */ + +/** + * @addtogroup image + * @{ + * + * @brief Provides APIs for access to the image interface. + * + * @since 12 + */ + +/** + * @file image_common.h + * + * @brief Declares the common enums and structs used by the image interface. + * + * @syscap SystemCapability.Multimedia.Image.Core + * @since 12 + */ + +#ifndef INTERFACES_KITS_NATIVE_INCLUDE_IMAGE_IMAGE_COMMON_H +#define INTERFACES_KITS_NATIVE_INCLUDE_IMAGE_IMAGE_COMMON_H +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Defines the image size. + * + * @since 12 + */ +struct Image_Size { + /** Image width, in pixels. */ + uint32_t width; + /** Image height, in pixels. */ + uint32_t height; +}; + +/** + * @brief Declaration the image size. + * + * @since 12 + */ +typedef struct Image_Size Image_Size; + +/** + * @brief Defines the region of the image source to decode. + * + * @since 12 + */ +struct Image_Region { + /** X coordinate of the start point, in pixels. */ + uint32_t x; + /** Y coordinate of the start point, in pixels. */ + uint32_t y; + /** Width of the region, in pixels. */ + uint32_t width; + /** Height of the region, in pixels. */ + uint32_t height; +}; + +/** + * @brief Declaration the image region. + * + * @since 12 + */ +typedef struct Image_Region Image_Region; + +/** + * @brief Defines the region of the image source to decode. + * + * @since 12 + */ +struct Image_String { + /** data for string type */ + char *data = nullptr; + /** data lenth for string type */ + size_t size = 0; +}; + +/** + * @brief Defines the property string (in key-value format) of the image source. + * + * @since 12 + */ +typedef struct Image_String Image_String; + +/** + * @brief Defines the image encode format. + * + * @since 12 + */ +typedef struct Image_String Image_MimeType; + +/** + * @brief Enumerates the return values that may be used by the interface. + * + * @since 12 + */ +typedef enum { + IMAGE_SUCCESS = 0, // Operation success + IMAGE_BAD_PARAMETER = 401, // Invalid parameter + IMAGE_UNSUPPORTED_MIM_ETYPE = 7600101, // unsupported mime type + IMAGE_UNKNOWN_MIME_TYPE = 7600102, // unknown mime type + IMAGE_TOO_LARGE = 7600103, // too large data or image + IMAGE_UNSUPPORTED_OPERATION = 7600201, // unsupported operations + IMAGE_UNSUPPORTED_METADATA = 7600202, // unsupported metadata + IMAGE_UNSUPPORTED_CONVERSION = 7600203, // unsupported conversion + IMAGE_INVALID_REGION = 7600204, // invalid region + IMAGE_ALLOC_FAILED = 7600301, // failed to allocate memory + IMAGE_COPY_FAILED = 7600302, // memory copy failed + IMAGE_UNKNOWN_ERROR = 7600901, // unknown error + IMAGE_BAD_SOURCE = 7700101, // decode data source exception + IMAGE_DECODE_FAILED = 7700301, // decode failed + IMAGE_ENCODE_FAILED = 7800301, // encode failed +} Image_ErrorCode; + +/** + * @brief Defines the bmp mime type. + * + * @since 12 + */ +static const char* MIME_TYPE_BMP = "image/bmp"; + +/** + * @brief Defines the jpeg mime type. + * + * @since 12 + */ +static const char* MIME_TYPE_JPEG = "image/jpeg"; + +/** + * @brief Defines the heic mime type. + * + * @since 12 + */ +static const char* MIME_TYPE_HEIC = "image/heic"; + +/** + * @brief Defines the png mime type. + * + * @since 12 + */ +static const char* MIME_TYPE_PNG = "image/png"; + +/** + * @brief Defines the webp mime type. + * + * @since 12 + */ +static const char* MIME_TYPE_WEBP = "image/webp"; + +/** + * @brief Defines the gif mime type. + * + * @since 12 + */ +static const char* MIME_TYPE_GIF = "image/gif"; + +/** + * @brief Defines the x-icon mime type. + * + * @since 12 + */ +static const char* MIME_TYPE_ICON = "image/x-icon"; + +/** + * @brief Defines a pointer to bits per sample, one of the image properties. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_BITS_PER_SAMPLE = "BitsPerSample"; + +/** + * @brief Defines a pointer to the orientation, one of the image properties. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_ORIENTATION = "Orientation"; + +/** + * @brief Defines a pointer to the image length, one of the image properties. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_IMAGE_LENGTH = "ImageLength"; + +/** + * @brief Defines a pointer to the image width, one of the image properties. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_IMAGE_WIDTH = "ImageWidth"; + +/** + * @brief Defines a pointer to the GPS latitude, one of the image properties. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_GPS_LATITUDE = "GPSLatitude"; + +/** + * @brief Defines a pointer to the GPS longitude, one of the image properties. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_GPS_LONGITUDE = "GPSLongitude"; + +/** + * @brief Defines a pointer to the GPS latitude reference information, one of the image properties. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_GPS_LATITUDE_REF = "GPSLatitudeRef"; + +/** + * @brief Defines a pointer to the GPS longitude reference information, one of the image properties. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_GPS_LONGITUDE_REF = "GPSLongitudeRef"; + +/** + * @brief Defines a pointer to the created date and time, one of the image properties. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_DATE_TIME_ORIGINAL = "DateTimeOriginal"; + +/** + * @brief Defines a pointer to the exposure time, one of the image properties. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_EXPOSURE_TIME = "ExposureTime"; + +/** + * @brief Defines a pointer to the scene type, one of the image properties. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_SCENE_TYPE = "SceneType"; + +/** + * @brief Defines a pointer to the ISO speed ratings, one of the image properties. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_ISO_SPEED_RATINGS = "ISOSpeedRatings"; + +/** + * @brief Defines a pointer to the f-number of the image, one of the image properties. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_F_NUMBER = "FNumber"; + +/** + * @brief Defines a pointer to the compressed bits per pixel, one of the image properties. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_COMPRESSED_BITS_PER_PIXEL = "CompressedBitsPerPixel"; + +/** + * @brief The scheme used for image compression. + * Used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_COMPRESSION = "Compression"; + +/** + * @brief Pixel composition, such as RGB or YCbCr. + * Used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_PHOTOMETRIC_INTERPRETATION = "PhotometricInterpretation"; + +/** + * @brief For each strip, the byte offset of that strip. + * Used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_STRIP_OFFSETS = "StripOffsets"; + +/** + * @brief The number of components per pixel. + * Used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_SAMPLES_PER_PIXEL = "SamplesPerPixel"; + +/** + * @brief The number of rows per strip of image data. + * Used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_ROWS_PER_STRIP = "RowsPerStrip"; + +/** + * @brief The total number of bytes in each strip of image data. + * Used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_STRIP_BYTE_COUNTS = "StripByteCounts"; + +/** + * @brief The image resolution in the width direction. + * Used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_X_RESOLUTION = "XResolution"; + +/** + * @brief The image resolution in the height direction. + * Used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_Y_RESOLUTION = "YResolution"; + +/** + * @brief Indicates whether pixel components are recorded in a chunky or planar format. + * Used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_PLANAR_CONFIGURATION = "PlanarConfiguration"; + +/** + * @brief The unit used to measure XResolution and YResolution. + * Used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_RESOLUTION_UNIT = "ResolutionUnit"; + +/** + * @brief The transfer function for the image, typically used for color correction. + * Used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_TRANSFER_FUNCTION = "TransferFunction"; + +/** + * @brief The name and version of the software used to generate the image. + * Used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_SOFTWARE = "Software"; + +/** + * @brief The name of the person who created the image. + * Used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_ARTIST = "Artist"; + +/** + * @brief The chromaticity of the white point of the image. + * Used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_WHITE_POINT = "WhitePoint"; + +/** + * @brief The chromaticity of the primary colors of the image. + * Used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_PRIMARY_CHROMATICITIES = "PrimaryChromaticities"; + +/** + * @brief The matrix coefficients for transformation from RGB to YCbCr image data. + * Used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_YCBCR_COEFFICIENTS = "YCbCrCoefficients"; + +/** + * @brief The sampling ratio of chrominance components to the luminance component. + * Used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_YCBCR_SUB_SAMPLING = "YCbCrSubSampling"; + +/** + * @brief The position of chrominance components in relation to the luminance component. + * Used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_YCBCR_POSITIONING = "YCbCrPositioning"; + +/** + * @brief The reference black point value and reference white point value. + * Used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_REFERENCE_BLACK_WHITE = "ReferenceBlackWhite"; + +/** + * @brief Copyright information for the image. + * Used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_COPYRIGHT = "Copyright"; + +/** + * @brief The offset to the start byte (SOI) of JPEG compressed thumbnail data. + * Used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_JPEG_INTERCHANGE_FORMAT = "JPEGInterchangeFormat"; + +/** + * @brief The number of bytes of JPEG compressed thumbnail data. + * Used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_JPEG_INTERCHANGE_FORMAT_LENGTH = "JPEGInterchangeFormatLength"; + +/** + * @brief The class of the program used by the camera to set exposure when the picture is taken. + * Used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_EXPOSURE_PROGRAM = "ExposureProgram"; + +/** + * @brief Indicates the spectral sensitivity of each channel of the camera used. + * Used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_SPECTRAL_SENSITIVITY = "SpectralSensitivity"; + +/** + * @brief Indicates the Opto-Electric Conversion Function (OECF) specified in ISO 14524. + * Used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_OECF = "OECF"; + +/** + * @brief The version of the Exif standard supported. + * Used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_EXIF_VERSION = "ExifVersion"; + +/** + * @brief The date and time when the image was stored as digital data. + * Used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_DATE_TIME_DIGITIZED = "DateTimeDigitized"; + +/** + * @brief Information specific to compressed data. + * Used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_COMPONENTS_CONFIGURATION = "ComponentsConfiguration"; + +/** + * @brief The shutter speed, expressed as an APEX (Additive System of Photographic Exposure) value. + * Used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_SHUTTER_SPEED_VALUE = "ShutterSpeedValue"; + +/** + * @brief The brightness value of the image, in APEX units. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_BRIGHTNESS_VALUE = "BrightnessValue"; + +/** + * @brief The smallest F number of lens. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_MAX_APERTURE_VALUE = "MaxApertureValue"; + +/** + * @brief The distance to the subject, measured in meters. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_SUBJECT_DISTANCE = "SubjectDistance"; + +/** + * @brief This tag indicate the location and area of the main subject in the overall scene. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_SUBJECT_AREA = "SubjectArea"; + +/** + * @brief A tag for manufacturers of Exif/DCF writers to record any desired infomation. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_MAKER_NOTE = "MakerNote"; + +/** + * @brief A tag for record fractions of seconds for the DateTime tag. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_SUBSEC_TIME = "SubsecTime"; + +/** + * @brief A tag used to record fractions of seconds for the DateTimeOriginal tag. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_SUBSEC_TIME_ORIGINAL = "SubsecTimeOriginal"; + +/** + * @brief A tag used to record fractions of seconds for the DateTimeDigitized tag. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_SUBSEC_TIME_DIGITIZED = "SubsecTimeDigitized"; + +/** + * @brief This tag denotes the Flashpix format version supported by an FPXR file, enhancing device compatibility. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_FLASHPIX_VERSION = "FlashpixVersion"; + +/** + * @brief The color space information tag, often recorded as the color space specifier. + * Used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_COLOR_SPACE = "ColorSpace"; + +/** + * @brief The name of an audio file related to the image data. + * Used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_RELATED_SOUND_FILE = "RelatedSoundFile"; + +/** + * @brief Strobe energy at image capture, in BCPS. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_FLASH_ENERGY = "FlashEnergy"; + +/** + * @brief Camera or input device spatial frequency table. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_SPATIAL_FREQUENCY_RESPONSE = "SpatialFrequencyResponse"; + +/** + * @brief Pixels per FocalPlaneResolutionUnit in the image width. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_FOCAL_PLANE_X_RESOLUTION = "FocalPlaneXResolution"; + +/** + * @brief Pixels per FocalPlaneResolutionUnit in the image height. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_FOCAL_PLANE_Y_RESOLUTION = "FocalPlaneYResolution"; + +/** + * @brief Unit for measuring FocalPlaneXResolution and FocalPlaneYResolution. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_FOCAL_PLANE_RESOLUTION_UNIT = "FocalPlaneResolutionUnit"; + +/** + * @brief Location of the main subject, relative to the left edge. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_SUBJECT_LOCATION = "SubjectLocation"; + +/** + * @brief Selected exposure index at capture. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_EXPOSURE_INDEX = "ExposureIndex"; + +/** + * @brief Image sensor type on the camera. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_SENSING_METHOD = "SensingMethod"; + +/** + * @brief Indicates the image source. + * Used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_FILE_SOURCE = "FileSource"; + +/** + * @brief Color filter array (CFA) geometric pattern of the image sensor. + * Used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_CFA_PATTERN = "CFAPattern"; + +/** + * @brief Indicates special processing on image data. + * Used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_CUSTOM_RENDERED = "CustomRendered"; + +/** + * @brief Exposure mode set when the image was shot. + * Used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_EXPOSURE_MODE = "ExposureMode"; + +/** + * @brief Digital zoom ratio at the time of capture. + * Used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_DIGITAL_ZOOM_RATIO = "DigitalZoomRatio"; + +/** + * @brief Type of scene captured. + * Used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_SCENE_CAPTURE_TYPE = "SceneCaptureType"; + +/** + * @brief Degree of overall image gain adjustment. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_GAIN_CONTROL = "GainControl"; + +/** + * @brief Direction of contrast processing applied by the camera. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_CONTRAST = "Contrast"; + +/** + * @brief Direction of saturation processing applied by the camera. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_SATURATION = "Saturation"; + +/** + * @brief The direction of sharpness processing applied by the camera. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_SHARPNESS = "Sharpness"; + +/** + * @brief Information on picture-taking conditions for a specific camera model. + * Used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_DEVICE_SETTING_DESCRIPTION = "DeviceSettingDescription"; + +/** + * @brief Indicates the distance range to the subject. + * Used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_SUBJECT_DISTANCE_RANGE = "SubjectDistanceRange"; + +/** + * @brief An identifier uniquely assigned to each image. + * Used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_IMAGE_UNIQUE_ID = "ImageUniqueID"; + +/** + * @brief The version of the GPSInfoIFD. + * Used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_GPS_VERSION_ID = "GPSVersionID"; + +/** + * @brief Reference altitude used for GPS altitude. + * Used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_GPS_ALTITUDE_REF = "GPSAltitudeRef"; + +/** + * @brief The altitude based on the reference in GPSAltitudeRef. + * Used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_GPS_ALTITUDE = "GPSAltitude"; + +/** + * @brief The GPS satellites used for measurements. + * Used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_GPS_SATELLITES = "GPSSatellites"; + +/** + * @brief The status of the GPS receiver when the image is recorded. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_GPS_STATUS = "GPSStatus"; + +/** + * @brief The GPS measurement mode. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_GPS_MEASURE_MODE = "GPSMeasureMode"; + +/** + * @brief The GPS DOP (data degree of precision). + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_GPS_DOP = "GPSDOP"; + +/** + * @brief The unit used to express the GPS receiver speed of movement. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_GPS_SPEED_REF = "GPSSpeedRef"; + +/** + * @brief The speed of GPS receiver movement. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_GPS_SPEED = "GPSSpeed"; + +/** + * @brief The reference for giving the direction of GPS receiver movement. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_GPS_TRACK_REF = "GPSTrackRef"; + +/** + * @brief The direction of GPS receiver movement. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_GPS_TRACK = "GPSTrack"; + +/** + * @brief The reference for the image's direction. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_GPS_IMG_DIRECTION_REF = "GPSImgDirectionRef"; + +/** + * @brief The direction of the image when captured. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_GPS_IMG_DIRECTION = "GPSImgDirection"; + +/** + * @brief Geodetic survey data used by the GPS receiver. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_GPS_MAP_DATUM = "GPSMapDatum"; + +/** + * @brief Indicates the latitude reference of the destination point. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_GPS_DEST_LATITUDE_REF = "GPSDestLatitudeRef"; + +/** + * @brief The latitude of the destination point. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_GPS_DEST_LATITUDE = "GPSDestLatitude"; + +/** + * @brief Indicates the longitude reference of the destination point. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_GPS_DEST_LONGITUDE_REF = "GPSDestLongitudeRef"; + +/** + * @brief A character string recording the name of the method used for location finding. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_GPS_PROCESSING_METHOD = "GPSProcessingMethod"; + +/** + * @brief A character string recording the name of the GPS area. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_GPS_AREA_INFORMATION = "GPSAreaInformation"; + +/** + * @brief This field denotes if differential correction was applied to GPS data, crucial for precise location accuracy. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_GPS_DIFFERENTIAL = "GPSDifferential"; + +/** + * @brief The serial number of the camera body. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_BODY_SERIAL_NUMBER = "BodySerialNumber"; + +/** + * @brief The name of the camera owner. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_CAMERA_OWNER_NAME = "CameraOwnerName"; + +/** + * @brief The name of the camera owner. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_COMPOSITE_IMAGE = "CompositeImage"; + +/** + * @brief The DNGVersion tag encodes the four-tier version number for DNG specification compliance. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_DNG_VERSION = "DNGVersion"; + +/** + * @brief The longitude of the destination point. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_GPS_DEST_LONGITUDE = "GPSDestLongitude"; + +/** + * @brief The reference for the bearing to the destination point. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_GPS_DEST_BEARING_REF = "GPSDestBearingRef"; + +/** + * @brief The bearing to the destination point. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_GPS_DEST_BEARING = "GPSDestBearing"; + +/** + * @brief The measurement unit for the distance to the target point. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_GPS_DEST_DISTANCE_REF = "GPSDestDistanceRef"; + +/** + * @brief The distance to the destination point. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_GPS_DEST_DISTANCE = "GPSDestDistance"; + +/** + * @brief DefaultCropSize specifies the final image size in raw coordinates, accounting for extra edge pixels. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_DEFAULT_CROP_SIZE = "DefaultCropSize"; + +/** + * @brief Indicates the value of coefficient gamma. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_GAMMA = "Gamma"; + +/** + * @brief The tag indicate the ISO speed latitude yyy value of the camera or input device that is defined in ISO 12232. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_ISO_SPEED_LATITUDEYYY = "ISOSpeedLatitudeyyy"; + +/** + * @brief The tag indicate the ISO speed latitude zzz value of the camera or input device that is defined in ISO 12232. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_ISO_SPEED_LATITUDEZZZ = "ISOSpeedLatitudezzz"; + +/** + * @brief The manufacturer of the lens. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_LENS_MAKE = "LensMake"; + +/** + * @brief The model name of the lens. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_LENS_MODEL = "LensModel"; + +/** + * @brief The serial number of the lens. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_LENS_SERIAL_NUMBER = "LensSerialNumber"; + +/** + * @brief Specifications of the lens used. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_LENS_SPECIFICATION = "LensSpecification"; + +/** + * @brief This tag provides a broad description of the data type in this subfile. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_NEW_SUBFILE_TYPE = "NewSubfileType"; + +/** + * @brief This tag records the UTC offset for the DateTime tag, ensuring accurate timestamps regardless of location. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_OFFSET_TIME = "OffsetTime"; + +/** + * @brief This tag logs the UTC offset when the image was digitized, aiding in accurate timestamp adjustment. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_OFFSET_TIME_DIGITIZED = "OffsetTimeDigitized"; + +/** + * @brief This tag records the UTC offset when the original image was created, crucial for time-sensitive applications. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_OFFSET_TIME_ORIGINAL = "OffsetTimeOriginal"; + +/** + * @brief Exposure times of source images for a composite image. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_SOURCE_EXPOSURE_TIMES_OF_COMPOSITE_IMAGE = "SourceExposureTimesOfCompositeImage"; + +/** + * @brief The number of source images used for a composite image. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_SOURCE_IMAGE_NUMBER_OF_COMPOSITE_IMAGE = "SourceImageNumberOfCompositeImage"; + +/** + * @brief This deprecated field signifies the type of data in this subfile. Use the NewSubfileType field instead. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_SUBFILE_TYPE = "SubfileType"; + +/** + * @brief This tag indicates horizontal positioning errors in meters. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_GPS_H_POSITIONING_ERROR = "GPSHPositioningError"; + +/** + * @brief This tag indicates the sensitivity of the camera or input device when the image was shot. + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_PHOTOGRAPHIC_SENSITIVITY = "PhotographicSensitivity"; + +/** + * @brief Burst Number + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_BURST_NUMBER = "HwMnoteBurstNumber"; + +/** + * @brief Face Conf + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_FACE_CONF = "HwMnoteFaceConf"; + +/** + * @brief Face Leye Center + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_FACE_LEYE_CENTER = "HwMnoteFaceLeyeCenter"; + +/** + * @brief Face Mouth Center + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_FACE_MOUTH_CENTER = "HwMnoteFaceMouthCenter"; + +/** + * @brief Face Pointer + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_FACE_POINTER = "HwMnoteFacePointer"; + +/** + * @brief Face Rect + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_FACE_RECT = "HwMnoteFaceRect"; + +/** + * @brief Face Reye Center + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_FACE_REYE_CENTER = "HwMnoteFaceReyeCenter"; + +/** + * @brief Face Smile Score + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_FACE_SMILE_SCORE = "HwMnoteFaceSmileScore"; + +/** + * @brief Face Version + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_FACE_VERSION = "HwMnoteFaceVersion"; + +/** + * @brief Front Camera + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_FRONT_CAMERA = "HwMnoteFrontCamera"; + +/** + * @brief Scene Pointer + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_SCENE_POINTER = "HwMnoteScenePointer"; + +/** + * @brief Scene Version + * It is used in {@link OH_ImageSource_GetImageProperty} and {@link OH_ImageSource_ModifyImageProperty}. + * + * @since 12 + */ +static const char *OHOS_IMAGE_PROPERTY_SCENE_VERSION = "HwMnoteSceneVersion"; +#ifdef __cplusplus +}; +#endif +/** @} */ + +#endif // INTERFACES_KITS_NATIVE_INCLUDE_IMAGE_IMAGE_COMMON_H \ No newline at end of file diff --git a/interfaces/kits/native/include/image/image_packer_native.h b/interfaces/kits/native/include/image/image_packer_native.h new file mode 100644 index 000000000..b14577fdf --- /dev/null +++ b/interfaces/kits/native/include/image/image_packer_native.h @@ -0,0 +1,238 @@ +/* + * Copyright (C) 2023 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. + */ + +/** + * @addtogroup image + * @{ + * + * @brief Provides APIs for access to the image interface. + * + * @since 12 + */ + +/** + * @file image_packer_native.h + * + * @brief Declares APIs for encoding image into data or file. + * + * @library libimage_packer.so + * @syscap SystemCapability.Multimedia.Image.ImagePacker + * @since 12 + */ + +#ifndef INTERFACES_KITS_NATIVE_INCLUDE_IMAGE_IMAGE_PACKER_NATIVE_H +#define INTERFACES_KITS_NATIVE_INCLUDE_IMAGE_IMAGE_PACKER_NATIVE_H +#include "image_common.h" +#include "image_source_native.h" +#include "pixelmap_native.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Define a ImagePacker struct type, used for ImagePacker pointer controls. + * + * @since 12 + */ +struct OH_ImagePackerNative; +typedef struct OH_ImagePackerNative OH_ImagePackerNative; + +/** + * @brief Defines the image packing options. + * + * @since 12 + */ +struct OH_PackingOptions; +typedef struct OH_PackingOptions OH_PackingOptions; + +/** + * @brief Enumerates packing dynamic range. + * + * @since 12 + */ +typedef enum { + /* + * Packing according to the content of the image. + */ + IMAGE_PACKER_DYNAMIC_RANGE_AUTO = 0, + /* + * Packing to standard dynamic range. + */ + IMAGE_PACKER_DYNAMIC_RANGE_SDR = 1, +}IMAGE_PACKER_DYNAMIC_RANGE; + +/** + * @brief Create a pointer for PackingOptions struct. + * + * @param options The PackingOptions pointer will be operated. + * @return Returns {@link Image_ErrorCode} + * @since 12 + */ +Image_ErrorCode OH_PackingOptions_Create(OH_PackingOptions **options); + +/** + * @brief Get mime type for DecodingOptions struct. + * + * @param options The DecodingOptions pointer will be operated. + * @param format the number of image format.The user can pass in a null pointer and zero size, we will allocate memory, + * but user must free memory after use. + * @return Returns {@link Image_ErrorCode} + * @since 12 + */ +Image_ErrorCode OH_PackingOptions_GetMimeType(OH_PackingOptions *options, + Image_MimeType *format); + +/** + * @brief Set format number for DecodingOptions struct. + * + * @param options The DecodingOptions pointer will be operated. + * @param format the number of image format. + * @return Returns {@link Image_ErrorCode} + * @since 12 + */ +Image_ErrorCode OH_PackingOptions_SetMimeType(OH_PackingOptions *options, + Image_MimeType *format); + +/** + * @brief Get quality for DecodingOptions struct. + * + * @param options The DecodingOptions pointer will be operated. + * @param quality the number of image quality. + * @return Returns {@link Image_ErrorCode} + * @since 12 + */ +Image_ErrorCode OH_PackingOptions_GetQuality(OH_PackingOptions *options, + uint32_t *quality); + +/** + * @brief Set quality number for DecodingOptions struct. + * + * @param options The DecodingOptions pointer will be operated. + * @param quality the number of image quality. + * @return Returns {@link Image_ErrorCode} + * @since 12 + */ +Image_ErrorCode OH_PackingOptions_SetQuality(OH_PackingOptions *options, + uint32_t quality); + +/** + * @brief delete DecodingOptions pointer. + * + * @param options The DecodingOptions pointer will be operated. + * @return Returns {@link Image_ErrorCode} + * @since 12 + */ +Image_ErrorCode OH_PackingOptions_Release(OH_PackingOptions *options); + +/** + * @brief Set desiredDynamicRange number for OH_ImagePackerNative struct. + * + * @param opts The PackingOptions pointer will be operated. + * @param desiredDynamicRange The number of image {@link IMAGE_PACKER_DYNAMIC_RANGE}. + * @return Returns {@link Image_ErrorCode} + * @since 12 + */ +Image_ErrorCode OH_PackingOptions_SetDesiredDynamicRange(OH_PackingOptions *opts, + int32_t desiredDynamicRange); + +/** + * @brief Get desiredDynamicRange number for OH_ImagePackerNative struct. + * + * @param opts The PackingOptions pointer will be operated. + * @param desiredDynamicRange The number of image {@link IMAGE_PACKER_DYNAMIC_RANGE}. + * @return Returns {@link Image_ErrorCode} + * @since 12 + */ +Image_ErrorCode OH_PackingOptions_GetDesiredDynamicRange(OH_PackingOptions *opts, + int32_t* desiredDynamicRange); + +/** + * @brief Create a pointer for OH_ImagePackerNative struct. + * + * @param options The OH_ImagePackerNative pointer will be operated. + * @return Returns {@link Image_ErrorCode} + * @since 12 + */ +Image_ErrorCode OH_ImagePackerNative_Create(OH_ImagePackerNative **imagePacker); + +/** + * @brief Encoding an ImageSource into the data with required format. + * + * @param imagePacker The imagePacker to use for packing. + * @param options Indicates the encoding {@link OH_PackingOptions}. + * @param imageSource The imageSource to be packed. + * @param outData The output data buffer to store the packed image. + * @param size A pointer to the size of the output data buffer. + * @return Returns {@link Image_ErrorCode} + * @since 12 + */ +Image_ErrorCode OH_ImagePackerNative_PackToDataFromImageSource(OH_ImagePackerNative *imagePacker, + OH_PackingOptions *options, OH_ImageSourceNative *imageSource, uint8_t *outData, size_t *size); + +/** + * @brief Encoding a Pixelmap into the data with required format. + * + * @param imagePacker The imagePacker to use for packing. + * @param options Indicates the encoding {@link OH_PackingOptions}. + * @param pixelmap The pixelmap to be packed. + * @param outData The output data buffer to store the packed image. + * @param size A pointer to the size of the output data buffer. + * @return Returns {@link Image_ErrorCode} + * @since 12 + */ +Image_ErrorCode OH_ImagePackerNative_PackToDataFromPixelmap(OH_ImagePackerNative *imagePacker, + OH_PackingOptions *options, OH_PixelmapNative *pixelmap, uint8_t *outData, size_t *size); + +/** + * @brief Encoding an ImageSource into the a file with fd with required format. + * + * @param imagePacker The image packer to use for packing. + * @param options Indicates the encoding {@link OH_PackingOptions}. + * @param imageSource The imageSource to be packed. + * @param fd Indicates a writable file descriptor. + * @return Returns {@link Image_ErrorCode} + * @since 12 + */ +Image_ErrorCode OH_ImagePackerNative_PackToFileFromImageSource(OH_ImagePackerNative *imagePacker, + OH_PackingOptions *options, OH_ImageSourceNative *imageSource, int32_t fd); + +/** + * @brief Encoding a Pixelmap into the a file with fd with required format + * + * @param imagePacker The image packer to use for packing. + * @param options Indicates the encoding {@link OH_PackingOptions}. + * @param pixelmap The pixelmap to be packed. + * @param fd Indicates a writable file descriptor. + * @return Returns {@link Image_ErrorCode} + * @since 12 + */ +Image_ErrorCode OH_ImagePackerNative_PackToFileFromPixelmap(OH_ImagePackerNative *imagePacker, + OH_PackingOptions *options, OH_PixelmapNative *pixelmap, int32_t fd); + +/** + * @brief Releases an imagePacker object. + * + * @param imagePacker A pointer to the image packer object to be released. + * @return Returns {@link Image_ErrorCode} + * @since 12 + */ +Image_ErrorCode OH_ImagePackerNative_Release(OH_ImagePackerNative *imagePacker); + +#ifdef __cplusplus +}; +#endif +/* *@} */ +#endif // INTERFACES_KITS_NATIVE_INCLUDE_IMAGE_IMAGE_PACKER_NATIVE_H \ No newline at end of file diff --git a/interfaces/kits/native/include/image/image_source_native.h b/interfaces/kits/native/include/image/image_source_native.h new file mode 100644 index 000000000..a0d2252fd --- /dev/null +++ b/interfaces/kits/native/include/image/image_source_native.h @@ -0,0 +1,433 @@ +/* + * Copyright (C) 2023 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. + */ + +/** + * @addtogroup image + * @{ + * + * @brief Provides APIs for access to the image interface. + * + * @since 12 + */ + +/** + * @file image_source_native.h + * + * @brief Declares APIs for decoding an image source into a pixel map. + * + * @library libimage_source.so + * @syscap SystemCapability.Multimedia.Image.ImageSource + * @since 12 + */ + +#ifndef INTERFACES_KITS_NATIVE_INCLUDE_IMAGE_IMAGE_SOURCE_NATIVE_H_ +#define INTERFACES_KITS_NATIVE_INCLUDE_IMAGE_IMAGE_SOURCE_NATIVE_H_ +#include "image_common.h" + +#include "pixelmap_native.h" +#include "raw_file.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Defines an image source object for the image interface. + * + * @since 12 + */ +struct OH_ImageSourceNative; +typedef struct OH_ImageSourceNative OH_ImageSourceNative; + +/** + * @brief Defines image source infomation + * {@link OH_ImageSourceInfo_Create}. + * + * @since 12 + */ +struct OH_ImageSource_Info; +typedef struct OH_ImageSource_Info OH_ImageSource_Info; + +/** + * @brief Enumerates decoding dynamic range.. + * + * @since 12 + */ +typedef enum { + /* + * Dynamic range depends on the image. + */ + IMAGE_DYNAMIC_RANGE_AUTO = 0, + /* + * Standard dynamic range. + */ + IMAGE_DYNAMIC_RANGE_SDR = 1, + /* + * High dynamic range. + */ + IMAGE_DYNAMIC_RANGE_HDR = 2, +}IMAGE_DYNAMIC_RANGE; + +/** + * @brief Create a pointer for OH_ImageSource_Info struct. + * + * @param info The OH_ImageSource_Info pointer will be operated. + * @return Returns {@link Image_ErrorCode} + * @since 12 + */ +Image_ErrorCode OH_ImageSourceInfo_Create(OH_ImageSource_Info **info); + +/** + * @brief Get width number for OH_ImageSource_Info struct. + * + * @param info The DecodingOptions pointer will be operated. + * @param width the number of image width. + * @return Returns {@link Image_ErrorCode} + * @since 12 + */ +Image_ErrorCode OH_ImageSourceInfo_GetWidth(OH_ImageSource_Info *info, uint32_t *width); + +/** + * @brief Get height number for OH_ImageSource_Info struct. + * + * @param info The DecodingOptions pointer will be operated. + * @param height the number of image height. + * @return Returns {@link Image_ErrorCode} + * @since 12 + */ +Image_ErrorCode OH_ImageSourceInfo_GetHeight(OH_ImageSource_Info *info, uint32_t *height); + +/** + * @brief Get isHdr for OH_ImageSource_Info struct. + * + * @param info The {@link OH_ImageSource_Info} pointer will be operated. + * @param isHdr Whether the image has a high dynamic range. + * @return Returns {@link Image_ErrorCode} + * @since 12 + */ +Image_ErrorCode OH_ImageSourceInfo_GetDynamicRange(OH_ImageSource_Info *info, bool *isHdr); + +/** + * @brief delete OH_ImageSource_Info pointer. + * + * @param info The OH_ImageSource_Info pointer will be operated. + * @return Returns {@link Image_ErrorCode} + * @since 12 + */ +Image_ErrorCode OH_ImageSourceInfo_Release(OH_ImageSource_Info *info); + +/** + * @brief Defines the options for decoding the image source. + * It is used in {@link OH_ImageSourceNative_CreatePixelmap}. + * + * @since 12 + */ +struct OH_DecodingOptions; +typedef struct OH_DecodingOptions OH_DecodingOptions; + +/** + * @brief Create a pointer for InitializationOtions struct. + * + * @param options The DecodingOptions pointer will be operated. + * @return Returns {@link Image_ErrorCode} + * @since 12 + */ +Image_ErrorCode OH_DecodingOptions_Create(OH_DecodingOptions **options); + +/** + * @brief Get pixelFormat number for DecodingOptions struct. + * + * @param options The DecodingOptions pointer will be operated. + * @param pixelFormat the number of image pixelFormat. + * @return Returns {@link Image_ErrorCode} + * @since 12 + */ +Image_ErrorCode OH_DecodingOptions_GetPixelFormat(OH_DecodingOptions *options, + int32_t *pixelFormat); + +/** + * @brief Set pixelFormat number for DecodingOptions struct. + * + * @param options The DecodingOptions pointer will be operated. + * @param pixelFormat the number of image pixelFormat. + * @return Returns {@link Image_ErrorCode} + * @since 12 + */ +Image_ErrorCode OH_DecodingOptions_SetPixelFormat(OH_DecodingOptions *options, + int32_t pixelFormat); + +/** + * @brief Get index number for DecodingOptions struct. + * + * @param options The DecodingOptions pointer will be operated. + * @param index the number of image index. + * @return Returns {@link Image_ErrorCode} + * @since 12 + */ +Image_ErrorCode OH_DecodingOptions_GetIndex(OH_DecodingOptions *options, uint32_t *index); + +/** + * @brief Set index number for DecodingOptions struct. + * + * @param options The DecodingOptions pointer will be operated. + * @param index the number of image index. + * @return Returns {@link Image_ErrorCode} + * @since 12 + */ +Image_ErrorCode OH_DecodingOptions_SetIndex(OH_DecodingOptions *options, uint32_t index); + +/** + * @brief Get rotate number for DecodingOptions struct. + * + * @param options The DecodingOptions pointer will be operated. + * @param rotate the number of image rotate. + * @return Returns {@link Image_ErrorCode} + * @since 12 + */ +Image_ErrorCode OH_DecodingOptions_GetRotate(OH_DecodingOptions *options, float *rotate); + +/** + * @brief Set rotate number for DecodingOptions struct. + * + * @param options The DecodingOptions pointer will be operated. + * @param rotate the number of image rotate. + * @return Returns {@link Image_ErrorCode} + * @since 12 + */ +Image_ErrorCode OH_DecodingOptions_SetRotate(OH_DecodingOptions *options, float rotate); + +/** + * @brief Get desiredSize number for DecodingOptions struct. + * + * @param options The DecodingOptions pointer will be operated. + * @param desiredSize the number of image desiredSize. + * @return Returns {@link Image_ErrorCode} + * @since 12 + */ +Image_ErrorCode OH_DecodingOptions_GetDesiredSize(OH_DecodingOptions *options, + Image_Size *desiredSize); + +/** + * @brief Set desiredSize number for DecodingOptions struct. + * + * @param options The DecodingOptions pointer will be operated. + * @param desiredSize the number of image desiredSize. + * @return Returns {@link Image_ErrorCode} + * @since 12 + */ +Image_ErrorCode OH_DecodingOptions_SetDesiredSize(OH_DecodingOptions *options, + Image_Size *desiredSize); + +/** + * @brief Set desiredRegion number for DecodingOptions struct. + * + * @param options The DecodingOptions pointer will be operated. + * @param desiredRegion the number of image desiredRegion. + * @return Returns {@link Image_ErrorCode} + * @since 12 + */ +Image_ErrorCode OH_DecodingOptions_GetDesiredRegion(OH_DecodingOptions *options, + Image_Region *desiredRegion); + +/** + * @brief Set desiredRegion number for DecodingOptions struct. + * + * @param options The DecodingOptions pointer will be operated. + * @param desiredRegion the number of image desiredRegion. + * @return Returns {@link Image_ErrorCode} + * @since 12 + */ +Image_ErrorCode OH_DecodingOptions_SetDesiredRegion(OH_DecodingOptions *options, + Image_Region *desiredRegion); + +/** + * @brief Get desiredDynamicRange for DecodingOptions struct. + * + * @param opts The DecodingOptions pointer will be operated. + * @param desiredDynamicRange the number of image {@link IMAGE_DYNAMIC_RANGE}. + * @return Returns {@link Image_ErrorCode} + * @since 12 + */ +Image_ErrorCode OH_DecodingOptions_GetDesiredDynamicRange(OH_DecodingOptions *opts, + int32_t *desiredDynamicRange); + +/** + * @brief Set desiredDynamicRange for DecodingOptions struct. + * + * @param opts The DecodingOptions pointer will be operated. + * @param desiredDynamicRange the number of image {@link IMAGE_DYNAMIC_RANGE}. + * @return Returns {@link Image_ErrorCode} + * @since 12 + */ +Image_ErrorCode OH_DecodingOptions_SetDesiredDynamicRange(OH_DecodingOptions *opts, + int32_t desiredDynamicRange); + +/** + * @brief delete DecodingOptions pointer. + * + * @param options The DecodingOptions pointer will be operated. + * @return Returns {@link Image_ErrorCode} + * @since 12 + */ +Image_ErrorCode OH_DecodingOptions_Release(OH_DecodingOptions *options); + +/** + * @brief Creates an ImageSource pointer. + * + * @param uri Indicates a pointer to the image source URI. Only a file URI or Base64 URI is accepted. + * @param uriSize Indicates the length of the image source URI. + * @param res Indicates a pointer to the ImageSource object created at the C++ native layer. + * @return Returns {@link Image_ErrorCode} + * @since 12 + */ +Image_ErrorCode OH_ImageSourceNative_CreateFromUri(char *uri, size_t uriSize, OH_ImageSourceNative **res); + +/** + * @brief Creates an void pointer + * + * @param fd Indicates the image source file descriptor. + * @param res Indicates a void pointer to the ImageSource object created at the C++ native layer. + * @return Returns {@link Image_ErrorCode} + * @since 12 + */ +Image_ErrorCode OH_ImageSourceNative_CreateFromFd(int32_t fd, OH_ImageSourceNative **res); + +/** + * @brief Creates an void pointer + * + * @param data Indicates a pointer to the image source data. Only a formatted packet data or Base64 data is accepted. + * @param dataSize Indicates the size of the image source data. + * @param res Indicates a void pointer to the ImageSource object created at the C++ native layer. + * @return Returns {@link Image_ErrorCode} + * @since 12 + */ +Image_ErrorCode OH_ImageSourceNative_CreateFromData(uint8_t *data, size_t dataSize, OH_ImageSourceNative **res); + +/** + * @brief Creates an void pointer + * + * @param rawFile Indicates the raw file's file descriptor. + * @param res Indicates a void pointer to the ImageSource object created at the C++ native layer. + * @return Returns {@link Image_ErrorCode} + * @since 12 + */ +Image_ErrorCode OH_ImageSourceNative_CreateFromRawFile(RawFileDescriptor *rawFile, OH_ImageSourceNative **res); + +/** + * @brief Decodes an void pointer + * based on the specified {@link OH_DecodingOptions} struct. + * + * @param source Indicates a void pointer(from ImageSource pointer convert). + * @param options Indicates a pointer to the options for decoding the image source. + * For details, see {@link OH_DecodingOptions}. + * @param resPixMap Indicates a void pointer to the Pixelmap object obtained at the C++ native layer. + * @return Returns {@link Image_ErrorCode} + * @since 12 + */ +Image_ErrorCode OH_ImageSourceNative_CreatePixelmap(OH_ImageSourceNative *source, OH_DecodingOptions *options, + OH_PixelmapNative **pixelmap); + +/** + * @brief Decodes an void pointer + * the Pixelmap objects at the C++ native layer + * based on the specified {@link OH_DecodingOptions} struct. + * + * @param source Indicates a void pointer(from ImageSource pointer convert). + * @param options Indicates a pointer to the options for decoding the image source. + * For details, see {@link OH_DecodingOptions}. + * @param resVecPixMap Indicates a pointer array to the Pixelmap objects obtained at the C++ native layer. + * It cannot be a null pointer. + * @param outSize Indicates a size of resVecPixMap. User can get size from {@link OH_ImageSourceNative_GetFrameCount}. + * @return Returns {@link Image_ErrorCode} + * @since 12 + */ +Image_ErrorCode OH_ImageSourceNative_CreatePixelmapList(OH_ImageSourceNative *source, OH_DecodingOptions *options, + OH_PixelmapNative *resVecPixMap[], size_t outSize); + +/** + * @brief Obtains the delay time list from some ImageSource objects (such as GIF image sources). + * + * @param source Indicates a void pointer(from ImageSource pointer convert). + * @param delayTimeList Indicates a pointer to the delay time list obtained. It cannot be a null pointer. + * @param size Indicates a size of delayTimeList. User can get size from {@link OH_ImageSourceNative_GetFrameCount}. + * @return Returns {@link Image_ErrorCode} + * @since 12 + */ +Image_ErrorCode OH_ImageSourceNative_GetDelayTimeList(OH_ImageSourceNative *source, + int32_t *delayTimeList, size_t size); + +/** + * @brief Obtains image source information from an ImageSource object by index. + * + * @param source Indicates a void pointer(from ImageSource pointer convert). + * @param index Indicates the index of the frame. + * @param info Indicates a pointer to the image source information obtained. + * For details, see {@link OH_ImageSource_Info}. + * @return Returns {@link Image_ErrorCode} + * @since 12 + */ +Image_ErrorCode OH_ImageSourceNative_GetImageInfo(OH_ImageSourceNative *source, int32_t index, + OH_ImageSource_Info *info); + +/** + * @brief Obtains the value of an image property from an ImageSource object. + * + * @param source Indicates a void pointer(from ImageSource pointer convert). + * @param key Indicates a pointer to the property. For details, see {@link Image_String}., key is an exif constant. + * Release after use ImageSource, see {@link OH_ImageSourceNative_Release}. + * @param value Indicates a pointer to the value obtained.The user can pass in a null pointer and zero size, + * we will allocate memory, but user must free memory after use. + * @return Returns {@link Image_ErrorCode} + * @since 12 + */ +Image_ErrorCode OH_ImageSourceNative_GetImageProperty(OH_ImageSourceNative *source, Image_String *key, + Image_String *value); + +/** + * @brief Modifies the value of an image property of an ImageSource object. + * @param source Indicates a void pointer(from ImageSource pointer convert). + * @param key Indicates a pointer to the property. For details, see {@link Image_String}., key is an exif constant. + * Release after use ImageSource, see {@link OH_ImageSourceNative_Release}. + * @param value Indicates a pointer to the new value of the property. + * @return Returns {@link Image_ErrorCode} + * @since 12 + */ +Image_ErrorCode OH_ImageSourceNative_ModifyImageProperty(OH_ImageSourceNative *source, Image_String *key, + Image_String *value); + +/** + * @brief Obtains the number of frames from an ImageSource object. + * + * @param source Indicates a pointer to the {@link OH_ImageSourceNative} object at the C++ native layer. + * @param res Indicates a pointer to the number of frames obtained. + * @return Returns {@link Image_ErrorCode} + * @since 12 + */ +Image_ErrorCode OH_ImageSourceNative_GetFrameCount(OH_ImageSourceNative *source, uint32_t *frameCount); + +/** + * @brief Releases an ImageSourc object. + * + * @param source Indicates a ImageSource pointer. + * @return Returns {@link Image_ErrorCode} + * @since 12 + */ +Image_ErrorCode OH_ImageSourceNative_Release(OH_ImageSourceNative *source); + +#ifdef __cplusplus +}; +#endif +/** @} */ +#endif // INTERFACES_KITS_NATIVE_INCLUDE_IMAGE_IMAGE_SOURCE_NATIVE_H \ No newline at end of file diff --git a/interfaces/kits/native/include/image/pixelmap_native.h b/interfaces/kits/native/include/image/pixelmap_native.h new file mode 100644 index 000000000..c54cc57d1 --- /dev/null +++ b/interfaces/kits/native/include/image/pixelmap_native.h @@ -0,0 +1,445 @@ +/* + * Copyright (C) 2023 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. + */ + +/** + * @addtogroup image + * @{ + * + * @brief Provides APIs for obtaining pixel map data and information. + * + * @Syscap SystemCapability.Multimedia.Image.Core + * @since 12 + */ + +/** + * @file pixelmap_native.h + * + * @brief Declares the APIs that can access a pixel map. + * + * @library libpixelmap.so + * @Syscap SystemCapability.Multimedia.Image.Core + * @since 12 + */ + +#ifndef INTERFACES_KITS_NATIVE_INCLUDE_IMAGE_PIXELMAP_NATIVE_H +#define INTERFACES_KITS_NATIVE_INCLUDE_IMAGE_PIXELMAP_NATIVE_H +#include "image_common.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Define a Pixelmap struct type, used for pixelmap pointer controls. + * + * @since 12 + */ +struct OH_PixelmapNative; +typedef struct OH_PixelmapNative OH_PixelmapNative; + +/** + * @brief Define a pixelmap alpha type. + * + * @since 12 + */ +typedef enum { + /* + * Unknown format + */ + PIXELMAP_ALPHA_TYPE_UNKNOWN = 0, + /* + * Opaque format + */ + PIXELMAP_ALPHA_TYPE_OPAQUE = 1, + /* + * Premultiplied format + */ + PIXELMAP_ALPHA_TYPE_PREMULTIPLIED = 2, +}PIXELMAP_ALPHA_TYPE; + +typedef enum { + /* + * Unknown format + */ + PIXEL_FORMAT_UNKNOWN = 0, + /* + * RGB_565 format + */ + PIXEL_FORMAT_RGB_565 = 2, + /* + * RGBA_8888 format + */ + PIXEL_FORMAT_RGBA_8888 = 3, + /* + * BGRA_8888 format + */ + PIXEL_FORMAT_BGRA_8888 = 4, + /* + * RGB_888 format + */ + PIXEL_FORMAT_RGB_888 = 5, + /* + * ALPHA_8 format + */ + PIXEL_FORMAT_ALPHA_8 = 6, + /* + * RGBA_F16 format + */ + PIXEL_FORMAT_RGBA_F16 = 7, + /* + * NV21 format + */ + PIXEL_FORMAT_NV21 = 8, + /* + * NV12 format + */ + PIXEL_FORMAT_NV12 = 9, +} PIXEL_FORMAT; + +/** + * @brief Defines the options used for creating a pixel map. + * + * @since 12 + */ +struct OH_Pixelmap_InitializationOptions; +typedef struct OH_Pixelmap_InitializationOptions OH_Pixelmap_InitializationOptions; + +/** + * @brief Create a for InitializationOtions struct. + * + * @param options The InitializationOtions pointer will be operated. + * @return Returns {@link Image_ErrorCode} + * @since 12 + */ +Image_ErrorCode OH_PixelmapInitializationOptions_Create(OH_Pixelmap_InitializationOptions **options); + +/** + * @brief Get width number for InitializationOtions struct. + * + * @param options The InitializationOtions pointer will be operated. + * @param width the number of image width. + * @return Returns {@link Image_ErrorCode} + * @since 12 + */ +Image_ErrorCode OH_PixelmapInitializationOptions_GetWidth(OH_Pixelmap_InitializationOptions *options, + uint32_t *width); + +/** + * @brief Set width number for InitializationOtions struct. + * + * @param options The InitializationOtions pointer will be operated. + * @param width the number of image width. + * @return Returns {@link Image_ErrorCode} + * @since 12 + */ +Image_ErrorCode OH_PixelmapInitializationOptions_SetWidth(OH_Pixelmap_InitializationOptions *options, + uint32_t width); + +/** + * @brief Get height number for InitializationOtions struct. + * + * @param options The InitializationOtions pointer will be operated. + * @param height the number of image height. + * @return Returns {@link Image_ErrorCode} + * @since 12 + */ +Image_ErrorCode OH_PixelmapInitializationOptions_GetHeight(OH_Pixelmap_InitializationOptions *options, + uint32_t *height); + +/** + * @brief Set height number for InitializationOtions struct. + * + * @param options The InitializationOtions pointer will be operated. + * @param height the number of image height. + * @return Returns {@link Image_ErrorCode} + * @since 12 + */ +Image_ErrorCode OH_PixelmapInitializationOptions_SetHeight(OH_Pixelmap_InitializationOptions *options, + uint32_t height); + +/** + * @brief Get pixelFormat number for InitializationOtions struct. + * + * @param options The InitializationOtions pointer will be operated. + * @param pixelFormat the number of image pixelFormat. + * @return Returns {@link Image_ErrorCode} + * @since 12 + */ +Image_ErrorCode OH_PixelmapInitializationOptions_GetPixelFormat(OH_Pixelmap_InitializationOptions *options, + int32_t *pixelFormat); + +/** + * @brief Set pixelFormat number for InitializationOtions struct. + * + * @param options The InitializationOtions pointer will be operated. + * @param pixelFormat the number of image pixelFormat. + * @return Returns {@link Image_ErrorCode} + * @since 12 + */ +Image_ErrorCode OH_PixelmapInitializationOptions_SetPixelFormat(OH_Pixelmap_InitializationOptions *options, + int32_t pixelFormat); + +/** + * @brief Get alphaType number for InitializationOtions struct. + * + * @param options The InitializationOtions pointer will be operated. + * @param alphaType the number of image alphaType. + * @return Returns {@link Image_ErrorCode} + * @since 12 + */ +Image_ErrorCode OH_PixelmapInitializationOptions_GetAlphaType(OH_Pixelmap_InitializationOptions *options, + int32_t *alphaType); + +/** + * @brief Set alphaType number for InitializationOtions struct. + * + * @param options The InitializationOtions pointer will be operated. + * @param alphaType the number of image alphaType. + * @return Returns {@link Image_ErrorCode} + * @since 12 + */ +Image_ErrorCode OH_PixelmapInitializationOptions_SetAlphaType(OH_Pixelmap_InitializationOptions *options, + int32_t alphaType); + +/** + * @brief delete InitializationOtions pointer. + * + * @param options The InitializationOtions pointer will be operated. + * @return Returns {@link Image_ErrorCode} + * @since 12 + */ +Image_ErrorCode OH_PixelmapInitializationOptions_Release(OH_Pixelmap_InitializationOptions *options); + +/** + * @brief Defines the pixel map information. + * + * @since 12 + */ +struct OH_Pixelmap_ImageInfo; +typedef struct OH_Pixelmap_ImageInfo OH_Pixelmap_ImageInfo; + +/** + * @brief Create imageinfo struct . + * + * @param info The imageinfo pointer will be operated. + * @return Returns {@link Image_ErrorCode} + * @since 12 + */ +Image_ErrorCode OH_PixelmapImageInfo_Create(OH_Pixelmap_ImageInfo **info); + +/** + * @brief Get width number for imageinfo struct. + * + * @param info The imageinfo pointer will be operated. + * @param width The number of imageinfo width. + * @return Returns {@link Image_ErrorCode} + * @since 12 + */ +Image_ErrorCode OH_PixelmapImageInfo_GetWidth(OH_Pixelmap_ImageInfo *info, uint32_t *width); + +/** + * @brief Get height number for imageinfo struct. + * + * @param info The imageinfo pointer will be operated. + * @param height The number of imageinfo height. + * @return Returns {@link Image_ErrorCode} + * @since 12 + */ +Image_ErrorCode OH_PixelmapImageInfo_GetHeight(OH_Pixelmap_ImageInfo *info, uint32_t *height); + +/** + * @brief Get rowStride number for imageinfo struct. + * + * @param info The imageinfo pointer will be operated. + * @param rowStride The number of imageinfo rowStride. + * @return Returns {@link Image_ErrorCode} + * @since 12 + */ +Image_ErrorCode OH_PixelmapImageInfo_GetRowStride(OH_Pixelmap_ImageInfo *info, uint32_t *rowStride); + +/** + * @brief Get pixelFormat number for imageinfo struct. + * + * @param info The imageinfo pointer will be operated. + * @param pixelFormat The number of imageinfo pixelFormat. + * @return Returns {@link Image_ErrorCode} + * @since 12 + */ +Image_ErrorCode OH_PixelmapImageInfo_GetPixelFormat(OH_Pixelmap_ImageInfo *info, int32_t *pixelFormat); + +/** + * @brief Get density number for imageinfo struct. + * + * @param info The imageinfo pointer will be operated. + * @param density The number of imageinfo density. + * @return Returns {@link Image_ErrorCode} + * @since 12 + */ +Image_ErrorCode OH_PixelmapImageInfo_GetAlphaType(OH_Pixelmap_ImageInfo *info, int32_t *alphaType); + +/** + * @brief Get isHdr for imageinfo struct. + * + * @param info The {@link OH_Pixelmap_ImageInfo} pointer will be operated. + * @param isHdr Whether the image has a high dynamic range. + * @return Returns {@link Image_ErrorCode} + * @see OH_PixelmapImageInfo_GetDynamicRange + * @since 12 + */ +Image_ErrorCode OH_PixelmapImageInfo_GetDynamicRange(OH_Pixelmap_ImageInfo *infos, bool *isHdr); + +/** + * @brief Delete imageinfo struct pointer. + * + * @param info The imageinfo pointer will be operated. + * @return Returns {@link Image_ErrorCode} + * @since 12 + */ +Image_ErrorCode OH_PixelmapImageInfo_Release(OH_Pixelmap_ImageInfo *info); + +/** + * @brief Creates a PixelMap object. + * + * @param data Color buffer in BGRA_8888 format. + * @param dataLength Color buffer size in BGRA_8888 format. + * @param options IPixel properties, including the alpha type, size, pixel format, and editable. + * @param pixelmap Pixelmap pointer for created. + * @return Returns {@link Image_ErrorCode} + * @since 12 + */ +Image_ErrorCode OH_PixelmapNative_CreatePixelmap(uint8_t *data, size_t dataLength, + OH_Pixelmap_InitializationOptions *options, OH_PixelmapNative **pixelmap); + +/** + * @brief Reads data of this pixel map to an Buffer. If this pixel map is created in the BGRA_8888 format, + * the data read is the same as the original data. + * + * @param pixelmap The Pixelmap pointer will be operated. + * @param destination Buffer to which the image pixel map data will be written. + * @param bufferSize Buffer size to which the image pixel map data will be written. + * @return Returns {@link Image_ErrorCode} + * @see OH_PixelmapNative + * @since 12 + */ +Image_ErrorCode OH_PixelmapNative_ReadPixels(OH_PixelmapNative *pixelmap, uint8_t *destination, size_t *bufferSize); + +/** + * @brief Reads image data in an Buffer and writes the data to a Pixelmap object. + * + * @param pixelmap The Pixelmap pointer will be operated. + * @param source Buffer from which the image data will be read. + * @param bufferSize Buffer size from which the image data will be read. + * @return Returns {@link Image_ErrorCode} + * @see OH_PixelmapNative + * @since 12 + */ +Image_ErrorCode OH_PixelmapNative_WritePixels(OH_PixelmapNative *pixelmap, uint8_t *source, size_t bufferSize); + +/** + * @brief Obtains pixel map information of this image. + * + * @param pixelmap The Pixelmap pointer will be operated. + * @param imageInfo Indicates the pointer to the image information. + * @return Returns {@link Image_ErrorCode} + * @see OH_PixelmapNative OH_Pixelmap_ImageInfo + * @since 12 + */ +Image_ErrorCode OH_PixelmapNative_GetImageInfo(OH_PixelmapNative *pixelmap, OH_Pixelmap_ImageInfo *imageInfo); + +/** + * @brief Sets an opacity rate for this image pixel map. + * + * @param pixelmap The Pixelmap pointer will be operated. + * @param rate Opacity rate to set. The value ranges from 0 to 1. + * @return Returns {@link Image_ErrorCode} + * @see OH_PixelmapNative + * @since 12 + */ +Image_ErrorCode OH_PixelmapNative_Opacity(OH_PixelmapNative *pixelmap, float rate); + +/** + * @brief Scales this image based on the input width and height. + * + * @param pixelmap The Pixelmap pointer will be operated. + * @param scaleX Scaling ratio of the width. + * @param scaleY Scaling ratio of the height. + * @return Returns {@link Image_ErrorCode} + * @see OH_PixelmapNative + * @since 12 + */ +Image_ErrorCode OH_PixelmapNative_Scale(OH_PixelmapNative *pixelmap, float scaleX, float scaleY); + +/** + * @brief Translates this image based on the input coordinates. + * + * @param pixelmap The Pixelmap pointer will be operated. + * @param x The distance to be translate in the X direction. + * @param y The distance to be translate in the Y direction. + * @return Returns {@link Image_ErrorCode} + * @see OH_PixelmapNative + * @since 12 + */ +Image_ErrorCode OH_PixelmapNative_Translate(OH_PixelmapNative *pixelmap, float x, float y); + +/** + * @brief Rotates this image based on the input angle. + * + * @param pixelmap The Pixelmap pointer will be operated. + * @param angle Angle to rotate. + * @return Returns {@link Image_ErrorCode} + * @see OH_PixelmapNative + * @since 12 + */ +Image_ErrorCode OH_PixelmapNative_Rotate(OH_PixelmapNative *pixelmap, float angle); + +/** + * @brief Flips this image horizontally or vertically, or both. + * + * @param pixelmap The Pixelmap pointer will be operated. + * @param shouldFilpHorizontally Whether to flip the image horizontally. + * @param shouldFilpVertically Whether to flip the image vertically. + * @return Returns {@link Image_ErrorCode} + * @see OH_PixelmapNative + * @since 12 + */ +Image_ErrorCode OH_PixelmapNative_Flip(OH_PixelmapNative *pixelmap, bool shouldFilpHorizontally, + bool shouldFilpVertically); + +/** + * @brief Crops this image based on the input size. + * + * @param pixelmap The Pixelmap pointer will be operated. + * @param region Area size, read according to area. + * @return Returns {@link Image_ErrorCode} + * @see OH_PixelmapNative + * @since 12 + */ +Image_ErrorCode OH_PixelmapNative_Crop(OH_PixelmapNative *pixelmap, Image_Region *region); + +/** + * @brief Releases an OH_PixelmapNative object. + * + * @param pixelmap The Pixelmap pointer will be operated. + * @return Returns {@link Image_ErrorCode} + * @see OH_PixelmapNative + * @since 12 + */ +Image_ErrorCode OH_PixelmapNative_Release(OH_PixelmapNative *pixelmap); + +#ifdef __cplusplus +}; +#endif +/** @} */ +#endif // INTERFACES_KITS_NATIVE_INCLUDE_IMAGE_PIXELMAP_NATIVE_H -- Gitee From ab3f4d933980b51f5202eb6688d90aea4c655067 Mon Sep 17 00:00:00 2001 From: yangfan Date: Fri, 12 Apr 2024 20:13:16 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E5=88=A0=E9=99=A4=E4=B8=8D=E9=9C=80?= =?UTF-8?q?=E8=A6=81=E7=9A=84=E5=A4=B4=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yangfan Change-Id: I8824df2e216b25fa68657a55e01e494ff5880f89 --- frameworks/innerkitsimpl/test/BUILD.gn | 2 -- 1 file changed, 2 deletions(-) diff --git a/frameworks/innerkitsimpl/test/BUILD.gn b/frameworks/innerkitsimpl/test/BUILD.gn index 4abb96c25..e8fc9b43d 100644 --- a/frameworks/innerkitsimpl/test/BUILD.gn +++ b/frameworks/innerkitsimpl/test/BUILD.gn @@ -1045,8 +1045,6 @@ ohos_unittest("ndktest2") { "/utils/include", "/interfaces/innerkits/include", "//third_party/googletest/googletest/include", - "../../../../../arkui/napi/interfaces/inner_api", - "../../../../../arkui/napi/interfaces/kits", "//third_party/node/src", "$resource_management_subsystem/interfaces/native/resource/include", ] -- Gitee From 04e629b205469d3ea53d4fc0ecfabc4249f3df81 Mon Sep 17 00:00:00 2001 From: yangfan Date: Fri, 12 Apr 2024 21:25:57 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E5=A4=B4=E6=96=87=E4=BB=B6=E5=BC=95?= =?UTF-8?q?=E7=94=A8=E6=96=B9=E5=BC=8F=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yangfan Change-Id: I870e5ecbba50de313309a77f99137fdf8f2c343d --- frameworks/kits/js/common/ndk/BUILD.gn | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/frameworks/kits/js/common/ndk/BUILD.gn b/frameworks/kits/js/common/ndk/BUILD.gn index 33a2001af..b4ec4898f 100644 --- a/frameworks/kits/js/common/ndk/BUILD.gn +++ b/frameworks/kits/js/common/ndk/BUILD.gn @@ -109,7 +109,14 @@ ohos_shared_library("image_source") { "image_source_native_impl.cpp", ] - public_configs = [ ":native_public_config" ] + include_dirs = [ + "include", + "$BASE_DIR/multimedia/image_framework/interfaces/kits/native/include", + "$BASE_DIR/multimedia/image_framework/interfaces/kits/native/include/image", + "$BASE_DIR/multimedia/image_framework/interfaces/innerkits/include", + "$resource_management_subsystem/interfaces/native/resource/include", + "$BASE_DIR/multimedia/image_framework/frameworks/kits/js/common/pixelmap_ndk", + ] deps = [ "$image_subsystem/frameworks/kits/js/common/pixelmap_ndk:pixelmap", @@ -136,7 +143,15 @@ ohos_shared_library("image_packer") { "image_packer_native.cpp", "image_packer_native_impl.cpp", ] - public_configs = [ ":native_public_config" ] + + include_dirs = [ + "include", + "$BASE_DIR/multimedia/image_framework/interfaces/kits/native/include", + "$BASE_DIR/multimedia/image_framework/interfaces/kits/native/include/image", + "$BASE_DIR/multimedia/image_framework/interfaces/innerkits/include", + "$BASE_DIR/multimedia/image_framework/frameworks/kits/js/common/pixelmap_ndk", + ] + deps = [ "$image_subsystem/frameworks/kits/js/common/ndk:image_source", "$image_subsystem/frameworks/kits/js/common/pixelmap_ndk:pixelmap", -- Gitee From 08609478f2ea209fcda2a7f56aace3f09f4dd653 Mon Sep 17 00:00:00 2001 From: yangfan Date: Fri, 12 Apr 2024 22:06:35 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E4=BD=BF=E7=94=A8externlDeps=E6=96=B9?= =?UTF-8?q?=E5=BC=8F=E4=BE=9D=E8=B5=96rawfile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yangfan Change-Id: I1da409baef20d203fc863bcb67333e90f43e0511 --- frameworks/kits/js/common/ndk/BUILD.gn | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/frameworks/kits/js/common/ndk/BUILD.gn b/frameworks/kits/js/common/ndk/BUILD.gn index b4ec4898f..cb2919f88 100644 --- a/frameworks/kits/js/common/ndk/BUILD.gn +++ b/frameworks/kits/js/common/ndk/BUILD.gn @@ -114,7 +114,6 @@ ohos_shared_library("image_source") { "$BASE_DIR/multimedia/image_framework/interfaces/kits/native/include", "$BASE_DIR/multimedia/image_framework/interfaces/kits/native/include/image", "$BASE_DIR/multimedia/image_framework/interfaces/innerkits/include", - "$resource_management_subsystem/interfaces/native/resource/include", "$BASE_DIR/multimedia/image_framework/frameworks/kits/js/common/pixelmap_ndk", ] @@ -124,7 +123,10 @@ ohos_shared_library("image_source") { "$image_subsystem/interfaces/kits/js/common:image", ] - external_deps = [ "c_utils:utils" ] + external_deps = [ + "c_utils:utils", + "resource:librawfile_ndk" + ] innerapi_tags = [ "ndk" ] subsystem_name = "multimedia" -- Gitee From be7132eb3f6aa504b4a8c51f44531edc0d1cf9ce Mon Sep 17 00:00:00 2001 From: yangfan Date: Fri, 12 Apr 2024 22:23:43 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E5=8E=BB=E6=8E=89=E9=80=9A=E8=BF=87rawfile?= =?UTF-8?q?=E5=88=9B=E5=BB=BAImageSource?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yangfan Change-Id: I75e8286097db5110c628d697d02665b2121cbab1 --- frameworks/kits/js/common/ndk/BUILD.gn | 5 +-- .../js/common/ndk/image_source_native.cpp | 36 +++++++++---------- .../common/ndk/image_source_native_impl.cpp | 24 ++++++------- .../ndk/include/image_source_native_impl.h | 2 +- .../include/image/image_source_native.h | 11 ------ 5 files changed, 32 insertions(+), 46 deletions(-) diff --git a/frameworks/kits/js/common/ndk/BUILD.gn b/frameworks/kits/js/common/ndk/BUILD.gn index cb2919f88..e3e93480f 100644 --- a/frameworks/kits/js/common/ndk/BUILD.gn +++ b/frameworks/kits/js/common/ndk/BUILD.gn @@ -123,10 +123,7 @@ ohos_shared_library("image_source") { "$image_subsystem/interfaces/kits/js/common:image", ] - external_deps = [ - "c_utils:utils", - "resource:librawfile_ndk" - ] + external_deps = [ "c_utils:utils" ] innerapi_tags = [ "ndk" ] subsystem_name = "multimedia" diff --git a/frameworks/kits/js/common/ndk/image_source_native.cpp b/frameworks/kits/js/common/ndk/image_source_native.cpp index f26a0b010..57fc7529f 100644 --- a/frameworks/kits/js/common/ndk/image_source_native.cpp +++ b/frameworks/kits/js/common/ndk/image_source_native.cpp @@ -343,24 +343,24 @@ Image_ErrorCode OH_ImageSourceNative_CreateFromData(uint8_t *data, size_t dataSi return IMAGE_SUCCESS; } -MIDK_EXPORT -Image_ErrorCode OH_ImageSourceNative_CreateFromRawFile(RawFileDescriptor *rawFile, OH_ImageSourceNative **res) -{ - if (rawFile == nullptr) { - return IMAGE_BAD_PARAMETER; - } - SourceOptions options; - auto imageSource = new OH_ImageSourceNative(*rawFile, options); - if (imageSource == nullptr || imageSource->GetInnerImageSource() == nullptr) { - if (imageSource) { - delete imageSource; - } - *res = nullptr; - return IMAGE_BAD_PARAMETER; - } - *res = imageSource; - return IMAGE_SUCCESS; -} +// MIDK_EXPORT +// Image_ErrorCode OH_ImageSourceNative_CreateFromRawFile(RawFileDescriptor *rawFile, OH_ImageSourceNative **res) +// { +// if (rawFile == nullptr) { +// return IMAGE_BAD_PARAMETER; +// } +// SourceOptions options; +// auto imageSource = new OH_ImageSourceNative(*rawFile, options); +// if (imageSource == nullptr || imageSource->GetInnerImageSource() == nullptr) { +// if (imageSource) { +// delete imageSource; +// } +// *res = nullptr; +// return IMAGE_BAD_PARAMETER; +// } +// *res = imageSource; +// return IMAGE_SUCCESS; +// } MIDK_EXPORT Image_ErrorCode OH_ImageSourceNative_CreatePixelmap(OH_ImageSourceNative *source, OH_DecodingOptions *ops, diff --git a/frameworks/kits/js/common/ndk/image_source_native_impl.cpp b/frameworks/kits/js/common/ndk/image_source_native_impl.cpp index 4e712c6b9..6fc2e0a03 100644 --- a/frameworks/kits/js/common/ndk/image_source_native_impl.cpp +++ b/frameworks/kits/js/common/ndk/image_source_native_impl.cpp @@ -73,18 +73,18 @@ OH_ImageSourceNative::OH_ImageSourceNative(uint8_t *data, size_t dataSize, Sourc innerImageSource_ = std::move(nativeImageSource); } -OH_ImageSourceNative::OH_ImageSourceNative(RawFileDescriptor rawFile, SourceOptions opts) -{ - uint32_t errorCode = IMAGE_BAD_PARAMETER; - int32_t rawFileLength = rawFile.start + rawFile.length; - std::unique_ptr nativeImageSource = ImageSource::CreateImageSource( - rawFile.fd, rawFile.start, rawFileLength, opts, errorCode); - if (nativeImageSource == nullptr) { - innerImageSource_ = nullptr; - return; - } - innerImageSource_ = std::move(nativeImageSource); -} +// OH_ImageSourceNative::OH_ImageSourceNative(RawFileDescriptor rawFile, SourceOptions opts) +// { +// uint32_t errorCode = IMAGE_BAD_PARAMETER; +// int32_t rawFileLength = rawFile.start + rawFile.length; +// std::unique_ptr nativeImageSource = ImageSource::CreateImageSource( +// rawFile.fd, rawFile.start, rawFileLength, opts, errorCode); +// if (nativeImageSource == nullptr) { +// innerImageSource_ = nullptr; +// return; +// } +// innerImageSource_ = std::move(nativeImageSource); +// } #ifdef __cplusplus }; diff --git a/frameworks/kits/js/common/ndk/include/image_source_native_impl.h b/frameworks/kits/js/common/ndk/include/image_source_native_impl.h index 9701f3251..a392adb9b 100644 --- a/frameworks/kits/js/common/ndk/include/image_source_native_impl.h +++ b/frameworks/kits/js/common/ndk/include/image_source_native_impl.h @@ -28,7 +28,7 @@ public: OH_ImageSourceNative(char *uri, size_t size, OHOS::Media::SourceOptions ops); OH_ImageSourceNative(int32_t fd, OHOS::Media::SourceOptions ops); OH_ImageSourceNative(uint8_t *data, size_t dataSize, OHOS::Media::SourceOptions ops); - OH_ImageSourceNative(RawFileDescriptor rawFile, OHOS::Media::SourceOptions ops); + // OH_ImageSourceNative(RawFileDescriptor rawFile, OHOS::Media::SourceOptions ops); ~OH_ImageSourceNative(); std::shared_ptr GetInnerImageSource(); std::string filePath_ = ""; diff --git a/interfaces/kits/native/include/image/image_source_native.h b/interfaces/kits/native/include/image/image_source_native.h index a0d2252fd..4eff8e5d2 100644 --- a/interfaces/kits/native/include/image/image_source_native.h +++ b/interfaces/kits/native/include/image/image_source_native.h @@ -37,7 +37,6 @@ #include "image_common.h" #include "pixelmap_native.h" -#include "raw_file.h" #ifdef __cplusplus extern "C" { @@ -315,16 +314,6 @@ Image_ErrorCode OH_ImageSourceNative_CreateFromFd(int32_t fd, OH_ImageSourceNati */ Image_ErrorCode OH_ImageSourceNative_CreateFromData(uint8_t *data, size_t dataSize, OH_ImageSourceNative **res); -/** - * @brief Creates an void pointer - * - * @param rawFile Indicates the raw file's file descriptor. - * @param res Indicates a void pointer to the ImageSource object created at the C++ native layer. - * @return Returns {@link Image_ErrorCode} - * @since 12 - */ -Image_ErrorCode OH_ImageSourceNative_CreateFromRawFile(RawFileDescriptor *rawFile, OH_ImageSourceNative **res); - /** * @brief Decodes an void pointer * based on the specified {@link OH_DecodingOptions} struct. -- Gitee From 2c307172121ddd39bd7907feaa76c3916d5279f6 Mon Sep 17 00:00:00 2001 From: yangfan Date: Fri, 12 Apr 2024 22:31:30 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E5=88=A0=E9=99=A4rawfile=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yangfan Change-Id: If2eea552e28a528291738675bcde573c884d6379 --- .../unittest/image_source_native_ndk_test.cpp | 16 ---------------- .../js/common/ndk/image_source_native.cpp | 19 ------------------- .../common/ndk/image_source_native_impl.cpp | 13 ------------- .../ndk/include/image_source_native_impl.h | 1 - 4 files changed, 49 deletions(-) diff --git a/frameworks/innerkitsimpl/test/unittest/image_source_native_ndk_test.cpp b/frameworks/innerkitsimpl/test/unittest/image_source_native_ndk_test.cpp index c90a772f7..e0843edcd 100644 --- a/frameworks/innerkitsimpl/test/unittest/image_source_native_ndk_test.cpp +++ b/frameworks/innerkitsimpl/test/unittest/image_source_native_ndk_test.cpp @@ -18,7 +18,6 @@ #include "image_source_native.h" #include "image_source_native_impl.h" -#include "raw_file.h" using namespace testing::ext; namespace OHOS { @@ -251,21 +250,6 @@ HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreateFromData, TestSize.Level GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreateFromData end"; } -/** - * @tc.name: OH_ImageSourceNative_CreateFromRawFile - * @tc.desc: test OH_ImageSourceNative_CreateFromRawFile - * @tc.type: FUNC - */ -HWTEST_F(ImagSourceNdk2Test, OH_ImageSourceNative_CreateFromRawFile, TestSize.Level3) -{ - GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreateFromRawFile start"; - OH_ImageSourceNative *imageSource = nullptr; - RawFileDescriptor *rawFile = nullptr; - Image_ErrorCode ret = OH_ImageSourceNative_CreateFromRawFile(rawFile, &imageSource); - ASSERT_EQ(ret, IMAGE_BAD_PARAMETER); - GTEST_LOG_(INFO) << "ImagSourceNdk2Test: OH_ImageSourceNative_CreateFromRawFile end"; -} - /** * @tc.name: OH_ImageSourceNative_CreatePixelmap * @tc.desc: test OH_ImageSourceNative_CreatePixelmap diff --git a/frameworks/kits/js/common/ndk/image_source_native.cpp b/frameworks/kits/js/common/ndk/image_source_native.cpp index 57fc7529f..52c953a36 100644 --- a/frameworks/kits/js/common/ndk/image_source_native.cpp +++ b/frameworks/kits/js/common/ndk/image_source_native.cpp @@ -343,25 +343,6 @@ Image_ErrorCode OH_ImageSourceNative_CreateFromData(uint8_t *data, size_t dataSi return IMAGE_SUCCESS; } -// MIDK_EXPORT -// Image_ErrorCode OH_ImageSourceNative_CreateFromRawFile(RawFileDescriptor *rawFile, OH_ImageSourceNative **res) -// { -// if (rawFile == nullptr) { -// return IMAGE_BAD_PARAMETER; -// } -// SourceOptions options; -// auto imageSource = new OH_ImageSourceNative(*rawFile, options); -// if (imageSource == nullptr || imageSource->GetInnerImageSource() == nullptr) { -// if (imageSource) { -// delete imageSource; -// } -// *res = nullptr; -// return IMAGE_BAD_PARAMETER; -// } -// *res = imageSource; -// return IMAGE_SUCCESS; -// } - MIDK_EXPORT Image_ErrorCode OH_ImageSourceNative_CreatePixelmap(OH_ImageSourceNative *source, OH_DecodingOptions *ops, OH_PixelmapNative **pixelmap) diff --git a/frameworks/kits/js/common/ndk/image_source_native_impl.cpp b/frameworks/kits/js/common/ndk/image_source_native_impl.cpp index 6fc2e0a03..5bb798f2d 100644 --- a/frameworks/kits/js/common/ndk/image_source_native_impl.cpp +++ b/frameworks/kits/js/common/ndk/image_source_native_impl.cpp @@ -73,19 +73,6 @@ OH_ImageSourceNative::OH_ImageSourceNative(uint8_t *data, size_t dataSize, Sourc innerImageSource_ = std::move(nativeImageSource); } -// OH_ImageSourceNative::OH_ImageSourceNative(RawFileDescriptor rawFile, SourceOptions opts) -// { -// uint32_t errorCode = IMAGE_BAD_PARAMETER; -// int32_t rawFileLength = rawFile.start + rawFile.length; -// std::unique_ptr nativeImageSource = ImageSource::CreateImageSource( -// rawFile.fd, rawFile.start, rawFileLength, opts, errorCode); -// if (nativeImageSource == nullptr) { -// innerImageSource_ = nullptr; -// return; -// } -// innerImageSource_ = std::move(nativeImageSource); -// } - #ifdef __cplusplus }; #endif \ No newline at end of file diff --git a/frameworks/kits/js/common/ndk/include/image_source_native_impl.h b/frameworks/kits/js/common/ndk/include/image_source_native_impl.h index a392adb9b..a96cfc110 100644 --- a/frameworks/kits/js/common/ndk/include/image_source_native_impl.h +++ b/frameworks/kits/js/common/ndk/include/image_source_native_impl.h @@ -28,7 +28,6 @@ public: OH_ImageSourceNative(char *uri, size_t size, OHOS::Media::SourceOptions ops); OH_ImageSourceNative(int32_t fd, OHOS::Media::SourceOptions ops); OH_ImageSourceNative(uint8_t *data, size_t dataSize, OHOS::Media::SourceOptions ops); - // OH_ImageSourceNative(RawFileDescriptor rawFile, OHOS::Media::SourceOptions ops); ~OH_ImageSourceNative(); std::shared_ptr GetInnerImageSource(); std::string filePath_ = ""; -- Gitee