X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;ds=inline;f=service%2Fsystem%2Flogger_service%2Fserver%2FscreenShot%2Fss_logger_scrshot.cpp;fp=service%2Fsystem%2Flogger_service%2Fserver%2FscreenShot%2Fss_logger_scrshot.cpp;h=db5bcba9bd66b7d6c7b1b930d8099862787efe54;hb=17cf21bcf8a2e29d2cbcf0a313474d2a4ee44f5d;hp=0000000000000000000000000000000000000000;hpb=9e86046cdb356913ae026f616e5bf17f6f238aa5;p=staging%2Fbasesystem.git diff --git a/service/system/logger_service/server/screenShot/ss_logger_scrshot.cpp b/service/system/logger_service/server/screenShot/ss_logger_scrshot.cpp new file mode 100755 index 0000000..db5bcba --- /dev/null +++ b/service/system/logger_service/server/screenShot/ss_logger_scrshot.cpp @@ -0,0 +1,89 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup tag_SS_LoggerService +/// \brief +/// +/// +/////////////////////////////////////////////////////////////////////////////// +#include +#include +#include +#include +#include + +#define MAX_IMAGE_WIDTH 1280 +#define MAX_IMAGE_HEIGHT 480 +#define COLOR_COMPONENT 4 + +int SS_Logger_SaveScreenShot(const char* filename, int type) { + FILE *outfile; + struct SCRSHOT_capture_arg stSCR; + struct jpeg_compress_struct cinfo; + struct jpeg_error_mgr jerr; + unsigned char *work_buf; + + stSCR.du = type; // 0:E2 1:M2 + stSCR.fmt = SCRSHOT_FMT_ARGB8888; + stSCR.buff = malloc(MAX_IMAGE_WIDTH * MAX_IMAGE_HEIGHT * COLOR_COMPONENT); + stSCR.buff_len = MAX_IMAGE_WIDTH * MAX_IMAGE_HEIGHT * COLOR_COMPONENT; + stSCR.ev_handler = NULL; // sync mode + + if (stSCR.buff == NULL) { + exit(1); + } + + if (SCRSHOT_RET_SUCCESS != SCRSHOT_capture(&stSCR)) { + exit(1); + } + + cinfo.err = jpeg_std_error(&jerr); + jpeg_create_compress(&cinfo); + + if ((outfile = fopen(filename, "wb")) == NULL) { + exit(1); + } + jpeg_stdio_dest(&cinfo, outfile); + cinfo.image_width = stSCR.width; + cinfo.image_height = stSCR.height; + cinfo.input_components = COLOR_COMPONENT; + cinfo.in_color_space = JCS_EXT_BGRA; + jpeg_set_defaults(&cinfo); + jpeg_start_compress(&cinfo, TRUE); + + work_buf = (unsigned char*) stSCR.buff; + for (unsigned int i = 0; i < stSCR.height; i++) { + jpeg_write_scanlines(&cinfo, (JSAMPARRAY) & (work_buf), 1); + work_buf += stSCR.width * COLOR_COMPONENT; + } + + jpeg_finish_compress(&cinfo); + jpeg_destroy_compress(&cinfo); + free(stSCR.buff); + fclose(outfile); + exit(0); +} + +int main(int argc, char *argv[]) { + if (argc < 3) { + exit(1); + } + int chType = atoi(argv[2]); + SS_Logger_SaveScreenShot(argv[1], chType); + + return 0; +}