1094332d3Sopenharmony_ci/* 2094332d3Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 3094332d3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4094332d3Sopenharmony_ci * you may not use this file except in compliance with the License. 5094332d3Sopenharmony_ci * You may obtain a copy of the License at 6094332d3Sopenharmony_ci * 7094332d3Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8094332d3Sopenharmony_ci * 9094332d3Sopenharmony_ci * Unless required by law or agreed to in writing, software 10094332d3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11094332d3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12094332d3Sopenharmony_ci * See the License for the specific language governing permissions and 13094332d3Sopenharmony_ci * limitations under the License. 14094332d3Sopenharmony_ci */ 15094332d3Sopenharmony_ci 16094332d3Sopenharmony_ci#include <getopt.h> 17094332d3Sopenharmony_ci#include <iostream> 18094332d3Sopenharmony_ci#include "command_parser.h" 19094332d3Sopenharmony_ci 20094332d3Sopenharmony_cinamespace OHOS::VDI::HEIF { 21094332d3Sopenharmony_ciusing namespace std; 22094332d3Sopenharmony_ci 23094332d3Sopenharmony_cienum ShortOption { 24094332d3Sopenharmony_ci OPT_UNKONWN = 0, 25094332d3Sopenharmony_ci OPT_HELP, 26094332d3Sopenharmony_ci OPT_PRIMARY_IMG, 27094332d3Sopenharmony_ci OPT_AUXILIARY_IMG, 28094332d3Sopenharmony_ci OPT_THUMBNAIL_IMG, 29094332d3Sopenharmony_ci OPT_GAIN_MAP, 30094332d3Sopenharmony_ci OPT_EXIF_DATA, 31094332d3Sopenharmony_ci OPT_USER_DATA, 32094332d3Sopenharmony_ci OPT_ICC_PROFILE, 33094332d3Sopenharmony_ci OPT_IT35, 34094332d3Sopenharmony_ci OPT_MIRROR, 35094332d3Sopenharmony_ci OPT_ROTATE, 36094332d3Sopenharmony_ci OPT_OUTPUT = 'o' 37094332d3Sopenharmony_ci}; 38094332d3Sopenharmony_ci 39094332d3Sopenharmony_cistatic struct option g_longOptions[] = { 40094332d3Sopenharmony_ci {"help", no_argument, nullptr, static_cast<int>(ShortOption::OPT_HELP)}, 41094332d3Sopenharmony_ci {"primaryImg", required_argument, nullptr, static_cast<int>(ShortOption::OPT_PRIMARY_IMG)}, 42094332d3Sopenharmony_ci {"auxiliaryImg", required_argument, nullptr, static_cast<int>(ShortOption::OPT_AUXILIARY_IMG)}, 43094332d3Sopenharmony_ci {"thumbnailImg", required_argument, nullptr, static_cast<int>(ShortOption::OPT_THUMBNAIL_IMG)}, 44094332d3Sopenharmony_ci {"gainMap", required_argument, nullptr, static_cast<int>(ShortOption::OPT_GAIN_MAP)}, 45094332d3Sopenharmony_ci {"exifData", required_argument, nullptr, static_cast<int>(ShortOption::OPT_EXIF_DATA)}, 46094332d3Sopenharmony_ci {"userData", required_argument, nullptr, static_cast<int>(ShortOption::OPT_USER_DATA)}, 47094332d3Sopenharmony_ci {"iccProfile", required_argument, nullptr, static_cast<int>(ShortOption::OPT_ICC_PROFILE)}, 48094332d3Sopenharmony_ci {"it35", required_argument, nullptr, static_cast<int>(ShortOption::OPT_IT35)}, 49094332d3Sopenharmony_ci {"mirror", required_argument, nullptr, static_cast<int>(ShortOption::OPT_MIRROR)}, 50094332d3Sopenharmony_ci {"rotate", required_argument, nullptr, static_cast<int>(ShortOption::OPT_ROTATE)}, 51094332d3Sopenharmony_ci {"out", required_argument, nullptr, static_cast<int>(ShortOption::OPT_OUTPUT)}, 52094332d3Sopenharmony_ci {nullptr, no_argument, nullptr, static_cast<int>(ShortOption::OPT_UNKONWN)}, 53094332d3Sopenharmony_ci}; 54094332d3Sopenharmony_ci 55094332d3Sopenharmony_civoid ShowUsage() 56094332d3Sopenharmony_ci{ 57094332d3Sopenharmony_ci std::string rotateValueOpt = "0: ANTI_CLOCKWISE_90, 1: ANTI_CLOCKWISE_180, 2: ANTI_CLOCKWISE_270"; 58094332d3Sopenharmony_ci std::cout << "Heif Hardware encode Demo Options:" << std::endl; 59094332d3Sopenharmony_ci std::cout << " --help help info." << std::endl; 60094332d3Sopenharmony_ci std::cout << " --primaryImg full path for primary image file." << std::endl; 61094332d3Sopenharmony_ci std::cout << " --auxiliaryImg (optional) full path for auxiliary image file." << std::endl; 62094332d3Sopenharmony_ci std::cout << " --thumbnailImg (optional) full path for thumbnail image file." << std::endl; 63094332d3Sopenharmony_ci std::cout << " --gainMap (optional) full path for gainMap file." << std::endl; 64094332d3Sopenharmony_ci std::cout << " --exifData (optional) full path for exifData file." << std::endl; 65094332d3Sopenharmony_ci std::cout << " --userData (optional) full path for userData file." << std::endl; 66094332d3Sopenharmony_ci std::cout << " --iccProfile (optional) full path for iccProfile file." << std::endl; 67094332d3Sopenharmony_ci std::cout << " --it35 (optional) full path for it35 file." << std::endl; 68094332d3Sopenharmony_ci std::cout << " --mirror (optional) image mirror info. 0: HORIZONTAL, 1: VERTICAL" << std::endl; 69094332d3Sopenharmony_ci std::cout << " --rotate (optional) image rotate info. " << rotateValueOpt << std::endl; 70094332d3Sopenharmony_ci std::cout << " -o, --out (optional) full path for output file." << std::endl; 71094332d3Sopenharmony_ci} 72094332d3Sopenharmony_ci 73094332d3Sopenharmony_ciCommandOpt Parse(int argc, char *argv[]) 74094332d3Sopenharmony_ci{ 75094332d3Sopenharmony_ci CommandOpt opt; 76094332d3Sopenharmony_ci int c; 77094332d3Sopenharmony_ci while ((c = getopt_long(argc, argv, "o:", g_longOptions, nullptr)) != -1) { 78094332d3Sopenharmony_ci switch (static_cast<ShortOption>(c)) { 79094332d3Sopenharmony_ci case ShortOption::OPT_HELP: 80094332d3Sopenharmony_ci ShowUsage(); 81094332d3Sopenharmony_ci break; 82094332d3Sopenharmony_ci case ShortOption::OPT_PRIMARY_IMG: 83094332d3Sopenharmony_ci opt.primaryImgPath = string(optarg); 84094332d3Sopenharmony_ci break; 85094332d3Sopenharmony_ci case ShortOption::OPT_AUXILIARY_IMG: 86094332d3Sopenharmony_ci opt.auxiliaryImgPath = string(optarg); 87094332d3Sopenharmony_ci break; 88094332d3Sopenharmony_ci case ShortOption::OPT_THUMBNAIL_IMG: 89094332d3Sopenharmony_ci opt.thumbnailImgPath = string(optarg); 90094332d3Sopenharmony_ci break; 91094332d3Sopenharmony_ci case ShortOption::OPT_GAIN_MAP: 92094332d3Sopenharmony_ci opt.gainMapPath = string(optarg); 93094332d3Sopenharmony_ci break; 94094332d3Sopenharmony_ci case ShortOption::OPT_EXIF_DATA: 95094332d3Sopenharmony_ci opt.exifDataPath = string(optarg); 96094332d3Sopenharmony_ci break; 97094332d3Sopenharmony_ci case ShortOption::OPT_USER_DATA: 98094332d3Sopenharmony_ci opt.userDataPath = string(optarg); 99094332d3Sopenharmony_ci break; 100094332d3Sopenharmony_ci case ShortOption::OPT_ICC_PROFILE: 101094332d3Sopenharmony_ci opt.iccProfilePath = string(optarg); 102094332d3Sopenharmony_ci break; 103094332d3Sopenharmony_ci case ShortOption::OPT_IT35: 104094332d3Sopenharmony_ci opt.it35Path = string(optarg); 105094332d3Sopenharmony_ci break; 106094332d3Sopenharmony_ci case ShortOption::OPT_MIRROR: 107094332d3Sopenharmony_ci opt.mirrorInfo = static_cast<ImageMirror>(stol(optarg)); 108094332d3Sopenharmony_ci break; 109094332d3Sopenharmony_ci case ShortOption::OPT_ROTATE: 110094332d3Sopenharmony_ci opt.rotateInfo = static_cast<ImageRotation>(stol(optarg)); 111094332d3Sopenharmony_ci break; 112094332d3Sopenharmony_ci case ShortOption::OPT_OUTPUT: 113094332d3Sopenharmony_ci opt.outputPath = string(optarg); 114094332d3Sopenharmony_ci break; 115094332d3Sopenharmony_ci default: 116094332d3Sopenharmony_ci break; 117094332d3Sopenharmony_ci } 118094332d3Sopenharmony_ci } 119094332d3Sopenharmony_ci return opt; 120094332d3Sopenharmony_ci} 121094332d3Sopenharmony_ci 122094332d3Sopenharmony_cistatic string GetMirrorPrintInfo(ImageMirror info) 123094332d3Sopenharmony_ci{ 124094332d3Sopenharmony_ci if (info == ImageMirror::NONE) { 125094332d3Sopenharmony_ci return "ImageMirror::NONE"; 126094332d3Sopenharmony_ci } 127094332d3Sopenharmony_ci if (info == ImageMirror::HORIZONTAL) { 128094332d3Sopenharmony_ci return "ImageMirror::HORIZONTAL"; 129094332d3Sopenharmony_ci } 130094332d3Sopenharmony_ci if (info == ImageMirror::VERTICAL) { 131094332d3Sopenharmony_ci return "ImageMirror::VERTICAL"; 132094332d3Sopenharmony_ci } 133094332d3Sopenharmony_ci return "unknown mirror info"; 134094332d3Sopenharmony_ci} 135094332d3Sopenharmony_ci 136094332d3Sopenharmony_cistatic string GetRotatePrintInfo(ImageRotation info) 137094332d3Sopenharmony_ci{ 138094332d3Sopenharmony_ci if (info == ImageRotation::NONE) { 139094332d3Sopenharmony_ci return "ImageRotation::NONE"; 140094332d3Sopenharmony_ci } 141094332d3Sopenharmony_ci if (info == ImageRotation::ANTI_CLOCKWISE_90) { 142094332d3Sopenharmony_ci return "ImageRotation::ANTI_CLOCKWISE_90"; 143094332d3Sopenharmony_ci } 144094332d3Sopenharmony_ci if (info == ImageRotation::ANTI_CLOCKWISE_180) { 145094332d3Sopenharmony_ci return "ImageRotation::ANTI_CLOCKWISE_180"; 146094332d3Sopenharmony_ci } 147094332d3Sopenharmony_ci if (info == ImageRotation::ANTI_CLOCKWISE_270) { 148094332d3Sopenharmony_ci return "ImageRotation::ANTI_CLOCKWISE_270"; 149094332d3Sopenharmony_ci } 150094332d3Sopenharmony_ci return "unknown rotate info"; 151094332d3Sopenharmony_ci} 152094332d3Sopenharmony_ci 153094332d3Sopenharmony_civoid CommandOpt::Print() const 154094332d3Sopenharmony_ci{ 155094332d3Sopenharmony_ci std::cout << "=========================== OPT INFO ===========================" << endl; 156094332d3Sopenharmony_ci std::cout << " primaryImgPath : " << primaryImgPath << endl; 157094332d3Sopenharmony_ci std::cout << " auxiliaryImgPath : " << auxiliaryImgPath << endl; 158094332d3Sopenharmony_ci std::cout << " thumbnailImgPath : " << thumbnailImgPath << endl; 159094332d3Sopenharmony_ci std::cout << " gainMapPath : " << gainMapPath << endl; 160094332d3Sopenharmony_ci std::cout << " exifDataPath : " << exifDataPath << endl; 161094332d3Sopenharmony_ci std::cout << " userDataPath : " << userDataPath << endl; 162094332d3Sopenharmony_ci std::cout << " iccProfilePath : " << iccProfilePath << endl; 163094332d3Sopenharmony_ci std::cout << " it35Path : " << it35Path << endl; 164094332d3Sopenharmony_ci std::cout << " mirrorInfo : " << GetMirrorPrintInfo(mirrorInfo) << endl; 165094332d3Sopenharmony_ci std::cout << " rotateInfo : " << GetRotatePrintInfo(rotateInfo) << endl; 166094332d3Sopenharmony_ci std::cout << " outputPath : " << outputPath << endl; 167094332d3Sopenharmony_ci std::cout << "=================================================================" << endl; 168094332d3Sopenharmony_ci} 169094332d3Sopenharmony_ci} 170