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 16 #ifndef SKIA_YUV_INFO_H 17 #define SKIA_YUV_INFO_H 18 19 #include "include/core/SkYUVAInfo.h" 20 #include "include/core/SkYUVAPixmaps.h" 21 22 #include "image/yuv_info.h" 23 24 namespace OHOS { 25 namespace Rosen { 26 namespace Drawing { 27 28 class SkiaYUVInfo { 29 public: ConvertToSkPlaneConfig(const YUVInfo::PlaneConfig & config)30 static SkYUVAInfo::PlaneConfig ConvertToSkPlaneConfig(const YUVInfo::PlaneConfig& config) 31 { 32 switch (config) { 33 case YUVInfo::PlaneConfig::Y_UV: 34 return SkYUVAInfo::PlaneConfig::kY_UV; 35 case YUVInfo::PlaneConfig::Y_VU: 36 return SkYUVAInfo::PlaneConfig::kY_VU; 37 case YUVInfo::PlaneConfig::UNKNOWN: 38 return SkYUVAInfo::PlaneConfig::kUnknown; 39 default: 40 return SkYUVAInfo::PlaneConfig::kUnknown; 41 } 42 } 43 ConvertToSkSubSampling(const YUVInfo::SubSampling & sampling)44 static SkYUVAInfo::Subsampling ConvertToSkSubSampling(const YUVInfo::SubSampling& sampling) 45 { 46 switch (sampling) { 47 case YUVInfo::SubSampling::K420: 48 return SkYUVAInfo::Subsampling::k420; 49 case YUVInfo::SubSampling::UNKNOWN: 50 return SkYUVAInfo::Subsampling::kUnknown; 51 default: 52 return SkYUVAInfo::Subsampling::kUnknown; 53 } 54 } 55 ConvertToSkYUVColorSpace(const YUVInfo::YUVColorSpace & colorspace)56 static SkYUVColorSpace ConvertToSkYUVColorSpace(const YUVInfo::YUVColorSpace& colorspace) 57 { 58 switch (colorspace) { 59 case YUVInfo::YUVColorSpace::JPEG_FULL_YUVCOLORSPACE: 60 return SkYUVColorSpace::kJPEG_Full_SkYUVColorSpace; 61 case YUVInfo::YUVColorSpace::IDENTITY_YUVCOLORSPACE: 62 return SkYUVColorSpace::kIdentity_SkYUVColorSpace; 63 case YUVInfo::YUVColorSpace::BT2020_10BIT_LIMITED_YUVCOLORSPACE: 64 return SkYUVColorSpace::kBT2020_10bit_Limited_SkYUVColorSpace; 65 default: 66 return SkYUVColorSpace::kIdentity_SkYUVColorSpace; 67 } 68 } 69 ConvertToSkDataType(const YUVInfo::YUVDataType & dataType)70 static SkYUVAPixmapInfo::DataType ConvertToSkDataType(const YUVInfo::YUVDataType& dataType) 71 { 72 switch (dataType) { 73 case YUVInfo::YUVDataType::UNORM_8: 74 return SkYUVAPixmapInfo::DataType::kUnorm8; 75 case YUVInfo::YUVDataType::UNORM_16: 76 return SkYUVAPixmapInfo::DataType::kUnorm16; 77 default: 78 return SkYUVAPixmapInfo::DataType::kUnorm8; 79 } 80 } 81 }; 82 } // namespace Drawing 83 } // namespace Rosen 84 } // namespace OHOS 85 #endif