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 IMAGE_PROCESSING_NATIVE_H 17 #define IMAGE_PROCESSING_NATIVE_H 18 19 #include <mutex> 20 21 #include "meta/format.h" 22 #include "surface_buffer.h" 23 #include "pixel_map.h" 24 25 #include "algorithm_types.h" 26 #include "image_processing_types.h" 27 28 namespace OHOS { 29 namespace Media { 30 namespace VideoProcessingEngine { 31 /** 32 * Native implementation for image processing. 33 */ 34 class ImageProcessingNative : public std::enable_shared_from_this<ImageProcessingNative> { 35 public: 36 ImageProcessing_ErrorCode Initialize(); 37 ImageProcessing_ErrorCode Deinitialize(); 38 ImageProcessing_ErrorCode SetParameter(const OH_AVFormat* parameter); 39 ImageProcessing_ErrorCode GetParameter(OH_AVFormat* parameter); 40 ImageProcessing_ErrorCode ConvertColorSpace(OH_PixelmapNative* sourceImage, OH_PixelmapNative* destinationImage); 41 ImageProcessing_ErrorCode Compose(OH_PixelmapNative* sourceImage, OH_PixelmapNative* sourceGainmap, 42 OH_PixelmapNative* destinationImage); 43 ImageProcessing_ErrorCode Decompose(OH_PixelmapNative* sourceImage, OH_PixelmapNative* destinationImage, 44 OH_PixelmapNative* destinationGainmap); 45 ImageProcessing_ErrorCode GenerateMetadata(OH_PixelmapNative* sourceImage); 46 ImageProcessing_ErrorCode EnhanceDetail(OH_PixelmapNative* sourceImage, OH_PixelmapNative* destinationImage); 47 48 protected: 49 ImageProcessingNative() = default; 50 virtual ~ImageProcessingNative() = default; 51 ImageProcessingNative(const ImageProcessingNative&) = delete; 52 ImageProcessingNative& operator=(const ImageProcessingNative&) = delete; 53 ImageProcessingNative(ImageProcessingNative&&) = delete; 54 ImageProcessingNative& operator=(ImageProcessingNative&&) = delete; 55 56 static ImageProcessing_ErrorCode AlgoErrorToNdk(AlgoErrorCode errorCode); 57 static ImageProcessing_ErrorCode GetSurfaceBufferFromPixelMap(const std::shared_ptr<PixelMap>& pixelMap, 58 sptr<SurfaceBuffer>& surfaceBuffer); 59 static ImageProcessing_ErrorCode GetSurfaceBufferFromPixelMapNoCopy(const std::shared_ptr<PixelMap>& pixelMap, 60 sptr<SurfaceBuffer>& surfaceBuffer); 61 static ImageProcessing_ErrorCode SetSurfaceBufferToPixelMap(const sptr<SurfaceBuffer>& surfaceBuffer, 62 std::shared_ptr<PixelMap>& pixelMap); 63 64 virtual ImageProcessing_ErrorCode InitializeInner(); 65 virtual ImageProcessing_ErrorCode DeinitializeInner(); 66 virtual ImageProcessing_ErrorCode SetParameter(const OHOS::Media::Format& parameter); 67 virtual ImageProcessing_ErrorCode GetParameter(OHOS::Media::Format& parameter); 68 virtual ImageProcessing_ErrorCode ConvertColorSpace(sptr<SurfaceBuffer>& sourceImage, 69 sptr<SurfaceBuffer>& destinationImage); 70 virtual ImageProcessing_ErrorCode Compose(sptr<SurfaceBuffer>& sourceImage, sptr<SurfaceBuffer>& sourceGainmap, 71 sptr<SurfaceBuffer>& destinationImage); 72 virtual ImageProcessing_ErrorCode Decompose(sptr<SurfaceBuffer>& sourceImage, 73 sptr<SurfaceBuffer>& destinationImage, sptr<SurfaceBuffer>& destinationGainmap); 74 virtual ImageProcessing_ErrorCode GenerateMetadata(sptr<SurfaceBuffer>& sourceImage); 75 virtual ImageProcessing_ErrorCode EnhanceDetail(sptr<SurfaceBuffer>& sourceImage, 76 sptr<SurfaceBuffer>& destinationImage); 77 78 private: 79 static ImageProcessing_ErrorCode CreateSurfaceBufferFromPixelMap(const std::shared_ptr<PixelMap>& pixelMap, 80 sptr<SurfaceBuffer>& surfaceBuffer); 81 static ImageProcessing_ErrorCode ConvertPixelMapToSurfaceBuffer(const std::shared_ptr<PixelMap>& pixelMap, 82 sptr<SurfaceBuffer>& surfaceBuffer); 83 static ImageProcessing_ErrorCode CopyPixelMapToSurfaceBuffer(const std::shared_ptr<PixelMap>& pixelMap, 84 sptr<SurfaceBuffer>& surfaceBuffer); 85 static ImageProcessing_ErrorCode CopySurfaceBufferToPixelMap(const sptr<SurfaceBuffer>& surfaceBuffer, 86 std::shared_ptr<PixelMap>& pixelMap); 87 88 mutable std::mutex lock_{}; 89 // Guarded by lock_ begin 90 bool isInitialized_{false}; 91 // Guarded by lock_ end 92 }; 93 } // namespace VideoProcessingEngine 94 } // namespace Media 95 } // namespace OHOS 96 97 #endif // IMAGE_PROCESSING_NATIVE_H 98