Android开机服务,修改mtk色温

发布时间:2026/8/8 17:33:01
Android开机服务,修改mtk色温 提示文章写完后目录可以自动生成如何生成可参考右边的帮助文档文章目录前言一、convert_tools.py生产几个bin文件二、开机服务init.gamma_switch_service.rc三、色温写入生效gamma_tool.cpp四、编译文件Android.mk五、模块添加device.mk前言1.使用convert_tools.py生产几个bin文件2.开机服务init.gamma_switch_service.rc3.色温写入生效gamma_tool.cpp4.编译文件5.模块添加一、convert_tools.py生产几个bin文件import re importstructimportsys import os defmain():iflen(sys.argv)2:print(请输入tbl文件路径)returntbl_file_pathsys.argv[1]ifnot os.path.exists(tbl_file_path):print(tbl文件{}不存在.format(tbl_file_path))returnprint(正在转换tbl文件tbl_file_path)withopen(tbl_file_path,r)as f:sf.read()res1[ifori inrange(len(s))ifs.startswith({,i)]res2[ifori inrange(len(s))ifs.startswith(},i)]rs[res1[0]1:res2[0]]rr.replace( ,)rr.replace(\n\t,)rr.rstrip(,)rr.split(,)(file_out,ext)os.path.splitext(tbl_file_path)withopen({}_r.bin.format(file_out),wb)as fp:forx in r:astruct.pack(H,int(x))fp.write(a)gs[res1[1]1:res2[1]]gg.replace( ,)gg.replace(\n\t,)gg.rstrip(,)gg.split(,)withopen({}_g.bin.format(file_out),wb)as fp:forx in g:astruct.pack(H,int(x))fp.write(a)bs[res1[1]1:res2[1]]bb.replace( ,)bb.replace(\n\t,)bb.rstrip(,)bb.split(,)withopen({}_b.bin.format(file_out),wb)as fp:forx in b:astruct.pack(H,int(x))fp.write(a)if__name____main__:main()二、开机服务init.gamma_switch_service.rcservice gamma_switch_service_default/vendor/bin/gamma_tool-p/vendor/etc/gamma/defaultclass main user root group root oneshot disabled seclabel u:r:shell:s0 service gamma_switch_service_eyes_protection/vendor/bin/gamma_tool-p/vendor/etc/gamma/eyes_protection class main user root group root oneshot disabled seclabel u:r:shell:s0 service gamma_switch_service_dicom/vendor/bin/gamma_tool-p/mnt/vendor/protect_f/gamma/dicom class main user root group root oneshot disabled seclabel u:r:shell:s0 on property:persist.sys.innocn_gamma_mode0start gamma_switch_service_default on property:persist.sys.innocn_gamma_mode1start gamma_switch_service_eyes_protection on property:persist.sys.innocn_gamma_mode2start gamma_switch_service_dicom三、色温写入生效gamma_tool.cpp#includestdint.h#includefcntl.h#includesys/ioctl.h#includesys/types.h#includeunistd.h#includestring.h#includestdlib.h#includedlfcn.h#includemath.h#includelinux/mediatek_drm.h#includeddp_drv.h#defineDISP_DEV_NODE_PATH/dev/dri/card0#defineDRM_IOCTL(id)DRM_IOCTL_##id#defineIOCTL_MTK_SET_GAMMALUTDRM_IOCTL(MTK_SET_GAMMALUT)intread_bin_size(constchar*filename){intsiz0;FILE*fpfopen(filename,rb);if(fp){fseek(fp,0,SEEK_END);sizftell(fp);fclose(fp);}returnsiz;}voidread_bin_data(constchar*path,unsignedshort*buf,intsize){FILE*infile;if((infilefopen(path,rb))NULL){return;}fread(buf,sizeof(unsignedshort),size,infile);fclose(infile);}voidconfigDriverGamma(unsignedshortr[],unsignedshortg[],unsignedshortb[]){intm_drvIDopen(DISP_DEV_NODE_PATH,O_RDONLY,0);DISP_GAMMA_LUT_T*driverGammanew DISP_GAMMA_LUT_T;unsignedshortR_entry,G_entry,B_entry;driverGamma-hw_idDISP_GAMMA0;for(inti0;iDISP_GAMMA_LUT_SIZE;i){R_entryr[i];G_entryg[i];B_entryb[i];driverGamma-lut[i]GAMMA_ENTRY(R_entry,G_entry);driverGamma-lut_1[i]B_entry;}ioctl(m_drvID,IOCTL_MTK_SET_GAMMALUT,driverGamma);delete driverGamma;}intmain(intargc,char*argv[]){if(argc1){printf(Unknown option\n);return-1;}intc0;char*gamma_file_rootNULL;while(EOF!(cgetopt(argc,argv,p:))){switch(c){casep:gamma_file_rootoptarg;break;default:printf(Unknown option:%c\n,optopt);return-1;}}charfileNameRed[256];sprintf(fileNameRed,%s/gamma_r.bin,gamma_file_root);charfileNameGreen[256];sprintf(fileNameGreen,%s/gamma_g.bin,gamma_file_root);charfileNameBlue[256];sprintf(fileNameBlue,%s/gamma_b.bin,gamma_file_root);unsignedshortgamma_data_red[1024];unsignedshortgamma_data_green[1024];unsignedshortgamma_data_blue[1024];intsizeread_bin_size(fileNameRed);if(size2048){read_bin_data(fileNameRed,gamma_data_red,size/2);}else{printf(Invalid gamma data file %s\n,fileNameRed);return-3;}sizeread_bin_size(fileNameGreen);if(size2048){read_bin_data(fileNameGreen,gamma_data_green,size/2);}else{printf(Invalid gamma data file %s\n,fileNameGreen);return-3;}sizeread_bin_size(fileNameBlue);if(size2048){read_bin_data(fileNameBlue,gamma_data_blue,size/2);}else{printf(Invalid gamma data file %s\n,fileNameBlue);return-3;}configDriverGamma(gamma_data_red,gamma_data_green,gamma_data_blue);printf(Gamma data file load success\n);return0;}四、编译文件Android.mkLOCAL_PATH:$(call my-dir)include $(CLEAR_VARS)LOCAL_SRC_FILES:\ gamma_tool.cpp#LOCAL_HEADER_LIBRARIESmtk_drm_headers#LOCAL_SHARED_LIBRARIES:\#libcutilsLOCAL_CFLAGS-DGAMMA_LIGHT LOCAL_CFLAGS-DGAMMA_12BIT_LUT LOCAL_MODULE:gamma_tool LOCAL_PROPRIETARY_MODULE:true LOCAL_MODULE_OWNER:mtk LOCAL_INIT_RC:init.gamma_switch_service.rc include $(MTK_EXECUTABLE)五、模块添加device.mkPRODUCT_PACKAGESInnocnAPI \ FactoryTest \ sn_writer \ config_mac_address \ EngineerMode \ gamma_tool \ set_dicom_brightness