1 /*
2  * Copyright (c) 2023 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 "drawing_sampling_options.h"
17 #include "utils/sampling_options.h"
18 #include "drawing_canvas_utils.h"
19 
20 using namespace OHOS;
21 using namespace Rosen;
22 using namespace Drawing;
23 
CastToSamplingOptions(OH_Drawing_SamplingOptions * cSamplingOptions)24 static SamplingOptions* CastToSamplingOptions(OH_Drawing_SamplingOptions* cSamplingOptions)
25 {
26     return reinterpret_cast<SamplingOptions*>(cSamplingOptions);
27 }
28 
OH_Drawing_SamplingOptionsCreate(OH_Drawing_FilterMode fm,OH_Drawing_MipmapMode mm)29 OH_Drawing_SamplingOptions* OH_Drawing_SamplingOptionsCreate(OH_Drawing_FilterMode fm, OH_Drawing_MipmapMode mm)
30 {
31     if (mm < MIPMAP_MODE_NONE || mm > MIPMAP_MODE_LINEAR) {
32         g_drawingErrorCode = OH_DRAWING_ERROR_PARAMETER_OUT_OF_RANGE;
33         return nullptr;
34     }
35     return (OH_Drawing_SamplingOptions*)new SamplingOptions(static_cast<FilterMode>(fm), static_cast<MipmapMode>(mm));
36 }
37 
OH_Drawing_SamplingOptionsDestroy(OH_Drawing_SamplingOptions * cSamplingOptions)38 void OH_Drawing_SamplingOptionsDestroy(OH_Drawing_SamplingOptions* cSamplingOptions)
39 {
40     if (!cSamplingOptions) {
41         return;
42     }
43     delete CastToSamplingOptions(cSamplingOptions);
44 }