1e0dac50fSopenharmony_ci/*
2e0dac50fSopenharmony_ci * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3e0dac50fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4e0dac50fSopenharmony_ci * you may not use this file except in compliance with the License.
5e0dac50fSopenharmony_ci * You may obtain a copy of the License at
6e0dac50fSopenharmony_ci *
7e0dac50fSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8e0dac50fSopenharmony_ci *
9e0dac50fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10e0dac50fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11e0dac50fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12e0dac50fSopenharmony_ci * See the License for the specific language governing permissions and
13e0dac50fSopenharmony_ci * limitations under the License.
14e0dac50fSopenharmony_ci */
15e0dac50fSopenharmony_ci
16e0dac50fSopenharmony_ci#ifndef SNAPSHOT_UTILS_H
17e0dac50fSopenharmony_ci#define SNAPSHOT_UTILS_H
18e0dac50fSopenharmony_ci
19e0dac50fSopenharmony_ci#include <cstdint>
20e0dac50fSopenharmony_ci#include <pixel_map.h>
21e0dac50fSopenharmony_ci#include <string>
22e0dac50fSopenharmony_ci
23e0dac50fSopenharmony_ci#include "display_manager.h"
24e0dac50fSopenharmony_ci#include "dm_common.h"
25e0dac50fSopenharmony_ci
26e0dac50fSopenharmony_cinamespace OHOS {
27e0dac50fSopenharmony_ci
28e0dac50fSopenharmony_cistruct WriteToJpegParam {
29e0dac50fSopenharmony_ci    uint32_t width;
30e0dac50fSopenharmony_ci    uint32_t height;
31e0dac50fSopenharmony_ci    uint32_t stride;
32e0dac50fSopenharmony_ci    Media::PixelFormat format;
33e0dac50fSopenharmony_ci    const uint8_t *data;
34e0dac50fSopenharmony_ci};
35e0dac50fSopenharmony_ci
36e0dac50fSopenharmony_cistruct CmdArguments {
37e0dac50fSopenharmony_ci    Rosen::DisplayId displayId = Rosen::DISPLAY_ID_INVALID;
38e0dac50fSopenharmony_ci    std::string fileName;
39e0dac50fSopenharmony_ci    std::string fileType;
40e0dac50fSopenharmony_ci    int32_t width = -1;
41e0dac50fSopenharmony_ci    int32_t height = -1;
42e0dac50fSopenharmony_ci    bool isDisplayIdSet = false;
43e0dac50fSopenharmony_ci    bool isWidthSet = false;
44e0dac50fSopenharmony_ci    bool isHeightSet = false;
45e0dac50fSopenharmony_ci};
46e0dac50fSopenharmony_ci
47e0dac50fSopenharmony_ciclass SnapShotUtils {
48e0dac50fSopenharmony_cipublic:
49e0dac50fSopenharmony_ci    SnapShotUtils() = default;
50e0dac50fSopenharmony_ci    ~SnapShotUtils() = default;
51e0dac50fSopenharmony_ci
52e0dac50fSopenharmony_ci    static void PrintUsage(const std::string& cmdLine);
53e0dac50fSopenharmony_ci    static bool CheckFileNameValid(const std::string& fileName, std::string fileType = "jpeg");
54e0dac50fSopenharmony_ci    static std::string GenerateFileName(std::string fileType, int offset = 0);
55e0dac50fSopenharmony_ci    static bool CheckWidthAndHeightValid(int32_t w, int32_t h);
56e0dac50fSopenharmony_ci    static bool RGBA8888ToRGB888(const uint8_t* rgba8888Buf, uint8_t* rgb888Buf, int32_t size);
57e0dac50fSopenharmony_ci    static bool RGB565ToRGB888(const uint8_t* rgb565Buf, uint8_t* rgb888Buf, int32_t size);
58e0dac50fSopenharmony_ci    static bool WriteRgb888ToJpeg(FILE* file, uint32_t width, uint32_t height, const uint8_t* data);
59e0dac50fSopenharmony_ci    static bool WriteToJpeg(const std::string& fileName, const WriteToJpegParam& param);
60e0dac50fSopenharmony_ci    static bool WriteToJpeg(int fd, const WriteToJpegParam& param);
61e0dac50fSopenharmony_ci    static bool WriteToJpegWithPixelMap(const std::string& fileName, Media::PixelMap& pixelMap);
62e0dac50fSopenharmony_ci    static bool WriteToJpegWithPixelMap(int fd, Media::PixelMap& pixelMap);
63e0dac50fSopenharmony_ci    static bool ProcessArgs(int argc, char * const argv[], CmdArguments& cmdArgments);
64e0dac50fSopenharmony_ci    static bool CheckWHValid(int32_t param);
65e0dac50fSopenharmony_ci    static bool CheckParamValid(const WriteToJpegParam& param);
66e0dac50fSopenharmony_ci    static bool SaveSnapShot(const std::string& filename, Media::PixelMap& pixelMap, std::string fileType = "jpeg");
67e0dac50fSopenharmony_ciprivate:
68e0dac50fSopenharmony_ci    static bool ProcessDisplayId(Rosen::DisplayId& displayId, bool isDisplayIdSet);
69e0dac50fSopenharmony_ci};
70e0dac50fSopenharmony_ci}
71e0dac50fSopenharmony_ci
72e0dac50fSopenharmony_ci#endif // SNAPSHOT_UTILS_H
73