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 "jpeg_utils.h" 23 #include "jpeglib.h" 24 #include "log_tags.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 FinalizeEncode() override; 36 37 private: 38 DISALLOW_COPY_AND_MOVE(JpegEncoder); 39 J_COLOR_SPACE GetEncodeFormat(Media::PixelFormat format, int32_t &componentsNum); 40 void Deinterweave(uint8_t *uvPlane, uint8_t *uPlane, uint8_t *vPlane, uint32_t curRow, uint32_t width, 41 uint32_t height); 42 uint32_t SetCommonConfig(); 43 void SetYuv420spExtraConfig(); 44 uint32_t SequenceEncoder(const uint8_t *data); 45 uint32_t Yuv420spEncoder(const uint8_t *data); 46 static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_PLUGIN, "JpegEncoder" }; 47 jpeg_compress_struct encodeInfo_; 48 JpegDstMgr dstMgr_; 49 ErrorMgr jerr_; 50 std::vector<Media::PixelMap *> pixelMaps_; 51 PlEncodeOptions encodeOpts_; 52 }; 53 } // namespace ImagePlugin 54 } // namespace OHOS 55 56 #endif // JPEG_ENCODER_H