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> Create(std::unique_ptr<Media::PixelMap>&& pixmap); 55 static RefPtr<PixelMap> CreatePixelMap(void* sptrAddr); 56 /** 57 * @param ptr: drawable pointer of type Napi::DrawableDescriptor& 58 */ 59 static RefPtr<PixelMap> GetFromDrawable(void* ptr); 60 static RefPtr<PixelMap> CreatePixelMapFromDataAbility(void* uniquePtr); 61 static RefPtr<PixelMap> ConvertSkImageToPixmap( 62 const uint32_t* colors, uint32_t colorLength, int32_t width, int32_t height); 63 virtual int32_t GetWidth() const = 0; 64 virtual int32_t GetHeight() const = 0; 65 virtual const uint8_t* GetPixels() const = 0; 66 virtual PixelFormat GetPixelFormat() const = 0; 67 virtual AlphaType GetAlphaType() const = 0; 68 virtual int32_t GetRowBytes() const = 0; 69 virtual int32_t GetByteCount() const = 0; 70 virtual void* GetPixelManager() const = 0; 71 virtual void* GetRawPixelMapPtr() const = 0; 72 virtual std::string GetId() = 0; 73 virtual std::string GetModifyId() = 0; 74 virtual std::shared_ptr<Media::PixelMap> GetPixelMapSharedPtr() = 0; 75 virtual void* GetWritablePixels() const = 0; 76 77 static void* GetReleaseContext(const RefPtr<PixelMap>& pixelMap); 78 // passed to SkImage to release PixelMap shared_ptr 79 static void ReleaseProc(const void* /* pixels */, void* context); 80 }; 81 82 } // namespace Ace 83 } // namespace OHOS 84 85 #endif // FOUNDATION_ACE_FRAMEWORKS_BASE_IMAGE_ACE_PIXEL_MAP_H 86