• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <hilog/log.h>
17 #include "image_packer_module_test.h"
18 #include "multimedia/image_framework/image/image_packer_native.h"
19 
20 #define CAMERA_LOG_TAG "CAMERA_TAGLOG"
21 #define CAMERA_LOG_DOMAIN 0x3200
22 #define LOG(fmt, ...) (void)OH_LOG_Print(LOG_APP, LOG_INFO, CAMERA_LOG_DOMAIN, CAMERA_LOG_TAG, fmt, ##__VA_ARGS__)
23 
ImagePackerModuleTest()24 ImagePackerModuleTest::ImagePackerModuleTest()
25 {
26 }
27 
~ImagePackerModuleTest()28 ImagePackerModuleTest::~ImagePackerModuleTest()
29 {
30 }
31 
PackToDataMultiFrames(OH_PackingOptionsForSequence * options,OH_PixelmapNative ** pixelmaps,size_t mapSize,uint8_t * outData,size_t * outDataSize)32 Image_ErrorCode ImagePackerModuleTest::PackToDataMultiFrames(OH_PackingOptionsForSequence *options,
33     OH_PixelmapNative **pixelmaps, size_t mapSize, uint8_t* outData, size_t* outDataSize)
34 {
35     LOG("PackToDataMultiFrames enter.");
36 
37     OH_ImagePackerNative *imagePacker = nullptr;
38     Image_ErrorCode ret = OH_ImagePackerNative_Create(&imagePacker);
39     if (ret != IMAGE_SUCCESS) {
40         OH_ImagePackerNative_Release(imagePacker);
41         LOG("Create Image Packer failed: err = %{public}d.", ret);
42         return ret;
43     }
44 
45     ret = OH_ImagePackerNative_PackToDataFromPixelmapSequence(imagePacker, options, pixelmaps,
46         mapSize, outData, outDataSize);
47     if (ret != IMAGE_SUCCESS) {
48         OH_ImagePackerNative_Release(imagePacker);
49         LOG("PackToDataMultiFrames failed: err = %{public}d.", ret);
50         return ret;
51     }
52     OH_ImagePackerNative_Release(imagePacker);
53     LOG("PackToDataMultiFrames end.");
54     return IMAGE_SUCCESS;
55 }
56 
PackToDataMultiFramesError(packMultiFramesOptions * opts,uint8_t * outData,size_t * outDataSize)57 Image_ErrorCode ImagePackerModuleTest::PackToDataMultiFramesError(
58     packMultiFramesOptions *opts, uint8_t* outData, size_t* outDataSize)
59 {
60     LOG("PackToDataMultiFramesError enter.");
61 
62     OH_ImagePackerNative *imagePacker = nullptr;
63     Image_ErrorCode ret = IMAGE_SUCCESS;
64     if (opts->mode != BAD_PARAMETER_IMAGEPACKER) {
65         ret = OH_ImagePackerNative_Create(&imagePacker);
66         if (ret != IMAGE_SUCCESS) {
67             OH_ImagePackerNative_Release(imagePacker);
68             LOG("Create Image Packer failed: err = %{public}d.", ret);
69             return ret;
70         }
71     }
72     if (opts->mode == BAD_PARAMETER_PACKINGOPTIONS) {
73         opts->options = nullptr;
74     }
75     if (opts->mode == BAD_PARAMETER_PIXELMAPS) {
76         opts->pixelmaps = nullptr;
77     }
78     if (opts->mode == BAD_PARAMETER_OUTDATA) {
79         ret = OH_ImagePackerNative_PackToDataFromPixelmapSequence(imagePacker, opts->options, opts->pixelmaps,
80         opts->mapSize, nullptr, outDataSize);
81     } else {
82         ret = OH_ImagePackerNative_PackToDataFromPixelmapSequence(imagePacker, opts->options, opts->pixelmaps,
83             opts->mapSize, outData, outDataSize);
84     }
85     if (ret != IMAGE_SUCCESS) {
86         OH_ImagePackerNative_Release(imagePacker);
87         LOG("PackToDataMultiFramesError failed: err = %{public}d.", ret);
88         return ret;
89     }
90     OH_ImagePackerNative_Release(imagePacker);
91     LOG("PackToDataMultiFramesError end.");
92     return IMAGE_SUCCESS;
93 }
94 
PackToFileMultiFrames(OH_PackingOptionsForSequence * options,OH_PixelmapNative ** pixelmaps,size_t mapSize,int32_t fd)95 Image_ErrorCode ImagePackerModuleTest::PackToFileMultiFrames(OH_PackingOptionsForSequence  *options,
96     OH_PixelmapNative **pixelmaps, size_t mapSize, int32_t fd)
97 {
98     LOG("PackToFileMultiFrames enter.");
99 
100     OH_ImagePackerNative *imagePacker = nullptr;
101     Image_ErrorCode ret = OH_ImagePackerNative_Create(&imagePacker);
102     if (ret != IMAGE_SUCCESS) {
103         OH_ImagePackerNative_Release(imagePacker);
104         LOG("Create Image Packer failed: err = %{public}d.", ret);
105         return ret;
106     }
107 
108     ret = OH_ImagePackerNative_PackToFileFromPixelmapSequence(imagePacker, options, pixelmaps, mapSize, fd);
109     if (ret != IMAGE_SUCCESS) {
110         OH_ImagePackerNative_Release(imagePacker);
111         LOG("PackToFileMultiFrames failed: err = %{public}d.", ret);
112         return ret;
113     }
114     OH_ImagePackerNative_Release(imagePacker);
115     LOG("PackToFileMultiFrames end.");
116     return IMAGE_SUCCESS;
117 }
118 
PackToFileMultiFramesError(packMultiFramesOptions * opts,int32_t fd)119 Image_ErrorCode ImagePackerModuleTest::PackToFileMultiFramesError(packMultiFramesOptions *opts, int32_t fd)
120 {
121     LOG("PackToFileMultiFramesError enter.");
122 
123     OH_ImagePackerNative *imagePacker = nullptr;
124     Image_ErrorCode ret = IMAGE_SUCCESS;
125     if (opts->mode != BAD_PARAMETER_IMAGEPACKER) {
126         ret = OH_ImagePackerNative_Create(&imagePacker);
127         if (ret != IMAGE_SUCCESS) {
128             OH_ImagePackerNative_Release(imagePacker);
129             LOG("Create Image Packer failed: err = %{public}d.", ret);
130             return ret;
131         }
132     }
133     if (opts->mode == BAD_PARAMETER_PACKINGOPTIONS) {
134         opts->options = nullptr;
135     }
136     if (opts->mode == BAD_PARAMETER_PIXELMAPS) {
137         opts->pixelmaps = nullptr;
138     }
139     ret = OH_ImagePackerNative_PackToFileFromPixelmapSequence(
140         imagePacker, opts->options, opts->pixelmaps, opts->mapSize, fd);
141     if (ret != IMAGE_SUCCESS) {
142         OH_ImagePackerNative_Release(imagePacker);
143         LOG("PackToFileMultiFramesError failed: err = %{public}d.", ret);
144         return ret;
145     }
146     OH_ImagePackerNative_Release(imagePacker);
147     LOG("PackToFileMultiFramesError end.");
148     return IMAGE_SUCCESS;
149 }
150