• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef IMAGE_INFO_H
17 #define IMAGE_INFO_H
18 #include "draw/color.h"
19 #include "effect/color_space.h"
20 #include "utils/rect.h"
21 namespace OHOS {
22 namespace Rosen {
23 namespace Drawing {
24 
25 enum class EncodedImageFormat {
26     JPEG,
27     PNG,
28     WEBP,
29     UNKNOWN,
30 };
31 
32 class ImageInfo {
33 public:
34     ImageInfo() = default;
35     ImageInfo(int width, int height, ColorType colorType, AlphaType alphaType,
36 	          std::shared_ptr<ColorSpace> colorSpace = nullptr)
width_(width)37         : width_(width), height_(height), colorType_(colorType), alphaType_(alphaType), colorSpace_(colorSpace) {}
38     ~ImageInfo() = default;
39 
MakeN32Premul(int32_t width,int32_t height)40     static ImageInfo MakeN32Premul(int32_t width, int32_t height)
41     {
42         return ImageInfo(width, height, COLORTYPE_N32, ALPHATYPE_PREMUL, nullptr);
43     }
44     /*
45      * @brief  Gets the width value of ImageInfo.
46      */
GetWidth()47     int GetWidth() const
48     {
49         return width_;
50     }
51 
52     /*
53      * @brief  Gets the height value of ImageInfo.
54      */
GetHeight()55     int GetHeight() const
56     {
57         return height_;
58     }
59 
60     /*
61      * @brief  Gets the color type value of ImageInfo.
62      */
GetColorType()63     ColorType GetColorType() const
64     {
65         return colorType_;
66     }
67 
68     /*
69      * @brief  Gets the alpha type value of ImageInfo.
70      */
GetAlphaType()71     AlphaType GetAlphaType() const
72     {
73         return alphaType_;
74     }
75 
76     /*
77      * @brief  Gets the color space value of ImageInfo.
78      */
GetColorSpace()79     std::shared_ptr<ColorSpace> GetColorSpace() const
80     {
81         return colorSpace_;
82     }
83 
84     /*
85      * @brief  Returns number of bytes per pixel.
86      */
GetBytesPerPixel()87     int32_t GetBytesPerPixel() const
88     {
89         // returns the number of bytes per pixel: 1byte, 2bytes, 4bytes
90         switch (colorType_) {
91             case COLORTYPE_ALPHA_8:
92                 return 1;
93             case COLORTYPE_RGB_565:
94             case COLORTYPE_ARGB_4444:
95                 return 2;
96             case COLORTYPE_RGBA_8888:
97             case COLORTYPE_BGRA_8888:
98             case COLORTYPE_N32:
99                 return 4;
100             default:
101                 return 0;
102         }
103     }
104 
105     /*
106      * @brief  Sets the width value of ImageInfo.
107      */
SetWidth(int width)108     void SetWidth(int width)
109     {
110         width_ = width;
111     }
112 
113     /*
114      * @brief  Sets the height value of ImageInfo.
115      */
SetHeight(int height)116     void SetHeight(int height)
117     {
118         height_ = height;
119     }
120 
121     /*
122      * @brief  Sets the color type value of ImageInfo.
123      */
SetColorType(ColorType colorType)124     void SetColorType(ColorType colorType)
125     {
126         colorType_ = colorType;
127     }
128 
129     /*
130      * @brief  Sets the alpha type value of ImageInfo.
131      */
SetAlphaType(AlphaType alphaType)132     void SetAlphaType(AlphaType alphaType)
133     {
134         alphaType_ = alphaType;
135     }
136 
137     /*
138      * @brief  Sets the color space value of ImageInfo.
139      */
SetColorSpace(std::shared_ptr<ColorSpace> colorSpace)140     void SetColorSpace(std::shared_ptr<ColorSpace> colorSpace)
141     {
142         colorSpace_ = colorSpace;
143     }
144 
145     /*
146      * @brief  Gets the bounds of ImageInfo.
147      */
GetBound()148     RectI GetBound() const
149     {
150         return RectI(0, 0, width_, height_);
151     }
152 
153 private:
154     int width_ = 0;
155     int height_ = 0;
156     ColorType colorType_ = COLORTYPE_UNKNOWN;
157     AlphaType alphaType_ = ALPHATYPE_UNKNOWN;
158     std::shared_ptr<ColorSpace> colorSpace_ = nullptr;
159 };
160 } // namespace Drawing
161 } // namespace Rosen
162 } // namespace OHOS
163 #endif // IMAGE_INFO_H
164