1 /* 2 * Copyright (c) 2024 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 PIXEL_MAP_H 16 #define PIXEL_MAP_H 17 18 #include "ffi_remote_data.h" 19 #include "pixel_map.h" 20 #include "image_source_impl.h" 21 #include <string> 22 23 namespace OHOS { 24 namespace Media { 25 class FFI_EXPORT PixelMapImpl : public OHOS::FFI::FFIData { 26 DECL_TYPE(PixelMapImpl, OHOS::FFI::FFIData) 27 public: 28 explicit PixelMapImpl(std::shared_ptr<PixelMap> ptr_); 29 std::shared_ptr<PixelMap> GetRealPixelMap(); 30 uint32_t ReadPixelsToBuffer(uint64_t &bufferSize, uint8_t *dst); 31 uint32_t WriteBufferToPixels(uint8_t *source, uint64_t &bufferSize); 32 int32_t GetDensity(); 33 uint32_t Opacity(float percent); 34 uint32_t Crop(Rect &rect); 35 uint32_t GetPixelBytesNumber(); 36 uint32_t GetBytesNumberPerRow(); 37 uint32_t ReadPixels(uint64_t &bufferSize, uint32_t &offset, uint32_t &stride, 38 Rect ®ion, uint8_t *dst); 39 uint32_t WritePixels(uint8_t *source, uint64_t &bufferSize, uint32_t &offset, 40 uint32_t &stride, Rect ®ion); 41 uint32_t SetColorSpace(std::shared_ptr<OHOS::ColorManager::ColorSpace> colorSpace); 42 std::shared_ptr<OHOS::ColorManager::ColorSpace> GetColorSpace(); 43 uint32_t ApplyColorSpace(std::shared_ptr<OHOS::ColorManager::ColorSpace> colorSpace); 44 45 void GetImageInfo(ImageInfo &imageInfo); 46 void Scale(float xAxis, float yAxis); 47 void Flip(bool xAxis, bool yAxis); 48 void Rotate(float degrees); 49 void Translate(float xAxis, float yAxis); 50 51 bool GetIsEditable(); 52 bool GetIsStrideAlignment(); 53 54 static std::unique_ptr<PixelMap> CreatePixelMap(const InitializationOptions &opts); 55 static std::unique_ptr<PixelMap> CreatePixelMap(uint32_t *colors, uint32_t colorLength, 56 InitializationOptions &opts); 57 static std::unique_ptr<PixelMap> CreateAlphaPixelMap(PixelMap &source, InitializationOptions &opts); 58 private: 59 std::shared_ptr<PixelMap> real_; 60 }; 61 } 62 } 63 64 #endif 65