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 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 
17 #ifndef ENCODE_BUFFER_HELPER_FUZZ
18 #define ENCODE_BUFFER_HELPER_FUZZ
19 
20 #include <map>
21 #include <list>
22 #include <set>
23 #include <fstream>
24 #include "log.h"
25 #include "v2_0/icodec_image.h"
26 #include "v1_2/display_composer_type.h"
27 #include "v1_2/display_buffer_type.h"
28 #include "v1_2/include/idisplay_buffer.h"
29 
30 namespace OHOS::VDI::HEIF {
31 uint32_t ToUint32(const uint8_t* ptr);
32 class EncodeBufferHelper {
33 public:
34     EncodeBufferHelper();
35     ~EncodeBufferHelper();
36     OHOS::sptr<OHOS::HDI::Base::NativeBuffer> CreateImgBuffer(uint8_t* data, size_t size);
37     OHOS::HDI::Codec::Image::V2_0::SharedBuffer CreateSharedBuffer(uint8_t* data, size_t size);
38 private:
39     struct PixelFileInfo {
40         uint32_t displayWidth;
41         uint32_t alignedWidth;
42         uint32_t displayHeight;
43         uint32_t alignedHeight;
44         int32_t pixFmt;
45     };
46 private:
47     bool InitialRgbaData(BufferHandle* handle, PixelFileInfo& pixelInfo, uint8_t* data, size_t size);
48 private:
49     OHOS::HDI::Display::Buffer::V1_2::IDisplayBuffer* bufferMgr_;
50     std::set<int> allocatedFd_;
51 };
52 } // OHOS::VDI::HEIF
53 
54 #endif // ENCODE_BUFFER_HELPER_FUZZ