diff --git a/bundle.json b/bundle.json index e1734784ec51dc69a090f57f866280f3d14a756a..295ab3dcee71740006d92d35fe738b307e923c15 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 955cb459755b31c4d6b9b0e648b0367cb652fe4e..e8fc9b43de405fbe19bf0f88c634f3b8921d138f 100644 --- a/frameworks/innerkitsimpl/test/BUILD.gn +++ b/frameworks/innerkitsimpl/test/BUILD.gn @@ -1037,6 +1037,33 @@ 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", + "//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 @@ -1541,6 +1568,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 0000000000000000000000000000000000000000..4f8a4ce00ac49f8ba2a9f30f5f083720ce54bf23 --- /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 0000000000000000000000000000000000000000..e0843edcde3dfc7538e705baa9cb5154f060a53a --- /dev/null +++ b/frameworks/innerkitsimpl/test/unittest/image_source_native_ndk_test.cpp @@ -0,0 +1,380 @@ +/* + * 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" + +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_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 0000000000000000000000000000000000000000..e0056c11162c95df6f705ef2932d799a2d4c8d69 --- /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 5d1c3d31aa3d0b75802b97e6b8e5ef71658f4279..e3e93480f75059aa2e9bc6fdbf4a2a90532d87d1 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,72 @@ 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", + ] + + 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/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", + ] + + 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", + "$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 0000000000000000000000000000000000000000..3f1093244adf9b39272600261eecd093a613d9fc --- /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 0000000000000000000000000000000000000000..fc4aadd5285753979ea49ac4d1f9e2211954d81e --- /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 0000000000000000000000000000000000000000..52c953a36ed3790055e6420b92ebd93defb0e70d --- /dev/null +++ b/frameworks/kits/js/common/ndk/image_source_native.cpp @@ -0,0 +1,535 @@ +/* + * 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_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 0000000000000000000000000000000000000000..5bb798f2d4d6655762ae609e22658a9c25e6c2dd --- /dev/null +++ b/frameworks/kits/js/common/ndk/image_source_native_impl.cpp @@ -0,0 +1,78 @@ +/* + * 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); +} + +#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 0000000000000000000000000000000000000000..5225e10601c3cb0961bd8a1ddc93f4bad42281b1 --- /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 0000000000000000000000000000000000000000..a96cfc110394ef89a141e295129df0e0ddba1013 --- /dev/null +++ b/frameworks/kits/js/common/ndk/include/image_source_native_impl.h @@ -0,0 +1,46 @@ +/* + * 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(); + 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 0000000000000000000000000000000000000000..1233ab2f756a25d19bcb83d75b9b3e837fc39de1 --- /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 51065b96161effcdf8ee2fce30c8d7b559d5497c..4371f0cba24a456eaa35f59480d5437d0019b76f 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 0000000000000000000000000000000000000000..9162ff84a894406187f15e6ae189c1b540ac4252 --- /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 0000000000000000000000000000000000000000..4f93dc56e9e1ac3e7097367d92d4419803d5752e --- /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 index 36f35754dc8f10a316b8300877065ef6e736e493..a234a05002a00b6bd9d7c9ce27ce79572c950580 100644 --- a/interfaces/kits/native/include/image/image_common.h +++ b/interfaces/kits/native/include/image/image_common.h @@ -26,7 +26,7 @@ * @file image_common.h * * @brief Declares the common enums and structs used by the image interface. - * @library libimage.so + * * @syscap SystemCapability.Multimedia.Image.Core * @since 12 */ @@ -1263,4 +1263,4 @@ static const char *OHOS_IMAGE_PROPERTY_SCENE_VERSION = "HwMnoteSceneVersion"; #endif /** @} */ -#endif // INTERFACES_KITS_NATIVE_INCLUDE_IMAGE_IMAGE_COMMON_H_ \ No newline at end of file +#endif // INTERFACES_KITS_NATIVE_INCLUDE_IMAGE_IMAGE_COMMON_H_ 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 0000000000000000000000000000000000000000..b14577fdfcbcbc3130b56f526581a75004540fb8 --- /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 0000000000000000000000000000000000000000..4eff8e5d2abcd2da4ddda1ce12aa70f5d0df5269 --- /dev/null +++ b/interfaces/kits/native/include/image/image_source_native.h @@ -0,0 +1,422 @@ +/* + * 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" + +#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 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 0000000000000000000000000000000000000000..c54cc57d170696b75c7bf2974e529f636b7cd7a2 --- /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