2 * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 ///////////////////////////////////////////////////////////////////////////////
18 /// \ingroup tag_SS_LoggerService
22 ///////////////////////////////////////////////////////////////////////////////
29 #define MAX_IMAGE_WIDTH 1280
30 #define MAX_IMAGE_HEIGHT 480
31 #define COLOR_COMPONENT 4
33 int SS_Logger_SaveScreenShot(const char* filename, int type) {
35 struct SCRSHOT_capture_arg stSCR;
36 struct jpeg_compress_struct cinfo;
37 struct jpeg_error_mgr jerr;
38 unsigned char *work_buf;
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
46 if (stSCR.buff == NULL) {
50 if (SCRSHOT_RET_SUCCESS != SCRSHOT_capture(&stSCR)) {
54 cinfo.err = jpeg_std_error(&jerr);
55 jpeg_create_compress(&cinfo);
57 if ((outfile = fopen(filename, "wb")) == NULL) {
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);
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;
74 jpeg_finish_compress(&cinfo);
75 jpeg_destroy_compress(&cinfo);
81 int main(int argc, char *argv[]) {
85 int chType = atoi(argv[2]);
86 SS_Logger_SaveScreenShot(argv[1], chType);