Remove unused directories and files in video_in_hal
[staging/basesystem.git] / systemservice / logger_service / server / screenShot / ss_logger_scrshot.cpp
1 /*
2  * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 ///////////////////////////////////////////////////////////////////////////////
18 /// \ingroup  tag_SS_LoggerService
19 /// \brief
20 ///
21 ///
22 ///////////////////////////////////////////////////////////////////////////////
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <jpeglib.h>
27 #include <du.h>
28
29 #define MAX_IMAGE_WIDTH    1280
30 #define MAX_IMAGE_HEIGHT  480
31 #define COLOR_COMPONENT    4
32
33 int SS_Logger_SaveScreenShot(const char* filename, int type) {
34   FILE *outfile;
35   struct SCRSHOT_capture_arg stSCR;
36   struct jpeg_compress_struct cinfo;
37   struct jpeg_error_mgr jerr;
38   unsigned char *work_buf;
39
40   stSCR.du = type;  // 0:E2 1:M2
41   stSCR.fmt = SCRSHOT_FMT_ARGB8888;
42   stSCR.buff = malloc(MAX_IMAGE_WIDTH * MAX_IMAGE_HEIGHT * COLOR_COMPONENT);
43   stSCR.buff_len = MAX_IMAGE_WIDTH * MAX_IMAGE_HEIGHT * COLOR_COMPONENT;
44   stSCR.ev_handler = NULL;  // sync mode
45
46   if (stSCR.buff == NULL) {
47     exit(1);
48   }
49
50   if (SCRSHOT_RET_SUCCESS != SCRSHOT_capture(&stSCR)) {
51     exit(1);
52   }
53
54   cinfo.err = jpeg_std_error(&jerr);
55   jpeg_create_compress(&cinfo);
56
57   if ((outfile = fopen(filename, "wb")) == NULL) {
58     exit(1);
59   }
60   jpeg_stdio_dest(&cinfo, outfile);
61   cinfo.image_width = stSCR.width;
62   cinfo.image_height = stSCR.height;
63   cinfo.input_components = COLOR_COMPONENT;
64   cinfo.in_color_space = JCS_EXT_BGRA;
65   jpeg_set_defaults(&cinfo);
66   jpeg_start_compress(&cinfo, TRUE);
67
68   work_buf = (unsigned char*) stSCR.buff;
69   for (unsigned int i = 0; i < stSCR.height; i++) {
70     jpeg_write_scanlines(&cinfo, (JSAMPARRAY) & (work_buf), 1);
71     work_buf += stSCR.width * COLOR_COMPONENT;
72   }
73
74   jpeg_finish_compress(&cinfo);
75   jpeg_destroy_compress(&cinfo);
76   free(stSCR.buff);
77   fclose(outfile);
78   exit(0);
79 }
80
81 int main(int argc, char *argv[]) {
82   if (argc < 3) {
83     exit(1);
84   }
85   int chType = atoi(argv[2]);
86   SS_Logger_SaveScreenShot(argv[1], chType);
87
88   return 0;
89 }