• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 FOUNDATION_ACE_FRAMEWORKS_BASE_IMAGE_ACE_PIXEL_MAP_H
17 #define FOUNDATION_ACE_FRAMEWORKS_BASE_IMAGE_ACE_PIXEL_MAP_H
18 
19 #include "base/memory/ace_type.h"
20 
21 namespace OHOS {
22 
23 namespace Media {
24 class PixelMap;
25 }
26 
27 namespace Ace {
28 
29 enum class PixelFormat : int32_t {
30     UNKNOWN = 0,
31     ARGB_8888 = 1,  // Each pixel is stored on 4 bytes.
32     RGB_565 = 2,    // Each pixel is stored on 2 bytes
33     RGBA_8888 = 3,
34     BGRA_8888 = 4,
35     RGB_888 = 5,
36     ALPHA_8 = 6,
37     RGBA_F16 = 7,
38     NV21 = 8, // Each pixel is stored on 3/2 bytes.
39     NV12 = 9,
40     CMYK = 10,
41 };
42 
43 enum class AlphaType : int32_t {
44     IMAGE_ALPHA_TYPE_UNKNOWN = 0,
45     IMAGE_ALPHA_TYPE_OPAQUE = 1,   // image pixels are stored as opaque.
46     IMAGE_ALPHA_TYPE_PREMUL = 2,   // image have alpha component, and all pixels have premultiplied by alpha value.
47     IMAGE_ALPHA_TYPE_UNPREMUL = 3, // image have alpha component, and all pixels stored without premultiply alpha value.
48 };
49 
50 class ACE_EXPORT PixelMap : public AceType {
51     DECLARE_ACE_TYPE(PixelMap, AceType)
52 
53 public:
54     static RefPtr<PixelMap> CreatePixelMap(void* sptrAddr);
55     static RefPtr<PixelMap> CreatePixelMapFromDataAbility(void* uniquePtr);
56     static RefPtr<PixelMap> ConvertSkImageToPixmap(const uint32_t *colors, uint32_t colorLength,
57         int32_t width, int32_t height);
58     virtual int32_t GetWidth() const = 0;
59     virtual int32_t GetHeight() const = 0;
60     virtual const uint8_t* GetPixels() const = 0;
61     virtual PixelFormat GetPixelFormat() const = 0;
62     virtual AlphaType GetAlphaType() const = 0;
63     virtual int32_t GetRowBytes() const = 0;
64     virtual int32_t GetByteCount() const = 0;
65     virtual void* GetPixelManager() const = 0;
66     virtual void* GetRawPixelMapPtr() const = 0;
67     virtual std::string GetId() = 0;
68     virtual std::string GetModifyId() = 0;
GetPixelMapSharedPtr()69     virtual std::shared_ptr<Media::PixelMap> GetPixelMapSharedPtr()
70     {
71         return nullptr;
72     }
73 
74     static void* GetReleaseContext(const RefPtr<PixelMap>& pixelMap);
75     // passed to SkImage to release PixelMap shared_ptr
76     static void ReleaseProc(const void* /* pixels */, void* context);
77 };
78 
79 } // namespace Ace
80 } // namespace OHOS
81 
82 #endif // FOUNDATION_ACE_FRAMEWORKS_BASE_IMAGE_ACE_PIXEL_MAP_H