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 #include "hardware/imagecodec/type_converter.h"
17 #include "hardware/imagecodec/image_codec_log.h"
18
19 namespace OHOS::ImagePlugin {
20 using namespace std;
21
22 vector<PixelFmt> g_pixelFmtTable = {
23 {GRAPHIC_PIXEL_FMT_YCBCR_420_SP, "NV12"},
24 {GRAPHIC_PIXEL_FMT_YCRCB_420_SP, "NV21"},
25 {GRAPHIC_PIXEL_FMT_YCBCR_P010, "NV12_10bit"},
26 {GRAPHIC_PIXEL_FMT_YCRCB_P010, "NV21_10bit"},
27 };
28
GraphicFmtToFmt(GraphicPixelFormat format)29 std::optional<PixelFmt> TypeConverter::GraphicFmtToFmt(GraphicPixelFormat format)
30 {
31 auto it = find_if(g_pixelFmtTable.begin(), g_pixelFmtTable.end(), [format](const PixelFmt& p) {
32 return p.graphicFmt == format;
33 });
34 if (it != g_pixelFmtTable.end()) {
35 return *it;
36 }
37 LOGW("unknown GraphicPixelFormat %{public}d", format);
38 return nullopt;
39 }
40 } // namespace OHOS::ImagePlugin