1 /*
2  * Copyright (c) 2023 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 #ifndef JPEG_HW_DECODER_DEMO_H
17 #define JPEG_HW_DECODER_DEMO_H
18 
19 #include "display_type.h"
20 #include "command_parser.h"
21 #include "hardware/jpeg_hw_decoder.h"
22 
23 namespace OHOS::ImagePlugin {
24 class JpegHwDecoderFlow {
25 public:
26     JpegHwDecoderFlow();
27     ~JpegHwDecoderFlow();
28     bool Run(const CommandOpt& opt, bool needDumpOutput);
29 private:
30     bool AllocOutputBuffer();
31     bool DoDecode();
32     bool DumpDecodeResult();
AlignUp(uint32_t width,uint32_t alignment)33     inline uint32_t AlignUp(uint32_t width, uint32_t alignment)
34     {
35         return ((width + alignment - 1) & (~(alignment - 1)));
36     };
37     std::optional<PixelFormat> UserColorFmtToPixelFmt(UserColorFormat usrColorFmt);
38 private:
39     static constexpr uint32_t ALIGN_8 = 8;
40     static constexpr uint32_t ALIGN_16 = 16;
41     OHOS::Media::Size orgImgSize_;
42     OHOS::Media::Size scaledImgSize_;
43     OHOS::Media::Size outputBufferSize_;
44     uint32_t sampleSize_;
45     PixelFormat outputColorFmt_;
46     std::string inputFile_;
47     std::string outputPath_;
48     OHOS::HDI::Display::Buffer::V1_0::IDisplayBuffer* bufferMgr_;
49     OHOS::HDI::Codec::Image::V2_0::CodecImageBuffer outputBuffer_;
50 };
51 } // OHOS::ImagePlugin
52 
53 #endif // JPEG_HW_DECODER_DEMO_H