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 #include "test_pixel_map_utils.h"
17 #include "image_source.h"
18 #include "test_effect_log.h"
19
20 namespace OHOS {
21 namespace Media {
22 namespace Effect {
23 namespace Test {
24
ParsePixelMapByPath(const std::string & pathName)25 std::unique_ptr<PixelMap> TestPixelMapUtils::ParsePixelMapByPath(const std::string &pathName)
26 {
27 SourceOptions opts;
28 uint32_t errorCode = 0;
29 std::unique_ptr<ImageSource> imageSource = ImageSource::CreateImageSource(pathName, opts, errorCode);
30 CHECK_AND_RETURN_RET_LOG(imageSource != nullptr, nullptr,
31 "ImageSource::CreateImageSource fail! pathName=%{public}s, errorCode=%{public}d", pathName.c_str(), errorCode);
32
33 DecodeOptions options;
34 options.desiredDynamicRange = DecodeDynamicRange::AUTO;
35 std::unique_ptr<PixelMap> pixelMap = imageSource->CreatePixelMap(options, errorCode);
36 CHECK_AND_RETURN_RET_LOG(pixelMap != nullptr, nullptr,
37 "CreatePixelMap fail! pathName=%{public}s, errorCode=%{public}d", pathName.c_str(), errorCode);
38
39 return pixelMap;
40 }
41 } // Test
42 } // namespace Effect
43 } // namespace Media
44 } // namespace OHOS