1 /*
2  * Copyright (C) 2021 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_ENCODER_H
17 #define JPEG_ENCODER_H
18 
19 #include <vector>
20 #include "abs_image_encoder.h"
21 #include "icc_profile_info.h"
22 #include "icc_profile_info.h"
23 #include "jpeg_utils.h"
24 #include "jpeglib.h"
25 #include "plugin_class_base.h"
26 
27 namespace OHOS {
28 namespace ImagePlugin {
29 class JpegEncoder : public AbsImageEncoder, public OHOS::MultimediaPlugin::PluginClassBase {
30 public:
31     JpegEncoder();
32     ~JpegEncoder() override;
33     uint32_t StartEncode(OutputDataStream &outputStream, PlEncodeOptions &option) override;
34     uint32_t AddImage(Media::PixelMap &pixelMap) override;
35     uint32_t AddPicture(Media::Picture &picture) override;
36     uint32_t FinalizeEncode() override;
37 
38 private:
39     DISALLOW_COPY_AND_MOVE(JpegEncoder);
40     J_COLOR_SPACE GetEncodeFormat(Media::PixelFormat format, int32_t &componentsNum);
41     void Deinterweave(uint8_t *uvPlane, uint8_t *uPlane, uint8_t *vPlane, uint32_t curRow, uint32_t width,
42                       uint32_t height);
43     uint32_t SetCommonConfig();
44     void SetYuv420spExtraConfig();
45     uint32_t SequenceEncoder(const uint8_t *data);
46     uint32_t Yuv420spEncoder(const uint8_t *data);
47     uint32_t RGBAF16Encoder(const uint8_t *data);
48     uint32_t RGB565Encoder(const uint8_t *data);
49     jpeg_compress_struct encodeInfo_;
50     JpegDstMgr dstMgr_;
51     ErrorMgr jerr_;
52     std::vector<Media::PixelMap *> pixelMaps_;
53     PlEncodeOptions encodeOpts_;
54     ICCProfileInfo iccProfileInfo_;
55 };
56 } // namespace ImagePlugin
57 } // namespace OHOS
58 #endif // JPEG_ENCODER_H
59