• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 SNAPSHOT_UTILS_H
17 #define SNAPSHOT_UTILS_H
18 
19 #include <cstdint>
20 #include <pixel_map.h>
21 #include <string>
22 
23 #include "display_manager.h"
24 #include "dm_common.h"
25 
26 namespace OHOS {
27 
28 struct WriteToJpegParam {
29     uint32_t width;
30     uint32_t height;
31     uint32_t stride;
32     Media::PixelFormat format;
33     const uint8_t *data;
34 };
35 
36 struct CmdArgments {
37     bool isDisplayIdSet = false;
38     Rosen::DisplayId displayId = Rosen::DISPLAY_ID_INVALID;
39     std::string fileName;
40     bool isWidthSet = false;
41     int32_t width = -1;
42     bool isHeightSet = false;
43     int32_t height = -1;
44 };
45 
46 class SnapShotUtils {
47 public:
48     SnapShotUtils() = default;
49     ~SnapShotUtils() = default;
50 
51     static void PrintUsage(const std::string &cmdLine);
52     static bool CheckFileNameValid(const std::string &fileName);
53     static std::string GenerateFileName(int offset = 0);
54     static bool CheckWidthAndHeightValid(int32_t w, int32_t h);
55     static bool RGBA8888ToRGB888(const uint8_t* rgba8888Buf, uint8_t *rgb888Buf, int32_t size);
56     static bool RGB565ToRGB888(const uint8_t* rgb565Buf, uint8_t *rgb888Buf, int32_t size);
57     static bool WriteRgb888ToJpeg(FILE* file, uint32_t width, uint32_t height, const uint8_t* data);
58     static bool WriteToJpeg(const std::string &fileName, const WriteToJpegParam &param);
59     static bool WriteToJpeg(int fd, const WriteToJpegParam &param);
60     static bool WriteToJpegWithPixelMap(const std::string &fileName, Media::PixelMap &pixelMap);
61     static bool WriteToJpegWithPixelMap(int fd, Media::PixelMap &pixelMap);
62     static bool ProcessArgs(int argc, char * const argv[], CmdArgments& cmdArgments);
63     static bool CheckWHValid(int32_t param);
64     static bool CheckParamValid(const WriteToJpegParam &param);
65 private:
66     static bool ProcessDisplayId(Rosen::DisplayId &displayId, bool isDisplayIdSet);
67 };
68 }
69 
70 #endif // SNAPSHOT_UTILS_H
71