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 #ifndef FOUNDATION_ACE_INTERFACE_INNERKITS_IMAGE_CONVERTER_H
16 #define FOUNDATION_ACE_INTERFACE_INNERKITS_IMAGE_CONVERTER_H
17 
18 #ifndef USE_ROSEN_DRAWING
19 #include "include/core/SkBitmap.h"
20 #include "include/core/SkImageInfo.h"
21 #else
22 #include "image/bitmap.h"
23 #endif
24 #include "include/core/SkSamplingOptions.h"
25 #ifndef PREVIEW
26 #include "pixel_map.h"
27 #include "image_source.h"
28 #else
29 #include "image_source_preview.h"
30 #endif
31 
32 namespace OHOS::Ace::Napi {
33 class ImageConverter {
34 public:
35     std::unique_ptr<Media::ImageSource> CreateImageSource(const char* item, uint32_t& errorCode);
36 #ifndef USE_ROSEN_DRAWING
37     static SkColorType PixelFormatToSkColorType(Media::PixelFormat pixelFormat);
38     static SkAlphaType AlphaTypeToSkAlphaType(Media::AlphaType alphaType);
39     static std::shared_ptr<SkBitmap> PixelMapToBitmap(
40         const std::shared_ptr<Media::PixelMap>& pixelMap);
41     static std::shared_ptr<Media::PixelMap> BitmapToPixelMap(
42         const std::shared_ptr<SkBitmap>& bitMap, Media::InitializationOptions& opts);
43 #else
44     static Rosen::Drawing::ColorType PixelFormatToColorType(Media::PixelFormat pixelFormat);
45     static Rosen::Drawing::AlphaType AlphaTypeToAlphaType(Media::AlphaType alphaType);
46     static std::shared_ptr<Rosen::Drawing::Bitmap> PixelMapToBitmap(
47         const std::shared_ptr<Media::PixelMap>& pixelMap);
48     static std::shared_ptr<Media::PixelMap> BitmapToPixelMap(
49         const std::shared_ptr<Rosen::Drawing::Bitmap>& bitMap, Media::InitializationOptions& opts);
50 #endif
51 };
52 } // namespace OHOS::Ace::Napi
53 #endif // #define FOUNDATION_ACE_INTERFACE_INNERKITS_IMAGE_CONVERTER_H
54 
55