├── BZ ├── config │ └── BZConfig.h ├── include │ ├── Algorithm.h │ ├── BZLog.h │ ├── BZUtils.h │ ├── BoZhi.h │ └── Processor.h ├── interface │ └── BZInterface.h └── src │ ├── Algorithm.cpp │ ├── BZLog.cpp │ ├── BZUtils.cpp │ ├── BoZhi.cpp │ ├── LibInterface.cpp │ └── Processor.cpp ├── ISP ├── config │ ├── DefaultIOCfg.h │ ├── ISPConfig.h │ ├── ISPListConfig.h │ └── Setting_1920x1080_D65_1000Lux.h ├── include │ ├── BMP.h │ ├── Buffer.h │ ├── Coder.h │ ├── FileManager.h │ ├── IOHelper.h │ ├── ISPCore.h │ ├── ISPItf.h │ ├── ISPList.h │ ├── ISPList.hpp │ ├── ISPListManager.h │ ├── ISPVideo.h │ ├── InterfaceWrapper.h │ ├── Log.h │ ├── MemPool.h │ ├── ParamManager.h │ ├── Settings.h │ └── Utils.h ├── interface │ └── BZInterface.h ├── src │ ├── Buffer.cpp │ ├── Coder.cpp │ ├── FileManager.cpp │ ├── IOHelper.cpp │ ├── ISPCore.cpp │ ├── ISPListManager.cpp │ ├── ISPVideo.cpp │ ├── InterfaceWrapper.cpp │ ├── Log.cpp │ ├── Main.cpp │ ├── MemPool.cpp │ ├── ParamManager.cpp │ └── Utils.cpp └── test │ ├── Test_Buffer.cpp │ └── Test_MemPool.cpp ├── LICENSE ├── README.md └── res └── 1MCC_IMG_20181229_001526_1.raw /BZ/config/BZConfig.h: -------------------------------------------------------------------------------- 1 | // License: GPL-3.0-or-later 2 | /* 3 | * BoZhi configuration file. 4 | * 5 | * Copyright (c) 2019 Peng Hao <635945005@qq.com> 6 | */ 7 | 8 | 9 | #ifdef LINUX_SYSTEM 10 | #define PATH_FMT "/" 11 | #define WORK_PATH "/home/hao/dev/ISP/ISP/" 12 | #elif defined WIN32_SYSTEM 13 | #define PATH_FMT "\\" 14 | #define WORK_PATH "D:\\test_project\\ISP_NEW\\ISP_NEW\\ISP_NEW\\" 15 | #endif 16 | 17 | #define DUMP_PATH "out" 18 | #define DUMP_FILE_NAME "dump.txt" 19 | -------------------------------------------------------------------------------- /BZ/include/Algorithm.h: -------------------------------------------------------------------------------- 1 | // License: GPL-3.0-or-later 2 | /* 3 | * BoZhi algorithm head file. 4 | * 5 | * Copyright (c) 2019 Peng Hao <635945005@qq.com> 6 | */ 7 | 8 | #pragma once 9 | 10 | #include "BZInterface.h" 11 | 12 | #define CHECK_PACKAGED(format) \ 13 | (((format) == BZ_UNPACKAGED_RAW10_LSB) || \ 14 | ((format) == BZ_UNPACKAGED_RAW10_MSB)) ? 0 : 1 15 | 16 | #define PIXELS2WORDS_MIPI_PACKAGED(pixelNum, bitspp) \ 17 | (((bitspp) < BITS_PER_WORD) ? 0 : \ 18 | (((bitspp) == BITS_PER_WORD) ? (pixelNum) : \ 19 | ((pixelNum) * (bitspp) / BITS_PER_WORD))) 20 | 21 | #define PIXELS2WORDS_UNPACKAGED(pixelNum, bitspp) \ 22 | (((bitspp) < BITS_PER_WORD) ? 0 : \ 23 | (((bitspp) == BITS_PER_WORD) ? (pixelNum) : \ 24 | ((pixelNum) * 2))) 25 | 26 | #define PIXELS2WORDS(pixelNum, bitspp, packaged) \ 27 | (((bitspp) % 2 || (bitspp) > 2 * BITS_PER_WORD || (bitspp) <= 0) ? 0 : \ 28 | ((packaged) ? PIXELS2WORDS_MIPI_PACKAGED(pixelNum, bitspp) : \ 29 | PIXELS2WORDS_UNPACKAGED(pixelNum, bitspp))) 30 | 31 | #define ALIGN(x, align) \ 32 | (align) ? (((x) + (align) - 1) & (~((align) - 1))) : (x) 33 | 34 | #define ALIGNx(pixelNum, bitspp, packaged, align) \ 35 | ALIGN(PIXELS2WORDS(pixelNum, bitspp, packaged), align) 36 | 37 | struct Buffer { 38 | size_t size; 39 | void *pAddr; 40 | }; 41 | 42 | struct DataInfo { 43 | size_t w; 44 | size_t h; 45 | int32_t fmt; 46 | int32_t order; 47 | int32_t bpp; 48 | Buffer buf; 49 | }; 50 | 51 | struct AlgInfo { 52 | int32_t type; 53 | bool en; 54 | DataInfo srcInfo; 55 | DataInfo dstInfo; 56 | Buffer param; 57 | }; 58 | 59 | enum RGBOrder { 60 | RO_RGB = 0, 61 | RO_BGR, 62 | RO_NUM 63 | }; 64 | 65 | enum YUVOrder { 66 | YO_YUV = 0, 67 | YO_YVU, 68 | YO_NUM 69 | }; 70 | 71 | enum YUVStruct { 72 | YS_444 = 0, 73 | YS_422, 74 | YS_420, 75 | YS_420_NV, 76 | YS_GREY, 77 | YS_NUM 78 | }; 79 | 80 | /* Bayer Process */ 81 | int32_t WrapBlackLevelCorrection(AlgInfo *info); 82 | int32_t WrapLensShadingCorrection(AlgInfo *info); 83 | 84 | /* RGB Process */ 85 | int32_t WrapDemosaic(AlgInfo *info); 86 | int32_t WrapWhiteBalance(AlgInfo *info); 87 | int32_t WrapColorCorrection(AlgInfo *info); 88 | int32_t WrapGammaCorrection(AlgInfo *info); 89 | 90 | /* YUVProcess */ 91 | int32_t WrapWaveletNR(AlgInfo *info); 92 | int32_t WrapEdgeEnhancement(AlgInfo *info); 93 | 94 | /* CST */ 95 | int32_t WrapCST_RAW2RGB(AlgInfo *info); 96 | int32_t WrapCST_RGB2YUV(AlgInfo *info); 97 | int32_t WrapCST_YUV2RGB(AlgInfo *info); 98 | 99 | -------------------------------------------------------------------------------- /BZ/include/BZLog.h: -------------------------------------------------------------------------------- 1 | // License: GPL-3.0-or-later 2 | /* 3 | * BoZhi log supports. 4 | * 5 | * Copyright (c) 2019 Peng Hao <635945005@qq.com> 6 | */ 7 | 8 | #pragma once 9 | #include "BoZhi.h" 10 | 11 | #define LOG_ON 1 12 | #define LOG_LEVEL (0x1 + 0x2 + 0x4 + 0x8) 13 | #define DBG_LEVEL (0x1) 14 | 15 | #define LOG_BUFFER_SIZE 256 16 | #define LOG_BUFFER_PERSERVE_SIZE 2 /* 2 preserve for \0 and \n */ 17 | #define LOG_BUFFER_LEFT_SIZE LOG_BUFFER_SIZE - LOG_BUFFER_PERSERVE_SIZE - sizeof(long long int) 18 | 19 | int32_t LogBase(const char* str, ...); 20 | void LogAddInfo(const char* str, ...); 21 | void LogPrint(const char* str, va_list va); 22 | 23 | enum BZLogMask { 24 | LOG_BASE_MASK = 0x1, 25 | LOG_ERROR_MASK = LOG_BASE_MASK, 26 | LOG_WARN_MASK = LOG_ERROR_MASK << 1, 27 | LOG_INFO_MASK = LOG_ERROR_MASK << 2, 28 | LOG_DEBUG_MASK = LOG_ERROR_MASK << 3, 29 | }; 30 | 31 | enum BZDbgMask { 32 | DBG_BASE_MASK = 0x1, 33 | DBG_CORE_MASK = DBG_BASE_MASK << 1, 34 | DBG_INTF_MASK = DBG_BASE_MASK << 2, 35 | DBG_PROC_MASK = DBG_BASE_MASK << 3, 36 | DBG_ALGO_MASK = DBG_BASE_MASK << 4, 37 | }; 38 | 39 | #ifdef LOG_FOR_DBG 40 | #define LOG_FORMAT " %d:%s: " 41 | #define LOG_FMT_PARAM , __LINE__, __func__ 42 | #else 43 | #define LOG_FORMAT " | " 44 | #define LOG_FMT_PARAM 45 | #endif 46 | 47 | #define LOG_MODULE " BZ " 48 | 49 | #define LogWrap(str, ...) ( \ 50 | (BoZhi::GetInstance()->GetCallbacks()->UtilsFuncs.Log) ? \ 51 | BoZhi::GetInstance()->GetCallbacks()->UtilsFuncs.Log(str, ##__VA_ARGS__) : \ 52 | LogBase(str, ##__VA_ARGS__)) 53 | 54 | #define BZLogError(on, str, ...) ((on) ? LogWrap(LOG_MODULE "E" LOG_FORMAT str LOG_FMT_PARAM, ##__VA_ARGS__) : (0)) 55 | #define BZLogWarn(on, str, ...) ((on) ? LogWrap(LOG_MODULE "W" LOG_FORMAT str LOG_FMT_PARAM, ##__VA_ARGS__) : (0)) 56 | #define BZLogInfo(on, str, ...) ((on) ? LogWrap(LOG_MODULE "I" LOG_FORMAT str LOG_FMT_PARAM, ##__VA_ARGS__) : (0)) 57 | #define BZLogDebug(on, str, ...) ((on) ? LogWrap(LOG_MODULE "D" LOG_FORMAT str LOG_FMT_PARAM, ##__VA_ARGS__) : (0)) 58 | 59 | #define BLOGE(str, ...) ((LOG_ON) ? BZLogError((LOG_LEVEL & LOG_ERROR_MASK), str, ##__VA_ARGS__) : (0)) 60 | #define BLOGW(str, ...) ((LOG_ON) ? BZLogWarn((LOG_LEVEL & LOG_WARN_MASK), str, ##__VA_ARGS__) : (0)) 61 | #define BLOGI(str, ...) ((LOG_ON) ? BZLogInfo((LOG_LEVEL & LOG_INFO_MASK), str, ##__VA_ARGS__) : (0)) 62 | #define BLOGD(str, ...) ((LOG_ON) ? BZLogDebug((LOG_LEVEL & LOG_DEBUG_MASK), str, ##__VA_ARGS__) : (0)) 63 | 64 | #define BLOGDC(str, ...) ((DBG_LEVEL & DBG_CORE_MASK) ? BLOGD(str, ##__VA_ARGS__) : (0)) 65 | #define BLOGDI(str, ...) ((DBG_LEVEL & DBG_INTF_MASK) ? BLOGD(str, ##__VA_ARGS__) : (0)) 66 | #define BLOGDP(str, ...) ((DBG_LEVEL & DBG_PROC_MASK) ? BLOGD(str, ##__VA_ARGS__) : (0)) 67 | #define BLOGDA(str, ...) ((DBG_LEVEL & DBG_ALGO_MASK) ? BLOGD(str, ##__VA_ARGS__) : (0)) 68 | -------------------------------------------------------------------------------- /BZ/include/BZUtils.h: -------------------------------------------------------------------------------- 1 | // License: GPL-3.0-or-later 2 | /* 3 | * BoZhi common fuctions head file. 4 | * 5 | * Copyright (c) 2019 Peng Hao <635945005@qq.com> 6 | */ 7 | 8 | #pragma once 9 | /* Regular lib */ 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #if defined __linux__ 18 | #define LINUX_SYSTEM 19 | #elif defined _WIN32 20 | #define WIN32_SYSTEM 21 | #endif 22 | 23 | #define BITS_PER_WORD 8 24 | #define FILE_PATH_MAX_SIZE 255 25 | 26 | #define SUCCESS(rt) ((rt) >= 0) ? true : false 27 | 28 | using namespace std; 29 | 30 | enum BZResult { 31 | BZ_INVALID_PARAM = -4, 32 | BZ_MEMORY_ERROR = -3, 33 | BZ_STATE_ERROR = -2, 34 | BZ_FAILED = -1, 35 | BZ_SUCCESS = 0, 36 | BZ_SKIP = 1 37 | }; 38 | 39 | typedef unsigned char uchar; 40 | -------------------------------------------------------------------------------- /BZ/include/BoZhi.h: -------------------------------------------------------------------------------- 1 | // License: GPL-3.0-or-later 2 | /* 3 | * BoZhi object head file. 4 | * 5 | * Copyright (c) 2019 Peng Hao <635945005@qq.com> 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include "Processor.h" 16 | 17 | enum BZState { 18 | BZ_STATE_NEW = 0, 19 | BZ_STATE_INITED, 20 | BZ_STATE_NUM 21 | }; 22 | 23 | class BoZhiItf { 24 | public: 25 | virtual ~BoZhiItf() {}; 26 | 27 | virtual int32_t Init() = 0; 28 | virtual int32_t DeInit() = 0; 29 | virtual int32_t RegisterCallbacks(void *pCBs) = 0; 30 | virtual int32_t Event(uint32_t *msg) = 0; 31 | virtual ISPCallbacks const* GetCallbacks() = 0; 32 | }; 33 | 34 | class BoZhi : public BoZhiItf { 35 | public: 36 | static BoZhi *GetInstance(); 37 | int32_t Init(); 38 | int32_t DeInit(); 39 | int32_t RegisterCallbacks(void *pCBs); 40 | int32_t Event(uint32_t *msg); 41 | ISPCallbacks const* GetCallbacks(); 42 | 43 | private: 44 | BoZhi(); 45 | virtual ~BoZhi(); 46 | 47 | int32_t CreateProcessor(int32_t id); 48 | int32_t DestroyProcessorById(int32_t id); 49 | int32_t DestroyAllProcessor(); 50 | Processor *FindProcessorById(int32_t id); 51 | int32_t Process(uint32_t *msg); 52 | void PrintMessage(uint32_t *msg); 53 | ISPCallbacks mISPCBs; 54 | int32_t mState; 55 | std::map mProcMap; 56 | mutex procMapLock; 57 | }; 58 | 59 | int32_t WrapLibInit(void* pOPS); 60 | int32_t WrapLibDeInit(); 61 | int32_t WrapRegistCallbacks(void* pOPS); 62 | void* WrapAlloc(size_t size); 63 | void* WrapAlloc(size_t size, size_t num); 64 | void* WrapFree(void* pBuf); 65 | 66 | -------------------------------------------------------------------------------- /BZ/include/Processor.h: -------------------------------------------------------------------------------- 1 | // License: GPL-3.0-or-later 2 | /* 3 | * Processor head file. 4 | * 5 | * Copyright (c) 2023 Peng Hao <635945005@qq.com> 6 | */ 7 | 8 | #pragma once 9 | #include "BZUtils.h" 10 | #include "Algorithm.h" 11 | #include 12 | #include 13 | #include 14 | 15 | struct Job { 16 | AlgInfo info; 17 | }; 18 | 19 | class Processor { 20 | public: 21 | Processor(int32_t); 22 | ~Processor(); 23 | 24 | bool IsWorkOn(); 25 | int32_t OffWork(); 26 | int32_t GetJob(Job *pJob); 27 | int32_t CancelJobs(); 28 | int32_t ScheduleJob(Job *pJob); 29 | int32_t HandleJob(Job *pJob); 30 | 31 | private: 32 | int32_t SetCtrl(Job* pJob); 33 | int32_t Process(Job* pJob); 34 | 35 | int32_t mId; 36 | bool workerStatus; 37 | thread workerThread; 38 | queue workQueue; 39 | mutex queueLock; 40 | }; 41 | -------------------------------------------------------------------------------- /BZ/interface/BZInterface.h: -------------------------------------------------------------------------------- 1 | // License: GPL-3.0-or-later 2 | /* 3 | * BoZhi exposed library interface. 4 | * 5 | * Copyright (c) 2019 Peng Hao <635945005@qq.com> 6 | */ 7 | 8 | #pragma once 9 | #include 10 | #include 11 | 12 | #define CCM_WIDTH 3 13 | #define CCM_HEIGHT 3 14 | #define LSC_LUT_WIDTH 17 15 | #define LSC_LUT_HEIGHT 13 16 | #define GAMMA_LUT_SIZE 1024 17 | 18 | #define LIB_FUNCS_NUM 3 19 | #define SYMBLE_SIZE_MAX 255 20 | 21 | extern "C" { 22 | typedef void (*LIB_VOID_FUNC_ADDR)(void*, ...); 23 | } 24 | 25 | enum BZRawFormat { 26 | BZ_ANDROID_RAW10 = 0, 27 | BZ_ORDINAL_RAW10, 28 | BZ_UNPACKAGED_RAW10_LSB, 29 | BZ_UNPACKAGED_RAW10_MSB, 30 | BZ_RAW_FORMAT_NUM 31 | }; 32 | 33 | enum BZBayerOrder { 34 | BZ_BO_BGGR = 0, 35 | BZ_BO_GBRG, 36 | BZ_BO_GRBG, 37 | BZ_BO_RGGB, 38 | BZ_BO_NUM 39 | }; 40 | 41 | enum BZParamType { 42 | BZ_PARAM_TYPE_IMAGE_INFO = 0, 43 | BZ_PARAM_TYPE_BLC, 44 | BZ_PARAM_TYPE_LSC, 45 | BZ_PARAM_TYPE_DMC, 46 | BZ_PARAM_TYPE_WB, 47 | BZ_PARAM_TYPE_CC, 48 | BZ_PARAM_TYPE_Gamma, 49 | BZ_PARAM_TYPE_WNR, 50 | BZ_PARAM_TYPE_EE, 51 | BZ_PARAM_TYPE_RAW2RGB, 52 | BZ_PARAM_TYPE_RGB2YUV, 53 | BZ_PARAM_TYPE_YUV2RGB, 54 | BZ_PARAM_TYPE_NUM 55 | }; 56 | 57 | struct BZImgInfo 58 | { 59 | int32_t width; 60 | int32_t height; 61 | int32_t bitspp; 62 | int32_t stride; 63 | int32_t rawFormat; 64 | int32_t bayerOrder; 65 | }; 66 | 67 | struct BZBlcParam { 68 | uint16_t offset; 69 | }; 70 | 71 | struct BZLscParam { 72 | float gainCh1[LSC_LUT_HEIGHT * LSC_LUT_WIDTH]; 73 | float gainCh2[LSC_LUT_HEIGHT * LSC_LUT_WIDTH]; 74 | float gainCh3[LSC_LUT_HEIGHT * LSC_LUT_WIDTH]; 75 | float gainCh4[LSC_LUT_HEIGHT * LSC_LUT_WIDTH]; 76 | }; 77 | 78 | struct BZWbParam { 79 | float rGain; 80 | float gGain; 81 | float bGain; 82 | }; 83 | 84 | struct BZCcParam { 85 | float ccm[CCM_HEIGHT * CCM_WIDTH]; 86 | }; 87 | 88 | struct BZGammaParam { 89 | uint16_t lut[GAMMA_LUT_SIZE]; 90 | }; 91 | 92 | struct BZWnrParam { 93 | int32_t ch1Threshold[3]; 94 | int32_t ch2Threshold[3]; 95 | int32_t ch3Threshold[3]; 96 | }; 97 | 98 | struct BZEeParam { 99 | float alpha; 100 | int32_t coreSize; 101 | int32_t sigma; 102 | }; 103 | 104 | struct BZParam { 105 | BZImgInfo info; 106 | BZBlcParam blc; 107 | BZLscParam lsc; 108 | BZWbParam wb; 109 | BZCcParam cc; 110 | BZGammaParam gamma; 111 | BZWnrParam wnr; 112 | BZEeParam ee; 113 | }; 114 | 115 | struct ISPUtilsFuncs { 116 | int32_t (*Log) (const char* str, ...); 117 | void (*DumpDataInt) (void* pData, ...); 118 | void* (*Alloc) (size_t size, ...); 119 | void* (*Free) (void* pBuf, ...); 120 | }; 121 | 122 | struct ISPCallbacks { 123 | void (*ISPNotify) (int32_t argNum, ...); 124 | ISPUtilsFuncs UtilsFuncs; 125 | }; 126 | 127 | enum BZCmd { 128 | BZ_CMD_CREATE_PROC = 0, 129 | BZ_CMD_PROCESS, 130 | BZ_CMD_NUM, 131 | }; 132 | 133 | enum BZMsg { 134 | MSG_D0 = 0, 135 | MSG_D1, 136 | MSG_D2, 137 | MSG_D3, 138 | MSG_D4, 139 | MSG_D5, 140 | MSG_D6, 141 | MSG_D7, 142 | MSG_D8, 143 | MSG_D9, 144 | MSG_NUM_MAX 145 | }; 146 | 147 | struct BZCtrl { 148 | bool en; 149 | void *pInfo; 150 | void *pSrc; 151 | void *pDst; 152 | void *pParam; 153 | }; 154 | 155 | struct BZOps 156 | { 157 | int32_t (*BZEvent) (uint32_t *msg); 158 | }; 159 | 160 | 161 | -------------------------------------------------------------------------------- /BZ/src/BZLog.cpp: -------------------------------------------------------------------------------- 1 | // License: GPL-3.0-or-later 2 | /* 3 | * BoZhi log supports. 4 | * 5 | * Copyright (c) 2019 Peng Hao <635945005@qq.com> 6 | */ 7 | 8 | #include "BZLog.h" 9 | #include 10 | 11 | int32_t LogBase(const char* str, ...) 12 | { 13 | va_list va; 14 | va_start(va, str); 15 | LogPrint(str, va); 16 | va_end(va); 17 | 18 | return 0; 19 | } 20 | 21 | void LogPrint(const char* str, va_list va) 22 | { 23 | char strBuffer[LOG_BUFFER_SIZE]; 24 | vsnprintf(strBuffer, LOG_BUFFER_SIZE - LOG_BUFFER_PERSERVE_SIZE, str, va); 25 | strBuffer[LOG_BUFFER_SIZE - 2] = '\0'; 26 | strBuffer[LOG_BUFFER_SIZE - 1] = '\n'; 27 | printf("%s\n", strBuffer); 28 | } 29 | -------------------------------------------------------------------------------- /BZ/src/BZUtils.cpp: -------------------------------------------------------------------------------- 1 | // License: GPL-3.0-or-later 2 | /* 3 | * BoZhi common fuctions implementation. 4 | * 5 | * Copyright (c) 2019 Peng Hao <635945005@qq.com> 6 | */ 7 | 8 | #include "BZUtils.h" 9 | 10 | -------------------------------------------------------------------------------- /BZ/src/BoZhi.cpp: -------------------------------------------------------------------------------- 1 | // License: GPL-3.0-or-later 2 | /* 3 | * BoZhi object source file. 4 | * 5 | * Copyright (c) 2019 Penint32_tHao <635945005@qq.com> 6 | */ 7 | 8 | #include "Algorithm.h" 9 | #include "BZLog.h" 10 | 11 | int32_t WrapEvent(uint32_t *msg) 12 | { 13 | int32_t rt = BZ_SUCCESS; 14 | 15 | rt = BoZhi::GetInstance()->Event(msg); 16 | 17 | return rt; 18 | } 19 | 20 | int32_t WrapGetOPS(void* pOPS) 21 | { 22 | int32_t rt = BZ_SUCCESS; 23 | 24 | BZOps* pLibOPS = static_cast(pOPS); 25 | if (!pLibOPS) { 26 | rt = BZ_INVALID_PARAM; 27 | BLOGE("Input is nullptr!"); 28 | return rt; 29 | } 30 | /* Add OPS if need */ 31 | pLibOPS->BZEvent = &WrapEvent; 32 | 33 | return rt; 34 | } 35 | 36 | int32_t WrapRegistCallbacks(void* pCBs) 37 | { 38 | int32_t rt = BZ_SUCCESS; 39 | 40 | rt = BoZhi::GetInstance()->RegisterCallbacks(pCBs); 41 | 42 | return (int32_t)rt; 43 | } 44 | 45 | int32_t WrapLibInit(void* pOPS) 46 | { 47 | int32_t rt = BZ_SUCCESS; 48 | 49 | rt = BoZhi::GetInstance()->Init(); 50 | if (!SUCCESS(rt)) { 51 | BLOGE("Failed to init BZ"); 52 | return rt; 53 | } 54 | 55 | rt = WrapGetOPS(pOPS); 56 | 57 | return rt; 58 | } 59 | 60 | int32_t WrapLibDeInit() 61 | { 62 | int32_t rt = BZ_SUCCESS; 63 | 64 | rt = BoZhi::GetInstance()->DeInit(); 65 | 66 | return rt; 67 | } 68 | 69 | void* WrapAlloc(size_t size) 70 | { 71 | size_t num = 1; 72 | return WrapAlloc(size, num); 73 | } 74 | 75 | void* WrapAlloc(size_t size, size_t num) 76 | { 77 | if (BoZhi::GetInstance()->GetCallbacks()->UtilsFuncs.Alloc) { 78 | return BoZhi::GetInstance()->GetCallbacks()->UtilsFuncs.Alloc(size * num); 79 | } else { 80 | return (void*) new uchar[size * num]; 81 | } 82 | } 83 | 84 | void* WrapFree(void* pBuf) 85 | { 86 | if (!pBuf) { 87 | BLOGE("Cannot free buf:%p", pBuf); 88 | return pBuf; 89 | } 90 | 91 | if (BoZhi::GetInstance()->GetCallbacks()->UtilsFuncs.Free) { 92 | return BoZhi::GetInstance()->GetCallbacks()->UtilsFuncs.Free(pBuf); 93 | } else { 94 | delete[] static_cast(pBuf); 95 | pBuf = NULL; 96 | } 97 | 98 | return pBuf; 99 | } 100 | 101 | BoZhi* BoZhi::GetInstance() 102 | { 103 | static BoZhi gInstance; 104 | return &gInstance; 105 | } 106 | 107 | BoZhi::BoZhi() 108 | { 109 | mISPCBs = { 0 }; 110 | mState = BZ_STATE_NEW; 111 | } 112 | 113 | BoZhi::~BoZhi() 114 | { 115 | memset(&mISPCBs, 0, sizeof(ISPCallbacks)); 116 | } 117 | 118 | int32_t BoZhi::Init() 119 | { 120 | int32_t rt = BZ_SUCCESS; 121 | int32_t curState = mState; 122 | 123 | if (mState != BZ_STATE_NEW) { 124 | rt = BZ_STATE_ERROR; 125 | BLOGE("Invalid state:%d", mState); 126 | return rt; 127 | } 128 | 129 | mState = BZ_STATE_INITED; 130 | BLOGDC("state %d -> %d", curState, mState); 131 | 132 | return rt; 133 | } 134 | 135 | int32_t BoZhi::DeInit() 136 | { 137 | int32_t rt = BZ_SUCCESS; 138 | int32_t curState = mState; 139 | 140 | mState = BZ_STATE_NEW; 141 | rt = DestroyAllProcessor(); 142 | BLOGDC("state %d -> %d", curState, mState); 143 | 144 | return rt; 145 | } 146 | 147 | int32_t BoZhi::RegisterCallbacks(void *pCBs) 148 | { 149 | int32_t rt = BZ_SUCCESS; 150 | ISPCallbacks* pISPCBs = static_cast(pCBs); 151 | 152 | if (!pISPCBs) { 153 | rt = BZ_INVALID_PARAM; 154 | BLOGE("Input is nullptr!"); 155 | return rt; 156 | } 157 | memcpy(&mISPCBs, pISPCBs, sizeof(ISPCallbacks)); 158 | 159 | return rt; 160 | } 161 | 162 | ISPCallbacks const* BoZhi::GetCallbacks() 163 | { 164 | return &mISPCBs; 165 | } 166 | 167 | int32_t BoZhi::Event(uint32_t *msg) 168 | { 169 | int32_t rt = BZ_SUCCESS; 170 | 171 | if (!msg) { 172 | rt = BZ_INVALID_PARAM; 173 | BLOGE("Msg is null"); 174 | return rt; 175 | } 176 | 177 | int32_t cmd = msg[MSG_D0]; 178 | switch (cmd) { 179 | case BZ_CMD_CREATE_PROC: 180 | rt = CreateProcessor(msg[MSG_D1]); 181 | break; 182 | case BZ_CMD_PROCESS: 183 | rt = Process(msg); 184 | break; 185 | case BZ_CMD_NUM: 186 | default: 187 | rt = BZ_FAILED; 188 | BLOGE("Invalid cmd:%d", cmd); 189 | PrintMessage(msg); 190 | break; 191 | } 192 | 193 | return rt; 194 | } 195 | 196 | void BoZhi::PrintMessage(uint32_t *msg) 197 | { 198 | if (!msg) { 199 | BLOGE("msg is null"); 200 | return; 201 | } 202 | for (size_t i = 0; i < MSG_NUM_MAX; i++) { 203 | BLOGI("msg[%d]:0x%x", i, msg[i]); 204 | } 205 | } 206 | 207 | int32_t BoZhi::CreateProcessor(int32_t id) 208 | { 209 | int32_t rt = BZ_SUCCESS; 210 | 211 | { 212 | unique_lock lock(procMapLock); 213 | if (mProcMap.find(id) != mProcMap.end()) { 214 | rt = BZ_FAILED; 215 | BLOGE("Processor(%d) already exist", id); 216 | return rt; 217 | } 218 | Processor *pProc = new Processor(id); 219 | if (!pProc) { 220 | rt = BZ_MEMORY_ERROR; 221 | BLOGE("Failed to new processor(%d)", id); 222 | return rt; 223 | } 224 | mProcMap.insert(make_pair(id, pProc)); 225 | } 226 | 227 | return rt; 228 | } 229 | 230 | int32_t BoZhi::DestroyProcessorById(int32_t id) 231 | { 232 | int32_t rt = BZ_SUCCESS; 233 | 234 | Processor *pProc = FindProcessorById(id); 235 | if (!pProc) { 236 | rt = BZ_FAILED; 237 | BLOGE("Cannot find Processor(%d)", id); 238 | return rt; 239 | } 240 | 241 | delete pProc; 242 | 243 | { 244 | unique_lock lock(procMapLock); 245 | mProcMap.erase(id); 246 | } 247 | BLOGDC("Processor(%d) is destroied", id); 248 | 249 | return rt; 250 | } 251 | 252 | int32_t BoZhi::DestroyAllProcessor() 253 | { 254 | int32_t rt = BZ_SUCCESS; 255 | int32_t id = 0; 256 | 257 | while(!mProcMap.empty()) { 258 | { 259 | unique_lock lock(procMapLock); 260 | id = mProcMap.begin()->first; 261 | } 262 | rt |= DestroyProcessorById(id); 263 | } 264 | 265 | return rt; 266 | } 267 | 268 | Processor *BoZhi::FindProcessorById(int32_t id) 269 | { 270 | Processor* pProc = NULL; 271 | 272 | { 273 | unique_lock lock(procMapLock); 274 | map::iterator iter = mProcMap.find(id); 275 | if (iter == mProcMap.end()) { 276 | BLOGE("Cannot find Processor(%d)", id); 277 | return NULL; 278 | } 279 | pProc = iter->second; 280 | } 281 | 282 | return pProc; 283 | } 284 | 285 | int32_t BoZhi::Process(uint32_t *msg) 286 | { 287 | int32_t rt = BZ_SUCCESS; 288 | 289 | if (!msg) { 290 | rt = BZ_INVALID_PARAM; 291 | BLOGE("Msg is null"); 292 | return rt; 293 | } 294 | 295 | int32_t id = msg[MSG_D1]; 296 | Processor *pProc = FindProcessorById(id); 297 | if (!pProc) { 298 | rt = BZ_FAILED; 299 | BLOGE("Cannot find Processor(%d)", id); 300 | return rt; 301 | } 302 | 303 | void* pVCtrl = NULL; 304 | #if __WORDSIZE == 64 305 | pVCtrl = (void*)(((uint64_t)msg[MSG_D3] & 0xffffffff) | (((uint64_t)msg[MSG_D4] << 32) & 0xffffffff00000000)); 306 | #elif __WORDSIZE == 32 307 | pVCtrl = (void*)msg[MSG_D3]; 308 | #endif 309 | BZCtrl* pCtrl = NULL; 310 | pCtrl = static_cast(pVCtrl); 311 | if (!pCtrl) { 312 | rt = BZ_FAILED; 313 | BLOGE("Faild to get ctrl(%p) from msg", pCtrl); 314 | return rt; 315 | } 316 | 317 | BZParam* pParam = static_cast(pCtrl->pInfo); 318 | 319 | Job job = {0}; 320 | job.info.type = msg[MSG_D2]; 321 | job.info.en = pCtrl->en; 322 | job.info.srcInfo.w = pParam->info.width; 323 | job.info.srcInfo.h = pParam->info.height; 324 | job.info.srcInfo.fmt = pParam->info.rawFormat; 325 | job.info.srcInfo.order = pParam->info.bayerOrder; 326 | job.info.srcInfo.bpp = pParam->info.bitspp; 327 | job.info.srcInfo.buf.size = 0; 328 | job.info.srcInfo.buf.pAddr = pCtrl->pSrc; 329 | job.info.dstInfo.w = pParam->info.width; 330 | job.info.dstInfo.h = pParam->info.height; 331 | job.info.dstInfo.fmt = pParam->info.rawFormat; 332 | job.info.dstInfo.order = pParam->info.bayerOrder; 333 | job.info.dstInfo.bpp =pParam->info.bitspp; 334 | job.info.dstInfo.buf.size = 0; 335 | job.info.dstInfo.buf.pAddr = pCtrl->pDst; 336 | job.info.param.size = 0; 337 | job.info.param.pAddr = pCtrl->pParam; 338 | 339 | rt = pProc->ScheduleJob(&job); 340 | 341 | return rt; 342 | } 343 | -------------------------------------------------------------------------------- /BZ/src/LibInterface.cpp: -------------------------------------------------------------------------------- 1 | // License: GPL-3.0-or-later 2 | /* 3 | * BoZhi interface implementation. 4 | * 5 | * Copyright (c) 2019 Peng Hao <635945005@qq.com> 6 | */ 7 | 8 | #include "BZInterface.h" 9 | #include "BoZhi.h" 10 | 11 | #ifdef LINUX_SYSTEM 12 | #define BZ_PRE_DECLARE 13 | #elif defined WIN32_SYSTEM 14 | #define BZ_PRE_DECLARE _declspec(dllexport) 15 | #endif 16 | 17 | extern "C" { 18 | BZ_PRE_DECLARE void LibInit(void* pOPS, ...) 19 | { 20 | WrapLibInit(pOPS); 21 | } 22 | 23 | BZ_PRE_DECLARE void LibDeInit(void* v, ...) 24 | { 25 | (void) v; 26 | WrapLibDeInit(); 27 | } 28 | 29 | BZ_PRE_DECLARE void RegistCallbacks(void* pCBs, ...) 30 | { 31 | WrapRegistCallbacks(pCBs); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /BZ/src/Processor.cpp: -------------------------------------------------------------------------------- 1 | // License: GPL-3.0-or-later 2 | /* 3 | * Processor source file. 4 | * 5 | * Copyright (c) 2023 Penint32_tHao <635945005@qq.com> 6 | */ 7 | 8 | #include "Processor.h" 9 | #include "BZLog.h" 10 | 11 | #define WORKER_WAIT_US 100 12 | 13 | void* WorkerFunc(void *pParam) 14 | { 15 | Processor *pProc = static_cast(pParam); 16 | 17 | if (!pProc) { 18 | BLOGE("Worker thread param is null"); 19 | return 0; 20 | } 21 | 22 | BLOGDP("Work S"); 23 | while (1) { 24 | if (!pProc->IsWorkOn()) { 25 | BLOGDP("Work E"); 26 | return NULL; 27 | } 28 | 29 | int32_t rt = BZ_SUCCESS; 30 | Job job = { 0 }; 31 | rt = pProc->GetJob(&job); 32 | if (rt == BZ_SUCCESS) { 33 | rt = pProc->HandleJob(&job); 34 | if (!SUCCESS(rt)) { 35 | BLOGE("Faild to handle job, %d", rt); 36 | } 37 | } else { 38 | usleep(WORKER_WAIT_US); 39 | } 40 | } 41 | } 42 | 43 | Processor::Processor(int32_t id) 44 | { 45 | mId = id; 46 | workerStatus = true; 47 | workerThread = thread(WorkerFunc, (void*)this); 48 | } 49 | 50 | Processor::~Processor() 51 | { 52 | OffWork(); 53 | workerThread.join(); 54 | } 55 | 56 | bool Processor::IsWorkOn() 57 | { 58 | return workerStatus; 59 | } 60 | 61 | int32_t Processor::OffWork() 62 | { 63 | int32_t rt = BZ_SUCCESS; 64 | 65 | rt = CancelJobs(); 66 | workerStatus = false; 67 | 68 | return rt; 69 | } 70 | 71 | int32_t Processor::CancelJobs() 72 | { 73 | int32_t rt = BZ_SUCCESS; 74 | 75 | { 76 | unique_lock lock(queueLock); 77 | 78 | int32_t cnt = 1; 79 | while (!workQueue.empty()) { 80 | BLOGDP("Job drop cnt:%d", cnt); 81 | workQueue.pop(); 82 | cnt++; 83 | } 84 | } 85 | 86 | return rt; 87 | } 88 | 89 | int32_t Processor::GetJob(Job *pJob) 90 | { 91 | int32_t rt = BZ_SUCCESS; 92 | 93 | if (!pJob) { 94 | rt = BZ_INVALID_PARAM; 95 | BLOGE("Input is null"); 96 | return rt; 97 | } 98 | 99 | { 100 | unique_lock lock(queueLock); 101 | 102 | if (!workQueue.empty()) { 103 | Job job = workQueue.front(); 104 | memcpy(pJob, &job, sizeof(Job)); 105 | workQueue.pop(); 106 | } else { 107 | rt = BZ_SKIP; 108 | } 109 | } 110 | 111 | return rt; 112 | } 113 | 114 | int32_t Processor::ScheduleJob(Job *pJob) 115 | { 116 | int32_t rt = BZ_SUCCESS; 117 | 118 | if (!pJob) { 119 | rt = BZ_INVALID_PARAM; 120 | BLOGE("Input is null"); 121 | return rt; 122 | } 123 | 124 | { 125 | unique_lock lock(queueLock); 126 | workQueue.push(*pJob); 127 | BLOGDP("job is added to queue%d(%d)", mId, workQueue.size()); 128 | } 129 | 130 | return rt; 131 | } 132 | 133 | int32_t Processor::HandleJob(Job *pJob) 134 | { 135 | int32_t rt = BZ_SUCCESS; 136 | 137 | if (!pJob) { 138 | rt = BZ_INVALID_PARAM; 139 | BLOGE("Input is null"); 140 | return rt; 141 | } 142 | 143 | rt = SetCtrl(pJob); 144 | if (!SUCCESS(rt)) { 145 | return rt; 146 | } 147 | 148 | rt = Process(pJob); 149 | 150 | return rt; 151 | } 152 | 153 | int32_t Processor::SetCtrl(Job *pJob) 154 | { 155 | int32_t rt = BZ_SUCCESS; 156 | 157 | if (!pJob) { 158 | rt = BZ_INVALID_PARAM; 159 | BLOGE("Input is null"); 160 | return rt; 161 | } 162 | 163 | return rt; 164 | } 165 | 166 | int32_t Processor::Process(Job *pJob) 167 | { 168 | int32_t rt = BZ_SUCCESS; 169 | 170 | if (!pJob) { 171 | rt = BZ_INVALID_PARAM; 172 | BLOGE("Job is null"); 173 | return rt; 174 | } 175 | 176 | switch(pJob->info.type) { 177 | case BZ_PARAM_TYPE_BLC: 178 | rt = WrapBlackLevelCorrection(&pJob->info); 179 | break; 180 | case BZ_PARAM_TYPE_LSC: 181 | rt = WrapLensShadingCorrection(&pJob->info); 182 | break; 183 | case BZ_PARAM_TYPE_DMC: 184 | rt = WrapDemosaic(&pJob->info); 185 | break; 186 | case BZ_PARAM_TYPE_WB: 187 | rt = WrapWhiteBalance(&pJob->info); 188 | break; 189 | case BZ_PARAM_TYPE_CC: 190 | rt = WrapColorCorrection(&pJob->info); 191 | break; 192 | case BZ_PARAM_TYPE_Gamma: 193 | rt = WrapGammaCorrection(&pJob->info); 194 | break; 195 | case BZ_PARAM_TYPE_WNR: 196 | rt = WrapWaveletNR(&pJob->info); 197 | break; 198 | case BZ_PARAM_TYPE_EE: 199 | rt = WrapEdgeEnhancement(&pJob->info); 200 | break; 201 | case BZ_PARAM_TYPE_RAW2RGB: 202 | rt = WrapCST_RAW2RGB(&pJob->info); 203 | break; 204 | case BZ_PARAM_TYPE_RGB2YUV: 205 | rt = WrapCST_RGB2YUV(&pJob->info); 206 | break; 207 | case BZ_PARAM_TYPE_YUV2RGB: 208 | rt = WrapCST_YUV2RGB(&pJob->info); 209 | break; 210 | case BZ_PARAM_TYPE_NUM: 211 | default: 212 | BLOGW("Nothing todo for job type:%d", pJob->info.type); 213 | break; 214 | } 215 | 216 | int32_t argNum = 3; 217 | BoZhi::GetInstance()->GetCallbacks()->ISPNotify(argNum, mId, pJob->info.type, rt); 218 | 219 | return rt; 220 | } 221 | -------------------------------------------------------------------------------- /ISP/config/DefaultIOCfg.h: -------------------------------------------------------------------------------- 1 | // License: GPL-3.0-or-later 2 | /* 3 | * Default medio infomation. 4 | * 5 | * Copyright (c) 2019 Peng Hao <635945005@qq.com> 6 | */ 7 | #include "ParamManager.h" 8 | #include "ISPConfig.h" 9 | 10 | #define INPUT_PATH (WORK_PATH RES_PATH PATH_FMT) 11 | #define OUTPUT_PATH (WORK_PATH RES_PATH PATH_FMT) 12 | 13 | #define DEFAULT_FILE_NAME "1MCC_IMG_20181229_001526_1" 14 | #define INPUT_NAME DEFAULT_FILE_NAME".raw" 15 | #define OUTPUT_IMG_NAME DEFAULT_FILE_NAME".bmp" 16 | #define OUTPUT_VIDEO_NAME DEFAULT_FILE_NAME".avi" 17 | 18 | const MediaInfo defaultMediaInfo { 19 | /* width, height, bitspp, stride, format, channel order */ 20 | {1920, 1080, 10, 0, ANDROID_RAW10, BO_BGGR}, 21 | /* FPS, max frame num*/ 22 | {30, 30}, 23 | /* media type: IMAGE_MEDIA, VIDEO_MEDIA */ 24 | IMAGE_MEDIA, 25 | // IMAGE_AND_VIDEO_MEDIA, 26 | }; 27 | -------------------------------------------------------------------------------- /ISP/config/ISPConfig.h: -------------------------------------------------------------------------------- 1 | // License: GPL-3.0-or-later 2 | /* 3 | * Project configuration infomation. 4 | * 5 | * Copyright (c) 2019 Peng Hao <635945005@qq.com> 6 | */ 7 | 8 | #ifdef LINUX_SYSTEM 9 | #define PATH_FMT "/" 10 | #define DYNAMIC_LIB_FMT ".so" 11 | #define WORK_PATH "/home/hao/dev/ISP/ISP/" 12 | #elif defined WIN32_SYSTEM 13 | #define PATH_FMT "\\" 14 | #define DYNAMIC_LIB_FMT ".dll" 15 | #define WORK_PATH "D:\\test_project\\ISP_NEW\\ISP_NEW\\ISP_NEW\\" 16 | #endif 17 | 18 | 19 | #define LIB_PATH "bin" 20 | #define RES_PATH "res" 21 | 22 | #define ALG_LIB_NAME "libbzalg" 23 | -------------------------------------------------------------------------------- /ISP/config/ISPListConfig.h: -------------------------------------------------------------------------------- 1 | // License: GPL-3.0-or-later 2 | /* 3 | * Static ISPList configurations. 4 | * 5 | * Copyright (c) 2019 Peng Hao <635945005@qq.com> 6 | */ 7 | 8 | #pragma once 9 | #include "ISPList.h" 10 | 11 | const ISPListProperty defaultListConfig = { 12 | {{"BLC", PROCESS_BLC, NODE_ON}, 13 | {"LSC", PROCESS_LSC, NODE_ON}, 14 | {"Demosaic", PROCESS_Demosaic, NODE_ON}, 15 | {"WB", PROCESS_WB, NODE_ON}, 16 | {"CC", PROCESS_CC, NODE_ON}, 17 | {"Gamma", PROCESS_GAMMA, NODE_ON}, 18 | {"WNR", PROCESS_WNR, NODE_ON}, 19 | {"EE", PROCESS_EE, NODE_ON}, 20 | {"CODER", PROCESS_CODER, NODE_ON}} 21 | }; 22 | -------------------------------------------------------------------------------- /ISP/config/Setting_1920x1080_D65_1000Lux.h: -------------------------------------------------------------------------------- 1 | // License: GPL-3.0-or-later 2 | /* 3 | * Static params for ISP with 1000lux D65 light source. 4 | * 5 | * Copyright (c) 2019 Peng Hao <635945005@qq.com> 6 | */ 7 | 8 | #pragma once 9 | #include "Settings.h" 10 | 11 | const BlcSetting BLC_SETTING_1920x1080_D65_1000Lux = { 12 | 10, 13 | 16 14 | }; 15 | 16 | const LscSetting LSC_SETTING_1920x1080_D65_1000Lux = { 17 | //bGain 18 | {{ 2.934418, 2.6059866, 2.220798, 1.94021428, 1.74472368, 1.600148, 1.50334871, 1.44453084, 1.42655516, 1.45087564, 1.51691735, 1.620021, 1.77389872, 1.984156, 2.26868367, 2.685018, 3.086324 }, 19 | { 2.780221, 2.42652345, 2.055793, 1.81020319, 1.61290979, 1.47168612, 1.37039435, 1.312223, 1.292875, 1.31676388, 1.381954, 1.48782563, 1.63721418, 1.83661532, 2.09502649, 2.48011971, 2.89426875 }, 20 | { 2.66630936, 2.266075, 1.92535543, 1.69699764, 1.50311673, 1.35843492, 1.26004076, 1.20359969, 1.1837939, 1.20910418, 1.27213573, 1.37395608, 1.51697993, 1.71529222, 1.95610869, 2.29821563, 2.73281074 }, 21 | { 2.56463766, 2.158125, 1.849616, 1.61822569, 1.42308247, 1.27978182, 1.18043447, 1.12182248, 1.10311854, 1.12834954, 1.19434536, 1.29403162, 1.43295217, 1.6283437, 1.86529028, 2.177293, 2.59969044 }, 22 | { 2.49308729, 2.09290552, 1.79948926, 1.56733191, 1.36901522, 1.2242583, 1.12401092, 1.06499517, 1.047911, 1.07009184, 1.13591647, 1.23624086, 1.37226307, 1.568607, 1.802117, 2.0997088, 2.51218 }, 23 | { 2.44614935, 2.05794668, 1.77400577, 1.53863382, 1.34037089, 1.19284844, 1.09375918, 1.03644383, 1.01813066, 1.04016006, 1.100972, 1.20247412, 1.33787072, 1.534938, 1.77078509, 2.0591023, 2.45250845 }, 24 | { 2.45007682, 2.05073738, 1.7705425, 1.53213227, 1.33331537, 1.18785942, 1.08808076, 1.0271945, 1.00769913, 1.03327465, 1.09398258, 1.19292164, 1.33314526, 1.52600241, 1.76134288, 2.0468235, 2.434896 }, 25 | { 2.46845961, 2.07147646, 1.78483438, 1.5487783, 1.35236824, 1.206258, 1.10778213, 1.04479361, 1.02893651, 1.050206, 1.11128664, 1.21239, 1.35215569, 1.54298, 1.78045, 2.06631827, 2.46595645 }, 26 | { 2.53892612, 2.12474346, 1.82424378, 1.59075677, 1.39276385, 1.24721909, 1.14948976, 1.08533442, 1.06639385, 1.08696747, 1.152703, 1.25387907, 1.39364779, 1.58492756, 1.8212918, 2.1178968, 2.52721024 }, 27 | { 2.633789, 2.21714544, 1.88529706, 1.64690328, 1.45256436, 1.30626082, 1.208156, 1.1472615, 1.12522137, 1.14996147, 1.21406388, 1.31402481, 1.45510221, 1.6442908, 1.88103974, 2.19772482, 2.63523436 }, 28 | { 2.75180864, 2.34643865, 1.97836983, 1.73083889, 1.53518808, 1.38939548, 1.289249, 1.22797668, 1.2085588, 1.230665, 1.29428446, 1.39603722, 1.54160321, 1.731839, 1.9690479, 2.323122, 2.762924 }, 29 | { 2.88964343, 2.5124588, 2.11312318, 1.8474673, 1.64406931, 1.49958229, 1.39923692, 1.33945262, 1.3191148, 1.3403734, 1.40577114, 1.5079881, 1.65210688, 1.84798753, 2.10569763, 2.50678158, 2.92251229 }, 30 | { 3.00785327, 2.7100594, 2.293494, 1.98375225, 1.78258061, 1.63429224, 1.53504336, 1.476219, 1.45520091, 1.47230053, 1.53835821, 1.63606775, 1.78734374, 1.98851943, 2.287967, 2.707317, 3.12480426 }}, 31 | 32 | //gbGain 33 | {{ 3.20395136, 2.84868073, 2.42183638, 2.12311363, 1.91179454, 1.756917, 1.64773118, 1.58069026, 1.55754256, 1.5834856, 1.645207, 1.74964738, 1.90877008, 2.1196, 2.41837454, 2.8678813, 3.28876615 }, 34 | { 3.04708457, 2.663059, 2.24919081, 1.97792578, 1.76208353, 1.60036659, 1.48812246, 1.417937, 1.39421225, 1.41655445, 1.48318923, 1.59559619, 1.75348139, 1.96583772, 2.233202, 2.655679, 3.10571742 }, 35 | { 2.92302465, 2.48888254, 2.1116817, 1.85055757, 1.63272786, 1.46424925, 1.34551013, 1.27543545, 1.24784422, 1.27263653, 1.34007871, 1.45550752, 1.61366773, 1.82921481, 2.08797812, 2.461877, 2.94127584 }, 36 | { 2.8214345, 2.3663547, 2.02269816, 1.75983441, 1.53516734, 1.361737, 1.2384063, 1.16158283, 1.13543427, 1.15850842, 1.231841, 1.34799671, 1.50860322, 1.7240684, 1.98546493, 2.32491326, 2.80031347 }, 37 | { 2.73184371, 2.289873, 1.96527112, 1.69687462, 1.46764481, 1.29081559, 1.161118, 1.08390057, 1.05756307, 1.07895672, 1.15257657, 1.27148235, 1.43292487, 1.64994228, 1.915042, 2.240633, 2.69434977 }, 38 | { 2.69206333, 2.253345, 1.93331969, 1.66203713, 1.43015265, 1.24909043, 1.12103391, 1.04398239, 1.015522, 1.03709757, 1.10727417, 1.22759187, 1.39046443, 1.61131787, 1.87466943, 2.18963933, 2.630392 }, 39 | { 2.67528725, 2.245041, 1.92658973, 1.65386665, 1.42180026, 1.2418189, 1.11271071, 1.03221583, 1.00493169, 1.0286479, 1.09747708, 1.216828, 1.38011265, 1.59923065, 1.86305082, 2.17897844, 2.61477852 }, 40 | { 2.70543, 2.26843548, 1.94370532, 1.6720295, 1.44359267, 1.26507568, 1.13638735, 1.05558419, 1.02966225, 1.05121982, 1.12055671, 1.24107945, 1.40166306, 1.61662066, 1.880561, 2.19829535, 2.64114118 }, 41 | { 2.77835655, 2.32503271, 1.98681116, 1.71911311, 1.49061728, 1.31596816, 1.1931448, 1.11112535, 1.0833174, 1.1038332, 1.17803967, 1.29450274, 1.45461929, 1.66681635, 1.927938, 2.25338554, 2.71144366 }, 42 | { 2.87977815, 2.42023182, 2.06020546, 1.78849733, 1.567631, 1.39687121, 1.27794135, 1.2006619, 1.17235661, 1.19521058, 1.26618552, 1.37799537, 1.53730309, 1.74319911, 1.99989152, 2.34575939, 2.824801 }, 43 | { 3.00670934, 2.570281, 2.167367, 1.89439619, 1.67329276, 1.51058328, 1.39316261, 1.32073271, 1.29580414, 1.31593478, 1.381983, 1.49326217, 1.64755106, 1.85299551, 2.108913, 2.49322033, 2.96424222 }, 44 | { 3.14779449, 2.760479, 2.327393, 2.03506637, 1.81627846, 1.65615547, 1.54346013, 1.47480285, 1.45027065, 1.46974921, 1.53530085, 1.64169729, 1.79380322, 1.995513, 2.268367, 2.69766188, 3.13380671 }, 45 | { 3.27151227, 2.97488356, 2.53580165, 2.202857, 1.99046743, 1.83107555, 1.71881962, 1.65477848, 1.630454, 1.65059066, 1.71336091, 1.81254041, 1.96194947, 2.165229, 2.478046, 2.92654252, 3.32641459 }}, 46 | 47 | //grGain 48 | {{ 3.25572634, 2.89292026, 2.4517138, 2.14141822, 1.91608775, 1.75056577, 1.6297735, 1.55698335, 1.53054082, 1.55629158, 1.62307167, 1.74096286, 1.90679991, 2.12313032, 2.435579, 2.887383, 3.319794 }, 49 | { 3.1139915, 2.71121383, 2.28292322, 2.001553, 1.773555, 1.60334086, 1.47839546, 1.40285826, 1.37624037, 1.39933944, 1.46882379, 1.58867931, 1.75515807, 1.97776151, 2.256206, 2.685162, 3.150439 }, 50 | { 2.99251127, 2.539546, 2.15274119, 1.88075721, 1.65062714, 1.47220039, 1.3437233, 1.26727808, 1.2381109, 1.26250851, 1.33401537, 1.4550693, 1.62251461, 1.84627759, 2.113808, 2.500503, 2.99223828 }, 51 | { 2.88620067, 2.42083025, 2.06689, 1.792972, 1.557844, 1.37428069, 1.24328971, 1.15899968, 1.13094807, 1.155757, 1.23183417, 1.35374939, 1.52196252, 1.74707985, 2.01720285, 2.36469722, 2.85595417 }, 52 | { 2.805475, 2.34426785, 2.01149154, 1.73086941, 1.49328375, 1.30466914, 1.168742, 1.08562386, 1.05711555, 1.07877731, 1.155649, 1.27911854, 1.45085931, 1.67629755, 1.95046341, 2.28564167, 2.75199223 }, 53 | { 2.75480866, 2.30931067, 1.97921109, 1.70017242, 1.456584, 1.266083, 1.12949848, 1.047226, 1.016633, 1.03824031, 1.11095607, 1.23864925, 1.40823913, 1.63847983, 1.9110508, 2.23481369, 2.68167949 }, 54 | { 2.74190378, 2.29949617, 1.97337341, 1.68797028, 1.44639432, 1.257866, 1.11907864, 1.035803, 1.0060153, 1.02904892, 1.10084367, 1.2262038, 1.39805651, 1.6266675, 1.89996767, 2.22219658, 2.66637921 }, 55 | { 2.76845646, 2.31891775, 1.984939, 1.70612419, 1.46595716, 1.27839935, 1.14174712, 1.05593383, 1.02896273, 1.050837, 1.12268, 1.24922979, 1.41899669, 1.64322937, 1.912983, 2.23781657, 2.69614768 }, 56 | { 2.8345952, 2.37168837, 2.02467871, 1.74893022, 1.50960279, 1.325559, 1.19417679, 1.1083734, 1.07775366, 1.09952343, 1.1761843, 1.2994734, 1.46681154, 1.68724191, 1.95761359, 2.28763771, 2.762187 }, 57 | { 2.93678975, 2.462873, 2.09207153, 1.81134331, 1.58088207, 1.3999697, 1.27424335, 1.191744, 1.16132, 1.18497109, 1.25811017, 1.37668681, 1.54437339, 1.75989628, 2.024353, 2.37870121, 2.86460948 }, 58 | { 3.05432677, 2.60200286, 2.19123387, 1.91062164, 1.68002653, 1.50665259, 1.38154352, 1.303675, 1.27637732, 1.29852414, 1.36698258, 1.4857558, 1.64721251, 1.8632412, 2.12321568, 2.51894569, 3.000998 }, 59 | { 3.18675113, 2.789452, 2.345823, 2.04380536, 1.81311774, 1.64452136, 1.52401233, 1.44757223, 1.42193472, 1.443355, 1.51186883, 1.62641156, 1.78541982, 1.99573874, 2.27726436, 2.7194345, 3.164886 }, 60 | { 3.30671382, 2.99426556, 2.54958248, 2.203216, 1.97926247, 1.80847907, 1.69107234, 1.61833107, 1.59140134, 1.61120772, 1.68296742, 1.78529263, 1.94878912, 2.151207, 2.4813168, 2.93416166, 3.34963751 }}, 61 | 62 | //rGain 63 | {{ 3.26140237, 2.90829229, 2.44395447, 2.14117551, 1.92580986, 1.76098931, 1.64909816, 1.57704759, 1.554534, 1.58389091, 1.65474868, 1.77599037, 1.95483339, 2.17210364, 2.49666047, 2.99027562, 3.42638421 }, 64 | { 3.10735345, 2.697388, 2.26802278, 1.99615026, 1.77538717, 1.60802543, 1.48951221, 1.41702485, 1.39288378, 1.420929, 1.49541867, 1.61999846, 1.79255354, 2.01902175, 2.304034, 2.75090647, 3.242971 }, 65 | { 2.97376251, 2.51484275, 2.12860441, 1.86797869, 1.64624727, 1.47517741, 1.35393524, 1.28068864, 1.25363386, 1.28241861, 1.35708928, 1.47977376, 1.64895618, 1.8743093, 2.14584637, 2.539748, 3.059384 }, 66 | { 2.858949, 2.38620639, 2.041443, 1.77220476, 1.54693, 1.37411761, 1.25212264, 1.171063, 1.14400363, 1.17096663, 1.25206625, 1.3736707, 1.54114032, 1.765352, 2.03399444, 2.38793254, 2.90239644 }, 67 | { 2.7713716, 2.310951, 1.97953582, 1.70900917, 1.47973192, 1.30391, 1.17499089, 1.09408915, 1.06599355, 1.08896232, 1.17121, 1.29502475, 1.46141851, 1.687468, 1.960504, 2.29183125, 2.79347658 }, 68 | { 2.71774817, 2.27686, 1.94907153, 1.6727308, 1.44130123, 1.26184094, 1.13418913, 1.05143952, 1.0188297, 1.04448736, 1.12113214, 1.24961007, 1.41669822, 1.64373708, 1.916427, 2.24438834, 2.72118878 }, 69 | { 2.72102714, 2.26686883, 1.9444381, 1.66600811, 1.43206453, 1.25416493, 1.12143385, 1.03733242, 1.00448644, 1.03098881, 1.10780609, 1.23636043, 1.40724814, 1.6315949, 1.90451217, 2.22804785, 2.701279 }, 70 | { 2.73730564, 2.29291, 1.96152222, 1.68367219, 1.45214558, 1.27432334, 1.142153, 1.0562, 1.02521479, 1.05012667, 1.12978125, 1.25924039, 1.426747, 1.65111053, 1.92359591, 2.247887, 2.73132014 }, 71 | { 2.81994367, 2.34834957, 2.004114, 1.73133981, 1.49727178, 1.32004464, 1.19515443, 1.10757565, 1.07641768, 1.10019207, 1.18332469, 1.308249, 1.47925, 1.69980335, 1.96897411, 2.306974, 2.80438614 }, 72 | { 2.92639732, 2.44216776, 2.07634854, 1.799391, 1.56975734, 1.39434123, 1.27109933, 1.190723, 1.15844178, 1.18562472, 1.26415074, 1.38814867, 1.5586611, 1.77739751, 2.04431272, 2.4038713, 2.91905713 }, 73 | { 3.055297, 2.585944, 2.17785, 1.90352452, 1.673042, 1.500913, 1.37676442, 1.29876518, 1.27201283, 1.29613686, 1.3717885, 1.49768281, 1.66706812, 1.887339, 2.15350842, 2.56109357, 3.0679822 }, 74 | { 3.192101, 2.78453779, 2.33802271, 2.03929257, 1.8125155, 1.64407277, 1.52214587, 1.44450521, 1.41926432, 1.44269049, 1.520358, 1.6435467, 1.81265891, 2.03104234, 2.32003713, 2.78072262, 3.248023 }, 75 | { 3.322562, 3.01884437, 2.54817438, 2.208989, 1.98511779, 1.81881928, 1.70027828, 1.62241781, 1.5952847, 1.62019539, 1.69814765, 1.817103, 1.98954976, 2.2055006, 2.55155873, 3.02624321, 3.44730616 }}, 76 | }; 77 | 78 | const WbSetting WB_SETTING_1920x1080_D65_1000Lux{ 79 | true, 80 | { 1.994, 1.0, 2.372 }, 81 | { 1.378, 1.0, 1.493 } 82 | }; 83 | 84 | const CcSetting CC_SETTING_1920x1080_D65_1000Lux{ 85 | {{ 1.819, -0.248, 0.213 }, 86 | { -1.069, 1.322, -1.078 }, 87 | { 0.250, -0.074, 1.865 }} 88 | }; 89 | 90 | const GammaSetting GAMMA_SETTING_1920x1080_D65_1000Lux{ 91 | { 0, 4, 9, 13, 18, 21, 24, 27, 92 | 30, 33, 36, 39, 42, 45, 48, 51, 93 | 54, 57, 60, 63, 66, 69, 72, 75, 94 | 78, 81, 85, 88, 92, 95, 99, 102, 95 | 106, 109, 112, 115, 118, 121, 125, 129, 96 | 133, 136, 140, 143, 147, 150, 153, 156, 97 | 159, 162, 165, 168, 171, 174, 177, 180, 98 | 183, 186, 189, 192, 195, 198, 201, 204, 99 | 207, 209, 212, 214, 217, 219, 222, 224, 100 | 227, 230, 233, 236, 239, 241, 244, 246, 101 | 249, 251, 254, 256, 259, 261, 264, 266, 102 | 269, 271, 273, 275, 277, 279, 282, 284, 103 | 287, 289, 292, 294, 297, 299, 301, 303, 104 | 305, 307, 309, 311, 313, 315, 317, 319, 105 | 321, 323, 325, 327, 329, 331, 333, 335, 106 | 337, 339, 341, 343, 345, 346, 348, 349, 107 | 351, 352, 354, 355, 357, 359, 361, 363, 108 | 365, 367, 369, 371, 373, 375, 377, 379, 109 | 381, 382, 384, 386, 388, 389, 391, 392, 110 | 394, 395, 397, 398, 400, 401, 403, 404, 111 | 406, 408, 410, 412, 414, 415, 417, 418, 112 | 420, 421, 423, 424, 426, 428, 430, 432, 113 | 434, 435, 437, 438, 440, 441, 442, 443, 114 | 444, 445, 447, 448, 450, 452, 454, 456, 115 | 458, 459, 461, 462, 464, 465, 466, 467, 116 | 468, 469, 471, 472, 474, 475, 477, 478, 117 | 480, 481, 483, 484, 486, 487, 489, 490, 118 | 492, 493, 494, 495, 496, 497, 499, 500, 119 | 502, 503, 505, 506, 508, 509, 510, 511, 120 | 512, 513, 515, 516, 518, 519, 521, 522, 121 | 524, 525, 526, 527, 528, 529, 531, 532, 122 | 534, 535, 536, 537, 538, 539, 540, 541, 123 | 542, 543, 545, 546, 548, 549, 550, 551, 124 | 552, 553, 555, 556, 558, 559, 561, 562, 125 | 564, 565, 566, 567, 568, 569, 570, 571, 126 | 572, 573, 574, 575, 576, 577, 578, 579, 127 | 580, 581, 582, 583, 584, 585, 586, 587, 128 | 588, 589, 590, 591, 592, 593, 595, 596, 129 | 598, 599, 600, 601, 602, 603, 604, 605, 130 | 606, 607, 608, 609, 610, 611, 612, 613, 131 | 614, 615, 616, 617, 618, 619, 620, 621, 132 | 622, 623, 624, 625, 626, 627, 628, 629, 133 | 630, 630, 631, 631, 632, 633, 634, 635, 134 | 636, 637, 638, 639, 640, 641, 642, 643, 135 | 645, 646, 647, 648, 649, 650, 651, 652, 136 | 653, 654, 655, 656, 657, 658, 659, 660, 137 | 661, 662, 663, 664, 665, 666, 667, 668, 138 | 669, 669, 670, 671, 672, 672, 673, 674, 139 | 675, 676, 677, 678, 679, 679, 680, 680, 140 | 681, 682, 683, 684, 685, 685, 686, 687, 141 | 688, 688, 689, 690, 691, 692, 693, 694, 142 | 695, 696, 697, 698, 699, 699, 700, 700, 143 | 701, 701, 702, 703, 704, 704, 705, 706, 144 | 707, 708, 709, 710, 711, 711, 712, 712, 145 | 713, 713, 714, 715, 716, 716, 717, 718, 146 | 719, 720, 721, 722, 723, 723, 724, 724, 147 | 725, 725, 726, 727, 728, 728, 729, 730, 148 | 731, 732, 733, 734, 735, 735, 736, 736, 149 | 737, 738, 739, 740, 741, 741, 742, 743, 150 | 744, 744, 745, 746, 747, 747, 748, 748, 151 | 749, 749, 750, 751, 752, 752, 753, 754, 152 | 755, 755, 756, 756, 757, 757, 758, 759, 153 | 760, 760, 761, 762, 763, 763, 764, 764, 154 | 765, 765, 766, 767, 768, 768, 769, 770, 155 | 771, 771, 772, 772, 773, 773, 774, 775, 156 | 776, 776, 777, 778, 779, 779, 780, 780, 157 | 781, 781, 782, 783, 784, 784, 785, 786, 158 | 787, 787, 788, 788, 789, 789, 790, 791, 159 | 792, 792, 793, 794, 795, 795, 796, 796, 160 | 797, 797, 798, 799, 800, 800, 801, 802, 161 | 803, 803, 804, 804, 805, 805, 806, 807, 162 | 808, 808, 809, 810, 811, 811, 812, 812, 163 | 813, 813, 814, 815, 816, 816, 817, 818, 164 | 819, 819, 820, 820, 821, 821, 822, 822, 165 | 823, 823, 824, 824, 825, 825, 826, 826, 166 | 827, 827, 828, 828, 829, 829, 830, 830, 167 | 831, 831, 832, 832, 833, 833, 834, 835, 168 | 836, 836, 837, 838, 839, 839, 840, 840, 169 | 841, 841, 842, 843, 844, 844, 845, 845, 170 | 846, 846, 847, 847, 848, 848, 849, 850, 171 | 851, 851, 852, 852, 853, 853, 854, 854, 172 | 855, 855, 856, 856, 857, 857, 858, 858, 173 | 859, 859, 860, 860, 861, 861, 862, 863, 174 | 864, 864, 865, 865, 866, 866, 867, 867, 175 | 868, 868, 869, 869, 870, 870, 871, 871, 176 | 872, 872, 873, 873, 874, 874, 875, 875, 177 | 876, 876, 877, 877, 878, 878, 879, 879, 178 | 880, 880, 881, 881, 882, 882, 883, 883, 179 | 884, 884, 885, 885, 886, 886, 887, 887, 180 | 888, 888, 889, 889, 890, 890, 891, 891, 181 | 892, 892, 893, 893, 894, 894, 895, 895, 182 | 896, 896, 897, 897, 898, 898, 899, 899, 183 | 900, 900, 901, 902, 903, 903, 904, 904, 184 | 905, 905, 906, 906, 907, 907, 908, 908, 185 | 909, 909, 910, 910, 911, 911, 912, 912, 186 | 913, 913, 914, 914, 915, 915, 915, 915, 187 | 916, 916, 917, 917, 918, 918, 919, 919, 188 | 920, 920, 921, 921, 922, 922, 922, 922, 189 | 923, 923, 924, 924, 925, 925, 926, 926, 190 | 927, 927, 928, 928, 929, 929, 930, 930, 191 | 931, 931, 931, 931, 932, 932, 933, 933, 192 | 934, 934, 934, 934, 935, 935, 936, 936, 193 | 937, 937, 938, 938, 939, 939, 940, 940, 194 | 941, 941, 942, 942, 943, 943, 944, 944, 195 | 945, 945, 946, 946, 947, 947, 947, 947, 196 | 948, 948, 949, 949, 950, 950, 951, 951, 197 | 952, 952, 953, 953, 954, 954, 954, 954, 198 | 955, 955, 956, 956, 957, 957, 958, 958, 199 | 959, 959, 960, 960, 961, 961, 962, 962, 200 | 963, 963, 963, 963, 964, 964, 965, 965, 201 | 966, 966, 966, 966, 967, 967, 968, 968, 202 | 969, 969, 970, 970, 971, 971, 971, 971, 203 | 972, 972, 973, 973, 974, 974, 974, 974, 204 | 975, 975, 975, 975, 976, 976, 977, 977, 205 | 978, 978, 979, 979, 980, 980, 981, 981, 206 | 982, 982, 982, 982, 983, 983, 984, 984, 207 | 985, 985, 986, 986, 987, 987, 987, 987, 208 | 988, 988, 989, 989, 990, 990, 991, 991, 209 | 992, 992, 993, 993, 994, 994, 994, 994, 210 | 995, 995, 996, 996, 997, 997, 998, 998, 211 | 999, 999, 1000, 1000, 1001, 1001, 1002, 1002, 212 | 1003, 1003, 1003, 1003, 1004, 1004, 1004, 1004, 213 | 1005, 1005, 1006, 1006, 1007, 1007, 1007, 1007, 214 | 1008, 1008, 1009, 1009, 1010, 1010, 1010, 1010, 215 | 1011, 1011, 1012, 1012, 1013, 1013, 1014, 1014, 216 | 1015, 1015, 1015, 1015, 1016, 1016, 1016, 1016, 217 | 1017, 1017, 1018, 1018, 1019, 1019, 1019, 1019, 218 | 1020, 1020, 1021, 1021, 1022, 1022, 1022, 1023 } 219 | }; 220 | 221 | const WnrSetting WNR_SETTING_1920x1080_D65_1000Lux{ 222 | {3, 4, 4}, 223 | {10, 10, 10}, 224 | {10, 10, 10} 225 | }; 226 | 227 | const EeSetting EE_SETTING_1920x1080_D65_1000Lux{ 228 | 1.0, 229 | 5, 230 | 4, 231 | }; 232 | -------------------------------------------------------------------------------- /ISP/include/BMP.h: -------------------------------------------------------------------------------- 1 | // License: GPL-3.0-or-later 2 | /* 3 | * Defined some structure to support BMP wihout official BMP head file. 4 | * 5 | * Copyright (c) 2019 Peng Hao <635945005@qq.com> 6 | */ 7 | 8 | #pragma once 9 | typedef unsigned char BYTE; 10 | typedef unsigned short WORD; 11 | typedef unsigned int DWORD; 12 | typedef int32_t LONG; 13 | 14 | struct BITMAPFILEHEADER { 15 | WORD bfType; 16 | WORD bfSize[2]; 17 | WORD bfReserved1; 18 | WORD bfReserved2; 19 | WORD bfOffBits[2]; 20 | }; 21 | 22 | struct RGBQUAD { 23 | BYTE rgbBlue; 24 | BYTE rgbGreen; 25 | BYTE rgbRed; 26 | BYTE rgbReserved; 27 | }; 28 | 29 | struct BITMAPINFOHEADER{ 30 | DWORD biSize; 31 | LONG biWidth; 32 | LONG biHeight; 33 | WORD biPlanes; 34 | WORD biBitCount; 35 | DWORD biCompression; 36 | DWORD biSizeImage; 37 | LONG biXPelsPerMeter; 38 | LONG biYPelsPerMeter; 39 | DWORD biClrUsed; 40 | DWORD biClrImportant; 41 | }; 42 | -------------------------------------------------------------------------------- /ISP/include/Buffer.h: -------------------------------------------------------------------------------- 1 | // License: GPL-3.0-or-later 2 | /* 3 | * Define ISP buffer. 4 | * 5 | * Copyright (c) 2023 Peng Hao <635945005@qq.com> 6 | */ 7 | #include "Utils.h" 8 | #include 9 | #include 10 | 11 | #ifndef __ISP_BUFFER_H__ 12 | #define __ISP_BUFFER_H__ 13 | 14 | using namespace std; 15 | namespace asteroidaxis::isp::resource { 16 | 17 | #define BUFFER_USE_MEM_T uchar 18 | 19 | #define SIZEOF_T(s) (size_t)((sizeof(s) % sizeof(BUFFER_USE_MEM_T)) ? \ 20 | (sizeof(s) / sizeof(BUFFER_USE_MEM_T) + 1) : \ 21 | (sizeof(s) / sizeof(BUFFER_USE_MEM_T))) 22 | 23 | class Buffer { 24 | public: 25 | static Buffer *Alloc(size_t size); 26 | static void Free(Buffer **ppBuf); 27 | void *Addr(); 28 | size_t Size(); 29 | void Reset(); 30 | 31 | private: 32 | Buffer() = delete; 33 | Buffer(const Buffer&) = delete; 34 | Buffer& operator = (const Buffer&) = delete; 35 | 36 | private: 37 | Buffer(void* addr, size_t size); 38 | ~Buffer(); 39 | void CheckFreeDone(void *pAddr); 40 | 41 | void *mAddr = NULL; 42 | size_t mSize = 0; 43 | }; 44 | 45 | class BufferMgr { 46 | public: 47 | static BufferMgr *GetInstance(); 48 | int32_t PushBufferToList(Buffer *pBuf); 49 | int32_t PopBufferFromList(Buffer *pBuf); 50 | int32_t ReleaseAllBuffer(); 51 | 52 | private: 53 | BufferMgr(); 54 | ~BufferMgr(); 55 | std::list bufList; 56 | mutex bufListLock; 57 | }; 58 | 59 | } 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /ISP/include/Coder.h: -------------------------------------------------------------------------------- 1 | // License: GPL-3.0-or-later 2 | /* 3 | * Coder head file. 4 | * 5 | * Copyright (c) 2023 Peng Hao <635945005@qq.com> 6 | */ 7 | 8 | struct InputInfo { 9 | 10 | } 11 | 12 | struct Format { 13 | int32_t cs; 14 | int32_t order; 15 | int32_t bpp; 16 | }; 17 | 18 | class Coder : public CoderItf { 19 | public: 20 | Coder(); 21 | ~CoderItf(); 22 | int32_t MediaDecode(InputInfo info); 23 | int32_t MediaEncode(OutputInfo info); 24 | 25 | private: 26 | int32_t ImageDecode(void* pData, Format inFmt, Format outFmt); 27 | int32_t ImageEncode(void* pData, Format inFmt, Format outFmt); 28 | int32_t VideoEncode(void* pData, Format inFmt, Format outFmt); 29 | 30 | }; 31 | -------------------------------------------------------------------------------- /ISP/include/FileManager.h: -------------------------------------------------------------------------------- 1 | // License: GPL-3.0-or-later 2 | /* 3 | * A file manager to manage files, provoid file operations. 4 | * 5 | * Copyright (c) 2019 Peng Hao <635945005@qq.com> 6 | */ 7 | 8 | #pragma once 9 | #include 10 | 11 | #include "Utils.h" 12 | #include "ISPVideo.h" 13 | #include "IOHelper.h" 14 | #ifdef LINUX_SYSTEM 15 | #include "BMP.h" 16 | #elif defined WIN32_SYSTEM 17 | #include 18 | #endif 19 | 20 | #define OUTPUT_FILE_TYPE_SIZE 4 /* size of 'bmp\0'/'avi\0' is 4 */ 21 | 22 | class FileManager; 23 | 24 | enum FileMgrState { 25 | FMGR_STATE_UNINITED = 0, 26 | FMGR_STATE_INITED, 27 | FMGR_STATE_NUM 28 | }; 29 | 30 | enum InputFileType { 31 | INPUT_FILE_TYPE_RAW, 32 | INPUT_FILE_TYPE_NUM 33 | }; 34 | 35 | enum OutputFileType { 36 | OUTPUT_FILE_TYPE_BMP, 37 | OUTPUT_FILE_TYPE_AVI, 38 | OUTPUT_FILE_TYPE_NUM 39 | }; 40 | 41 | struct InputInfo { 42 | char path[FILE_PATH_MAX_SIZE]; 43 | int32_t type; 44 | int32_t size; 45 | }; 46 | 47 | struct OutputImgInfo { 48 | char path[FILE_PATH_MAX_SIZE]; 49 | int32_t type; 50 | int32_t size; 51 | int32_t width; 52 | int32_t height; 53 | int32_t channels; 54 | }; 55 | 56 | struct OutputVideoInfo { 57 | char path[FILE_PATH_MAX_SIZE]; 58 | int32_t type; 59 | int32_t width; 60 | int32_t height; 61 | int32_t fps; 62 | int32_t frameNum; 63 | }; 64 | 65 | struct OutputInfo { 66 | OutputImgInfo imgInfo; 67 | OutputVideoInfo videoInfo; 68 | }; 69 | 70 | struct VideoThreadParam { 71 | ISPVideo* pVideo; 72 | }; 73 | 74 | class FileManagerItf : public IOHelper { 75 | public: 76 | virtual ~FileManagerItf() {}; 77 | 78 | virtual InputInfo GetInputInfo() = 0; 79 | virtual OutputInfo GetOutputInfo() = 0; 80 | virtual OutputImgInfo GetOutputImgInfo() = 0; 81 | virtual int32_t GetOutputVideoInfo(OutputVideoInfo* pInfo) = 0; 82 | virtual int32_t SetInputInfo(InputInfo info) = 0; 83 | virtual int32_t SetOutputInfo(OutputInfo info) = 0; 84 | virtual int32_t SetOutputImgInfo(OutputImgInfo info) = 0; 85 | virtual int32_t SetOutputVideoInfo(OutputVideoInfo info) = 0; 86 | virtual int32_t ReadData(uint8_t* buffer, int32_t bufferSize) = 0; 87 | virtual int32_t SaveImgData(uint8_t* srcData) = 0; 88 | virtual int32_t CreateVideo(void* dst) = 0; 89 | virtual int32_t SaveVideoData(int32_t frameCount) = 0; 90 | virtual int32_t DestroyVideo() = 0; 91 | virtual int32_t Mipi10decode(void* src, void* dst, ImgInfo* info) = 0; 92 | virtual int32_t Input(IOInfo in) = 0; 93 | virtual int32_t GetIOInfo(void* pInfo) = 0; 94 | }; 95 | 96 | class FileManager : public FileManagerItf { 97 | public: 98 | static FileManager* GetInstance(); 99 | virtual InputInfo GetInputInfo() { return mInputInfo; }; 100 | virtual OutputInfo GetOutputInfo() { return mOutputInfo; }; 101 | virtual OutputImgInfo GetOutputImgInfo() { return mOutputInfo.imgInfo; }; 102 | virtual int32_t GetOutputVideoInfo(OutputVideoInfo* pInfo); 103 | virtual int32_t SetInputInfo(InputInfo info); 104 | virtual int32_t SetOutputInfo(OutputInfo info); 105 | virtual int32_t SetOutputImgInfo(OutputImgInfo info); 106 | virtual int32_t SetOutputVideoInfo(OutputVideoInfo info); 107 | virtual int32_t ReadData(uint8_t* buffer, int32_t bufferSize); 108 | virtual int32_t SaveImgData(uint8_t* srcData); 109 | virtual int32_t CreateVideo(void* dst); 110 | virtual int32_t SaveVideoData(int32_t frameCount); 111 | virtual int32_t DestroyVideo(); 112 | virtual int32_t Mipi10decode(void* src, void* dst, ImgInfo* info); 113 | virtual int32_t Input(IOInfo in); 114 | virtual int32_t GetIOInfo(void* pInfo); 115 | 116 | private: 117 | FileManager(); 118 | virtual ~FileManager(); 119 | 120 | int32_t Init(); 121 | int32_t DeInit(); 122 | int32_t ReadRawData(uint8_t* buffer, int32_t bufferSize); 123 | int32_t SaveBMPData(uint8_t* srcData, int32_t channels); 124 | int32_t SetBMP(uint8_t* srcData, int32_t channels, BYTE* dstData); 125 | void WriteBMP(BYTE* data, int32_t channels); 126 | void HelpMenu(); 127 | void SupportInfo(); 128 | 129 | InputInfo mInputInfo; 130 | OutputInfo mOutputInfo; 131 | int32_t mState; 132 | std::unique_ptr mVideo; /* TODO[M]: move into ISPList */ 133 | VideoThreadParam mVTParam; 134 | int32_t IOInfoFlag; /* 0: Dynamic info 1: Static info*/ 135 | }; 136 | 137 | void DumpDataInt(void* pData, ... 138 | /* int32_t height, int32_t width, int32_t bitWidth, char* dumpPath */); 139 | 140 | -------------------------------------------------------------------------------- /ISP/include/IOHelper.h: -------------------------------------------------------------------------------- 1 | // License: GPL-3.0-or-later 2 | /* 3 | * I/O helper head file. 4 | * 5 | * Copyright (c) 2019 Peng Hao <635945005@qq.com> 6 | */ 7 | 8 | #include "Utils.h" 9 | #include "DefaultIOCfg.h" 10 | 11 | #define MAX_IO_PARAM_CNT 10 12 | 13 | struct IOInfo { 14 | int argc; 15 | char* argv[MAX_IO_PARAM_CNT]; 16 | char* envp[MAX_IO_PARAM_CNT]; 17 | }; 18 | 19 | class IOHelper { 20 | public: 21 | IOHelper(); 22 | virtual ~IOHelper(); 23 | virtual int32_t Input(IOInfo in) = 0; 24 | virtual void HelpMenu() = 0; 25 | /* TODO: parse input config file */ 26 | protected: 27 | void *pDynamicInfo; 28 | void *pStaticInfo; 29 | 30 | private: 31 | }; 32 | 33 | -------------------------------------------------------------------------------- /ISP/include/ISPCore.h: -------------------------------------------------------------------------------- 1 | // License: GPL-3.0-or-later 2 | /* 3 | * ISPCore head file. 4 | * 5 | * Copyright (c) 2019 Peng Hao <635945005@qq.com> 6 | */ 7 | 8 | #pragma once 9 | 10 | #include "Utils.h" 11 | #include "ISPItf.h" 12 | #include "FileManager.h" 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | enum CoreState { 19 | CORE_IDLE = 0, 20 | CORE_INITED, 21 | CORE_PROCESSING, 22 | CORE_STATE_NUM 23 | }; 24 | 25 | class ISPCore : public ISPItf { 26 | public: 27 | static ISPCore* GetInstance(); 28 | virtual int32_t Process(void *pInfo, ...); 29 | virtual bool IsActive(); 30 | virtual bool NeedExit(); 31 | virtual void* GetThreadParam(); 32 | 33 | private: 34 | ISPCore(); 35 | virtual ~ISPCore(); 36 | 37 | bool mExit; 38 | int32_t mState; 39 | thread mThread; 40 | IOInfo mThreadParam; 41 | }; 42 | 43 | -------------------------------------------------------------------------------- /ISP/include/ISPItf.h: -------------------------------------------------------------------------------- 1 | // License: GPL-3.0-or-later 2 | /* 3 | * ISP singleton head file. 4 | * 5 | * Copyright (c) 2019 Peng Hao <635945005@qq.com> 6 | */ 7 | 8 | #pragma once 9 | 10 | class ISPItf { 11 | public: 12 | virtual ~ISPItf() {}; 13 | virtual int32_t Process(void *pInfo, ...) = 0; 14 | virtual bool IsActive() = 0; 15 | virtual bool NeedExit() = 0; 16 | virtual void* GetThreadParam() = 0; 17 | }; 18 | 19 | -------------------------------------------------------------------------------- /ISP/include/ISPList.h: -------------------------------------------------------------------------------- 1 | // License: GPL-3.0-or-later 2 | /* 3 | * ISPList is a serial abstract object helps to construct processing 4 | * steps more flexabl. 5 | * 6 | * Copyright (c) 2019 Peng Hao <635945005@qq.com> 7 | */ 8 | 9 | #pragma once 10 | 11 | #include "InterfaceWrapper.h" 12 | #include "ParamManager.h" 13 | #include "Buffer.h" 14 | #include 15 | 16 | using namespace asteroidaxis::isp::resource; 17 | 18 | #define NODE_NAME_MAX_SZIE 15 19 | #define NODE_WAIT_US_MAX 300000 20 | #define NODE_CHECK_GAP_US 100 21 | 22 | enum ProcessType { 23 | PROCESS_BLC = 0, 24 | PROCESS_LSC, 25 | PROCESS_Demosaic, 26 | PROCESS_WB, 27 | PROCESS_CC, 28 | PROCESS_GAMMA, 29 | PROCESS_WNR, 30 | PROCESS_EE, 31 | PROCESS_CODER, 32 | PROCESS_TYPE_NUM 33 | }; 34 | 35 | enum NecProcessType { 36 | NEC_PROCESS_HEAD = PROCESS_TYPE_NUM + 1, 37 | NEC_PROCESS_CST_RAW2RGB, 38 | NEC_PROCESS_CST_RGB2YUV, 39 | NEC_PROCESS_CST_YUV2RGB, 40 | NEC_PROCESS_TYPE_NUM 41 | }; 42 | 43 | enum NodeSwitch { 44 | NODE_OFF = 0, 45 | NODE_ON 46 | }; 47 | 48 | struct NotifyData { 49 | int32_t rt; 50 | }; 51 | 52 | /* NODE */ 53 | struct ISPNodeProperty { 54 | char name[NODE_NAME_MAX_SZIE]; 55 | int32_t type; 56 | int32_t enable; 57 | }; 58 | 59 | template 60 | class ISPNode { 61 | public: 62 | ISPNode(int32_t id); 63 | ISPNode() = delete; 64 | virtual ~ISPNode(); 65 | virtual int32_t GetNodeName(char* name); 66 | virtual int32_t Init(ISPNodeProperty* cfg, T1* input, T2* output); 67 | virtual int32_t Process(); 68 | virtual int32_t Notify(NotifyData data); 69 | virtual int32_t Enable(); 70 | virtual int32_t Disable(); 71 | virtual bool isOn(); 72 | virtual ISPNodeProperty GetProperty(); 73 | 74 | ISPNode* pNext; 75 | 76 | protected: 77 | virtual int32_t WaitResult(); 78 | int32_t mHostId; 79 | bool mInited; 80 | Buffer *pCtrl; 81 | atomic rtTrigger; 82 | ISPNodeProperty mProperty; 83 | }; 84 | 85 | /* NEC NODE */ 86 | template 87 | class ISPNecNode : public ISPNode { 88 | public: 89 | ISPNecNode(int32_t id); 90 | ~ISPNecNode(); 91 | int32_t Init(ISPNodeProperty* cfg, T1* input, T2* output); 92 | int32_t Process(); 93 | }; 94 | 95 | /* Node List */ 96 | enum ISPListState { 97 | ISP_LIST_NEW = 0, 98 | ISP_LIST_INITED, 99 | ISP_LIST_CONFIGED, 100 | ISP_LIST_CONSTRUCTED, 101 | ISP_LIST_RUNNING 102 | }; 103 | 104 | enum StateTransOrientation { 105 | STATE_TRANS_FORWARD = 0, 106 | STATE_TRANS_BACKWARD, 107 | STATE_TRANS_TO_SELF 108 | }; 109 | 110 | struct ISPListProperty { 111 | ISPNodeProperty NodeProperty[PROCESS_TYPE_NUM]; 112 | }; 113 | 114 | struct ISPListHeadProperty { 115 | ISPNodeProperty NecNodeProperty[NEC_PROCESS_TYPE_NUM - NEC_PROCESS_HEAD]; 116 | }; 117 | 118 | template 119 | class ISPList { 120 | public: 121 | ISPList(int32_t id); 122 | ~ISPList(); 123 | int32_t Init(T1* pRawBuf, T2* pRgbBuf, T3* pYuvBuf, T4* pPostBuf); 124 | int32_t SetListConfig(ISPListProperty* pCfg); 125 | int32_t FindNodePropertyIndex(int32_t type, int32_t* index); 126 | int32_t FindNecNodePropertyIndex(int32_t type, int32_t* index); 127 | int32_t CreatISPList(); 128 | int32_t AddNode(int32_t type); 129 | int32_t GetNodeNum(); 130 | int32_t Process(); 131 | int32_t EnableNodebyType(int32_t type); 132 | int32_t DisableNodebyType(int32_t type); 133 | int32_t EnableNecNodebyType(int32_t type); 134 | int32_t DisableNecNodebyType(int32_t type); 135 | int32_t NotifyNodeByType(int32_t type, NotifyData data); 136 | 137 | private: 138 | int32_t CreateNecList(); 139 | int32_t CreateRawList(); 140 | int32_t CreateRgbList(); 141 | int32_t CreateYuvList(); 142 | int32_t CreatePostList(); 143 | int32_t AddNodeToRawTail(ISPNode* pNode); 144 | int32_t AddNodeToRgbTail(ISPNode* pNode); 145 | int32_t AddNodeToYuvTail(ISPNode* pNode); 146 | int32_t AddNodeToPostTail(ISPNode* pNode); 147 | int32_t TriggerRgbProcess(); 148 | int32_t RgbProcess(); 149 | int32_t TriggerYuvProcess(); 150 | int32_t YuvProcess(); 151 | int32_t TriggerPostProcess(); 152 | int32_t PostProcess(); 153 | int32_t StateTransform(int32_t orientation); 154 | 155 | int32_t mId; 156 | ISPNecNode* mRawHead; 157 | ISPNecNode* mRgbHead; 158 | ISPNecNode* mYuvHead; 159 | ISPNecNode* mPostHead; 160 | int32_t mNodeNum; 161 | T1* pRawBuffer; 162 | T2* pRgbBuffer; 163 | T3* pYuvBuffer; 164 | T4* pPostBuffer; 165 | ISPListProperty mProperty; 166 | int32_t mState; 167 | }; 168 | 169 | -------------------------------------------------------------------------------- /ISP/include/ISPListManager.h: -------------------------------------------------------------------------------- 1 | // License: GPL-3.0-or-later 2 | /* 3 | * ISPListManager supports multi ISPList. 4 | * 5 | * Copyright (c) 2019 Peng Hao <635945005@qq.com> 6 | */ 7 | 8 | #pragma once 9 | #include "ISPList.h" 10 | #include 11 | 12 | using namespace std; 13 | 14 | enum ListCfgIndex { 15 | LIST_CFG_DEFAULT = 0, 16 | LIST_CFG_NUM 17 | }; 18 | 19 | class ISPListManagerItf 20 | { 21 | public: 22 | virtual ~ISPListManagerItf() {}; 23 | 24 | virtual int32_t CreateList(uint16_t* pRaw, uint16_t* pBGR, uint8_t* pYUV, uint8_t* pPOST, int32_t cfgIndex, int32_t* id) = 0; 25 | virtual int32_t DestroyListbyId(int32_t id) = 0; 26 | virtual int32_t DestroyAllList() = 0; 27 | virtual int32_t StartById(int32_t id) = 0; 28 | virtual int32_t EnableNodebyType(int32_t id, int32_t type) = 0; 29 | virtual int32_t DisableNodebyType(int32_t id, int32_t type) = 0; 30 | virtual int32_t NotifyList(int32_t id, int32_t type, NotifyData data) = 0; 31 | }; 32 | 33 | class ISPListManager : public ISPListManagerItf 34 | { 35 | public: 36 | static ISPListManager* GetInstance(); 37 | virtual int32_t CreateList(uint16_t* pRaw, uint16_t* pBGR, uint8_t* pYUV, uint8_t* pPOST, int32_t cfgIndex, int32_t* id); 38 | virtual int32_t DestroyListbyId(int32_t id); 39 | virtual int32_t DestroyAllList(); 40 | virtual int32_t StartById(int32_t id); 41 | virtual int32_t EnableNodebyType(int32_t id, int32_t type); 42 | virtual int32_t DisableNodebyType(int32_t id, int32_t type); 43 | virtual int32_t NotifyList(int32_t id, int32_t type, NotifyData data); 44 | 45 | private: 46 | ISPListManager(); 47 | virtual ~ISPListManager(); 48 | int32_t Init(); 49 | ISPList* FindListById(int32_t id); 50 | 51 | ISPListProperty* pISPListConfigs; 52 | map*> mListMap; 53 | mutex mListMapLock; 54 | }; 55 | -------------------------------------------------------------------------------- /ISP/include/ISPVideo.h: -------------------------------------------------------------------------------- 1 | // License: GPL-3.0-or-later 2 | /* 3 | * ISPVideo head file. 4 | * 5 | * Copyright (c) 2019 Peng Hao <635945005@qq.com> 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #include "Utils.h" 15 | #include "ParamManager.h" 16 | 17 | enum VideoState { 18 | VIDEO_STATE_NEW = 0, 19 | VIDEO_STATE_INITED, 20 | VIDEO_STATE_READY, 21 | VIDEO_STATE_LOCK, 22 | VIDEO_STATE_WAIT_FRAME_DONE, 23 | VIDEO_STATE_NUM 24 | }; 25 | 26 | class ISPVideo { 27 | public: 28 | ISPVideo(); 29 | ~ISPVideo(); 30 | 31 | int32_t Init(void* pData); 32 | int32_t CreateThread(void* pThreadParam); 33 | int32_t DestroyThread(); 34 | 35 | int32_t Record(void* pRecorder, int32_t w, int32_t h); 36 | int32_t Wait(); 37 | int32_t Notify(); 38 | 39 | void* pSrc; 40 | 41 | private: 42 | int32_t mState; 43 | 44 | thread mThread; 45 | mutex mMutex; 46 | condition_variable mCond; 47 | }; 48 | 49 | void* VideoEncodeFunc(void* pVideo); 50 | -------------------------------------------------------------------------------- /ISP/include/InterfaceWrapper.h: -------------------------------------------------------------------------------- 1 | // License: GPL-3.0-or-later 2 | /* 3 | * Interface wrapper head file. 4 | * 5 | * Copyright (c) 2019 Peng Hao <635945005@qq.com> 6 | */ 7 | 8 | #pragma once 9 | #include "Utils.h" 10 | #include "BZInterface.h" 11 | #include 12 | 13 | enum ISPLibsId { 14 | ISP_ALG_LIB = 0, 15 | /* TODO: Add lib if need */ 16 | ISP_LIBS_NUM 17 | }; 18 | 19 | struct ISPLibs { 20 | void* pAlgLib; 21 | /* TODO: Add lib if need */ 22 | }; 23 | 24 | struct ISPLibsOps { 25 | BZOps algOPS; 26 | /* TODO: Add lib if need */ 27 | }; 28 | 29 | enum ItfWrapperState { 30 | ITFWRAPPER_STATE_NOT_READY = 0, 31 | ITFWRAPPER_STATE_READY 32 | }; 33 | 34 | class InterfaceWrapperBase { 35 | public: 36 | ~InterfaceWrapperBase() {}; 37 | 38 | virtual int32_t AlgISPListCreate(int32_t id) = 0; 39 | virtual int32_t AlgProcess(int32_t id, int32_t type, void *pCtrl) = 0; 40 | virtual int32_t NotifyMain() = 0; 41 | virtual int32_t IsReady() = 0; 42 | virtual size_t GetAlgParamSize() = 0; 43 | }; 44 | 45 | class InterfaceWrapper : public InterfaceWrapperBase { 46 | public: 47 | static InterfaceWrapper* GetInstance(); 48 | static int32_t RemoveInstance(); 49 | virtual int32_t AlgISPListCreate(int32_t id); 50 | virtual int32_t AlgProcess(int32_t id, int32_t type, void *pCtrl); 51 | virtual int32_t NotifyMain() { return 0; }; 52 | virtual int32_t IsReady(); 53 | virtual size_t GetAlgParamSize(); 54 | 55 | private: 56 | InterfaceWrapper(); 57 | virtual ~InterfaceWrapper(); 58 | int32_t Init(); 59 | int32_t DeInit(); 60 | int32_t LoadLib(int32_t libId, const char* path); 61 | int32_t ReleaseLib(int32_t libId); 62 | int32_t InterfaceInit(int32_t libId); 63 | int32_t InterfaceDeInit(int32_t libId); 64 | int32_t AlgInterfaceInit(); 65 | int32_t AlgInterfaceDeInit(); 66 | static InterfaceWrapper *pItfW; 67 | ISPLibs mLibs; 68 | ISPLibsOps mLibsOPS; 69 | BZParam mISPLibParams; 70 | int32_t mState; 71 | }; 72 | 73 | -------------------------------------------------------------------------------- /ISP/include/Log.h: -------------------------------------------------------------------------------- 1 | // License: GPL-3.0-or-later 2 | /* 3 | * ISP log head file. 4 | * 5 | * Copyright (c) 2019 Peng Hao <635945005@qq.com> 6 | */ 7 | 8 | #pragma once 9 | #include "Utils.h" 10 | 11 | #define LOG_ON 1 12 | #define LOG_LEVEL (0x1 + 0x2 + 0x4 + 0x8) 13 | #define DBG_LEVEL (0x1) 14 | 15 | #define LOG_BUFFER_SIZE 256 16 | #define LOG_BUFFER_PERSERVE_SIZE 2 /* 2 preserve for \0 and \n */ 17 | #define LOG_BUFFER_TIME_SIZE 24 /* 24 char "xxxx-xx-xx xx:xx:xx:xxx " */ 18 | #define LOG_BUFFER_LEFT_SIZE LOG_BUFFER_SIZE - LOG_BUFFER_PERSERVE_SIZE - LOG_BUFFER_TIME_SIZE - sizeof(long long int) 19 | 20 | int32_t LogBase(const char* str, ...); 21 | void LogAddInfo(bool needExtInfo, const char* str, va_list va); 22 | void LogPrint(const char* str, va_list va); 23 | 24 | enum ISPLogMask { 25 | LOG_BASE_MASK = 0x1, 26 | LOG_ERROR_MASK = LOG_BASE_MASK, 27 | LOG_WARN_MASK = LOG_BASE_MASK << 1, 28 | LOG_INFO_MASK = LOG_BASE_MASK << 2, 29 | LOG_DEBUG_MASK = LOG_BASE_MASK << 3, 30 | }; 31 | 32 | enum ISPDbgMask { 33 | DBG_BASE_MASK = 0x1, 34 | DBG_CORE_MASK = DBG_BASE_MASK << 1, 35 | DBG_FILE_MASK = DBG_BASE_MASK << 2, 36 | DBG_PARM_MASK = DBG_BASE_MASK << 3, 37 | DBG_LIST_MASK = DBG_BASE_MASK << 4, 38 | DBG_INTF_MASK = DBG_BASE_MASK << 5, 39 | DBG_MEMY_MASK = DBG_BASE_MASK << 6, 40 | }; 41 | 42 | #ifdef LOG_FOR_DBG 43 | #define LOG_FORMAT " %d:%s: " 44 | #define LOG_FMT_PARAM , __LINE__, __func__ 45 | #else 46 | #define LOG_FORMAT " | " 47 | #define LOG_FMT_PARAM 48 | #endif 49 | 50 | #define LOG_MODULE "ISP " 51 | 52 | #define ISPLogError(on, str, ...) ((on) ? \ 53 | LogBase(LOG_MODULE "E" LOG_FORMAT str LOG_FMT_PARAM, ##__VA_ARGS__) \ 54 | : (0)) 55 | 56 | #define ISPLogWarn(on, str, ...) ((on) ? \ 57 | LogBase(LOG_MODULE "W" LOG_FORMAT str LOG_FMT_PARAM, ##__VA_ARGS__) \ 58 | : (0)) 59 | 60 | #define ISPLogInfo(on, str, ...) ((on) ? \ 61 | LogBase(LOG_MODULE "I" LOG_FORMAT str LOG_FMT_PARAM, ##__VA_ARGS__) \ 62 | : (0)) 63 | 64 | #define ISPLogDebug(on, str, ...) ((on) ? \ 65 | LogBase(LOG_MODULE "D" LOG_FORMAT str LOG_FMT_PARAM, ##__VA_ARGS__) \ 66 | : (0)) 67 | 68 | #define ILOGE(str, ...) ((LOG_ON) ? ISPLogError((LOG_LEVEL & LOG_ERROR_MASK), str, ##__VA_ARGS__) : (0)) 69 | #define ILOGW(str, ...) ((LOG_ON) ? ISPLogWarn((LOG_LEVEL & LOG_WARN_MASK), str, ##__VA_ARGS__) : (0)) 70 | #define ILOGI(str, ...) ((LOG_ON) ? ISPLogInfo((LOG_LEVEL & LOG_INFO_MASK), str, ##__VA_ARGS__) : (0)) 71 | #define ILOGD(str, ...) ((LOG_ON) ? ISPLogDebug((LOG_LEVEL & LOG_DEBUG_MASK), str, ##__VA_ARGS__) : (0)) 72 | 73 | #define ILOGDC(str, ...) ((DBG_LEVEL & DBG_CORE_MASK) ? ILOGD(str, ##__VA_ARGS__) : (0)) 74 | #define ILOGDF(str, ...) ((DBG_LEVEL & DBG_FILE_MASK) ? ILOGD(str, ##__VA_ARGS__) : (0)) 75 | #define ILOGDL(str, ...) ((DBG_LEVEL & DBG_LIST_MASK) ? ILOGD(str, ##__VA_ARGS__) : (0)) 76 | #define ILOGDI(str, ...) ((DBG_LEVEL & DBG_INTF_MASK) ? ILOGD(str, ##__VA_ARGS__) : (0)) 77 | #define ILOGDM(str, ...) ((DBG_LEVEL & DBG_MEMY_MASK) ? ILOGD(str, ##__VA_ARGS__) : (0)) 78 | #define ILOGDP(str, ...) ((DBG_LEVEL & DBG_PARM_MASK) ? ILOGD(str, ##__VA_ARGS__) : (0)) 79 | -------------------------------------------------------------------------------- /ISP/include/MemPool.h: -------------------------------------------------------------------------------- 1 | // License: GPL-3.0-or-later 2 | /* 3 | * Define memory pool. 4 | * 5 | * Copyright (c) 2019 Peng Hao <635945005@qq.com> 6 | */ 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include "Utils.h" 12 | 13 | #if DBG_MEM_OVERWRITE_CHECK_ON 14 | #include 15 | #endif 16 | 17 | using namespace std; 18 | 19 | namespace asteroidaxis::isp::resource { 20 | 21 | #define MEM_BLK_L0_MAX_NUM 16 22 | #define MEM_BLK_L1_MAX_NUM 8 23 | #define MEM_BLK_L2_MAX_NUM 4 24 | 25 | #define MEM_BLK_L0_SIZE 1024 * 1024 26 | #define MEM_BLK_L1_SIZE MEM_BLK_L0_MAX_NUM * MEM_BLK_L0_SIZE 27 | #define MEM_BLK_L2_SIZE MEM_BLK_L1_MAX_NUM * MEM_BLK_L1_SIZE 28 | 29 | #define MEM_BASE_TYPE uchar 30 | 31 | void* ISPAlloc(size_t size, ...); 32 | void* ISPFree(void* pBuf, ...); 33 | 34 | enum MemBlockLevel { 35 | MEM_BLK_L0 = 0, 36 | MEM_BLK_L1, 37 | MEM_BLK_L2, 38 | MEM_BLK_LEVEL_NUM 39 | }; 40 | 41 | struct MemBlockInfo { 42 | int32_t level; 43 | size_t max; 44 | size_t size; 45 | }; 46 | 47 | const MemBlockInfo gMemBlockCfg[MEM_BLK_LEVEL_NUM] = { 48 | {MEM_BLK_L0, MEM_BLK_L0_MAX_NUM, MEM_BLK_L0_SIZE}, 49 | {MEM_BLK_L1, MEM_BLK_L1_MAX_NUM, MEM_BLK_L1_SIZE}, 50 | {MEM_BLK_L2, MEM_BLK_L2_MAX_NUM, MEM_BLK_L2_SIZE}, 51 | }; 52 | 53 | struct MemSegment { 54 | MEM_BASE_TYPE *pAddr; 55 | size_t size; 56 | }; 57 | 58 | struct MemBlock { 59 | MEM_BASE_TYPE *blockBase; 60 | size_t blockSize; 61 | size_t busySize; 62 | list idleList; 63 | list busyList; 64 | }; 65 | 66 | enum MemOperations { 67 | MO_REQ = 0, 68 | MO_REV, 69 | MO_NUM 70 | }; 71 | 72 | #if DBG_MEM_OVERWRITE_CHECK_ON 73 | #define OVERWRITE_CHECK_TIME_GAP_US (100) 74 | #define OVERWRITE_CHECK_SIZE ((8 + 1) * sizeof(MEM_BASE_TYPE)) /* one for '\0' */ 75 | const char gOverwiteSymbol[OVERWRITE_CHECK_SIZE] = 76 | {'@', 'D', 'B', 'G', 77 | 'M', 'E', 'M', '@', 78 | '\0'}; 79 | 80 | struct MemThreadParam { 81 | unordered_map *pSymbolMap; 82 | uint32_t exit; 83 | mutex *pLock; 84 | }; 85 | 86 | void *OverwriteCheckingFunc(void *param); 87 | #endif 88 | 89 | template 90 | class MemoryPoolItf 91 | { 92 | public: 93 | virtual ~MemoryPoolItf() {}; 94 | virtual T *RequireBuffer(size_t TSize) = 0; 95 | virtual T *RevertBuffer(T *pBuffer) = 0; 96 | }; 97 | 98 | template 99 | class MemoryPool : public MemoryPoolItf 100 | { 101 | public: 102 | static MemoryPool *GetInstance(); 103 | virtual T *RequireBuffer(size_t TSize); 104 | virtual T *RevertBuffer(T *pBuffer); 105 | int32_t PrintPool(); 106 | 107 | private: 108 | MemoryPool(); 109 | virtual ~MemoryPool(); 110 | int32_t AllocBlock(int32_t level); 111 | int32_t ReleaseBlock(int32_t level, uint32_t index); 112 | int32_t MemoryReset(MEM_BASE_TYPE *pAddr, size_t size, int32_t operation); 113 | T *RequireFromExistBlock(size_t size); 114 | T *RequireFromNewBlock(size_t size); 115 | T *RevertByLevel(T *pBuf, int32_t level, size_t *size); 116 | MemBlockInfo const *mMemBlockCfg[MEM_BLK_LEVEL_NUM]; 117 | vector mUsageInfo[MEM_BLK_LEVEL_NUM]; 118 | mutex mUsageInfoLock; 119 | #if DBG_MEM_OVERWRITE_CHECK_ON 120 | unordered_map mSymbolMap; 121 | thread dbgThread; 122 | MemThreadParam mThreadParam; 123 | #endif 124 | }; 125 | 126 | template 127 | MemoryPool *MemoryPool::GetInstance() 128 | { 129 | static MemoryPool gInstance; 130 | return &gInstance; 131 | } 132 | 133 | template 134 | MemoryPool::MemoryPool() 135 | { 136 | for (int32_t level = 0; level < MEM_BLK_LEVEL_NUM; level++) { 137 | mMemBlockCfg[level] = &gMemBlockCfg[level]; 138 | } 139 | 140 | #if DBG_MEM_OVERWRITE_CHECK_ON 141 | mThreadParam.pSymbolMap = &mSymbolMap; 142 | mThreadParam.exit = 0; 143 | mThreadParam.pLock = &mUsageInfoLock; 144 | dbgThread = thread(OverwriteCheckingFunc, (void *)&mThreadParam); 145 | #endif 146 | } 147 | 148 | template 149 | MemoryPool::~MemoryPool() 150 | { 151 | #if DBG_MEM_OVERWRITE_CHECK_ON 152 | mThreadParam.exit = 1; 153 | dbgThread.join(); 154 | mThreadParam.pLock = NULL; 155 | #endif 156 | 157 | for (int32_t level = 0; level < MEM_BLK_LEVEL_NUM; level++) { 158 | while(mUsageInfo[level].size()) { 159 | ReleaseBlock(level, 0); 160 | } 161 | mMemBlockCfg[level] = NULL; 162 | } 163 | PrintPool(); 164 | } 165 | 166 | template 167 | int32_t MemoryPool::AllocBlock(int32_t level) 168 | { 169 | int32_t rt = ISP_SUCCESS; 170 | 171 | if (mUsageInfo[level].size() >= mMemBlockCfg[level]->max) { 172 | rt = ISP_INVALID_PARAM; 173 | ILOGE("Level:%d overflow", level); 174 | PrintPool(); 175 | return rt; 176 | } 177 | 178 | MemBlock blk = { 0 }; 179 | blk.blockBase = new MEM_BASE_TYPE[mMemBlockCfg[level]->size]; 180 | if (!blk.blockBase) { 181 | rt = ISP_MEMORY_ERROR; 182 | ILOGE("Level:%d alloc %u failed!", level, mMemBlockCfg[level]->size); 183 | return rt; 184 | } 185 | 186 | { 187 | unique_lock lock(mUsageInfoLock); 188 | blk.blockSize = mMemBlockCfg[level]->size; 189 | memset(blk.blockBase, 0, blk.blockSize); 190 | blk.busySize = 0; 191 | MemSegment idleSeg = { 0 }; 192 | idleSeg.pAddr = blk.blockBase; 193 | idleSeg.size = blk.blockSize; 194 | blk.idleList.push_back(idleSeg); 195 | mUsageInfo[level].push_back(blk); 196 | ILOGDM("L%d B%d: alloc %u", level, mUsageInfo[level].size() - 1, blk.blockSize); 197 | } 198 | 199 | return rt; 200 | } 201 | 202 | template 203 | int32_t MemoryPool::ReleaseBlock(int32_t level, uint32_t index) 204 | { 205 | int32_t rt = ISP_SUCCESS; 206 | 207 | if (index >= mUsageInfo[level].size()) { 208 | rt = ISP_INVALID_PARAM; 209 | ILOGE("Invalid block index:%d", index); 210 | return rt; 211 | } 212 | 213 | { 214 | unique_lock lock(mUsageInfoLock); 215 | MEM_BASE_TYPE *p = mUsageInfo[level][index].blockBase; 216 | if (!p) { 217 | rt = ISP_FAILED; 218 | ILOGE("Fatal ERROR: cannot find block base"); 219 | return rt; 220 | } 221 | 222 | while(!mUsageInfo[level][index].idleList.empty()) { 223 | mUsageInfo[level][index].idleList.pop_back(); 224 | } 225 | 226 | while(!mUsageInfo[level][index].busyList.empty()) { 227 | auto seg = mUsageInfo[level][index].busyList.end(); 228 | seg--; 229 | rt = MemoryReset(seg->pAddr, seg->size, MO_REV); 230 | ILOGW("Revert busy buf (addf:%p size:%u)", seg->pAddr, seg->size); 231 | mUsageInfo[level][index].busyList.pop_back(); 232 | } 233 | 234 | delete[] p; 235 | size_t blkSize = mUsageInfo[level][index].blockSize; 236 | mUsageInfo[level][index].blockSize = 0; 237 | mUsageInfo[level][index].busySize = 0; 238 | mUsageInfo[level].erase(mUsageInfo[level].begin() + index); 239 | ILOGDM("L%d B%d: release %u", level, index, blkSize); 240 | if (!mUsageInfo[level].size()) { 241 | ILOGDM("L%d all released", level); 242 | } 243 | } 244 | 245 | return rt; 246 | } 247 | 248 | template 249 | int32_t MemoryPool::PrintPool() 250 | { 251 | int32_t rt = ISP_SKIP; 252 | int32_t segCnt = 0; 253 | 254 | for (int32_t level = 0; level < MEM_BLK_LEVEL_NUM; level++) { 255 | if (!mUsageInfo[level].empty()) { 256 | rt = ISP_SUCCESS; 257 | break; 258 | } 259 | } 260 | 261 | if (rt != ISP_SUCCESS) { 262 | return rt; 263 | } 264 | 265 | ILOGI("<<<<<<<<<<<<<<<<<<<<<< MEM STATE >>>>>>>>>>>>>>>>>>>>>>>"); 266 | for (int32_t level = 0; level < MEM_BLK_LEVEL_NUM; level++) { 267 | for (auto blk = mUsageInfo[level].begin(); blk != mUsageInfo[level].end(); blk++) { 268 | ILOGI("L%d B%d(%u) addr:%-8p size:%-8u used:%.2f%%", 269 | level, 270 | blk - mUsageInfo[level].begin(), 271 | mUsageInfo[level].size(), 272 | blk->blockBase, 273 | blk->blockSize, 274 | (float)blk->busySize * 100 / blk->blockSize); 275 | segCnt = 0; 276 | for (auto seg = blk->idleList.begin(); seg != blk->idleList.end(); seg++) { 277 | ILOGI(" Idle: S%d(%u) addr:%-8p size:%-8u", 278 | segCnt, 279 | blk->idleList.size(), 280 | seg->pAddr, 281 | seg->size); 282 | segCnt++; 283 | } 284 | segCnt = 0; 285 | for (auto seg = blk->busyList.begin(); seg != blk->busyList.end(); seg++) { 286 | ILOGI(" Busy: S%d(%u) addr:%-8p size:%-8u", 287 | segCnt, 288 | blk->busyList.size(), 289 | seg->pAddr, 290 | seg->size); 291 | segCnt++; 292 | } 293 | } 294 | } 295 | 296 | return rt; 297 | } 298 | 299 | template 300 | T *MemoryPool::RequireBuffer(size_t TSize) 301 | { 302 | T *pBuffer = NULL; 303 | size_t size = TSize * sizeof(T); 304 | #if DBG_MEM_OVERWRITE_CHECK_ON 305 | size += OVERWRITE_CHECK_SIZE; 306 | #endif 307 | 308 | if (!size || size > mMemBlockCfg[MEM_BLK_LEVEL_NUM - 1]->size) { 309 | ILOGE("Require invalid size:C%u (N%u x T%u) ", size, sizeof(T), TSize); 310 | return NULL; 311 | } 312 | 313 | pBuffer = RequireFromExistBlock(size); 314 | if (!pBuffer) { 315 | pBuffer = RequireFromNewBlock(size); 316 | } 317 | 318 | if (!pBuffer) { 319 | ILOGE("Faild to require buffer C%u (N%u x T%u)", size, sizeof(T), TSize); 320 | PrintPool(); 321 | } else { 322 | ILOGDM("C%u (N%u x T%u) is required", size, sizeof(T), TSize); 323 | } 324 | 325 | return pBuffer; 326 | } 327 | 328 | template 329 | T *MemoryPool::RevertBuffer(T *pBuffer) 330 | { 331 | size_t size = 0; 332 | 333 | if (!pBuffer) { 334 | ILOGE("Invalid buffer:%p", pBuffer); 335 | return pBuffer; 336 | } 337 | 338 | for (int32_t level = 0; level < MEM_BLK_LEVEL_NUM; level++) { 339 | pBuffer = RevertByLevel(pBuffer, level, &size); 340 | if (!pBuffer) { 341 | ILOGDM("C%u (N%u x T%u) is reverted", size, sizeof(T), size / sizeof(T)); 342 | break; 343 | } else if (level == MEM_BLK_LEVEL_NUM - 1) { 344 | ILOGE("Invalid buffer:%p not in pool", pBuffer); 345 | PrintPool(); 346 | } 347 | } 348 | 349 | return pBuffer; 350 | } 351 | 352 | template 353 | T *MemoryPool::RequireFromExistBlock(size_t size) 354 | { 355 | T *pBuffer = NULL; 356 | 357 | { 358 | unique_lock lock(mUsageInfoLock); 359 | for (int32_t level = 0; level < MEM_BLK_LEVEL_NUM; level++) { 360 | if (size > mMemBlockCfg[level]->size) { 361 | continue; 362 | } 363 | for (auto blk = mUsageInfo[level].begin(); blk != mUsageInfo[level].end(); blk++) { 364 | if (size > blk->blockSize - blk->busySize) { 365 | continue; 366 | } 367 | for (auto seg = blk->idleList.begin(); seg != blk->idleList.end(); seg++) { 368 | if (size <= seg->size) { 369 | MemSegment idleSeg = { 0 }; 370 | MemSegment busySeg = { 0 }; 371 | busySeg.pAddr = seg->pAddr; 372 | busySeg.size = size; 373 | MemoryReset(busySeg.pAddr, busySeg.size, MO_REQ); 374 | blk->busyList.push_front(busySeg); 375 | 376 | pBuffer = static_cast(busySeg.pAddr); 377 | 378 | idleSeg.pAddr = seg->pAddr + size; 379 | idleSeg.size = seg->size - size; 380 | blk->idleList.erase(seg); 381 | blk->idleList.push_front(idleSeg); 382 | 383 | blk->busySize += size; 384 | return pBuffer; 385 | } 386 | } 387 | } 388 | } 389 | } 390 | 391 | return pBuffer; 392 | } 393 | 394 | template 395 | T *MemoryPool::RequireFromNewBlock(size_t size) 396 | { 397 | T *pBuffer = NULL; 398 | 399 | for (int32_t level = 0; level < MEM_BLK_LEVEL_NUM; level++) { 400 | if (size > mMemBlockCfg[level]->size) { 401 | if (level == MEM_BLK_LEVEL_NUM - 1) { 402 | ILOGE("Reguire buffer(%u) failed!", size); 403 | return NULL; 404 | } 405 | } else { 406 | if (SUCCESS(AllocBlock(level))) { 407 | unique_lock lock(mUsageInfoLock); 408 | MemBlock* blk = &mUsageInfo[level].back(); 409 | list::iterator seg = blk->idleList.end(); 410 | seg--; 411 | 412 | MemSegment idleSeg = { 0 }; 413 | MemSegment busySeg = { 0 }; 414 | busySeg.pAddr = seg->pAddr; 415 | busySeg.size = size; 416 | MemoryReset(busySeg.pAddr, busySeg.size, MO_REQ); 417 | blk->busyList.push_front(busySeg); 418 | 419 | pBuffer = static_cast(busySeg.pAddr); 420 | 421 | idleSeg.pAddr = seg->pAddr + size; 422 | idleSeg.size = seg->size - size; 423 | blk->idleList.erase(seg); 424 | blk->idleList.push_front(idleSeg); 425 | 426 | blk->busySize += size; 427 | return pBuffer; 428 | } 429 | } 430 | } 431 | 432 | return pBuffer; 433 | } 434 | 435 | template 436 | T *MemoryPool::RevertByLevel(T *pBuf, int32_t level, size_t *size) 437 | { 438 | if (level >= MEM_BLK_LEVEL_NUM) { 439 | ILOGE("Invalid level:%d", level); 440 | return pBuf; 441 | } 442 | 443 | if (!size) { 444 | ILOGE("size is null"); 445 | return pBuf; 446 | } 447 | 448 | { 449 | unique_lock lock(mUsageInfoLock); 450 | for (auto blk = mUsageInfo[level].begin(); blk != mUsageInfo[level].end(); blk++) { 451 | if (static_cast(pBuf) < blk->blockBase || 452 | static_cast(pBuf) >= blk->blockBase + blk->blockSize) { 453 | continue; 454 | } 455 | size_t cnt = 1; 456 | for (auto seg = blk->busyList.begin(); seg != blk->busyList.end(); seg++) { 457 | if (static_cast(pBuf) == seg->pAddr) { 458 | bool isNewSeg = true; 459 | *size = seg->size; 460 | MemoryReset(seg->pAddr, seg->size, MO_REV); 461 | 462 | MemSegment tmpSeg = { 0 }; 463 | tmpSeg.pAddr = seg->pAddr; 464 | tmpSeg.size = seg->size; 465 | 466 | /* 1. Forward merge */ 467 | MEM_BASE_TYPE *nextAddr = tmpSeg.pAddr + tmpSeg.size; 468 | for (auto idleSeg = blk->idleList.begin(); idleSeg != blk->idleList.end(); idleSeg++) { 469 | if (nextAddr == idleSeg->pAddr) { 470 | tmpSeg.size += idleSeg->size; 471 | blk->idleList.erase(idleSeg); 472 | break; 473 | } 474 | } 475 | 476 | /* 2. Backward merge */ 477 | for (auto idleSeg = blk->idleList.begin(); idleSeg != blk->idleList.end(); idleSeg++) { 478 | MEM_BASE_TYPE *lastAddr = idleSeg->pAddr + idleSeg->size; 479 | if (lastAddr == tmpSeg.pAddr) { 480 | idleSeg->size += tmpSeg.size; 481 | isNewSeg = false; 482 | break; 483 | } 484 | } 485 | 486 | if (isNewSeg) { 487 | blk->idleList.push_front(tmpSeg); 488 | } 489 | blk->busyList.erase(seg); 490 | blk->busySize -= *size; 491 | pBuf = NULL; 492 | return pBuf; 493 | } else if (cnt == blk->busyList.size()) { 494 | ILOGE("Fatal Error: cannot match buffer:%p in segment", pBuf); 495 | PrintPool(); 496 | return pBuf; 497 | } 498 | cnt++; 499 | } 500 | } 501 | } 502 | 503 | return pBuf; 504 | } 505 | 506 | template 507 | int32_t MemoryPool::MemoryReset(MEM_BASE_TYPE *pAddr, size_t size, int32_t operation) 508 | { 509 | int32_t rt = ISP_SUCCESS; 510 | 511 | if (operation == MO_REQ) { 512 | #if DBG_MEM_OVERWRITE_CHECK_ON 513 | memcpy(pAddr + size - OVERWRITE_CHECK_SIZE, gOverwiteSymbol, OVERWRITE_CHECK_SIZE); 514 | mSymbolMap.insert(pair(pAddr, 515 | pAddr + size - OVERWRITE_CHECK_SIZE)); 516 | #endif 517 | /* No need to reset mem for require buffer */ 518 | } else if (operation == MO_REV) { 519 | #if DBG_MEM_OVERWRITE_CHECK_ON 520 | mSymbolMap.erase(pAddr); 521 | #endif 522 | memset(pAddr, 0, size); 523 | } else { 524 | rt = ISP_FAILED; 525 | ILOGE("Invalid operation:%d", operation); 526 | } 527 | 528 | return rt; 529 | } 530 | 531 | } 532 | -------------------------------------------------------------------------------- /ISP/include/ParamManager.h: -------------------------------------------------------------------------------- 1 | // License: GPL-3.0-or-later 2 | /* 3 | * ParamManager aims to manage multi params. 4 | * 5 | * Copyright (c) 2019 Peng Hao <635945005@qq.com> 6 | */ 7 | 8 | #pragma once 9 | #include 10 | #include 11 | #include "Utils.h" 12 | #include "Settings.h" 13 | #include "Buffer.h" 14 | 15 | using namespace std; 16 | using namespace asteroidaxis::isp::resource; 17 | 18 | #define CHECK_PACKAGED(format) \ 19 | (((format) == UNPACKAGED_RAW10_LSB) || \ 20 | ((format) == UNPACKAGED_RAW10_MSB)) ? 0 : 1 21 | 22 | #define PIXELS2WORDS_MIPI_PACKAGED(pixelNum, bitspp) \ 23 | (((bitspp) < BITS_PER_WORD) ? 0 : \ 24 | (((bitspp) == BITS_PER_WORD) ? (pixelNum) : \ 25 | ((pixelNum) * (bitspp) / BITS_PER_WORD))) 26 | 27 | #define PIXELS2WORDS_UNPACKAGED(pixelNum, bitspp) \ 28 | (((bitspp) < BITS_PER_WORD) ? 0 : \ 29 | (((bitspp) == BITS_PER_WORD) ? (pixelNum) : \ 30 | ((pixelNum) * 2))) 31 | 32 | #define PIXELS2WORDS(pixelNum, bitspp, packaged) \ 33 | (((bitspp) % 2 || (bitspp) > 2 * BITS_PER_WORD || (bitspp) <= 0) ? 0 : \ 34 | ((packaged) ? PIXELS2WORDS_MIPI_PACKAGED(pixelNum, bitspp) : \ 35 | PIXELS2WORDS_UNPACKAGED(pixelNum, bitspp))) 36 | 37 | #define ALIGN(x, align) \ 38 | (align) ? (((x) + (align) - 1) & (~((align) - 1))) : (x) 39 | 40 | #define ALIGNx(pixelNum, bitspp, packaged, align) \ 41 | ALIGN(PIXELS2WORDS(pixelNum, bitspp, packaged), align) 42 | 43 | enum MediaType { 44 | IMAGE_MEDIA = 0, 45 | VIDEO_MEDIA, 46 | IMAGE_AND_VIDEO_MEDIA, 47 | MEDIA_TYPE_NUM 48 | }; 49 | 50 | enum SettingIndex { 51 | SETTING_1920x1080_D65_1000Lux = 0, 52 | SETTING_INDEX_NUM 53 | }; 54 | 55 | enum ParamMgrSate { 56 | PM_STATE_UNINIT = 0, 57 | PM_STATE_MEDIA_INFO_SET, 58 | PM_STATE_NUM 59 | }; 60 | 61 | enum RawFormat { 62 | ANDROID_RAW10 = 0, 63 | ORDINAL_RAW10, 64 | UNPACKAGED_RAW10_LSB, 65 | UNPACKAGED_RAW10_MSB, 66 | RAW_FORMAT_NUM 67 | }; 68 | 69 | enum ColorSpace { 70 | CS_Bayer = 0, 71 | CS_YUV, 72 | CS_RGB, 73 | CS_NUM 74 | }; 75 | 76 | enum DataPackageType { 77 | DPT_Packaged = 0, 78 | DPT_Unpackaged, 79 | DPT_NUM 80 | }; 81 | 82 | enum BayerOrder { 83 | BO_BGGR = 0, 84 | BO_GBRG, 85 | BO_GRBG, 86 | BO_RGGB, 87 | BO_NUM 88 | }; 89 | 90 | struct ImgInfo 91 | { 92 | int32_t width; 93 | int32_t height; 94 | int32_t bitspp; 95 | int32_t stride; 96 | int32_t rawFormat; 97 | int32_t bayerOrder; 98 | }; 99 | 100 | struct VideoInfo 101 | { 102 | int32_t fps; 103 | int32_t frameNum; 104 | }; 105 | 106 | struct MediaInfo 107 | { 108 | ImgInfo img; 109 | VideoInfo video; 110 | int32_t type; 111 | }; 112 | 113 | struct ISPParamInfo { 114 | int32_t id; 115 | int32_t settingIndex; 116 | Buffer *buf; 117 | }; 118 | 119 | struct ISPSetting { 120 | void *pBlc; 121 | void *pLsc; 122 | void *pWb; 123 | void *pCc; 124 | void *pGamma; 125 | void *pWnr; 126 | void *pEe; 127 | }; 128 | 129 | class ISPParamManagerItf { 130 | public: 131 | virtual ~ISPParamManagerItf() {}; 132 | 133 | virtual int32_t SetMediaInfo(MediaInfo* info) = 0; 134 | virtual int32_t GetImgDimension(int32_t* width, int32_t* height) = 0; 135 | virtual int32_t GetVideoFPS(int32_t* fps) = 0; 136 | virtual int32_t GetVideoFrameNum(int32_t* num) = 0; 137 | virtual int32_t CreateParam(int32_t hostId, int32_t settingId) = 0; 138 | virtual int32_t DeleteParam(int32_t hostId) = 0; 139 | virtual void* GetParam(int32_t id, int32_t type) = 0; 140 | }; 141 | 142 | class ISPParamManager : public ISPParamManagerItf { 143 | public: 144 | static ISPParamManager* GetInstance(); 145 | virtual int32_t SetMediaInfo(MediaInfo* info); 146 | virtual int32_t GetImgDimension(int32_t* width, int32_t* height); 147 | virtual int32_t GetVideoFPS(int32_t* fps); 148 | virtual int32_t GetVideoFrameNum(int32_t* num); 149 | virtual int32_t CreateParam(int32_t hostId, int32_t settingId); 150 | virtual int32_t DeleteParam(int32_t hostId); 151 | virtual void* GetParam(int32_t id, int32_t type); 152 | 153 | private: 154 | ISPParamManager(); 155 | virtual ~ISPParamManager(); 156 | 157 | ISPParamInfo *GetParamInfoById(int id); 158 | void* GetParamByType(ISPParamInfo *pInfo, int32_t type); 159 | int32_t FillinParam(ISPParamInfo *pParamInfo); 160 | int32_t FillinParamByType(ISPParamInfo *pInfo, int32_t type); 161 | int32_t SetImgInfo(ImgInfo* info); 162 | int32_t SetVideoInfo(VideoInfo* info); 163 | int32_t FillinImgInfo(void *pInfo); 164 | int32_t FillinBLCParam(void *pParam, ISPSetting *pSetting); 165 | int32_t FillinLSCParam(void *pParam, ISPSetting *pSetting); 166 | int32_t FillinWBParam(void *pParam, ISPSetting *pSetting); 167 | int32_t FillinCCParam(void *pParam, ISPSetting *pSetting); 168 | int32_t FillinGAMMAParam(void *pParam, ISPSetting *pSetting); 169 | int32_t FillinWNRParam(void *pParam, ISPSetting *pSetting); 170 | int32_t FillinEEParam(void *pParam, ISPSetting *pSetting); 171 | void DumpParamInfo(); 172 | 173 | mutex mParamListLock; 174 | list mActiveParamList; 175 | MediaInfo mMediaInfo; 176 | int32_t mState; 177 | }; 178 | -------------------------------------------------------------------------------- /ISP/include/Settings.h: -------------------------------------------------------------------------------- 1 | // License: GPL-3.0-or-later 2 | /* 3 | * Define some param struct which is used in ISP. 4 | * 5 | * Copyright (c) 2019 Peng Hao <635945005@qq.com> 6 | */ 7 | 8 | #pragma once 9 | 10 | #define CCM_WIDTH 3 11 | #define CCM_HEIGHT 3 12 | #define LSC_LUT_WIDTH 17 13 | #define LSC_LUT_HEIGHT 13 14 | #define GAMMA_LUT_SIZE 1024 15 | 16 | struct BlcSetting { 17 | uint32_t bitNum; 18 | uint16_t BlcDefaultValue; 19 | }; 20 | 21 | struct LscSetting { 22 | float gainCh1[LSC_LUT_HEIGHT][LSC_LUT_WIDTH]; 23 | float gainCh2[LSC_LUT_HEIGHT][LSC_LUT_WIDTH]; 24 | float gainCh3[LSC_LUT_HEIGHT][LSC_LUT_WIDTH]; 25 | float gainCh4[LSC_LUT_HEIGHT][LSC_LUT_WIDTH]; 26 | }; 27 | 28 | struct WbGain { 29 | float rGain; 30 | float gGain; 31 | float bGain; 32 | }; 33 | 34 | struct WbSetting { 35 | bool Wb1stGamma2rd; 36 | WbGain gainType1; 37 | WbGain gainType2; 38 | }; 39 | 40 | struct CcSetting { 41 | float ccm[CCM_HEIGHT][CCM_WIDTH]; 42 | }; 43 | 44 | struct GammaSetting { 45 | uint16_t lut[GAMMA_LUT_SIZE]; 46 | }; 47 | 48 | struct WnrSetting { 49 | int32_t ch1Threshold[3]; 50 | int32_t ch2Threshold[3]; 51 | int32_t ch3Threshold[3]; 52 | }; 53 | 54 | struct EeSetting { 55 | float alpha; 56 | int32_t coreSize; 57 | int32_t sigma; 58 | }; 59 | -------------------------------------------------------------------------------- /ISP/include/Utils.h: -------------------------------------------------------------------------------- 1 | // License: GPL-3.0-or-later 2 | /* 3 | * Common fuction head file. 4 | * 5 | * Copyright (c) 2019 Peng Hao <635945005@qq.com> 6 | */ 7 | 8 | #pragma once 9 | #if defined __linux__ 10 | #define LINUX_SYSTEM 11 | #elif defined _WIN32 12 | #define WIN32_SYSTEM 13 | #endif 14 | 15 | /* Regular lib */ 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include "Log.h" 27 | 28 | #ifdef LINUX_SYSTEM 29 | #include 30 | #elif defined WIN32_SYSTEM 31 | #endif 32 | 33 | #define VERSION 0 34 | #define SUB_VERSION 1 35 | 36 | typedef unsigned char uchar; 37 | 38 | #define SERIAL_NUM_TAIL(n) ((n) == 1 ? "st" : \ 39 | ((n) == 2 ? "nd" : \ 40 | ((n) == 3 ? "rd" : "th"))) 41 | 42 | #define SYSTEM_YEAR_OFFSET 1900 43 | #define SYSTEM_MONTH_OFFSET 1 44 | #define LOCAL_TIME_ZOOM_OFFSET 8 /* Beijing time zoom */ 45 | 46 | #define BITS_PER_WORD 8 47 | #define FILE_PATH_MAX_SIZE 255 48 | 49 | #define SUCCESS(rt) ((rt) >= 0) ? true : false 50 | 51 | enum ISPResult { 52 | ISP_TIMEOUT = -5, 53 | ISP_INVALID_PARAM = -4, 54 | ISP_MEMORY_ERROR = -3, 55 | ISP_STATE_ERROR = -2, 56 | ISP_FAILED = -1, 57 | ISP_SUCCESS = 0, 58 | ISP_SKIP = 1 59 | }; 60 | 61 | using namespace std; 62 | 63 | char Int2Char(int32_t i); 64 | int32_t Char2Int(char c); 65 | void getTimeChar(char* hours, char* minutes, char* seconds, char* milliseconds); 66 | void getTimeInt(int32_t* hours, int32_t* minutes, int32_t* seconds, int32_t* milliseconds); 67 | void getDateInt(int32_t* years, int32_t* months, int32_t* days); 68 | void getTimeWithDateInt(int32_t* years, int32_t* months, int32_t* days, int32_t* hours, int32_t* minutes, int32_t* seconds, int32_t* milliseconds); 69 | void getTimeWithDateChar(char* years, char* months, char* days, char* hours, char* minutes, char* seconds, char* milliseconds); 70 | int32_t CharNum2IntNum(char* pC); 71 | -------------------------------------------------------------------------------- /ISP/interface/BZInterface.h: -------------------------------------------------------------------------------- 1 | // License: GPL-3.0-or-later 2 | /* 3 | * BoZhi exposed library interface. 4 | * 5 | * Copyright (c) 2019 Peng Hao <635945005@qq.com> 6 | */ 7 | 8 | #pragma once 9 | #include 10 | #include 11 | 12 | #define CCM_WIDTH 3 13 | #define CCM_HEIGHT 3 14 | #define LSC_LUT_WIDTH 17 15 | #define LSC_LUT_HEIGHT 13 16 | #define GAMMA_LUT_SIZE 1024 17 | 18 | #define LIB_FUNCS_NUM 3 19 | #define SYMBLE_SIZE_MAX 255 20 | 21 | extern "C" { 22 | typedef void (*LIB_VOID_FUNC_ADDR)(void*, ...); 23 | } 24 | 25 | enum BZRawFormat { 26 | BZ_ANDROID_RAW10 = 0, 27 | BZ_ORDINAL_RAW10, 28 | BZ_UNPACKAGED_RAW10_LSB, 29 | BZ_UNPACKAGED_RAW10_MSB, 30 | BZ_RAW_FORMAT_NUM 31 | }; 32 | 33 | enum BZBayerOrder { 34 | BZ_BO_BGGR = 0, 35 | BZ_BO_GBRG, 36 | BZ_BO_GRBG, 37 | BZ_BO_RGGB, 38 | BZ_BO_NUM 39 | }; 40 | 41 | enum BZParamType { 42 | BZ_PARAM_TYPE_IMAGE_INFO = 0, 43 | BZ_PARAM_TYPE_BLC, 44 | BZ_PARAM_TYPE_LSC, 45 | BZ_PARAM_TYPE_DMC, 46 | BZ_PARAM_TYPE_WB, 47 | BZ_PARAM_TYPE_CC, 48 | BZ_PARAM_TYPE_Gamma, 49 | BZ_PARAM_TYPE_WNR, 50 | BZ_PARAM_TYPE_EE, 51 | BZ_PARAM_TYPE_RAW2RGB, 52 | BZ_PARAM_TYPE_RGB2YUV, 53 | BZ_PARAM_TYPE_YUV2RGB, 54 | BZ_PARAM_TYPE_NUM 55 | }; 56 | 57 | struct BZImgInfo 58 | { 59 | int32_t width; 60 | int32_t height; 61 | int32_t bitspp; 62 | int32_t stride; 63 | int32_t rawFormat; 64 | int32_t bayerOrder; 65 | }; 66 | 67 | struct BZBlcParam { 68 | uint16_t offset; 69 | }; 70 | 71 | struct BZLscParam { 72 | float gainCh1[LSC_LUT_HEIGHT * LSC_LUT_WIDTH]; 73 | float gainCh2[LSC_LUT_HEIGHT * LSC_LUT_WIDTH]; 74 | float gainCh3[LSC_LUT_HEIGHT * LSC_LUT_WIDTH]; 75 | float gainCh4[LSC_LUT_HEIGHT * LSC_LUT_WIDTH]; 76 | }; 77 | 78 | struct BZWbParam { 79 | float rGain; 80 | float gGain; 81 | float bGain; 82 | }; 83 | 84 | struct BZCcParam { 85 | float ccm[CCM_HEIGHT * CCM_WIDTH]; 86 | }; 87 | 88 | struct BZGammaParam { 89 | uint16_t lut[GAMMA_LUT_SIZE]; 90 | }; 91 | 92 | struct BZWnrParam { 93 | int32_t ch1Threshold[3]; 94 | int32_t ch2Threshold[3]; 95 | int32_t ch3Threshold[3]; 96 | }; 97 | 98 | struct BZEeParam { 99 | float alpha; 100 | int32_t coreSize; 101 | int32_t sigma; 102 | }; 103 | 104 | struct BZParam { 105 | BZImgInfo info; 106 | BZBlcParam blc; 107 | BZLscParam lsc; 108 | BZWbParam wb; 109 | BZCcParam cc; 110 | BZGammaParam gamma; 111 | BZWnrParam wnr; 112 | BZEeParam ee; 113 | }; 114 | 115 | struct ISPUtilsFuncs { 116 | int32_t (*Log) (const char* str, ...); 117 | void (*DumpDataInt) (void* pData, ...); 118 | void* (*Alloc) (size_t size, ...); 119 | void* (*Free) (void* pBuf, ...); 120 | }; 121 | 122 | struct ISPCallbacks { 123 | void (*ISPNotify) (int32_t argNum, ...); 124 | ISPUtilsFuncs UtilsFuncs; 125 | }; 126 | 127 | enum BZCmd { 128 | BZ_CMD_CREATE_PROC = 0, 129 | BZ_CMD_PROCESS, 130 | BZ_CMD_NUM, 131 | }; 132 | 133 | enum BZMsg { 134 | MSG_D0 = 0, 135 | MSG_D1, 136 | MSG_D2, 137 | MSG_D3, 138 | MSG_D4, 139 | MSG_D5, 140 | MSG_D6, 141 | MSG_D7, 142 | MSG_D8, 143 | MSG_D9, 144 | MSG_NUM_MAX 145 | }; 146 | 147 | struct BZCtrl { 148 | bool en; 149 | void *pInfo; 150 | void *pSrc; 151 | void *pDst; 152 | void *pParam; 153 | }; 154 | 155 | struct BZOps 156 | { 157 | int32_t (*BZEvent) (uint32_t *msg); 158 | }; 159 | 160 | 161 | -------------------------------------------------------------------------------- /ISP/src/Buffer.cpp: -------------------------------------------------------------------------------- 1 | // License: GPL-3.0-or-later 2 | /* 3 | * ISP buffer implementation. 4 | * 5 | * Copyright (c) 2023 Peng Hao <635945005@qq.com> 6 | */ 7 | 8 | #include "Utils.h" 9 | #include "Buffer.h" 10 | #include "MemPool.h" 11 | 12 | namespace asteroidaxis::isp::resource { 13 | 14 | Buffer::Buffer(void* addr, size_t size) 15 | { 16 | mAddr = addr; 17 | mSize = size; 18 | } 19 | 20 | Buffer::~Buffer() 21 | { 22 | if (mAddr) { 23 | mAddr = MemoryPool::GetInstance()->RevertBuffer( 24 | static_cast(mAddr)); 25 | } 26 | mSize = 0; 27 | } 28 | 29 | Buffer *Buffer::Alloc(size_t size) 30 | { 31 | Buffer *pBuf = new Buffer( 32 | MemoryPool::GetInstance()->RequireBuffer(size), 33 | size); 34 | BufferMgr::GetInstance()->PushBufferToList(pBuf); 35 | return pBuf; 36 | } 37 | 38 | void Buffer::Free(Buffer **ppBuf) 39 | { 40 | if (!ppBuf || !*ppBuf) { 41 | return; 42 | } 43 | BufferMgr::GetInstance()->PopBufferFromList(*ppBuf); 44 | (*ppBuf)->CheckFreeDone(MemoryPool::GetInstance()->RevertBuffer( 45 | static_cast((*ppBuf)->Addr()))); 46 | delete *ppBuf; 47 | *ppBuf = NULL; 48 | } 49 | 50 | void *Buffer::Addr() 51 | { 52 | return mAddr; 53 | } 54 | 55 | size_t Buffer::Size() 56 | { 57 | return mSize; 58 | } 59 | 60 | void Buffer::Reset() 61 | { 62 | if (mAddr) { 63 | memset(mAddr, 0, mSize); 64 | } 65 | } 66 | 67 | void Buffer::CheckFreeDone(void *pAddr) 68 | { 69 | if (!pAddr) { 70 | mAddr = NULL; 71 | mSize = 0; 72 | } 73 | } 74 | 75 | BufferMgr *BufferMgr::GetInstance() 76 | { 77 | static BufferMgr gInstance; 78 | return &gInstance; 79 | } 80 | 81 | BufferMgr::BufferMgr() 82 | { 83 | } 84 | 85 | BufferMgr::~BufferMgr() 86 | { 87 | ReleaseAllBuffer(); 88 | } 89 | 90 | int32_t BufferMgr::PushBufferToList(Buffer *pBuf) 91 | { 92 | int32_t rt = ISP_SUCCESS; 93 | if (!pBuf) { 94 | rt = ISP_INVALID_PARAM; 95 | ILOGE("Buffer is null"); 96 | return rt; 97 | } 98 | 99 | if (!pBuf->Addr()) { 100 | rt = ISP_INVALID_PARAM; 101 | ILOGE("Buffer is invalid"); 102 | return rt; 103 | } 104 | 105 | { 106 | unique_lock lock(bufListLock); 107 | bufList.push_back(pBuf); 108 | } 109 | return rt; 110 | } 111 | 112 | int32_t BufferMgr::PopBufferFromList(Buffer *pBuf) 113 | { 114 | int32_t rt = ISP_SUCCESS; 115 | if (!pBuf) { 116 | rt = ISP_INVALID_PARAM; 117 | ILOGE("Buffer is null"); 118 | return rt; 119 | } 120 | 121 | { 122 | unique_lock lock(bufListLock); 123 | for (auto iter = bufList.begin(); iter != bufList.end(); iter++) { 124 | if (!*iter) { 125 | rt = ISP_FAILED; 126 | ILOGE("Fatal: list node is null"); 127 | return rt; 128 | } 129 | if ((*iter)->Addr() == pBuf->Addr()) { 130 | bufList.erase(iter); 131 | break; 132 | } 133 | } 134 | } 135 | return rt; 136 | } 137 | 138 | int32_t BufferMgr::ReleaseAllBuffer() 139 | { 140 | int32_t rt = ISP_SUCCESS; 141 | list::iterator iter; 142 | 143 | while(!bufList.empty()) { 144 | { 145 | unique_lock lock(bufListLock); 146 | iter = bufList.begin(); 147 | if (iter == bufList.end()) { 148 | ILOGW("Buffer list is empty"); 149 | return rt; 150 | } 151 | if (!*iter) { 152 | rt = ISP_FAILED; 153 | ILOGE("Fatal: list node is null"); 154 | return rt; 155 | } 156 | } 157 | Buffer::Free(&*iter); 158 | } 159 | 160 | return rt; 161 | } 162 | 163 | } 164 | -------------------------------------------------------------------------------- /ISP/src/Coder.cpp: -------------------------------------------------------------------------------- 1 | // License: GPL-3.0-or-later 2 | /* 3 | * Defined a coder provoid media encode/decode method. 4 | * 5 | * Copyright (c) 2023 Peng Hao <635945005@qq.com> 6 | */ 7 | 8 | -------------------------------------------------------------------------------- /ISP/src/FileManager.cpp: -------------------------------------------------------------------------------- 1 | // License: GPL-3.0-or-later 2 | /* 3 | * Defined a file manager to manage files, provoid file operations. 4 | * 5 | * Copyright (c) 2019 Peng Hao <635945005@qq.com> 6 | */ 7 | 8 | #include "FileManager.h" 9 | #include 10 | 11 | #define MIN_IO_PARAM_CNT 4 12 | 13 | struct ImgFmtInfo { 14 | uint32_t fmt; 15 | uint32_t bitWidth; 16 | uint32_t cspace; 17 | uint32_t order; 18 | uint32_t dpt; 19 | char info[20]; 20 | }; 21 | 22 | const ImgFmtInfo gSupportedFmt[] = { 23 | {V4L2_PIX_FMT_SBGGR8, 8, CS_Bayer, BO_BGGR, DPT_NUM, "Raw8-bggr" }, 24 | {V4L2_PIX_FMT_SGBRG8, 8, CS_Bayer, BO_GBRG, DPT_NUM, "Raw8-gbrg" }, 25 | {V4L2_PIX_FMT_SGRBG8, 8, CS_Bayer, BO_GRBG, DPT_NUM, "Raw8-grbg" }, 26 | {V4L2_PIX_FMT_SRGGB8, 8, CS_Bayer, BO_RGGB, DPT_NUM, "Raw8-rggb" }, 27 | {V4L2_PIX_FMT_SBGGR10, 10, CS_Bayer, BO_BGGR, DPT_Unpackaged, "Raw10-bggr" }, 28 | {V4L2_PIX_FMT_SGBRG10, 10, CS_Bayer, BO_GBRG, DPT_Unpackaged, "Raw10-gbrg" }, 29 | {V4L2_PIX_FMT_SGRBG10, 10, CS_Bayer, BO_GRBG, DPT_Unpackaged, "Raw10-grbg" }, 30 | {V4L2_PIX_FMT_SRGGB10, 10, CS_Bayer, BO_RGGB, DPT_Unpackaged, "Raw10-rggb" }, 31 | {V4L2_PIX_FMT_SBGGR10P, 10, CS_Bayer, BO_BGGR, DPT_Packaged, "Raw10-bggr-packed" }, 32 | {V4L2_PIX_FMT_SGBRG10P, 10, CS_Bayer, BO_GBRG, DPT_Packaged, "Raw10-gbrg-packed" }, 33 | {V4L2_PIX_FMT_SGRBG10P, 10, CS_Bayer, BO_GRBG, DPT_Packaged, "Raw10-grbg-packed" }, 34 | {V4L2_PIX_FMT_SRGGB10P, 10, CS_Bayer, BO_RGGB, DPT_Packaged, "Raw10-rggb-packed" }, 35 | {V4L2_PIX_FMT_SBGGR12P, 12, CS_Bayer, BO_BGGR, DPT_Packaged, "Raw12-bggr-packed" }, 36 | {V4L2_PIX_FMT_SGBRG12P, 12, CS_Bayer, BO_GBRG, DPT_Packaged, "Raw12-gbrg-packed" }, 37 | {V4L2_PIX_FMT_SGRBG12P, 12, CS_Bayer, BO_GRBG, DPT_Packaged, "Raw12-grbg-packed" }, 38 | {V4L2_PIX_FMT_SRGGB12P, 12, CS_Bayer, BO_RGGB, DPT_Packaged, "Raw12-rggb-packed" }, 39 | }; 40 | 41 | FileManager* FileManager::GetInstance() 42 | { 43 | static FileManager gInstance; 44 | return &gInstance; 45 | } 46 | 47 | FileManager::FileManager() 48 | { 49 | memset(&mInputInfo, 0, sizeof(InputInfo)); 50 | memset(&mOutputInfo, 0, sizeof(OutputInfo)); 51 | IOInfoFlag = 0; 52 | 53 | mState = FMGR_STATE_UNINITED; 54 | Init(); 55 | } 56 | 57 | FileManager::~FileManager() 58 | { 59 | DeInit(); 60 | memset(&mInputInfo, 0, sizeof(InputInfo)); 61 | memset(&mOutputInfo, 0, sizeof(OutputInfo)); 62 | 63 | mState = FMGR_STATE_UNINITED; 64 | } 65 | 66 | int32_t FileManager::Init() 67 | { 68 | int32_t rt = ISP_SUCCESS; 69 | 70 | mVTParam = { 0 }; 71 | if(!pDynamicInfo) { 72 | rt = ISP_STATE_ERROR; 73 | ILOGE("IO info buffer is null %d", rt); 74 | return rt; 75 | } 76 | memset(pDynamicInfo, 0, sizeof(MediaInfo)); 77 | mState = FMGR_STATE_INITED; 78 | 79 | return rt; 80 | } 81 | 82 | int32_t FileManager::DeInit() 83 | { 84 | int32_t rt = ISP_SUCCESS; 85 | 86 | mVTParam = { 0 }; 87 | memset(pDynamicInfo, 0, sizeof(MediaInfo)); 88 | mState = FMGR_STATE_UNINITED; 89 | 90 | return rt; 91 | } 92 | 93 | int32_t FileManager::SetInputInfo(InputInfo info) 94 | { 95 | int32_t rt = ISP_SUCCESS; 96 | 97 | mInputInfo.type = info.type; 98 | mInputInfo.size = info.size; 99 | if (IOInfoFlag) { 100 | strcat(mInputInfo.path, INPUT_PATH); 101 | strcat(mInputInfo.path, INPUT_NAME); 102 | } 103 | 104 | return rt; 105 | } 106 | 107 | int32_t FileManager::SetOutputInfo(OutputInfo info) 108 | { 109 | int32_t rt = ISP_SUCCESS; 110 | 111 | mOutputInfo.imgInfo.type = info.imgInfo.type; 112 | mOutputInfo.imgInfo.size = info.imgInfo.size; 113 | mOutputInfo.imgInfo.width = info.imgInfo.width; 114 | mOutputInfo.imgInfo.height = info.imgInfo.height; 115 | mOutputInfo.imgInfo.channels = info.imgInfo.channels; 116 | mOutputInfo.videoInfo.type = info.videoInfo.type; 117 | mOutputInfo.videoInfo.width = info.videoInfo.width; 118 | mOutputInfo.videoInfo.height = info.videoInfo.height; 119 | mOutputInfo.videoInfo.fps = info.videoInfo.fps; 120 | mOutputInfo.videoInfo.frameNum = info.videoInfo.frameNum; 121 | if (IOInfoFlag) { 122 | strcat(mOutputInfo.imgInfo.path, OUTPUT_PATH); 123 | strcat(mOutputInfo.imgInfo.path, OUTPUT_IMG_NAME); 124 | strcat(mOutputInfo.videoInfo.path, OUTPUT_PATH); 125 | strcat(mOutputInfo.videoInfo.path, OUTPUT_VIDEO_NAME); 126 | } 127 | 128 | return rt; 129 | } 130 | 131 | int32_t FileManager::SetOutputImgInfo(OutputImgInfo info) 132 | { 133 | int32_t rt = ISP_SUCCESS; 134 | 135 | memcpy(&mOutputInfo.imgInfo, &info, sizeof(OutputImgInfo)); 136 | 137 | return rt; 138 | } 139 | 140 | int32_t FileManager::SetOutputVideoInfo(OutputVideoInfo info) 141 | { 142 | int32_t rt = ISP_SUCCESS; 143 | 144 | memcpy(&mOutputInfo.videoInfo, &info, sizeof(OutputVideoInfo)); 145 | 146 | return rt; 147 | } 148 | 149 | int32_t FileManager::GetOutputVideoInfo(OutputVideoInfo* pInfo) 150 | { 151 | int32_t rt = ISP_SUCCESS; 152 | 153 | if (!pInfo) { 154 | rt = ISP_INVALID_PARAM; 155 | ILOGE("Invalid input!"); 156 | return rt; 157 | } 158 | 159 | memcpy(pInfo, &mOutputInfo.videoInfo, sizeof(OutputVideoInfo)); 160 | 161 | return rt; 162 | } 163 | 164 | int32_t FileManager::ReadData(uint8_t* buffer, int32_t bufferSize) 165 | { 166 | int32_t rt = ISP_SUCCESS; 167 | 168 | switch(mInputInfo.type) { 169 | case INPUT_FILE_TYPE_RAW: 170 | rt = ReadRawData(buffer, bufferSize); 171 | break; 172 | case INPUT_FILE_TYPE_NUM: 173 | default: 174 | rt = ISP_FAILED; 175 | ILOGE("Not support input type:%d", mInputInfo.type); 176 | break; 177 | } 178 | return rt; 179 | } 180 | 181 | int32_t FileManager::ReadRawData(uint8_t* buffer, int32_t bufferSize) 182 | { 183 | int32_t rt = ISP_SUCCESS; 184 | 185 | if (mState != FMGR_STATE_INITED) { 186 | rt = ISP_STATE_ERROR; 187 | ILOGE("File manager not ready"); 188 | return rt; 189 | } 190 | 191 | ILOGI("Raw input path:%s", mInputInfo.path); 192 | ifstream inputFile(mInputInfo.path, ios::in | ios::binary); 193 | if (inputFile.fail()) { 194 | rt = ISP_FAILED; 195 | ILOGE("Open RAW failed! path:%s rt:%d", mInputInfo.path, rt); 196 | return rt; 197 | } 198 | 199 | inputFile.seekg(0, ios::end); 200 | streampos fileSize = inputFile.tellg(); 201 | mInputInfo.size = (int32_t)fileSize; 202 | ILOGDF("File size:%d", mInputInfo.size); 203 | inputFile.seekg(0, ios::beg); 204 | 205 | if (bufferSize < mInputInfo.size) { 206 | mInputInfo.size = bufferSize; 207 | ILOGW("Read part of file (%d/%u)", mInputInfo.size, fileSize); 208 | } 209 | inputFile.read((char*)buffer, mInputInfo.size); 210 | inputFile.close(); 211 | 212 | return rt; 213 | } 214 | 215 | int32_t FileManager::SaveImgData(uint8_t* srcData) 216 | { 217 | int32_t rt = ISP_SUCCESS; 218 | 219 | switch(mOutputInfo.imgInfo.type) { 220 | case OUTPUT_FILE_TYPE_BMP: 221 | rt = SaveBMPData(srcData, mOutputInfo.imgInfo.channels); 222 | break; 223 | case OUTPUT_FILE_TYPE_NUM: 224 | default: 225 | rt = ISP_FAILED; 226 | ILOGE("Not support output type:%d", mInputInfo.type); 227 | break; 228 | } 229 | return rt; 230 | } 231 | 232 | int32_t FileManager::SaveBMPData(uint8_t* srcData, int32_t channels) 233 | { 234 | int32_t rt = ISP_SUCCESS; 235 | if (mState != FMGR_STATE_INITED) { 236 | rt = ISP_FAILED; 237 | ILOGE("File manager not init"); 238 | return rt; 239 | } 240 | 241 | mOutputInfo.imgInfo.size = mOutputInfo.imgInfo.width * 242 | mOutputInfo.imgInfo.height * 243 | mOutputInfo.imgInfo.channels; 244 | BYTE* BMPdata = new BYTE[mOutputInfo.imgInfo.size]; 245 | rt = SetBMP(srcData, mOutputInfo.imgInfo.channels, BMPdata); 246 | if (!SUCCESS(rt)) { 247 | ILOGE("SetBMP failed. rt:&d", rt); 248 | delete[] BMPdata; 249 | return rt; 250 | } 251 | 252 | WriteBMP(BMPdata, channels); 253 | delete[] BMPdata; 254 | 255 | return rt; 256 | } 257 | 258 | int32_t FileManager::SetBMP(uint8_t* srcData, int32_t channels, BYTE* dstData) 259 | { 260 | int32_t rt = ISP_SUCCESS; 261 | int32_t j = 0; 262 | BYTE temp; 263 | 264 | switch (channels) { 265 | case 1: 266 | memcpy(dstData, srcData, mOutputInfo.imgInfo.width * mOutputInfo.imgInfo.height); 267 | break; 268 | case 3: 269 | for (int32_t row = 0; row < mOutputInfo.imgInfo.height; row++) { 270 | for (int32_t col = 0; col < mOutputInfo.imgInfo.width; col++) { 271 | dstData[row * mOutputInfo.imgInfo.width * 3 + col * 3] = 272 | srcData[row * mOutputInfo.imgInfo.width + col]; 273 | dstData[row * mOutputInfo.imgInfo.width * 3 + col * 3 + 1] = 274 | srcData[mOutputInfo.imgInfo.width * mOutputInfo.imgInfo.height + row * mOutputInfo.imgInfo.width + col]; 275 | dstData[row * mOutputInfo.imgInfo.width * 3 + col * 3 + 2] = 276 | srcData[2 * mOutputInfo.imgInfo.width * mOutputInfo.imgInfo.height + row * mOutputInfo.imgInfo.width + col]; 277 | } 278 | } 279 | break; 280 | default: 281 | rt = ISP_INVALID_PARAM; 282 | ILOGE("Invalid BMP output channels:%d", channels); 283 | return rt; 284 | /* TODO[L]: does it need to be support? */ 285 | } 286 | 287 | /* Convertion for the head & tail of data array */ 288 | while (j < mOutputInfo.imgInfo.size - j) { 289 | temp = dstData[mOutputInfo.imgInfo.size - j - 1]; 290 | dstData[mOutputInfo.imgInfo.size - j - 1] = dstData[j]; 291 | dstData[j] = temp; 292 | j++; 293 | } 294 | 295 | /* Mirror flip */ 296 | for (int32_t row = 0; row < mOutputInfo.imgInfo.height; row++) { 297 | int32_t col = 0; 298 | while (col < channels * mOutputInfo.imgInfo.width - col) { 299 | temp = dstData[row * channels * mOutputInfo.imgInfo.width + channels * mOutputInfo.imgInfo.width - col - 1]; 300 | dstData[channels * row * mOutputInfo.imgInfo.width + channels * mOutputInfo.imgInfo.width - col - 1] = 301 | dstData[channels * row * mOutputInfo.imgInfo.width + col]; 302 | dstData[channels * row * mOutputInfo.imgInfo.width + col] = temp; 303 | col++; 304 | } 305 | } 306 | 307 | return rt; 308 | } 309 | 310 | void FileManager::WriteBMP(BYTE* data, int32_t channels) 311 | { 312 | BITMAPFILEHEADER header = { 0 }; 313 | BITMAPINFOHEADER headerinfo = { 0 }; 314 | int32_t tempSize; 315 | 316 | ILOGDF("BYTE:%d WORD:%d DWORD:%d LONG:%d", 317 | sizeof(BYTE), sizeof(WORD), sizeof(DWORD), sizeof(LONG)); 318 | headerinfo.biSize = sizeof(BITMAPINFOHEADER); 319 | headerinfo.biHeight = mOutputInfo.imgInfo.height; 320 | headerinfo.biWidth = mOutputInfo.imgInfo.width; 321 | headerinfo.biPlanes = 1; 322 | headerinfo.biBitCount = (channels == 1) ? 8 : 24; 323 | headerinfo.biCompression = 0; //BI_RGB 324 | headerinfo.biSizeImage = mOutputInfo.imgInfo.size; 325 | headerinfo.biClrUsed = (channels == 1) ? 256 : 0; 326 | headerinfo.biClrImportant = 0; 327 | 328 | header.bfType = ('M' << 8) + 'B'; // equals to 0x4D42; 329 | header.bfReserved1 = 0; 330 | header.bfReserved2 = 0; 331 | 332 | tempSize = (channels == 1) ? 333 | (sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD)) : 334 | (sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER)); 335 | 336 | #ifdef LINUX_SYSTEM 337 | header.bfOffBits[0] = (tempSize % 0x10000) & 0xffff; 338 | header.bfOffBits[1] = (tempSize / 0x10000) & 0xffff; 339 | ILOGDF("ch:%d head:%d headinfo:%d bfOffBits:%d(%x %x)", 340 | channels, sizeof(BITMAPFILEHEADER), sizeof(BITMAPINFOHEADER), 341 | tempSize, header.bfOffBits[1], header.bfOffBits[0]); 342 | #elif defined WIN32_SYSTEM 343 | header.bfOffBits = tempSize; 344 | #endif 345 | 346 | tempSize += headerinfo.biSizeImage; 347 | #ifdef LINUX_SYSTEM 348 | header.bfSize[0] = (tempSize % 0x10000) & 0xffff; 349 | header.bfSize[1] = (tempSize / 0x10000) & 0xffff; 350 | ILOGDF("biSizeImage:%d bfSize:%d(%x %x)", headerinfo.biSizeImage, 351 | tempSize, header.bfSize[1], header.bfSize[0]); 352 | #elif defined WIN32_SYSTEM 353 | header.bfSize = tempSize; 354 | #endif 355 | 356 | ofstream outputFile(mOutputInfo.imgInfo.path, ios::binary); 357 | if (outputFile.fail()) { 358 | ILOGE("Cannot open ouput file:%s", mOutputInfo.imgInfo.path); 359 | return; 360 | } 361 | outputFile.write((char*)& header, sizeof(BITMAPFILEHEADER)); 362 | outputFile.write((char*)& headerinfo, sizeof(BITMAPINFOHEADER)); 363 | if (channels == 1) { 364 | static RGBQUAD palette[256]; 365 | for (int32_t i = 0; i < 256; i++) 366 | { 367 | palette[i].rgbBlue = i; 368 | palette[i].rgbGreen = i; 369 | palette[i].rgbRed = i; 370 | } 371 | outputFile.write((char*)palette, sizeof(RGBQUAD) * 256); 372 | } 373 | outputFile.write((char*)data, mOutputInfo.imgInfo.size); 374 | outputFile.close(); 375 | ILOGI("BMP output:%s", mOutputInfo.imgInfo.path); 376 | } 377 | 378 | int32_t FileManager::CreateVideo(void* dst) 379 | { 380 | int32_t rt = ISP_SUCCESS; 381 | 382 | if (!mVideo) { 383 | mVideo = std::make_unique(); 384 | } 385 | 386 | rt = mVideo->Init(dst); 387 | if (!SUCCESS(rt)) { 388 | return rt; 389 | } 390 | 391 | mVTParam.pVideo = mVideo.get(); 392 | rt = mVideo->CreateThread((void*)&mVTParam); 393 | ILOGI("Video fps:%d total frame:%d", 394 | mOutputInfo.videoInfo.fps, mOutputInfo.videoInfo.frameNum); 395 | 396 | return rt; 397 | } 398 | 399 | int32_t FileManager::SaveVideoData(int32_t frameCount) 400 | { 401 | int32_t rt = ISP_SUCCESS; 402 | 403 | rt = mVideo->Notify(); 404 | ILOGDF("Notify F:%d", frameCount); 405 | 406 | return rt; 407 | } 408 | 409 | 410 | int32_t FileManager::DestroyVideo() 411 | { 412 | int32_t rt = ISP_SUCCESS; 413 | 414 | rt = mVideo->DestroyThread(); 415 | 416 | return rt; 417 | } 418 | 419 | int32_t FileManager::Mipi10decode(void* src, void* dst, ImgInfo* info) 420 | { 421 | int32_t rt = ISP_SUCCESS; 422 | int32_t leftShift = 0; 423 | 424 | if (!info) { 425 | rt = ISP_INVALID_PARAM; 426 | ILOGE("Input is null"); 427 | return rt; 428 | } 429 | 430 | leftShift = info->bitspp - BITS_PER_WORD; 431 | if (leftShift < 0 || leftShift > 8) { 432 | rt = ISP_INVALID_PARAM; 433 | ILOGE("Not support bpp:%d", info->bitspp); 434 | return rt; 435 | } 436 | 437 | int32_t alignedW = ALIGNx(info->width, info->bitspp, CHECK_PACKAGED(info->rawFormat), info->stride); 438 | switch (info->rawFormat) { 439 | case ANDROID_RAW10: 440 | for (int32_t row = 0; row < info->height; row++) { 441 | for (int32_t col = 0; col < alignedW; col += 5) { 442 | if (col * BITS_PER_WORD / info->bitspp < info->width && row < info->height) { 443 | static_cast(dst)[row * info->width + col * BITS_PER_WORD / info->bitspp] = 444 | ((static_cast(src)[row * alignedW + col] & 0xffff) << leftShift) | 445 | ((static_cast(src)[row * alignedW + col + 4] & 0x3) & 0x3ff); 446 | static_cast(dst)[row * info->width + col * BITS_PER_WORD / info->bitspp + 1] = 447 | ((static_cast(src)[row * alignedW + col + 1] & 0xffff) << leftShift) | 448 | (((static_cast(src)[row * alignedW + col + 4] >> 2) & 0x3) & 0x3ff); 449 | static_cast(dst)[row * info->width + col * BITS_PER_WORD / info->bitspp + 2] = 450 | ((static_cast(src)[row * alignedW + col + 2] & 0xffff) << leftShift) | 451 | (((static_cast(src)[row * alignedW + col + 4] >> 4) & 0x3) & 0x3ff); 452 | static_cast(dst)[row * info->width + col * BITS_PER_WORD / info->bitspp + 3] = 453 | ((static_cast(src)[row * alignedW + col + 3] & 0xffff) << leftShift) | 454 | (((static_cast(src)[row * alignedW + col + 4] >> 6) & 0x3) & 0x3ff); 455 | } 456 | } 457 | } 458 | break; 459 | case ORDINAL_RAW10: 460 | for (int32_t row = 0; row < info->height; row++) { 461 | for (int32_t col = 0; col < alignedW; col += 5) { 462 | if (col * BITS_PER_WORD / info->bitspp < info->width && row < info->height) { 463 | static_cast(dst)[row * info->width + col * BITS_PER_WORD / info->bitspp] = 464 | (((static_cast(src)[row * alignedW + col + 0] >> 0) & (0xff >> 0)) & 0xffff) | 465 | (((static_cast(src)[row * alignedW + col + 1] & 0x03) << 8) & 0xffff); 466 | static_cast(dst)[row * info->width + col * BITS_PER_WORD / info->bitspp + 1] = 467 | (((static_cast(src)[row * alignedW + col + 1] >> 2) & (0xff >> 2)) & 0xffff) | 468 | (((static_cast(src)[row * alignedW + col + 2] & 0x0f) << 6) & 0xffff); 469 | static_cast(dst)[row * info->width + col * BITS_PER_WORD / info->bitspp + 2] = 470 | (((static_cast(src)[row * alignedW + col + 2] >> 4) & (0xff >> 4)) & 0xffff) | 471 | (((static_cast(src)[row * alignedW + col + 3] & 0x3f) << 4) & 0xffff); 472 | static_cast(dst)[row * info->width + col * BITS_PER_WORD / info->bitspp + 3] = 473 | (((static_cast(src)[row * alignedW + col + 3] >> 6) & (0xff >> 6)) & 0xffff) | 474 | (((static_cast(src)[row * alignedW + col + 4] & 0xff) << 2) & 0xffff); 475 | } 476 | } 477 | } 478 | break; 479 | case UNPACKAGED_RAW10_LSB: 480 | for (int32_t row = 0; row < info->height; row++) { 481 | for (int32_t col = 0; col < alignedW; col += 2) { 482 | static_cast(dst)[row * info->width + col / 2] = 483 | (static_cast(src)[row * alignedW + col] & 0xffff) | 484 | (((static_cast(src)[row * alignedW + col + 1] & 0x3) & 0xffff) << BITS_PER_WORD); 485 | } 486 | } 487 | break; 488 | case UNPACKAGED_RAW10_MSB: 489 | for (int32_t row = 0; row < info->height; row++) { 490 | for (int32_t col = 0; col < alignedW; col += 2) { 491 | static_cast(dst)[row * info->width + col / 2] = 492 | ((static_cast(src)[row * alignedW + col] >> (BITS_PER_WORD - leftShift)) & 0xffff) | 493 | ((static_cast(src)[row * alignedW + col + 1] & 0xffff) << leftShift); 494 | } 495 | } 496 | break; 497 | case RAW_FORMAT_NUM: 498 | default: 499 | rt = ISP_INVALID_PARAM; 500 | ILOGE("Not support raw type:%d", info->rawFormat); 501 | return rt; 502 | } 503 | 504 | ILOGDF("MIPI decode finished"); 505 | return rt; 506 | } 507 | 508 | void DumpDataInt(void* pData, ... 509 | /* int32_t height, int32_t width, int32_t bitWidth, char* dumpPath */) 510 | { 511 | int32_t width = 0; 512 | int32_t height = 0; 513 | int32_t bitWidth = 0; 514 | char* dumpPath = NULL; 515 | va_list va; 516 | 517 | if (pData == NULL) { 518 | ILOGE("Dump failed. data is NULL"); 519 | return; 520 | } 521 | 522 | va_start(va, pData); 523 | width = static_cast(va_arg(va, int32_t)); 524 | height = static_cast(va_arg(va, int32_t)); 525 | bitWidth = static_cast(va_arg(va, int32_t)); 526 | dumpPath = static_cast(va_arg(va, char*)); 527 | va_end(va); 528 | if (!dumpPath) { 529 | ILOGE("dumpPath is null"); 530 | return; 531 | } 532 | 533 | ofstream dumpFile(dumpPath); 534 | if (!dumpFile) { 535 | ILOGE("Cannot create dump file:%s", dumpPath); 536 | return; 537 | } 538 | 539 | for (int32_t i = 0; i < height; i++) { 540 | dumpFile << i << ": "; 541 | for (int32_t j = 0; j < width; j++) { 542 | switch (bitWidth) { 543 | case sizeof(uint16_t) : 544 | dumpFile << (int)static_cast(pData)[i * width + j] << ' '; 545 | break; 546 | case sizeof(uint8_t) : 547 | dumpFile << (int)static_cast(pData)[i * width + j] << ' '; 548 | break; 549 | default: 550 | ILOGE("Dump failed. Unsopported data bitWidth:%d", bitWidth); 551 | } 552 | } 553 | dumpFile << endl; 554 | } 555 | ILOGI("Data saved as int at:%s", dumpPath); 556 | dumpFile.close(); 557 | } 558 | 559 | int32_t CheckInputPath(char* pPath, void* pIn, void* pOut) 560 | { 561 | int32_t rt = ISP_SUCCESS; 562 | 563 | if (!pPath || !pIn || !pOut) { 564 | rt = ISP_INVALID_PARAM; 565 | ILOGE("Null input %d", rt); 566 | return rt; 567 | } 568 | 569 | if (access(pPath, F_OK)) { 570 | rt = ISP_FAILED; 571 | ILOGE("File not exit. %s", pPath); 572 | return rt; 573 | } 574 | 575 | if (access(pPath, R_OK)) { 576 | rt = ISP_FAILED; 577 | ILOGE("Lack of read right for %s", pPath); 578 | return rt; 579 | } 580 | 581 | int32_t len = 0, dotIndex = 0; 582 | while(pPath[len] != '\0') { 583 | len++; 584 | } 585 | if (len >= FILE_PATH_MAX_SIZE) { 586 | rt = ISP_INVALID_PARAM; 587 | ILOGE("Input file path:%s over size:%d > %d", pPath, len, FILE_PATH_MAX_SIZE); 588 | return rt; 589 | } 590 | 591 | dotIndex = len; 592 | while(pPath[dotIndex] != '.' && dotIndex > 0) { 593 | dotIndex--; 594 | } 595 | if (dotIndex + OUTPUT_FILE_TYPE_SIZE >= FILE_PATH_MAX_SIZE) { 596 | rt = ISP_INVALID_PARAM; 597 | ILOGE("Output file path:%s size:%d > %d", pPath, dotIndex + OUTPUT_FILE_TYPE_SIZE, FILE_PATH_MAX_SIZE); 598 | return rt; 599 | } 600 | memcpy(static_cast(pIn)->path, pPath, len); 601 | memcpy(static_cast(pOut)->imgInfo.path, pPath, dotIndex + 1); 602 | memcpy(static_cast(pOut)->imgInfo.path + dotIndex + 1, "bmp\0", OUTPUT_FILE_TYPE_SIZE); 603 | memcpy(static_cast(pOut)->videoInfo.path, pPath, dotIndex + 1); 604 | memcpy(static_cast(pOut)->videoInfo.path + dotIndex + 1, "avi\0", OUTPUT_FILE_TYPE_SIZE); 605 | ILOGDF("path:%s", pPath); 606 | 607 | return rt; 608 | } 609 | 610 | int32_t CheckInputSize(char* pCharW, char* pCharH, void* pInfo) 611 | { 612 | int32_t rt = ISP_SUCCESS; 613 | 614 | if (!pCharW || !pCharH || !pInfo) { 615 | rt = ISP_INVALID_PARAM; 616 | ILOGE("Input is null"); 617 | return rt; 618 | } 619 | 620 | int32_t w, h; 621 | w = CharNum2IntNum(pCharW); 622 | h = CharNum2IntNum(pCharH); 623 | 624 | if (w < 0 || h < 0) { 625 | rt = ISP_INVALID_PARAM; 626 | ILOGE("Invalid Size: %sx%s", pCharW, pCharH); 627 | return rt; 628 | } 629 | 630 | static_cast(pInfo)->img.width = w; 631 | static_cast(pInfo)->img.height = h; 632 | ILOGDF("size:%dx%d", w, h); 633 | 634 | return rt; 635 | } 636 | 637 | int32_t CheckInputFmt(char* pCharFmt, void* pInfo) 638 | { 639 | int32_t rt = ISP_SUCCESS; 640 | uint32_t len = 0; 641 | uint32_t fmt = 0x0; 642 | 643 | if (!pCharFmt || !pInfo) { 644 | rt = ISP_INVALID_PARAM; 645 | ILOGE("Input is null"); 646 | return rt; 647 | } 648 | 649 | while(pCharFmt[len] != '\0') { 650 | len++; 651 | } 652 | if (len + 1 < 4) { 653 | rt = ISP_INVALID_PARAM; 654 | ILOGE("Invalid format:%s", pCharFmt); 655 | return rt; 656 | } 657 | 658 | fmt = len == 4 ? 659 | v4l2_fourcc(pCharFmt[0], pCharFmt[1], pCharFmt[2], pCharFmt[3]) : 660 | v4l2_fourcc(pCharFmt[0], pCharFmt[1], pCharFmt[2], ' '); 661 | for (int32_t i = sizeof(gSupportedFmt) / sizeof(ImgFmtInfo) - 1; i >= 0; i--) { 662 | if (gSupportedFmt[i].fmt == fmt) { 663 | ILOGDF("Format: %s (%c%c%c%c)", gSupportedFmt[i].info, 664 | fmt, fmt >> 8, fmt >> 16, fmt >> 24); 665 | static_cast(pInfo)->img.bitspp = gSupportedFmt[i].bitWidth; 666 | static_cast(pInfo)->img.bayerOrder = gSupportedFmt[i].order; 667 | static_cast(pInfo)->img.stride = 0; /* 0 as default */ 668 | if (fmt == V4L2_PIX_FMT_SBGGR10P || 669 | fmt == V4L2_PIX_FMT_SGBRG10P || 670 | fmt == V4L2_PIX_FMT_SGRBG10P || 671 | fmt == V4L2_PIX_FMT_SRGGB10P) { 672 | static_cast(pInfo)->img.rawFormat = ANDROID_RAW10; 673 | /* TODO[L]: find v4l2 fmt for ORDINAL_RAW10 */ 674 | // } else if (fmt == ??) { 675 | // static_cast(pInfo)->img.rawFormat = ORDINAL_RAW10; 676 | } else if (fmt == V4L2_PIX_FMT_SBGGR10 || 677 | fmt == V4L2_PIX_FMT_SGBRG10 || 678 | fmt == V4L2_PIX_FMT_SGRBG10 || 679 | fmt == V4L2_PIX_FMT_SRGGB10) { 680 | static_cast(pInfo)->img.rawFormat = UNPACKAGED_RAW10_LSB; 681 | } else { 682 | static_cast(pInfo)->img.rawFormat = RAW_FORMAT_NUM; 683 | } 684 | break; 685 | } else if (i == 0) { 686 | rt = ISP_INVALID_PARAM; 687 | ILOGE("Not support format:%s(0x%x)", pCharFmt, fmt); 688 | } 689 | } 690 | 691 | return rt; 692 | } 693 | 694 | int32_t CheckInputStride(char* pCharStride, void* pInfo) 695 | { 696 | int32_t rt = ISP_SUCCESS; 697 | 698 | if (!pCharStride || !pInfo) { 699 | rt = ISP_INVALID_PARAM; 700 | ILOGE("Input is null"); 701 | return rt; 702 | } 703 | 704 | int32_t stride; 705 | stride = CharNum2IntNum(pCharStride); 706 | 707 | if (stride < 0 || stride % 2 != 0) { 708 | rt = ISP_INVALID_PARAM; 709 | ILOGE("Invalid stride: %s", pCharStride); 710 | return rt; 711 | } 712 | static_cast(pInfo)->img.stride = stride; 713 | ILOGDF("stride: %u", stride); 714 | 715 | return rt; 716 | } 717 | 718 | int32_t CheckOutputFPS(char* pFPS, void* pInfo) 719 | { 720 | int32_t rt = ISP_SUCCESS; 721 | 722 | if (!pFPS || !pInfo) { 723 | rt = ISP_INVALID_PARAM; 724 | ILOGE("Input is null"); 725 | return rt; 726 | } 727 | 728 | int32_t fps = CharNum2IntNum(pFPS); 729 | if (fps < 0) { 730 | rt = ISP_INVALID_PARAM; 731 | ILOGE("Invalid fps: %s", pFPS); 732 | return rt; 733 | } 734 | static_cast(pInfo)->video.fps = fps; 735 | ILOGDF("video fps: %u", fps); 736 | 737 | return rt; 738 | } 739 | 740 | int32_t CheckOutputFrameNum(char* pFNum, void* pInfo) 741 | { 742 | int32_t rt = ISP_SUCCESS; 743 | 744 | if (!pFNum || !pInfo) { 745 | rt = ISP_INVALID_PARAM; 746 | ILOGE("Input is null"); 747 | return rt; 748 | } 749 | 750 | int32_t num = CharNum2IntNum(pFNum); 751 | if (num < 0) { 752 | rt = ISP_INVALID_PARAM; 753 | ILOGE("Invalid frame number: %s", pFNum); 754 | return rt; 755 | } 756 | static_cast(pInfo)->video.frameNum = num; 757 | ILOGDF("video frame number: %u", num); 758 | 759 | return rt; 760 | } 761 | 762 | int FileManager::Input(IOInfo ioInfo) 763 | { 764 | int32_t rt = ISP_SUCCESS; 765 | 766 | if (ioInfo.argc <= 1) { 767 | IOInfoFlag = 1; 768 | ILOGI("Use default I/O config"); 769 | return rt; 770 | } 771 | 772 | for (int32_t i = 0; i < (ioInfo.argc < MAX_IO_PARAM_CNT ? ioInfo.argc : MAX_IO_PARAM_CNT); i++) { 773 | if (!ioInfo.argv[i]) { 774 | rt = ISP_INVALID_PARAM; 775 | ILOGE("Null param[%d]", i); 776 | return rt; 777 | } 778 | 779 | if (i == 1) { 780 | if (!strcmp(ioInfo.argv[i], "-h") || !strcmp(ioInfo.argv[i], "-help")) { 781 | HelpMenu(); 782 | rt = ISP_SKIP; 783 | break; 784 | } 785 | if (!strcmp(ioInfo.argv[i], "-l") || !strcmp(ioInfo.argv[i], "-list")) { 786 | SupportInfo(); 787 | rt = ISP_SKIP; 788 | break; 789 | } 790 | 791 | if (ioInfo.argc - 1 < MIN_IO_PARAM_CNT) { 792 | rt = ISP_INVALID_PARAM; 793 | ILOGE("Insufficient param num:%d < expected param num:%d", ioInfo.argc - 1, MIN_IO_PARAM_CNT); 794 | return rt; 795 | } 796 | rt = CheckInputPath(ioInfo.argv[i], &mInputInfo, &mOutputInfo); 797 | if (!SUCCESS(rt)) { 798 | return rt; 799 | } 800 | } 801 | if (i == 3) { 802 | rt = CheckInputSize(ioInfo.argv[i-1], ioInfo.argv[i], pDynamicInfo); 803 | if (!SUCCESS(rt)) { 804 | return rt; 805 | } 806 | } 807 | if (i == 4) { 808 | rt = CheckInputFmt(ioInfo.argv[i], pDynamicInfo); 809 | if (!SUCCESS(rt)) { 810 | return rt; 811 | } 812 | } 813 | if (i == 5) { 814 | rt = CheckInputStride(ioInfo.argv[i], pDynamicInfo); 815 | if (!SUCCESS(rt)) { 816 | return rt; 817 | } 818 | } 819 | if (i == 6) { 820 | rt = CheckOutputFPS(ioInfo.argv[i], pDynamicInfo); 821 | if (!SUCCESS(rt)) { 822 | return rt; 823 | } 824 | } 825 | if (i == 7) { 826 | rt = CheckOutputFrameNum(ioInfo.argv[i], pDynamicInfo); 827 | if (!SUCCESS(rt)) { 828 | return rt; 829 | } else { 830 | static_cast(pDynamicInfo)->type = IMAGE_AND_VIDEO_MEDIA; 831 | } 832 | } 833 | } 834 | 835 | return rt; 836 | } 837 | 838 | void FileManager::SupportInfo() 839 | { 840 | ILOGI("=================================================================="); 841 | ILOGI(" Support Format List"); 842 | ILOGI("=================================================================="); 843 | ILOGI(" %-25s \t| %-10s \t| %s", "Image Format", "Bit Width", "FMT Param"); 844 | ILOGI("------------------------------------------------------------------"); 845 | for (uint32_t i = 0; i < sizeof(gSupportedFmt)/sizeof(ImgFmtInfo); i++) { 846 | if (i > 0 && ( 847 | gSupportedFmt[i].bitWidth != 848 | gSupportedFmt[i-1].bitWidth || 849 | gSupportedFmt[i].cspace != 850 | gSupportedFmt[i-1].cspace || 851 | gSupportedFmt[i].dpt != 852 | gSupportedFmt[i-1].dpt 853 | )) { 854 | ILOGI("------------------------------------------------------------------"); 855 | } 856 | ILOGI(" %-25s \t| %-10u \t| %c%c%c%c" 857 | #ifdef LOG_FOR_DBG 858 | "(0x%-4x)" 859 | #endif 860 | , gSupportedFmt[i].info, 861 | gSupportedFmt[i].bitWidth, 862 | gSupportedFmt[i].fmt, 863 | gSupportedFmt[i].fmt >> 8, 864 | gSupportedFmt[i].fmt >> 16, 865 | gSupportedFmt[i].fmt >> 24 866 | #ifdef LOG_FOR_DBG 867 | , gSupportedFmt[i].fmt 868 | #endif 869 | ); 870 | } 871 | ILOGI("------------------------------------------------------------------"); 872 | ILOGI(" \t"); 873 | } 874 | 875 | void FileManager::HelpMenu() 876 | { 877 | ILOGI("=================================================================="); 878 | ILOGI(" ISP v%d.%d", VERSION, SUB_VERSION); 879 | ILOGI(" Copyright (c) 2019 Peng Hao <635945005@qq.com>"); 880 | ILOGI("=================================================================="); 881 | ILOGI(" User Guide:"); 882 | ILOGI(" 1. To get help, use cmd: ./ISP -h or ./ISP -help"); 883 | ILOGI(" 2. To check format list, use cmd: ./ISP -l or ./ISP -list"); 884 | ILOGI(" 3. To view an image, use cmd like this: ./ISP $path $width $height $fmt ($stride)"); 885 | ILOGI(" \tpath\t: Target image path, like: /usr/bin/example.raw"); 886 | ILOGI(" \twidth\t: Image width, like: 640"); 887 | ILOGI(" \theight\t: Image height, like: 480"); 888 | ILOGI(" \tfmt\t: Image format, like: pBAA. Please check column in format list"); 889 | ILOGI(" \tstride\t: Optional if output img only. Set the stride for image"); 890 | ILOGI(" \tfps\t: If output img & video, set the video fps"); 891 | ILOGI(" \tframe num\t: If output img & video, set the total frame number"); 892 | ILOGI(" \t"); 893 | } 894 | 895 | int32_t FileManager::GetIOInfo(void* pInfo) 896 | { 897 | int32_t rt = ISP_SUCCESS; 898 | 899 | if (!pInfo) { 900 | rt = ISP_INVALID_PARAM; 901 | ILOGE("Null input! %d", rt); 902 | return rt; 903 | } 904 | 905 | switch(IOInfoFlag) { 906 | case 0: 907 | memcpy(pInfo, pDynamicInfo, sizeof(MediaInfo)); 908 | break; 909 | case 1: 910 | memcpy(pInfo, pStaticInfo, sizeof(MediaInfo)); 911 | break; 912 | default: 913 | ILOGE("Invalid I/O flag:%d", IOInfoFlag); 914 | break; 915 | } 916 | 917 | return rt; 918 | } 919 | -------------------------------------------------------------------------------- /ISP/src/IOHelper.cpp: -------------------------------------------------------------------------------- 1 | // License: GPL-3.0-or-later 2 | /* 3 | * I/O helper. 4 | * 5 | * Copyright (c) 2019 Peng Hao <635945005@qq.com> 6 | */ 7 | 8 | #include "IOHelper.h" 9 | 10 | IOHelper::IOHelper() 11 | { 12 | pStaticInfo = (void*)&defaultMediaInfo; 13 | pDynamicInfo = (void*) new MediaInfo; 14 | if (!pDynamicInfo) { 15 | ILOGE("Faild to malloc dynamic info buffer!"); 16 | } 17 | } 18 | 19 | IOHelper::~IOHelper() 20 | { 21 | pStaticInfo = NULL; 22 | if (pDynamicInfo) { 23 | delete static_cast(pDynamicInfo); 24 | pDynamicInfo = NULL; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /ISP/src/ISPCore.cpp: -------------------------------------------------------------------------------- 1 | // License: GPL-3.0-or-later 2 | /* 3 | * ISP core function implementation. 4 | * 5 | * Copyright (c) 2019 Peng Hao <635945005@qq.com> 6 | */ 7 | 8 | #include "ISPCore.h" 9 | #include "ParamManager.h" 10 | #include "ISPListManager.h" 11 | 12 | #if DBG_OPENCV_ON 13 | #include "opencv2/core/core.hpp" 14 | #include "opencv2/imgproc/imgproc.hpp" 15 | #include "opencv2/calib3d/calib3d.hpp" 16 | #include "opencv2/highgui/highgui.hpp" 17 | #include "opencv2/photo.hpp" 18 | 19 | using namespace cv; 20 | #endif 21 | 22 | /* For img display with UI window */ 23 | #ifdef LINUX_SYSTEM 24 | #include 25 | #include 26 | #endif 27 | 28 | #define SRCNAME "Source" 29 | #define RESNAME "Result" 30 | #define TMPNAME "Temp" 31 | 32 | #define WAIT_ACTIVE_GAP_US 1000 33 | 34 | using namespace asteroidaxis::isp::resource; 35 | 36 | void* CoreFunc(void); 37 | 38 | ISPCore* ISPCore::GetInstance() 39 | { 40 | static ISPCore gInstance; 41 | return &gInstance; 42 | } 43 | 44 | 45 | ISPCore::ISPCore(): 46 | mExit(false), 47 | mState(CORE_IDLE) 48 | { 49 | memset(&mThreadParam, 0, sizeof(IOInfo)); 50 | mThread = thread(CoreFunc); 51 | mState = CORE_INITED; 52 | } 53 | 54 | ISPCore::~ISPCore() 55 | { 56 | mExit = true; 57 | if (mState != CORE_IDLE) { 58 | mThread.join(); 59 | mState = CORE_IDLE; 60 | } 61 | InterfaceWrapper::RemoveInstance(); 62 | } 63 | 64 | bool ISPCore::IsActive() 65 | { 66 | return mState == CORE_PROCESSING; 67 | } 68 | 69 | bool ISPCore::NeedExit() 70 | { 71 | return mExit; 72 | } 73 | 74 | int32_t ISPCore::Process(void *pInfo, ...) 75 | { 76 | int32_t rt = ISP_SUCCESS; 77 | 78 | memcpy(&mThreadParam, pInfo, sizeof(IOInfo)); 79 | mState = mState == CORE_INITED ? mState + 1 : mState; 80 | 81 | return rt; 82 | } 83 | 84 | void* ISPCore::GetThreadParam() 85 | { 86 | return &mThreadParam; 87 | } 88 | 89 | int32_t ImgShow(void *data, size_t w, size_t h) 90 | { 91 | int32_t rt = ISP_SUCCESS; 92 | 93 | if (!data) { 94 | rt = ISP_INVALID_PARAM; 95 | ILOGE("Input is null"); 96 | return rt; 97 | } 98 | 99 | int32_t winSizey; 100 | bool supportWin = false; 101 | #ifdef LINUX_SYSTEM 102 | winsize winSize; 103 | ioctl(STDIN_FILENO, TIOCGWINSZ, &winSize); 104 | if (!winSize.ws_row) { 105 | ILOGW("Cannot get terminal size(%d,%d)! Skip img show", 106 | winSize.ws_col, winSize.ws_row); 107 | } else { 108 | winSizey = winSize.ws_row; 109 | supportWin = true; 110 | } 111 | #elif defined WIN32_SYSTEM 112 | winSizey = GetSystemMetrics(SM_CYSCREEN); 113 | supportWin = true; 114 | #endif 115 | 116 | if (supportWin) { 117 | int32_t showSizex = 0, showSizey = 0; 118 | showSizey = winSizey * 2 / 3; 119 | showSizex = showSizey * w / h; 120 | ILOGDC("Display size(%dx%d)", showSizex, showSizey); 121 | #if DBG_OPENCV_ON 122 | int32_t pixelNum = w * h; 123 | Mat img = Mat(h, w, CV_8UC3, Scalar(0, 0, 0)); 124 | for (size_t row = 0; row < h; row++) { 125 | for (size_t col = 0; col < w; col++) { 126 | img.data[row * w * 3 + col * 3] = 127 | static_cast(data)[row * w + col]; 128 | img.data[row * w * 3 + col * 3 + 1] = 129 | static_cast(data)[pixelNum + row * w + col]; 130 | img.data[row * w * 3 + col * 3 + 2] = 131 | static_cast(data)[2 * pixelNum + row * w + col]; 132 | } 133 | } 134 | namedWindow("Image", 0); 135 | resizeWindow("Image", showSizex, showSizey); 136 | imshow("Image", img); 137 | waitKey(0); /* for the possibility of interacting with window, keep the value as 0 */ 138 | 139 | if (!img.empty()) { 140 | img.release(); 141 | } 142 | #endif 143 | } 144 | 145 | return rt; 146 | } 147 | 148 | void* CoreFunc(void) 149 | { 150 | int32_t waitActiveCnt = 0; 151 | while(!ISPCore::GetInstance()->IsActive()) { 152 | if (ISPCore::GetInstance()->NeedExit()) { 153 | return NULL; 154 | } 155 | waitActiveCnt++; 156 | usleep(WAIT_ACTIVE_GAP_US); 157 | ILOGDC("Waiting for ISP ready... (%d)", waitActiveCnt); 158 | } 159 | 160 | if (!InterfaceWrapper::GetInstance()) { 161 | return NULL; 162 | } 163 | 164 | IOInfo *pInfo = static_cast(ISPCore::GetInstance()->GetThreadParam()); 165 | if (FileManager::GetInstance()->Input(*pInfo) != ISP_SUCCESS) { 166 | return NULL; 167 | } 168 | 169 | MediaInfo mediaInfo = { 0 }; 170 | if (!SUCCESS(FileManager::GetInstance()->GetIOInfo(&mediaInfo))) { 171 | return NULL; 172 | } 173 | if (!SUCCESS(ISPParamManager::GetInstance()->SetMediaInfo(&mediaInfo))) { 174 | return NULL; 175 | } 176 | 177 | int32_t numPixel = 0, alignedW = 0, bufferSize = 0; 178 | numPixel = mediaInfo.img.width * mediaInfo.img.height; 179 | alignedW = ALIGNx(mediaInfo.img.width, mediaInfo.img.bitspp, 180 | CHECK_PACKAGED(mediaInfo.img.rawFormat), mediaInfo.img.stride); 181 | bufferSize = alignedW * mediaInfo.img.height; 182 | ILOGI("Image size:%dx%d pixelNum:%d", 183 | mediaInfo.img.width, mediaInfo.img.height, numPixel); 184 | ILOGI("Align (%d,%d) bufferSize:%d", 185 | alignedW, mediaInfo.img.height, bufferSize); 186 | 187 | Buffer *mipiRawData = Buffer::Alloc(bufferSize); 188 | Buffer *rawData = Buffer::Alloc(numPixel * SIZEOF_T(uint16_t)); 189 | Buffer *bgrData = Buffer::Alloc(numPixel * 3 * SIZEOF_T(uint16_t)); 190 | Buffer *yuvData = Buffer::Alloc(numPixel * 3); 191 | Buffer *postData = Buffer::Alloc(numPixel * 3); 192 | if (!mipiRawData || !rawData || !bgrData || !yuvData || !postData) { 193 | ILOGE("Failed to alloc buffers!(%p %p %p %p %p)", 194 | mipiRawData, rawData, bgrData, yuvData, postData); 195 | return NULL; 196 | } 197 | 198 | InputInfo inputInfo = { 0 }; 199 | OutputInfo outputInfo = { 0 }; 200 | inputInfo.type = INPUT_FILE_TYPE_RAW; 201 | outputInfo.imgInfo.type = OUTPUT_FILE_TYPE_BMP; 202 | if (!SUCCESS(ISPParamManager::GetInstance()->GetImgDimension(&outputInfo.imgInfo.width, 203 | &outputInfo.imgInfo.height))) { 204 | return NULL; 205 | } 206 | outputInfo.imgInfo.channels = 3; 207 | outputInfo.videoInfo.type = OUTPUT_FILE_TYPE_AVI; 208 | if (!SUCCESS(ISPParamManager::GetInstance()->GetVideoFPS(&outputInfo.videoInfo.fps))) { 209 | return NULL; 210 | } 211 | if (!SUCCESS(ISPParamManager::GetInstance()->GetVideoFrameNum(&outputInfo.videoInfo.frameNum))) { 212 | return NULL; 213 | } 214 | if (!SUCCESS(ISPParamManager::GetInstance()->GetImgDimension(&outputInfo.videoInfo.width, 215 | &outputInfo.videoInfo.height))) { 216 | return NULL; 217 | } 218 | 219 | if (!SUCCESS(FileManager::GetInstance()->SetInputInfo(inputInfo))) { 220 | return NULL; 221 | } 222 | if (!SUCCESS(FileManager::GetInstance()->SetOutputInfo(outputInfo))) { 223 | return NULL; 224 | } 225 | 226 | int32_t listId = 0; 227 | if (!SUCCESS(ISPListManager::GetInstance()->CreateList((uint16_t*)rawData->Addr(), 228 | (uint16_t*)bgrData->Addr(), 229 | (uint8_t*)yuvData->Addr(), 230 | (uint8_t*)postData->Addr(), 231 | LIST_CFG_DEFAULT, &listId))) { 232 | return NULL; 233 | } 234 | 235 | if (mediaInfo.type >= VIDEO_MEDIA && mediaInfo.type < MEDIA_TYPE_NUM) { 236 | if (!SUCCESS(FileManager::GetInstance()->CreateVideo(postData->Addr()))) { 237 | return NULL; 238 | } 239 | } 240 | 241 | int32_t frameNum = 0; 242 | if (mediaInfo.type == IMAGE_MEDIA) { 243 | frameNum = 1; 244 | } 245 | else if (mediaInfo.type >= VIDEO_MEDIA && mediaInfo.type < MEDIA_TYPE_NUM) { 246 | if (!SUCCESS(ISPParamManager::GetInstance()->GetVideoFrameNum(&frameNum))) { 247 | return NULL; 248 | } 249 | } 250 | 251 | for (int32_t frameCount = 1; frameCount <= frameNum; frameCount++) { 252 | ILOGI("L%d =========================== %d(%d) ==========================", 253 | listId, frameCount, frameNum); 254 | if (!SUCCESS(FileManager::GetInstance()->ReadData((uint8_t*)mipiRawData->Addr(), 255 | bufferSize))) { 256 | return NULL; 257 | } 258 | if (!SUCCESS(FileManager::GetInstance()->Mipi10decode((void*)mipiRawData->Addr(), 259 | (void*)rawData->Addr(), &mediaInfo.img))) { 260 | return NULL; 261 | } 262 | 263 | if (!SUCCESS(ISPListManager::GetInstance()->StartById(listId))) { 264 | return NULL; 265 | } 266 | 267 | if (mediaInfo.type >= VIDEO_MEDIA && mediaInfo.type < MEDIA_TYPE_NUM) { 268 | if (!SUCCESS(FileManager::GetInstance()->SaveVideoData(frameCount))) { 269 | ILOGE("Faild to save video for F:%d", frameCount); 270 | return NULL; 271 | } 272 | } 273 | } 274 | 275 | if (mediaInfo.type >= VIDEO_MEDIA && mediaInfo.type < MEDIA_TYPE_NUM) { 276 | if (!SUCCESS(FileManager::GetInstance()->DestroyVideo())) { 277 | return NULL; 278 | } 279 | } 280 | 281 | if (!SUCCESS(ISPListManager::GetInstance()->DestroyListbyId(listId))) { 282 | return NULL; 283 | } 284 | 285 | ImgShow(postData->Addr(), mediaInfo.img.width, mediaInfo.img.height); 286 | 287 | Buffer::Free(&mipiRawData); 288 | Buffer::Free(&rawData); 289 | Buffer::Free(&bgrData); 290 | Buffer::Free(&yuvData); 291 | Buffer::Free(&postData); 292 | 293 | InterfaceWrapper::RemoveInstance(); 294 | return NULL; 295 | } 296 | -------------------------------------------------------------------------------- /ISP/src/ISPListManager.cpp: -------------------------------------------------------------------------------- 1 | // License: GPL-3.0-or-later 2 | /* 3 | * Implementation of ISPListManager functions. 4 | * 5 | * Copyright (c) 2019 Peng Hao <635945005@qq.com> 6 | */ 7 | 8 | #include "ISPListManager.h" 9 | #include "ISPListConfig.h" 10 | #include "ISPList.hpp" 11 | #include "InterfaceWrapper.h" 12 | #include "ParamManager.h" 13 | 14 | void *gISPListConfigs[LIST_CFG_NUM] = { 15 | (void *)&defaultListConfig 16 | }; 17 | 18 | ISPListManager::ISPListManager(): 19 | pISPListConfigs(NULL) 20 | { 21 | Init(); 22 | } 23 | 24 | ISPListManager::~ISPListManager() 25 | { 26 | DestroyAllList(); 27 | } 28 | 29 | ISPListManager* ISPListManager::GetInstance() 30 | { 31 | static ISPListManager gListMgr; 32 | return &gListMgr; 33 | } 34 | 35 | int32_t ISPListManager::Init() 36 | { 37 | int32_t rt = ISP_SUCCESS; 38 | 39 | pISPListConfigs = static_cast(gISPListConfigs[LIST_CFG_DEFAULT]); 40 | 41 | return rt; 42 | } 43 | 44 | int32_t ISPListManager::CreateList(uint16_t* pRaw, uint16_t* pBGR, uint8_t* pYUV, uint8_t* pPOST, int32_t cfgIndex, int32_t *id) 45 | { 46 | int32_t rt = ISP_SUCCESS; 47 | int32_t listId = 0; 48 | ISPList* pIspList = NULL; 49 | 50 | if (cfgIndex >= LIST_CFG_NUM) 51 | { 52 | rt = ISP_INVALID_PARAM; 53 | ILOGE("Invaled cfgIndex:%d %d", cfgIndex, rt); 54 | return rt; 55 | } 56 | 57 | { 58 | unique_lock lock(mListMapLock); 59 | 60 | if (!mListMap.empty()) { 61 | for (auto iter = mListMap.begin(); iter != mListMap.end(); iter++) 62 | { 63 | if (iter->first > listId) { /* Id can be reused */ 64 | break; 65 | } else if (iter->first < listId) { 66 | rt = ISP_FAILED; 67 | ILOGE("Fatal: impossible condition"); 68 | } 69 | listId++; 70 | } 71 | } 72 | } 73 | 74 | pIspList = new ISPList(listId); 75 | if (!pIspList) { 76 | rt = ISP_MEMORY_ERROR; 77 | ILOGE("Faile to new ISPList, %d", rt); 78 | return rt; 79 | } 80 | 81 | rt = pIspList->Init(pRaw, pBGR, pYUV, pPOST); 82 | if (!SUCCESS(rt)) { 83 | delete pIspList; 84 | return rt; 85 | } 86 | 87 | rt = pIspList->SetListConfig(&pISPListConfigs[LIST_CFG_DEFAULT + cfgIndex]); 88 | if (!SUCCESS(rt)) { 89 | delete pIspList; 90 | return rt; 91 | } 92 | 93 | rt = ISPParamManager::GetInstance()->CreateParam(listId, SETTING_1920x1080_D65_1000Lux); 94 | if (!SUCCESS(rt)) { 95 | delete pIspList; 96 | return rt; 97 | } 98 | 99 | rt = pIspList->CreatISPList(); 100 | if (!SUCCESS(rt)) { 101 | ISPParamManager::GetInstance()->DeleteParam(listId); 102 | delete pIspList; 103 | return rt; 104 | } 105 | 106 | { 107 | unique_lock lock(mListMapLock); 108 | mListMap.insert(make_pair(listId, pIspList)); 109 | } 110 | 111 | return rt; 112 | } 113 | 114 | ISPList* ISPListManager::FindListById(int32_t id) 115 | { 116 | ISPList* pIspList = NULL; 117 | map*>::iterator iter; 118 | 119 | { 120 | unique_lock lock(mListMapLock); 121 | 122 | iter = mListMap.find(id); 123 | if (iter == mListMap.end()) { 124 | ILOGE("Invaled id:%d", id); 125 | } else { 126 | pIspList = iter->second; 127 | } 128 | } 129 | 130 | return pIspList; 131 | } 132 | 133 | int32_t ISPListManager::DestroyAllList() 134 | { 135 | int32_t rt = ISP_SUCCESS; 136 | 137 | while (mListMap.size()) { 138 | rt |= DestroyListbyId(mListMap.begin()->first); 139 | if (!SUCCESS(rt)) { 140 | ILOGE("Faild to destroy list(%d)", mListMap.begin()->first); 141 | } 142 | } 143 | 144 | return rt; 145 | } 146 | 147 | int32_t ISPListManager::DestroyListbyId(int32_t id) 148 | { 149 | int32_t rt = ISP_SUCCESS; 150 | ISPList* pIspList = NULL; 151 | 152 | pIspList = FindListById(id); 153 | if (!pIspList) { 154 | rt = ISP_INVALID_PARAM; 155 | ILOGE("Invaled index:%d.", id); 156 | return rt; 157 | } 158 | 159 | rt = ISPParamManager::GetInstance()->DeleteParam(id); 160 | if (!SUCCESS(rt)) { 161 | return rt; 162 | } 163 | 164 | { 165 | unique_lock lock(mListMapLock); 166 | mListMap.erase(id); 167 | delete pIspList; 168 | } 169 | 170 | return rt; 171 | } 172 | 173 | int32_t ISPListManager::StartById(int32_t id) 174 | { 175 | int32_t rt = ISP_SUCCESS; 176 | ISPList* pIspList = NULL; 177 | 178 | pIspList = FindListById(id); 179 | if (!pIspList) { 180 | rt = ISP_INVALID_PARAM; 181 | ILOGE("Invaled index:%d.", id); 182 | return rt; 183 | } 184 | 185 | rt = pIspList->Process(); 186 | 187 | return rt; 188 | } 189 | 190 | int32_t ISPListManager::EnableNodebyType(int32_t id, int32_t type) 191 | { 192 | int32_t rt = ISP_SUCCESS; 193 | ISPList* pIspList = NULL; 194 | 195 | pIspList = FindListById(id); 196 | if (!pIspList) { 197 | rt = ISP_INVALID_PARAM; 198 | ILOGE("Invaled index:%d.", id); 199 | return rt; 200 | } 201 | 202 | rt = pIspList->EnableNodebyType(type); 203 | 204 | return rt; 205 | } 206 | 207 | int32_t ISPListManager::DisableNodebyType(int32_t id, int32_t type) 208 | { 209 | int32_t rt = ISP_SUCCESS; 210 | ISPList* pIspList = NULL; 211 | 212 | pIspList = FindListById(id); 213 | if (!pIspList) { 214 | rt = ISP_INVALID_PARAM; 215 | ILOGE("Invaled index:%d.", id); 216 | return rt; 217 | } 218 | 219 | pIspList->DisableNodebyType(type); 220 | 221 | return rt; 222 | } 223 | 224 | int32_t ISPListManager::NotifyList(int32_t id, int32_t type, NotifyData data) 225 | { 226 | int32_t rt = ISP_SUCCESS; 227 | ISPList* pIspList = NULL; 228 | 229 | pIspList = FindListById(id); 230 | if (!pIspList) { 231 | rt = ISP_INVALID_PARAM; 232 | ILOGE("Invaled index:%d.", id); 233 | return rt; 234 | } 235 | 236 | rt = pIspList->NotifyNodeByType(type, data); 237 | 238 | return rt; 239 | } 240 | -------------------------------------------------------------------------------- /ISP/src/ISPVideo.cpp: -------------------------------------------------------------------------------- 1 | // License: GPL-3.0-or-later 2 | /* 3 | * ISPVideo aims to support video record in ISP. 4 | * 5 | * Copyright (c) 2019 Peng Hao <635945005@qq.com> 6 | */ 7 | 8 | #include "ISPVideo.h" 9 | #include "FileManager.h" 10 | 11 | #if DBG_OPENCV_ON 12 | #include "opencv2/core/core.hpp" 13 | #include "opencv2/imgproc/imgproc.hpp" 14 | #include "opencv2/calib3d/calib3d.hpp" 15 | #include "opencv2/highgui/highgui.hpp" 16 | 17 | using namespace cv; 18 | #endif 19 | using namespace std; 20 | 21 | ISPVideo::ISPVideo(): 22 | pSrc(NULL), 23 | mState(VIDEO_STATE_NEW) 24 | { 25 | } 26 | 27 | ISPVideo::~ISPVideo() 28 | { 29 | } 30 | 31 | int32_t ISPVideo::Init(void* pData) 32 | { 33 | int32_t rt = ISP_SUCCESS; 34 | 35 | if (mState != VIDEO_STATE_NEW) { 36 | rt = ISP_STATE_ERROR; 37 | ILOGE("Invalid state:%d", mState); 38 | return rt; 39 | } 40 | 41 | if (!pData) { 42 | ILOGE("Invalid param!"); 43 | rt = ISP_INVALID_PARAM; 44 | return rt; 45 | } 46 | 47 | pSrc = pData; 48 | mState = VIDEO_STATE_INITED; 49 | 50 | return rt; 51 | } 52 | 53 | 54 | int32_t ISPVideo::CreateThread(void* pThreadParam) 55 | { 56 | int32_t rt = ISP_SUCCESS; 57 | 58 | if (mState != VIDEO_STATE_INITED) { 59 | rt = ISP_STATE_ERROR; 60 | ILOGE("Invalid state:%d", mState); 61 | return rt; 62 | } 63 | 64 | mThread = thread(VideoEncodeFunc, pThreadParam); 65 | ILOGD("video thread start running"); 66 | mState = VIDEO_STATE_READY; 67 | 68 | return rt; 69 | } 70 | 71 | int32_t ISPVideo::DestroyThread() 72 | { 73 | int32_t rt = ISP_SUCCESS; 74 | 75 | if (mState == VIDEO_STATE_LOCK || mState == VIDEO_STATE_WAIT_FRAME_DONE) { 76 | ILOGI("Waite video thread finish", mState); 77 | } 78 | 79 | mThread.join(); 80 | ILOGD("video thread exit"); 81 | mState = VIDEO_STATE_INITED; 82 | 83 | return rt; 84 | } 85 | 86 | int32_t ISPVideo::Record(void* pRecorder, int32_t w, int32_t h) 87 | { 88 | int32_t rt = ISP_SUCCESS; 89 | 90 | if (!w || !h) { 91 | rt = ISP_INVALID_PARAM; 92 | ILOGE("Invalid param"); 93 | return rt; 94 | } 95 | 96 | { 97 | unique_lock lock(mMutex); 98 | mCond.wait(lock); 99 | #if DBG_OPENCV_ON 100 | if (!pRecorder) { 101 | rt = ISP_INVALID_PARAM; 102 | ILOGE("Input param is null"); 103 | return rt; 104 | } 105 | 106 | VideoWriter* pVR = static_cast(pRecorder); 107 | if (pVR->isOpened()) { 108 | Mat src = Mat(h, w, CV_8UC3, Scalar(0, 0, 0)); 109 | for (int32_t row = 0; row < h; row++) { 110 | for (int32_t col = 0; col < w; col++) { 111 | src.data[row * w * 3 + col * 3] = static_cast(pSrc)[row * w + col]; 112 | src.data[row * w * 3 + col * 3 + 1] = static_cast(pSrc)[w * h + row * w + col]; 113 | src.data[row * w * 3 + col * 3 + 2] = static_cast(pSrc)[2 * w * h + row * w + col]; 114 | } 115 | } 116 | *pVR << src; 117 | } 118 | #else 119 | ILOGW("Not support video recording"); 120 | #endif 121 | } 122 | 123 | return rt; 124 | } 125 | 126 | int32_t ISPVideo::Notify() 127 | { 128 | int32_t rt = ISP_SUCCESS; 129 | 130 | { 131 | unique_lock lock(mMutex); 132 | mCond.notify_one(); 133 | } 134 | 135 | return rt; 136 | } 137 | 138 | void* VideoEncodeFunc(void* threadParam) 139 | { 140 | VideoThreadParam* pParam = static_cast(threadParam); 141 | ISPVideo* pISPVideo = NULL; 142 | OutputVideoInfo info = { 0 }; 143 | void* pWriter = NULL; 144 | 145 | if (!pParam) { 146 | ILOGE("Invalid thread param!"); 147 | return NULL; 148 | } 149 | 150 | pISPVideo = static_cast(pParam->pVideo); 151 | if (!pISPVideo) { 152 | ILOGE("Invalid param!"); 153 | return NULL; 154 | } 155 | 156 | if(!SUCCESS(FileManager::GetInstance()->GetOutputVideoInfo(&info))) { 157 | return NULL; 158 | } 159 | 160 | #if DBG_OPENCV_ON 161 | pWriter = (void*) new VideoWriter(info.path, VideoWriter::fourcc('M', 'J', 'P', 'G'), info.fps, Size(info.width, info.height)); 162 | #endif 163 | if (!pWriter) { 164 | ILOGE("Failed to initialize VideoWriter!"); 165 | return NULL; 166 | } 167 | 168 | for (int32_t frameCount = 1; frameCount <= info.frameNum; frameCount++) { 169 | pISPVideo->Record(pWriter, info.width, info.height); 170 | ILOGD("Recording F:%d (%ds)", frameCount, frameCount / info.fps); 171 | if (frameCount == info.frameNum) { 172 | ILOGI("Video output path:%s", info.path); 173 | } 174 | } 175 | 176 | if (pWriter) { 177 | #if DBG_OPENCV_ON 178 | delete static_cast(pWriter); 179 | #endif 180 | } 181 | 182 | return 0; 183 | } 184 | -------------------------------------------------------------------------------- /ISP/src/InterfaceWrapper.cpp: -------------------------------------------------------------------------------- 1 | // License: GPL-3.0-or-later 2 | /* 3 | * ISP interface wrapper, supports ISP interact with other interfaces. 4 | * 5 | * Copyright (c) 2019 Peng Hao <635945005@qq.com> 6 | */ 7 | 8 | #include "InterfaceWrapper.h" 9 | #include "ISPConfig.h" 10 | #include "ISPListManager.h" 11 | #include "FileManager.h" 12 | #include "MemPool.h" 13 | #ifdef LINUX_SYSTEM 14 | #include 15 | #elif defined WIN32_SYSTEM 16 | #include 17 | #endif 18 | 19 | using namespace asteroidaxis::isp::resource; 20 | 21 | #define ALG_DYNAMIC_LIB_PATH (WORK_PATH LIB_PATH PATH_FMT ALG_LIB_NAME DYNAMIC_LIB_FMT) 22 | 23 | #define CALL_OPS(ops, op, params...) \ 24 | (((ops).op) ? (ops).op(params) : ISP_FAILED) 25 | 26 | //static ISPCallbacks gISPCallbacks; 27 | void ISPWrapNotify(int32_t argNum, ...) 28 | { 29 | NotifyData data = { 0 }; 30 | int32_t id = 0; 31 | int32_t type = 0; 32 | va_list va; 33 | 34 | va_start(va, argNum); 35 | id = va_arg(va, int32_t); 36 | type = va_arg(va, int32_t); 37 | data.rt = va_arg(va, int32_t); 38 | va_end(va); 39 | 40 | ISPListManager::GetInstance()->NotifyList(id, type, data); 41 | } 42 | 43 | const char LIB_SYMBLE[LIB_FUNCS_NUM][SYMBLE_SIZE_MAX] = { 44 | "LibInit", 45 | "LibDeInit", 46 | "RegistCallbacks" 47 | }; 48 | 49 | InterfaceWrapper *InterfaceWrapper::pItfW = NULL; 50 | static mutex gInstanceLock; 51 | 52 | InterfaceWrapper* InterfaceWrapper::GetInstance() 53 | { 54 | { 55 | unique_lock lock(gInstanceLock); 56 | 57 | if (!pItfW) { 58 | pItfW = new InterfaceWrapper(); 59 | if (!pItfW) { 60 | ILOGE("Faild to new ITF"); 61 | return NULL; 62 | } 63 | } 64 | 65 | return pItfW->IsReady() ? pItfW : NULL; 66 | } 67 | } 68 | 69 | int32_t InterfaceWrapper::RemoveInstance() 70 | { 71 | int32_t rt = ISP_SUCCESS; 72 | static int32_t rCnt = 0; 73 | 74 | { 75 | unique_lock lock(gInstanceLock); 76 | if (pItfW) { 77 | delete pItfW; 78 | pItfW = NULL; 79 | } else if (rCnt > 0) { 80 | ILOGDI("Remove ITF cnt:%d", rCnt); 81 | } 82 | rCnt++; 83 | } 84 | 85 | return rt; 86 | } 87 | 88 | int32_t InterfaceWrapper::IsReady() 89 | { 90 | return mState; 91 | } 92 | 93 | InterfaceWrapper::InterfaceWrapper() 94 | { 95 | mLibs = { NULL }; 96 | mLibsOPS = { 0 }; 97 | mISPLibParams = { 0 }; 98 | mState = ITFWRAPPER_STATE_NOT_READY; 99 | 100 | if (SUCCESS(Init())) { 101 | mState = ITFWRAPPER_STATE_READY; 102 | } 103 | } 104 | 105 | InterfaceWrapper::~InterfaceWrapper() 106 | { 107 | if (SUCCESS(DeInit())) { 108 | memset((void*)&mISPLibParams, 0, sizeof(BZParam)); 109 | } else { 110 | ILOGE("Fail to deinit!"); 111 | } 112 | 113 | mState = ITFWRAPPER_STATE_NOT_READY; 114 | } 115 | 116 | int32_t InterfaceWrapper::Init() 117 | { 118 | int32_t rt = ISP_SUCCESS; 119 | 120 | rt = LoadLib(ISP_ALG_LIB, ALG_DYNAMIC_LIB_PATH); 121 | if (!SUCCESS(rt)) { 122 | ILOGE("Failed to load lib"); 123 | return rt; 124 | } 125 | 126 | rt = InterfaceInit(ISP_ALG_LIB); 127 | 128 | return rt; 129 | /* TODO[L]: load libs if need */ 130 | } 131 | 132 | int32_t InterfaceWrapper::DeInit() 133 | { 134 | int32_t rt = ISP_SUCCESS; 135 | 136 | if (mState != ITFWRAPPER_STATE_READY) { 137 | rt = ISP_STATE_ERROR; 138 | ILOGE("Invalid state:%d", mState); 139 | return rt; 140 | } 141 | 142 | for (int32_t index = ISP_ALG_LIB; index < ISP_LIBS_NUM; index++) { 143 | rt = InterfaceDeInit(index); 144 | if (!SUCCESS(rt)) { 145 | ILOGE("Failed to deinit interface:%d", index); 146 | return rt; 147 | } 148 | } 149 | 150 | for (int32_t index = ISP_ALG_LIB; index < ISP_LIBS_NUM; index++) { 151 | rt = ReleaseLib(index); 152 | if (!SUCCESS(rt)) { 153 | ILOGE("Failed to release lib:%d", index); 154 | return rt; 155 | } 156 | } 157 | 158 | return rt; 159 | } 160 | 161 | int32_t InterfaceWrapper::LoadLib(int32_t libId, const char* path) 162 | { 163 | int32_t rt = ISP_SUCCESS; 164 | 165 | void** pLib = NULL; 166 | 167 | switch(libId) { 168 | case ISP_ALG_LIB: 169 | pLib = &mLibs.pAlgLib; 170 | break; 171 | case ISP_LIBS_NUM: 172 | default: 173 | break; 174 | } 175 | 176 | if (!pLib) { 177 | rt = ISP_INVALID_PARAM; 178 | ILOGE("Invalid lib id:%d", libId); 179 | return rt; 180 | } 181 | 182 | #ifdef LINUX_SYSTEM 183 | *pLib = dlopen(path, RTLD_LAZY); 184 | #elif defined WIN32_SYSTEM 185 | int32_t length = 0; 186 | for (length = 0; length < FILE_PATH_MAX_SIZE; length++) { 187 | if (path[length] == '\0') { 188 | break; 189 | } 190 | } 191 | if (length >= FILE_PATH_MAX_SIZE - 1) { 192 | rt = ISP_INVALID_PARAM; 193 | ILOGE("Invalid lib path length:%d", length); 194 | return rt; 195 | } 196 | WCHAR wPath[FILE_PATH_MAX_SIZE] = { L'\0' }; 197 | MultiByteToWideChar(CP_ACP, 0, path, length, wPath, 198 | length); 199 | *pLib = LoadLibrary(wPath); 200 | #endif 201 | if (!*pLib) { 202 | rt = ISP_FAILED; 203 | ILOGE("Faild to open lib:%s", path); 204 | return rt; 205 | } 206 | ILOGDI("Load lib:%d %s", libId, path); 207 | 208 | return rt; 209 | } 210 | 211 | int32_t InterfaceWrapper::ReleaseLib(int32_t libId) 212 | { 213 | int32_t rt = ISP_SUCCESS; 214 | 215 | void** pLib = NULL; 216 | 217 | switch(libId) { 218 | case ISP_ALG_LIB: 219 | pLib = &mLibs.pAlgLib; 220 | break; 221 | case ISP_LIBS_NUM: 222 | default: 223 | break; 224 | } 225 | 226 | if (!pLib) { 227 | rt = ISP_INVALID_PARAM; 228 | ILOGE("Invalid lib id:%d", libId); 229 | return rt; 230 | } 231 | 232 | if (!(*pLib)) { 233 | rt = ISP_FAILED; 234 | ILOGE("Lib not load:%d", libId); 235 | return rt; 236 | } 237 | 238 | #ifdef LINUX_SYSTEM 239 | dlclose(*pLib); 240 | #elif defined WIN32_SYSTEM 241 | FreeLibrary((HMODULE)*pLib); 242 | #endif 243 | *pLib = NULL; 244 | ILOGDI("Release lib:%d", libId); 245 | 246 | return rt; 247 | } 248 | 249 | int32_t InterfaceWrapper::InterfaceInit(int32_t libId) 250 | { 251 | int32_t rt = ISP_SUCCESS; 252 | 253 | switch(libId) { 254 | case ISP_ALG_LIB: 255 | rt = AlgInterfaceInit(); 256 | break; 257 | case ISP_LIBS_NUM: 258 | default: 259 | rt = ISP_INVALID_PARAM; 260 | ILOGE("Invalid lib id:%d", libId); 261 | break; 262 | } 263 | 264 | return rt; 265 | } 266 | 267 | int32_t InterfaceWrapper::InterfaceDeInit(int32_t libId) 268 | { 269 | int32_t rt = ISP_SUCCESS; 270 | 271 | switch(libId) { 272 | case ISP_ALG_LIB: 273 | rt = AlgInterfaceDeInit(); 274 | break; 275 | case ISP_LIBS_NUM: 276 | default: 277 | rt = ISP_INVALID_PARAM; 278 | ILOGE("Invalid lib id:%d", libId); 279 | break; 280 | } 281 | 282 | return rt; 283 | } 284 | 285 | int32_t InterfaceWrapper::AlgInterfaceInit() 286 | { 287 | int32_t rt = ISP_SUCCESS; 288 | LIB_VOID_FUNC_ADDR funcs[LIB_FUNCS_NUM] = {NULL}; 289 | 290 | if (!mLibs.pAlgLib) { 291 | rt = ISP_FAILED; 292 | ILOGE("Wrap not init!"); 293 | return rt; 294 | } 295 | 296 | for (int32_t i = 0; i < LIB_FUNCS_NUM; i++) { 297 | #ifdef LINUX_SYSTEM 298 | funcs[i] = (LIB_VOID_FUNC_ADDR)dlsym(mLibs.pAlgLib, LIB_SYMBLE[i]); 299 | #elif defined WIN32_SYSTEM 300 | funcs[i] = (LIB_VOID_FUNC_ADDR)GetProcAddress((HMODULE)mLibs.pAlgLib, LIB_SYMBLE[i]); 301 | #endif 302 | ILOGDI("Lib Func[%d]:%p", i, funcs[i]); 303 | } 304 | 305 | if (!funcs[0]) { 306 | rt = ISP_FAILED; 307 | ILOGE("Lib Func[0]:%p", funcs[0]); 308 | return rt; 309 | } 310 | 311 | funcs[0]((void*)&mLibsOPS.algOPS); 312 | 313 | if (!funcs[2]) { 314 | rt = ISP_FAILED; 315 | ILOGE("Lib Func[2]:%p", funcs[2]); 316 | return rt; 317 | } 318 | 319 | /* TODO[L]: add callbacks if need */ 320 | ISPCallbacks CBs = { 0 }; 321 | CBs.ISPNotify = ISPWrapNotify; 322 | CBs.UtilsFuncs.Log = LogBase; 323 | CBs.UtilsFuncs.DumpDataInt = DumpDataInt; 324 | CBs.UtilsFuncs.Alloc = ISPAlloc; 325 | CBs.UtilsFuncs.Free = ISPFree; 326 | funcs[2]((void*)&CBs); 327 | 328 | return rt; 329 | } 330 | 331 | int32_t InterfaceWrapper::AlgInterfaceDeInit() 332 | { 333 | int32_t rt = ISP_SUCCESS; 334 | LIB_VOID_FUNC_ADDR funcs[LIB_FUNCS_NUM] = {NULL}; 335 | 336 | if (!mLibs.pAlgLib) { 337 | rt = ISP_FAILED; 338 | ILOGE("Wrap not init!"); 339 | return rt; 340 | } 341 | 342 | memset(&mLibsOPS.algOPS, 0, sizeof(BZOps)); 343 | 344 | for (int32_t i = 0; i < LIB_FUNCS_NUM; i++) { 345 | #ifdef LINUX_SYSTEM 346 | funcs[i] = (LIB_VOID_FUNC_ADDR)dlsym(mLibs.pAlgLib, LIB_SYMBLE[i]); 347 | #elif defined WIN32_SYSTEM 348 | funcs[i] = (LIB_VOID_FUNC_ADDR)GetProcAddress((HMODULE)mLibs.pAlgLib, LIB_SYMBLE[i]); 349 | #endif 350 | ILOGDI("Lib Func[%d]:%p", i, funcs[i]); 351 | } 352 | 353 | if (!funcs[1]) { 354 | rt = ISP_FAILED; 355 | ILOGE("Lib Func[1]:%p", funcs[1]); 356 | return rt; 357 | } 358 | 359 | funcs[1](NULL); 360 | 361 | return rt; 362 | } 363 | 364 | int32_t InterfaceWrapper::AlgISPListCreate(int32_t id) 365 | { 366 | int32_t rt = ISP_SUCCESS; 367 | uint32_t msg[MSG_NUM_MAX] = { 0 }; 368 | 369 | msg[MSG_D0] = BZ_CMD_CREATE_PROC; 370 | msg[MSG_D1] = (uint32_t)id; 371 | 372 | rt = CALL_OPS(mLibsOPS.algOPS, BZEvent, msg); 373 | return rt; 374 | } 375 | 376 | int32_t InterfaceWrapper::AlgProcess(int32_t id, int32_t type, void *pCtrl) 377 | { 378 | int32_t rt = ISP_SUCCESS; 379 | uint32_t msg[MSG_NUM_MAX] = { 0 }; 380 | 381 | msg[MSG_D0] = BZ_CMD_PROCESS; 382 | msg[MSG_D1] = (uint32_t)id; 383 | msg[MSG_D2] = (uint32_t)type; 384 | #if __WORDSIZE == 64 385 | msg[MSG_D3] = (uint64_t)pCtrl & 0xffffffff; 386 | msg[MSG_D4] = ((uint64_t)pCtrl >> 32) & 0xffffffff; 387 | #elif __WORDSIZE == 32 388 | msg[MSG_D3] = (uint32_t)pCtrl; 389 | #endif 390 | 391 | rt = CALL_OPS(mLibsOPS.algOPS, BZEvent, msg); 392 | 393 | return rt; 394 | } 395 | 396 | size_t InterfaceWrapper::GetAlgParamSize() 397 | { 398 | return sizeof(BZParam); 399 | } 400 | -------------------------------------------------------------------------------- /ISP/src/Log.cpp: -------------------------------------------------------------------------------- 1 | // License: GPL-3.0-or-later 2 | /* 3 | * ISP log supports. 4 | * 5 | * Copyright (c) 2019 Peng Hao <635945005@qq.com> 6 | */ 7 | 8 | #include "Log.h" 9 | #include 10 | 11 | #define LOG_NEED_EXT_INFO true 12 | 13 | int32_t LogBase(const char* str, ...) 14 | { 15 | bool needExtInfo = LOG_NEED_EXT_INFO; 16 | 17 | va_list va; 18 | va_start(va, str); 19 | LogAddInfo(needExtInfo, str, va); 20 | va_end(va); 21 | 22 | return 0; 23 | } 24 | 25 | void LogAddInfo(bool needExtInfo, const char* str, va_list va) 26 | { 27 | if (needExtInfo) { 28 | char strBuffer[LOG_BUFFER_LEFT_SIZE]; 29 | char years[4] = { '0', '0', '0', '0' }; 30 | char monthes[2] = { '0', '0' }; 31 | char days[2] = { '0', '0' }; 32 | char milliseconds[3] = { '0','0','0' }; 33 | char seconds[2] = { '0', '0' }; 34 | char minutes[2] = { '0', '0' }; 35 | char hours[2] = { '0', '0' }; 36 | 37 | getTimeWithDateChar(years, monthes, days, hours, minutes, seconds, milliseconds); 38 | snprintf(strBuffer, LOG_BUFFER_LEFT_SIZE, "%c%c%c%c-%c%c-%c%c %c%c:%c%c:%c%c:%c%c%c %s", 39 | years[0], years[1], years[2], years[3], 40 | monthes[0], monthes[1], 41 | days[0], days[1], 42 | hours[0], hours[1], 43 | minutes[0], minutes[1], 44 | seconds[0], seconds[1], 45 | milliseconds[0], milliseconds[1], milliseconds[2], 46 | str); 47 | LogPrint(strBuffer, va); 48 | } else { 49 | LogPrint(str, va); 50 | } 51 | } 52 | 53 | void LogPrint(const char* str, va_list va) 54 | { 55 | char strBuffer[LOG_BUFFER_SIZE]; 56 | vsnprintf(strBuffer, LOG_BUFFER_SIZE - LOG_BUFFER_PERSERVE_SIZE, str, va); 57 | strBuffer[LOG_BUFFER_SIZE - 2] = '\0'; 58 | strBuffer[LOG_BUFFER_SIZE - 1] = '\n'; 59 | printf("%s\n", strBuffer); 60 | } 61 | -------------------------------------------------------------------------------- /ISP/src/Main.cpp: -------------------------------------------------------------------------------- 1 | // License: GPL-3.0-or-later 2 | /* 3 | * ISP main function implementation. 4 | * 5 | * Copyright (c) 2019 Peng Hao <635945005@qq.com> 6 | */ 7 | 8 | #include "ISPCore.h" 9 | 10 | int main(int argc, char *argv[], char *envp[]) 11 | { 12 | int rt = 0; 13 | 14 | IOInfo ioInfo = { 0 }; 15 | ioInfo.argc = argc > MAX_IO_PARAM_CNT ? MAX_IO_PARAM_CNT : argc; 16 | for (int32_t i = 0; i < ioInfo.argc; i++) { 17 | ioInfo.argv[i] = argv[i]; 18 | ioInfo.envp[i] = envp[i]; 19 | } 20 | 21 | ISPItf* ispItf = ISPCore::GetInstance(); 22 | if (ispItf) { 23 | rt = ispItf->Process(&ioInfo); 24 | } 25 | 26 | return rt; 27 | } 28 | -------------------------------------------------------------------------------- /ISP/src/MemPool.cpp: -------------------------------------------------------------------------------- 1 | // License: GPL-3.0-or-later 2 | /* 3 | * Memory pool implementation. 4 | * 5 | * Copyright (c) 2019 Peng Hao <635945005@qq.com> 6 | */ 7 | 8 | #include "MemPool.h" 9 | 10 | namespace asteroidaxis::isp::resource { 11 | 12 | #if DBG_MEM_OVERWRITE_CHECK_ON 13 | void* OverwriteCheckingFunc(void* param) 14 | { 15 | MemThreadParam *pParam = static_cast(param); 16 | ILOGDM("Overwrite checking start"); 17 | 18 | if (!pParam) { 19 | ILOGE("Invalid thread param"); 20 | return NULL; 21 | } 22 | 23 | uint8_t overwriteDetected = 0; 24 | while(1 && !pParam->exit) { 25 | { 26 | unique_lock lock(*(pParam->pLock)); 27 | 28 | if (!pParam->pSymbolMap->empty()) { 29 | for (auto it = pParam->pSymbolMap->begin(); it != pParam->pSymbolMap->end(); it++) { 30 | overwriteDetected = 0; 31 | for(size_t index = 0; index < OVERWRITE_CHECK_SIZE; index++) { 32 | overwriteDetected |= 33 | ~(it->second[index]) & 34 | gOverwiteSymbol[index]; 35 | } 36 | if (overwriteDetected) { 37 | ILOGE("Fatal Error 0x%x: ================ MEMORY OVERWRITE DETECTED ==============", 38 | overwriteDetected); 39 | ILOGE("addr:%p symbleAddr:%p symble:%s", 40 | it->first, it->second, 41 | it->second); 42 | std::abort(); 43 | break; 44 | } 45 | } 46 | } 47 | } 48 | usleep(OVERWRITE_CHECK_TIME_GAP_US); 49 | } 50 | 51 | ILOGDM("Overwrite checking end"); 52 | return 0; 53 | } 54 | #endif 55 | 56 | void* ISPAlloc(size_t size, ...) 57 | { 58 | return MemoryPool::GetInstance()->RequireBuffer(size); 59 | } 60 | 61 | void* ISPFree(void* pBuf, ...) 62 | { 63 | return (void*)MemoryPool::GetInstance()->RevertBuffer(static_cast(pBuf)); 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /ISP/src/ParamManager.cpp: -------------------------------------------------------------------------------- 1 | // License: GPL-3.0-or-later 2 | /* 3 | * ParamManager aims to manage multi params. 4 | * 5 | * Copyright (c) 2019 Peng Hao <635945005@qq.com> 6 | */ 7 | 8 | #include "ParamManager.h" 9 | #include "InterfaceWrapper.h" 10 | #include "Setting_1920x1080_D65_1000Lux.h" 11 | 12 | using namespace asteroidaxis::isp::resource; 13 | 14 | const ISPSetting gISPSettings[SETTING_INDEX_NUM] { 15 | { 16 | /* BLC_SETTING */ (void *)&BLC_SETTING_1920x1080_D65_1000Lux, 17 | /* LSC_SETTING */ (void *)&LSC_SETTING_1920x1080_D65_1000Lux, 18 | /* WB_PARM */ (void *)&WB_SETTING_1920x1080_D65_1000Lux, 19 | /* CC_SETTING */ (void *)&CC_SETTING_1920x1080_D65_1000Lux, 20 | /* GAMMA_SETTING */ (void *)&GAMMA_SETTING_1920x1080_D65_1000Lux, 21 | /* WNR_SETTING */ (void *)&WNR_SETTING_1920x1080_D65_1000Lux, 22 | /* EE_SETTING */ (void *)&EE_SETTING_1920x1080_D65_1000Lux, 23 | }, 24 | }; 25 | 26 | ISPParamManager* ISPParamManager::GetInstance() 27 | { 28 | static ISPParamManager gInstance; 29 | return &gInstance; 30 | } 31 | 32 | ISPParamManager::ISPParamManager() 33 | { 34 | mMediaInfo.img = { 0 }; 35 | mState = PM_STATE_UNINIT; 36 | } 37 | 38 | ISPParamManager::~ISPParamManager() 39 | { 40 | { 41 | unique_lock lock(mParamListLock); 42 | for (auto iter = mActiveParamList.begin(); iter != mActiveParamList.end(); iter++) { 43 | if (iter->buf) { 44 | Buffer::Free(&iter->buf); 45 | } 46 | } 47 | mActiveParamList.clear(); 48 | } 49 | } 50 | 51 | ISPParamInfo *ISPParamManager::GetParamInfoById(int id) 52 | { 53 | ISPParamInfo *pInfo = NULL; 54 | 55 | { 56 | unique_lock lock(mParamListLock); 57 | for (auto iter = mActiveParamList.begin(); iter != mActiveParamList.end(); iter++) { 58 | if (iter->id == id) { 59 | pInfo = &(*iter); 60 | } 61 | } 62 | } 63 | 64 | return pInfo; 65 | } 66 | 67 | int32_t ISPParamManager::CreateParam(int32_t hostId, int32_t settingId) 68 | { 69 | int32_t rt = ISP_SUCCESS; 70 | ISPParamInfo paramInfo = { 0 }; 71 | 72 | paramInfo.id = hostId; 73 | paramInfo.settingIndex = settingId; 74 | paramInfo.buf = Buffer::Alloc(InterfaceWrapper::GetInstance()->GetAlgParamSize()); 75 | 76 | rt = FillinParam(¶mInfo); 77 | if (!SUCCESS(rt)) { 78 | if (paramInfo.buf) { 79 | Buffer::Free(¶mInfo.buf); 80 | } 81 | return rt; 82 | } 83 | 84 | { 85 | unique_lock lock(mParamListLock); 86 | mActiveParamList.push_back(paramInfo); 87 | } 88 | 89 | return rt; 90 | } 91 | 92 | int32_t ISPParamManager::DeleteParam(int32_t hostId) 93 | { 94 | int32_t rt = ISP_FAILED; 95 | list::iterator iter = mActiveParamList.begin(); 96 | 97 | { 98 | unique_lock lock(mParamListLock); 99 | while (iter != mActiveParamList.end()) { 100 | if (iter->id == hostId) { 101 | if (iter->buf) { 102 | Buffer::Free(&iter->buf); 103 | } 104 | mActiveParamList.erase(iter); 105 | rt = ISP_SUCCESS; 106 | break; 107 | } 108 | iter++; 109 | } 110 | } 111 | 112 | if (!SUCCESS(rt)) { 113 | ILOGE("Invalid id:%d", hostId); 114 | } 115 | 116 | return rt; 117 | } 118 | 119 | int32_t ISPParamManager::FillinParam(ISPParamInfo *pParamInfo) 120 | { 121 | int32_t rt = ISP_SUCCESS; 122 | 123 | if (!pParamInfo) { 124 | rt = ISP_INVALID_PARAM; 125 | ILOGE("Input is null"); 126 | return rt; 127 | } 128 | 129 | if (pParamInfo->settingIndex >= SETTING_INDEX_NUM) { 130 | rt = ISP_INVALID_PARAM; 131 | ILOGE("Invaled setting index:%d. id:%d", pParamInfo->settingIndex, pParamInfo->id); 132 | return rt; 133 | } 134 | 135 | if (!pParamInfo->buf) { 136 | rt = ISP_MEMORY_ERROR; 137 | ILOGE("Param buffer is null. id:%d index:%d", pParamInfo->id, pParamInfo->settingIndex); 138 | return rt; 139 | } 140 | 141 | if (pParamInfo->buf->Size() != InterfaceWrapper::GetInstance()->GetAlgParamSize() || 142 | !pParamInfo->buf->Addr()) { 143 | rt = ISP_MEMORY_ERROR; 144 | ILOGE("Invalid param (addr:%p size:%u). id:%d index:%d", 145 | pParamInfo->buf->Addr(), pParamInfo->buf->Size(), 146 | pParamInfo->id, pParamInfo->settingIndex); 147 | return rt; 148 | } 149 | 150 | /* TODO[H]: according to list node on/off state to get param */ 151 | for (int32_t paramType = 0; paramType < BZ_PARAM_TYPE_NUM; paramType++) { 152 | rt |= FillinParamByType(pParamInfo, paramType); 153 | if (!SUCCESS(rt)) { 154 | return rt; 155 | } 156 | } 157 | 158 | return rt; 159 | } 160 | 161 | void* ISPParamManager::GetParam(int32_t id, int32_t type) 162 | { 163 | return GetParamByType(GetParamInfoById(id), type); 164 | } 165 | 166 | void ISPParamManager::DumpParamInfo() 167 | { 168 | { 169 | unique_lock lock(mParamListLock); 170 | ILOGI("Total %d active param.", mActiveParamList.size()); 171 | for (auto iter = mActiveParamList.begin(); iter != mActiveParamList.end(); iter++) { 172 | ILOGI("param[%d] id:%d index:%d size:%u addr:0x%x)", 173 | iter = mActiveParamList.begin(), 174 | iter->id, 175 | iter->settingIndex, 176 | iter->buf->Size(), 177 | iter->buf->Addr()); 178 | } 179 | } 180 | } 181 | 182 | void* ISPParamManager::GetParamByType(ISPParamInfo *pInfo, int32_t type) 183 | { 184 | void *pTargetParam = NULL; 185 | 186 | if (!pInfo) { 187 | ILOGE("Input is null!"); 188 | DumpParamInfo(); 189 | return NULL; 190 | } 191 | 192 | if (!pInfo->buf) { 193 | ILOGE("Buffer is null!"); 194 | return NULL; 195 | } 196 | 197 | BZParam *pParams = static_cast(pInfo->buf->Addr()); 198 | if (!pParams) { 199 | ILOGE("Param buffer is null!"); 200 | return NULL; 201 | } 202 | 203 | switch(type) { 204 | //TODO[M]: use offset table instead. 205 | case BZ_PARAM_TYPE_IMAGE_INFO: 206 | pTargetParam = (void*)&pParams->info; 207 | break; 208 | case BZ_PARAM_TYPE_BLC: 209 | pTargetParam = (void*)&pParams->blc; 210 | break; 211 | case BZ_PARAM_TYPE_LSC: 212 | pTargetParam = (void*)&pParams->lsc; 213 | break; 214 | case BZ_PARAM_TYPE_WB: 215 | pTargetParam = (void*)&pParams->wb; 216 | break; 217 | case BZ_PARAM_TYPE_CC: 218 | pTargetParam = (void*)&pParams->cc; 219 | break; 220 | case BZ_PARAM_TYPE_Gamma: 221 | pTargetParam = (void*)&pParams->gamma; 222 | break; 223 | case BZ_PARAM_TYPE_WNR: 224 | pTargetParam = (void*)&pParams->wnr; 225 | break; 226 | case BZ_PARAM_TYPE_EE: 227 | pTargetParam = (void*)&pParams->ee; 228 | break; 229 | case BZ_PARAM_TYPE_DMC: 230 | case BZ_PARAM_TYPE_RAW2RGB: 231 | case BZ_PARAM_TYPE_RGB2YUV: 232 | case BZ_PARAM_TYPE_YUV2RGB: 233 | case BZ_PARAM_TYPE_NUM: 234 | /* No param */ 235 | pTargetParam = NULL; 236 | break; 237 | default: 238 | pTargetParam = NULL; 239 | ILOGE("Invalid param type:%d", type); 240 | break; 241 | } 242 | 243 | return pTargetParam; 244 | } 245 | 246 | int32_t ISPParamManager::SetMediaInfo(MediaInfo* info) 247 | { 248 | int32_t rt = ISP_SUCCESS; 249 | 250 | if (!info) { 251 | rt = ISP_INVALID_PARAM; 252 | ILOGE("Input is null! %d", rt); 253 | return rt; 254 | } 255 | 256 | rt = SetImgInfo(&info->img); 257 | if (!SUCCESS(rt)) { 258 | rt = ISP_FAILED; 259 | ILOGE("Failed to set img info %d", rt); 260 | return rt; 261 | } 262 | 263 | rt = SetVideoInfo(&info->video); 264 | if (!SUCCESS(rt)) { 265 | rt = ISP_FAILED; 266 | ILOGE("Failed to set video info %d", rt); 267 | return rt; 268 | } 269 | 270 | mState = PM_STATE_MEDIA_INFO_SET; 271 | 272 | return rt; 273 | } 274 | 275 | int32_t ISPParamManager::SetImgInfo(ImgInfo* info) 276 | { 277 | int32_t rt = ISP_SUCCESS; 278 | 279 | if (info) { 280 | memcpy(&mMediaInfo.img, info, sizeof(ImgInfo)); 281 | } 282 | else { 283 | rt = ISP_INVALID_PARAM; 284 | ILOGE("Input is null! %d", rt); 285 | } 286 | 287 | return rt; 288 | } 289 | 290 | int32_t ISPParamManager::SetVideoInfo(VideoInfo* info) 291 | { 292 | int32_t rt = ISP_SUCCESS; 293 | 294 | if (info) { 295 | memcpy(&mMediaInfo.video, info, sizeof(VideoInfo)); 296 | } 297 | else { 298 | rt = ISP_INVALID_PARAM; 299 | ILOGE("Input is null! %d", rt); 300 | } 301 | 302 | return rt; 303 | } 304 | 305 | int32_t ISPParamManager::GetImgDimension(int32_t* width, int32_t* height) 306 | { 307 | int32_t rt = ISP_SUCCESS; 308 | 309 | if (mState < PM_STATE_MEDIA_INFO_SET) { 310 | rt = ISP_STATE_ERROR; 311 | ILOGE("Invalid param manager state:%d", mState); 312 | return rt; 313 | } 314 | 315 | if (width && height) { 316 | *width = mMediaInfo.img.width; 317 | *height = mMediaInfo.img.height; 318 | } 319 | else { 320 | rt = ISP_INVALID_PARAM; 321 | ILOGE("Input is null! %d", rt); 322 | } 323 | 324 | return rt; 325 | } 326 | 327 | int32_t ISPParamManager::GetVideoFPS(int32_t* fps) 328 | { 329 | int32_t rt = ISP_SUCCESS; 330 | 331 | if (mState < PM_STATE_MEDIA_INFO_SET) { 332 | rt = ISP_STATE_ERROR; 333 | ILOGE("Invalid param manager state:%d", mState); 334 | return rt; 335 | } 336 | 337 | if (fps) { 338 | *fps = mMediaInfo.video.fps; 339 | } 340 | else { 341 | rt = ISP_INVALID_PARAM; 342 | ILOGE("Input is null! %d", rt); 343 | } 344 | 345 | return rt; 346 | } 347 | 348 | int32_t ISPParamManager::GetVideoFrameNum(int32_t* num) 349 | { 350 | int32_t rt = ISP_SUCCESS; 351 | 352 | if (mState < PM_STATE_MEDIA_INFO_SET) { 353 | rt = ISP_STATE_ERROR; 354 | ILOGE("Invalid param manager state:%d", mState); 355 | return rt; 356 | } 357 | 358 | if (num) { 359 | *num = mMediaInfo.video.frameNum; 360 | } 361 | else { 362 | rt = ISP_INVALID_PARAM; 363 | ILOGE("Input is null! %d", rt); 364 | } 365 | 366 | return rt; 367 | } 368 | 369 | int32_t ISPParamManager::FillinImgInfo(void *pInfo) 370 | { 371 | int32_t rt = ISP_SUCCESS; 372 | 373 | BZImgInfo *pImgInfo = static_cast(pInfo); 374 | if (!pImgInfo) { 375 | rt = ISP_INVALID_PARAM; 376 | ILOGE("Input is null!"); 377 | return rt; 378 | } 379 | 380 | if (mState != PM_STATE_MEDIA_INFO_SET) { 381 | rt = ISP_INVALID_PARAM; 382 | ILOGE("Invalid pm state:%d", mState); 383 | return rt; 384 | } 385 | 386 | if (SUCCESS(rt)) { 387 | pImgInfo->width = mMediaInfo.img.width; 388 | pImgInfo->height = mMediaInfo.img.height; 389 | pImgInfo->rawFormat = mMediaInfo.img.rawFormat; 390 | pImgInfo->bitspp = mMediaInfo.img.bitspp; 391 | pImgInfo->stride = mMediaInfo.img.stride; 392 | pImgInfo->bayerOrder = mMediaInfo.img.bayerOrder; 393 | } 394 | 395 | return rt; 396 | } 397 | 398 | int32_t ISPParamManager::FillinParamByType(ISPParamInfo *pInfo, int32_t type) 399 | { 400 | int32_t rt = ISP_SUCCESS; 401 | 402 | if (!pInfo) { 403 | rt = ISP_INVALID_PARAM; 404 | ILOGE("Input is null!"); 405 | return rt; 406 | } 407 | 408 | if (!pInfo->buf) { 409 | rt = ISP_INVALID_PARAM; 410 | ILOGE("Buffer is null!"); 411 | return rt; 412 | } 413 | 414 | BZParam *pParams = static_cast(pInfo->buf->Addr()); 415 | if (!pParams) { 416 | rt = ISP_INVALID_PARAM; 417 | ILOGE("Param buffer is null!"); 418 | return rt; 419 | } 420 | 421 | void *pTargetParam = GetParamByType(pInfo, type); 422 | switch(type) { 423 | /* TODO[M]: use a func array. */ 424 | case BZ_PARAM_TYPE_IMAGE_INFO: 425 | rt = FillinImgInfo(pTargetParam); 426 | break; 427 | case BZ_PARAM_TYPE_BLC: 428 | rt = FillinBLCParam(pTargetParam, (ISPSetting*)&gISPSettings[pInfo->settingIndex]); 429 | break; 430 | case BZ_PARAM_TYPE_LSC: 431 | rt = FillinLSCParam(pTargetParam, (ISPSetting*)&gISPSettings[pInfo->settingIndex]); 432 | break; 433 | case BZ_PARAM_TYPE_WB: 434 | rt = FillinWBParam(pTargetParam, (ISPSetting*)&gISPSettings[pInfo->settingIndex]); 435 | break; 436 | case BZ_PARAM_TYPE_CC: 437 | rt = FillinCCParam(pTargetParam, (ISPSetting*)&gISPSettings[pInfo->settingIndex]); 438 | break; 439 | case BZ_PARAM_TYPE_Gamma: 440 | rt = FillinGAMMAParam(pTargetParam, (ISPSetting*)&gISPSettings[pInfo->settingIndex]); 441 | break; 442 | case BZ_PARAM_TYPE_WNR: 443 | rt = FillinWNRParam(pTargetParam, (ISPSetting*)&gISPSettings[pInfo->settingIndex]); 444 | break; 445 | case BZ_PARAM_TYPE_EE: 446 | rt = FillinEEParam(pTargetParam, (ISPSetting*)&gISPSettings[pInfo->settingIndex]); 447 | break; 448 | case BZ_PARAM_TYPE_DMC: 449 | case BZ_PARAM_TYPE_RAW2RGB: 450 | case BZ_PARAM_TYPE_RGB2YUV: 451 | case BZ_PARAM_TYPE_YUV2RGB: 452 | /* No param needs to fill in */ 453 | break; 454 | case BZ_PARAM_TYPE_NUM: 455 | default: 456 | rt = ISP_INVALID_PARAM; 457 | ILOGE("Invalid param type:%d", type); 458 | break; 459 | } 460 | 461 | return rt; 462 | } 463 | 464 | int32_t ISPParamManager::FillinBLCParam(void *pParam, ISPSetting *pSetting) 465 | { 466 | int32_t rt = ISP_SUCCESS; 467 | 468 | BZBlcParam* pBlcParam = static_cast(pParam); 469 | if (!pBlcParam || !pSetting) { 470 | rt = ISP_INVALID_PARAM; 471 | ILOGE("Input is null!"); 472 | return rt; 473 | } 474 | 475 | int difBitNum = static_cast(pSetting->pBlc)->bitNum - 8; 476 | if (0 < difBitNum && difBitNum < 4) { 477 | pBlcParam->offset = (static_cast(pSetting->pBlc)->BlcDefaultValue << difBitNum); 478 | } 479 | else { 480 | pBlcParam->offset = static_cast(pSetting->pBlc)->BlcDefaultValue; 481 | } 482 | 483 | return rt; 484 | } 485 | 486 | int32_t ISPParamManager::FillinLSCParam(void *pParam, ISPSetting *pSetting) 487 | { 488 | int32_t rt = ISP_SUCCESS; 489 | 490 | BZLscParam *pLscParam = static_cast(pParam); 491 | if (!pLscParam || !pSetting) { 492 | rt = ISP_INVALID_PARAM; 493 | ILOGE("Input is null!"); 494 | return rt; 495 | } 496 | 497 | for (int32_t i = 0; i < LSC_LUT_HEIGHT; i++) { 498 | memcpy(pLscParam->gainCh1 + i * LSC_LUT_WIDTH, static_cast(pSetting->pLsc)->gainCh1[i], LSC_LUT_WIDTH * sizeof(float)); 499 | memcpy(pLscParam->gainCh2 + i * LSC_LUT_WIDTH, static_cast(pSetting->pLsc)->gainCh2[i], LSC_LUT_WIDTH * sizeof(float)); 500 | memcpy(pLscParam->gainCh3 + i * LSC_LUT_WIDTH, static_cast(pSetting->pLsc)->gainCh3[i], LSC_LUT_WIDTH * sizeof(float)); 501 | memcpy(pLscParam->gainCh4 + i * LSC_LUT_WIDTH, static_cast(pSetting->pLsc)->gainCh4[i], LSC_LUT_WIDTH * sizeof(float)); 502 | } 503 | 504 | return rt; 505 | } 506 | 507 | int32_t ISPParamManager::FillinWBParam(void *pParam, ISPSetting *pSetting) 508 | { 509 | int32_t rt = ISP_SUCCESS; 510 | 511 | BZWbParam *pWbParam = static_cast(pParam); 512 | if (!pWbParam || !pSetting) { 513 | rt = ISP_INVALID_PARAM; 514 | ILOGE("Input is null!"); 515 | return rt; 516 | } 517 | 518 | int32_t mode = static_cast(pSetting->pWb)->Wb1stGamma2rd; 519 | pWbParam->rGain = mode ? static_cast(pSetting->pWb)->gainType1.rGain : static_cast(pSetting->pWb)->gainType2.rGain; 520 | pWbParam->gGain = mode ? static_cast(pSetting->pWb)->gainType1.gGain : static_cast(pSetting->pWb)->gainType2.gGain; 521 | pWbParam->bGain = mode ? static_cast(pSetting->pWb)->gainType1.bGain : static_cast(pSetting->pWb)->gainType2.bGain; 522 | 523 | return rt; 524 | } 525 | 526 | int32_t ISPParamManager::FillinCCParam(void *pParam, ISPSetting *pSetting) 527 | { 528 | int32_t rt = ISP_SUCCESS; 529 | 530 | BZCcParam *pCcParam = static_cast(pParam); 531 | if (!pCcParam || !pSetting) { 532 | rt = ISP_INVALID_PARAM; 533 | ILOGE("Input is null!"); 534 | return rt; 535 | } 536 | 537 | for (int32_t row = 0; row < CCM_HEIGHT; row++) { 538 | memcpy(pCcParam->ccm + row * CCM_WIDTH, static_cast(pSetting->pCc)->ccm[row], CCM_WIDTH * sizeof(float)); 539 | } 540 | 541 | return rt; 542 | } 543 | 544 | int32_t ISPParamManager::FillinGAMMAParam(void *pParam, ISPSetting *pSetting) 545 | { 546 | int32_t rt = ISP_SUCCESS; 547 | 548 | BZGammaParam *pGammaParam = static_cast(pParam); 549 | if (!pGammaParam || !pSetting) { 550 | rt = ISP_INVALID_PARAM; 551 | ILOGE("Input is null!"); 552 | return rt; 553 | } 554 | 555 | memcpy(pGammaParam->lut, &static_cast(pSetting->pGamma)->lut, 1024 * sizeof(uint16_t)); 556 | 557 | return rt; 558 | } 559 | 560 | int32_t ISPParamManager::FillinWNRParam(void *pParam, ISPSetting *pSetting) 561 | { 562 | int32_t rt = ISP_SUCCESS; 563 | 564 | BZWnrParam *pWnrParam = static_cast(pParam); 565 | if (!pWnrParam || !pSetting) { 566 | rt = ISP_INVALID_PARAM; 567 | ILOGE("Input is null!"); 568 | return rt; 569 | } 570 | 571 | for (int32_t l = 0; l < 3; l++) { 572 | pWnrParam->ch1Threshold[l] = static_cast(pSetting->pWnr)->ch1Threshold[l]; 573 | pWnrParam->ch2Threshold[l] = static_cast(pSetting->pWnr)->ch2Threshold[l]; 574 | pWnrParam->ch3Threshold[l] = static_cast(pSetting->pWnr)->ch3Threshold[l]; 575 | } 576 | 577 | return rt; 578 | } 579 | 580 | int32_t ISPParamManager::FillinEEParam(void *pParam, ISPSetting *pSetting) 581 | { 582 | int32_t rt = ISP_SUCCESS; 583 | 584 | BZEeParam *pEeParam = static_cast(pParam); 585 | if (!pEeParam || !pSetting) { 586 | rt = ISP_INVALID_PARAM; 587 | ILOGE("Input is null!"); 588 | return rt; 589 | } 590 | 591 | pEeParam->alpha = static_cast(pSetting->pEe)->alpha; 592 | pEeParam->coreSize = static_cast(pSetting->pEe)->coreSize; 593 | pEeParam->sigma = static_cast(pSetting->pEe)->sigma; 594 | 595 | return rt; 596 | } 597 | 598 | -------------------------------------------------------------------------------- /ISP/src/Utils.cpp: -------------------------------------------------------------------------------- 1 | // License: GPL-3.0-or-later 2 | /* 3 | * Common fuctions supports ISP. 4 | * 5 | * Copyright (c) 2019 Peng Hao <635945005@qq.com> 6 | */ 7 | 8 | #include "Utils.h" 9 | 10 | using namespace std; 11 | 12 | char Int2Char(int32_t i) 13 | { 14 | char result = 'x'; 15 | 16 | if (i >= 0 && i <= 9) { 17 | result = '0' + i; 18 | } 19 | 20 | return result; 21 | } 22 | 23 | int32_t Char2Int(char c) 24 | { 25 | int32_t result = -1; 26 | 27 | if (c >= '0' && c <= '9') { 28 | result = c - '0'; 29 | } 30 | 31 | return result; 32 | } 33 | 34 | void getTimeChar(char* hours, char* minutes, char* seconds, char* milliseconds) 35 | { 36 | int32_t ms = 0, s = 0, m = 0, h = 0; 37 | 38 | getTimeInt(&h, &m, &s, &ms); 39 | 40 | *hours = Int2Char(h / 10); 41 | *(hours + 1) = Int2Char(h % 10); 42 | 43 | *minutes = Int2Char(m / 10); 44 | *(minutes + 1) = Int2Char(m % 10); 45 | 46 | *seconds = Int2Char(s / 10); 47 | *(seconds + 1) = Int2Char(s % 10); 48 | 49 | *milliseconds = Int2Char(ms / 100); 50 | *(milliseconds + 1) = Int2Char(ms / 10 % 10); 51 | *(milliseconds + 2) = Int2Char(ms % 10); 52 | } 53 | 54 | void getTimeInt(int32_t* hours, int32_t* minutes, int32_t* seconds, int32_t* milliseconds) 55 | { 56 | auto c_time = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()); 57 | 58 | *milliseconds = c_time.count() % 1000; 59 | *seconds = c_time.count() / 1000 % 60; 60 | *minutes = c_time.count() / 1000 / 60 % 60; 61 | *hours = c_time.count() / 1000 / 60 / 60 % 24 + LOCAL_TIME_ZOOM_OFFSET; 62 | } 63 | 64 | 65 | void getDateInt(int32_t* years, int32_t* months, int32_t* days) 66 | { 67 | int32_t hours = 0; 68 | int32_t minutes = 0; 69 | int32_t seconds = 0; 70 | int32_t milliseconds = 0; 71 | getTimeWithDateInt(years, months, days, &hours, &minutes, &seconds, &milliseconds); 72 | } 73 | 74 | void getTimeWithDateInt(int32_t* years, int32_t* months, int32_t* days, int32_t* hours, int32_t* minutes, int32_t* seconds, int32_t* milliseconds) 75 | { 76 | auto tp = std::chrono::system_clock::now(); 77 | auto ms_time = std::chrono::duration_cast(tp.time_since_epoch()); 78 | 79 | std::time_t systemTime = std::chrono::system_clock::to_time_t(tp); 80 | tm* pTime; 81 | pTime = gmtime(&systemTime); 82 | 83 | *milliseconds = ms_time.count() % 1000; 84 | *seconds = pTime->tm_sec; 85 | *minutes = pTime->tm_min; 86 | *hours = pTime->tm_hour + LOCAL_TIME_ZOOM_OFFSET; 87 | *days = pTime->tm_mday; 88 | *months = pTime->tm_mon + SYSTEM_MONTH_OFFSET; 89 | *years = pTime->tm_year + SYSTEM_YEAR_OFFSET; 90 | } 91 | 92 | void getTimeWithDateChar(char* years, char* months, char* days, char* hours, char* minutes, char* seconds, char* milliseconds) 93 | { 94 | int32_t dy = 0, dm = 0, dd = 0, tms = 0, ts = 0, tm = 0, th = 0; 95 | 96 | getTimeWithDateInt(&dy, &dm, &dd, &th, &tm, &ts, &tms); 97 | 98 | *years = Int2Char(dy / 1000); 99 | *(years + 1) = Int2Char(dy / 100 % 10); 100 | *(years + 2) = Int2Char(dy / 10 % 10); 101 | *(years + 3) = Int2Char(dy % 10); 102 | 103 | *months = Int2Char(dm / 10); 104 | *(months + 1) = Int2Char(dm % 10); 105 | 106 | *months = Int2Char(dm / 10); 107 | *(months + 1) = Int2Char(dm % 10); 108 | 109 | *days = Int2Char(dd / 10); 110 | *(days + 1) = Int2Char(dd % 10); 111 | 112 | *minutes = Int2Char(tm / 10); 113 | *(minutes + 1) = Int2Char(tm % 10); 114 | 115 | *seconds = Int2Char(ts / 10); 116 | *(seconds + 1) = Int2Char(ts % 10); 117 | 118 | *milliseconds = Int2Char(tms / 100); 119 | *(milliseconds + 1) = Int2Char(tms / 10 % 10); 120 | *(milliseconds + 2) = Int2Char(tms % 10); 121 | } 122 | 123 | 124 | int32_t CharNum2IntNum(char* pC) 125 | { 126 | int32_t rt = 0; 127 | int32_t len = 0; 128 | 129 | if (!pC) 130 | return -1; 131 | 132 | while(pC[len] != '\0') { 133 | len++; 134 | } 135 | 136 | for(int32_t i = len - 1; i >= 0; i--) { 137 | if (Char2Int(pC[i]) == -1) { 138 | return -1; 139 | } else { 140 | rt += Char2Int(pC[i]) * pow(10, (len - 1 - i)); 141 | } 142 | } 143 | 144 | return rt; 145 | } 146 | -------------------------------------------------------------------------------- /ISP/test/Test_Buffer.cpp: -------------------------------------------------------------------------------- 1 | // License: GPL-3.0-or-later 2 | /* 3 | * Buffer test. 4 | * 5 | * Copyright (c) 2019 Peng Hao <635945005@qq.com> 6 | */ 7 | 8 | #include "Utils.h" 9 | #include "Buffer.h" 10 | 11 | using namespace asteroidaxis::isp::resource; 12 | 13 | #define OVERWRITE_OFFSET 0 14 | #define TEST_NAME "BUF" 15 | 16 | int main() { 17 | ILOGI("%s TEST S", TEST_NAME); 18 | 19 | size_t size = 1920 * 1080; 20 | ILOGI("size:%u", size); 21 | Buffer* buf = Buffer::Alloc(size); 22 | ILOGI("buf(%u %p)", buf->Size(), buf->Addr()); 23 | 24 | Buffer::Free(&buf); 25 | ILOGI("buf:%p", buf); 26 | 27 | ILOGI("%s TEST E", TEST_NAME); 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /ISP/test/Test_MemPool.cpp: -------------------------------------------------------------------------------- 1 | // License: GPL-3.0-or-later 2 | /* 3 | * Memory pool test. 4 | * 5 | * Copyright (c) 2019 Peng Hao <635945005@qq.com> 6 | */ 7 | 8 | #include "Utils.h" 9 | #include "MemPool.h" 10 | 11 | using namespace asteroidaxis::isp::resource; 12 | 13 | #define OVERWRITE_OFFSET 0 14 | 15 | int main() { 16 | ILOGI("MEM TEST S"); 17 | MemoryPoolItf *gMemPool = MemoryPool::GetInstance(); 18 | 19 | unsigned char* pc = NULL; 20 | size_t size = 1920 * 1080; 21 | unsigned char* p1 = gMemPool->RequireBuffer(size); 22 | unsigned char* p2 = gMemPool->RequireBuffer(size); 23 | pc = p2; 24 | memset(pc, 1, size); 25 | ILOGI("memset p:%p size:%u", pc, size); 26 | unsigned char* p3 = gMemPool->RequireBuffer(size); 27 | #if DBG_MEM_OVERWRITE_CHECK_ON 28 | pc = p3; 29 | memset(pc, 1, size + OVERWRITE_OFFSET); 30 | ILOGE("memset p:%p size:%u", pc, size + OVERWRITE_OFFSET); 31 | pc = p3; 32 | memset(pc, 1, size + OVERWRITE_OFFSET); 33 | ILOGE("memset p:%p size:%u", pc, size + OVERWRITE_OFFSET); 34 | #endif 35 | unsigned char* p4 = gMemPool->RequireBuffer(size); 36 | #if DBG_MEM_OVERWRITE_CHECK_ON 37 | pc = p4; 38 | memset(pc, 1, size + OVERWRITE_OFFSET); 39 | ILOGE("memset p:%p size:%u", pc, size + OVERWRITE_OFFSET); 40 | usleep(100 * OVERWRITE_CHECK_TIME_GAP_US); 41 | #endif 42 | 43 | size = 4608 * 3456; 44 | unsigned char* p5 = gMemPool->RequireBuffer(size); 45 | gMemPool->RevertBuffer(p2); 46 | gMemPool->RevertBuffer(p4); 47 | gMemPool->RevertBuffer(p3); 48 | 49 | size = 1920 * 1080; 50 | p2 = gMemPool->RequireBuffer(size); 51 | gMemPool->RevertBuffer(p2); 52 | gMemPool->RevertBuffer(p1); 53 | gMemPool->RevertBuffer(p5); 54 | 55 | float* pf = NULL; 56 | size = 1920 * 1080; 57 | float* p6 = static_cast((void *)gMemPool->RequireBuffer(size * sizeof(float))); 58 | pf = static_cast(p6); 59 | memset((void *)pf, 0.1, size * sizeof(float)); 60 | ILOGI("memset p:%p size:%u", pf, size * sizeof(float)); 61 | 62 | float* p7 = static_cast((void *)gMemPool->RequireBuffer(size * sizeof(float))); 63 | #if DBG_MEM_OVERWRITE_CHECK_ON 64 | pf = static_cast(p7); 65 | memset((void *)pf, 0.1, (size + OVERWRITE_OFFSET) * sizeof(float)); 66 | ILOGE("memset p:%p size:%u", pf, (size + OVERWRITE_OFFSET) * sizeof(float)); 67 | usleep(100 * OVERWRITE_CHECK_TIME_GAP_US); 68 | #endif 69 | 70 | void *p8 = (void *)gMemPool->RequireBuffer(size * sizeof(float)); 71 | gMemPool->RevertBuffer(static_cast((void *)p6)); 72 | gMemPool->RevertBuffer(static_cast((void *)p7)); 73 | gMemPool->RevertBuffer(static_cast(p8)); 74 | 75 | ILOGI("MEM TEST E"); 76 | 77 | return 0; 78 | } 79 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | CSDN: https://blog.csdn.net/weixin_42910064/article/details/102454839 3 | 4 | WeiChat Official Accounts:泡视界 5 | 6 | # Image-Signal-Processing 7 | It is an basic implementation of ISP for learning only 8 | 9 | ## ISP basic knowledge 10 | 11 | ## Reading and Displaying Raw data 12 | 13 | ## Demosaic Operation 14 | 15 | ## saveing BMP 16 | 17 | ## Black Level Correction 18 | 19 | ## White Balance 20 | 21 | ## Gamma 22 | 23 | -------------------------------------------------------------------------------- /res/1MCC_IMG_20181229_001526_1.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BoyPao/ImageSignalProcessing-ISP/b5dd9186e96830a38f5e5775c3d827534588e123/res/1MCC_IMG_20181229_001526_1.raw --------------------------------------------------------------------------------