• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 #include "image_source_adapter.h"
17 #include "camera_log.h"
18 
19 #include "pixel_map.h"
20 
21 namespace OHOS {
22 namespace CameraStandard {
ImageSourceAdapter()23 ImageSourceAdapter::ImageSourceAdapter()
24 {
25     MEDIA_DEBUG_LOG("ImageSourceAdapter constructor");
26 }
27 
~ImageSourceAdapter()28 ImageSourceAdapter::~ImageSourceAdapter()
29 {
30     MEDIA_DEBUG_LOG("ImageSourceAdapter destructor");
31 }
32 
CreateImageSource(const uint8_t * data,uint32_t size,const Media::SourceOptions & opts,uint32_t & errorCode)33 int32_t ImageSourceAdapter::CreateImageSource(const uint8_t *data, uint32_t size, const Media::SourceOptions& opts,
34     uint32_t& errorCode)
35 {
36     MEDIA_DEBUG_LOG("CreateImageSource start");
37     imageSource_ =
38         OHOS::Media::ImageSource::CreateImageSource(data, size, opts, errorCode);
39     CHECK_RETURN_RET_ELOG(imageSource_ == nullptr, -1, "CreateImageSource failed");
40     return 0;
41 }
42 
CreatePixelMap(const Media::DecodeOptions & opts,uint32_t & errorCode)43 std::unique_ptr<Media::PixelMap> ImageSourceAdapter::CreatePixelMap(const Media::DecodeOptions& opts,
44     uint32_t& errorCode)
45 {
46     MEDIA_DEBUG_LOG("CreatePixelMap start");
47     CHECK_RETURN_RET_ELOG(imageSource_ == nullptr, nullptr, "imageSource_ is nullptr");
48     std::unique_ptr<Media::PixelMap> pixelMap = imageSource_->CreatePixelMap(opts, errorCode);
49     CHECK_RETURN_RET_ELOG(pixelMap == nullptr, nullptr, "CreatePixelMap failed");
50     return pixelMap;
51 }
52 
createImageSourceIntf()53 extern "C" ImageSourceIntf *createImageSourceIntf()
54 {
55     return new ImageSourceAdapter();
56 }
57 }  // namespace CameraStandard
58 }  // namespace OHOS