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 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 METADATA_GENERATOR_IMAGE_NATIVE_H 17 #define METADATA_GENERATOR_IMAGE_NATIVE_H 18 19 #include <atomic> 20 #include <functional> 21 #include <mutex> 22 #include <unordered_map> 23 24 #include "detail_enhancer_common.h" 25 #include "detail_enhancer_image_fwk.h" 26 #include "image_processing_utils.h" 27 #include "surface_buffer.h" 28 #include "surface_buffer_impl.h" 29 #include "surface_type.h" 30 #include "vpe_log.h" 31 #include "image_processing_native_template.h" 32 #include "image_processing_types.h" 33 #include "pixelmap_native_impl.h" 34 #include "detail_enhancer_image.h" 35 #include "metadata_generator.h" 36 37 namespace OHOS { 38 namespace Media { 39 namespace VideoProcessingEngine { 40 class MetadataGeneratorImageNative : public ImageProcessingNativeTemplate<MetadataGeneratorImageNative> { 41 public: 42 DEFINE_WITH_DISALLOW_COPY_AND_MOVE(MetadataGeneratorImageNative); 43 44 ImageProcessing_ErrorCode InitializeInner() override; 45 ImageProcessing_ErrorCode DeinitializeInner() override; 46 ImageProcessing_ErrorCode SetParameter(const OHOS::Media::Format& parameter) override; 47 ImageProcessing_ErrorCode GetParameter(OHOS::Media::Format& parameter) override; 48 ImageProcessing_ErrorCode Process(const std::shared_ptr<OHOS::Media::PixelMap>& sourceImage, 49 std::shared_ptr<OHOS::Media::PixelMap>& destinationImage) override; 50 ImageProcessing_ErrorCode ConvertColorSpace(const std::shared_ptr<OHOS::Media::PixelMap>& sourceImage, 51 std::shared_ptr<OHOS::Media::PixelMap>& destinationImage) override; 52 ImageProcessing_ErrorCode Compose(const std::shared_ptr<OHOS::Media::PixelMap>& sourceImage, 53 const std::shared_ptr<OHOS::Media::PixelMap>& sourceGainmap, 54 std::shared_ptr<OHOS::Media::PixelMap>& destinationImage) override; 55 ImageProcessing_ErrorCode Decompose(const std::shared_ptr<OHOS::Media::PixelMap>& sourceImage, 56 std::shared_ptr<OHOS::Media::PixelMap>& destinationImage, 57 std::shared_ptr<OHOS::Media::PixelMap>& destinationGainmap) override; 58 ImageProcessing_ErrorCode GenerateMetadata(const std::shared_ptr<OHOS::Media::PixelMap>& sourceImage) override; 59 ImageProcessing_ErrorCode EnhanceDetail(const std::shared_ptr<OHOS::Media::PixelMap>& sourceImage, 60 std::shared_ptr<OHOS::Media::PixelMap>& destinationImage) override; 61 private: 62 ImageProcessing_ErrorCode CheckParameter(); 63 ImageProcessing_ErrorCode ConvertPixelmapToSurfaceBuffer(const std::shared_ptr<OHOS::Media::PixelMap>& pixelmap, 64 sptr<SurfaceBuffer>& bufferImpl); 65 uint32_t GetColorSpaceType(const CM_ColorSpaceInfo &colorSpaceInfo); 66 CM_ColorSpaceInfo GetColorSpaceInfo(const uint32_t colorSpaceType); 67 mutable std::mutex lock_{}; 68 // Guarded by lock_ begin 69 std::atomic<bool> isInitialized_{false}; 70 std::shared_ptr<MetadataGenerator> metadataGenerator_{}; 71 // Guarded by lock_ end 72 }; 73 } // namespace VideoProcessingEngine 74 } // namespace Media 75 } // namespace OHOS 76 77 #endif // METADATA_GENERATOR_IMAGE_NATIVE_H