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