Uint32 w, h; Uint16 *box; status = DRV_ipipeGetBoxcarBuf(&bufId, 0); if(status!= OSA_SOK) { OSA_ERROR("ERROR: DRV_ipipeGetBoxcarBuf()\n"); return status; } pBufInfo = DRV_ipipeGetBoxcarBufInfo(bufId); DRV_ipipePutBoxcarBuf(bufId); box = pBufInfo->virtAddr; w = gDRV_ipipeObj.boxcarInfo.width; //Boxcar width h = gDRV_ipipeObj.boxcarInfo.height; // Boxcar height
Uint32 sz = w*h, sz4 = sz*4, hsz = 512; Uint32 hist[hsz]; int GN[3] = { -16, 0, 16}; memset(hist, 0, sizeof(Uint32)*hsz); //AE and WB for(i=0; i < sz4; i+=4) { r = box[i+2]>>2; g = box[i+1]>>2; b = box[i ]>>2; RR += r; GG += g; BB += b; Y += ((117*b + 601*g + 306*r)>>10); hist[r>>3]++; hist[g>>3]++; hist[b>>3]++; for(j=0; j < ns; j++) { GB[j] += abs(g - (b*(512 + GN[j])>>9)); GR[j] += abs(g - (r*(512 + GN[j])>>9)); } } Y = Y/sz; hn->Y.New = Y; RR = RR/sz; GG = GG/sz; BB = BB/sz;
//Find histogram min sum = 0; for(i=0; sum < hn->SatTh; i++) sum += hist[i]; hn->Hmin.New = i; //Find histogram max sum = 0; for(i=hsz-1; sum < hn->SatTh; i--) sum += hist[i]; hn->Hmax.New = i;
if(hn->Y.New) tmp = (hn->Y.New > hn->YAE) ? hn->Y.New*100/hn->YAE : hn->YAE*100/hn->Y.New; if(tmp > 200){ if(hn->Y.New) hn->Exp.New = hn->Exp.Old*(hn->Y.New*2 + hn->YAE)/(hn->Y.New*3); } else if(tmp > 20){ if(hn->Y.New > hn->YAE) hn->Exp.New = hn->Exp.Old*99/100; else hn->Exp.New = hn->Exp.Old*100/99; } if(hn->Exp.New > hn->Exp.Range.max) hn->Exp.New = hn->Exp.Range.max;
#define HISTORY 30 int history = 0; typedef struct IAEWBF_Param{ XDAS_Int32 Old; //Old value XDAS_Int32 New; //New value XDAS_Int32 Step; //The step of changing XDAS_Int32 Avrg; //Sum of all history value XDAS_Int32 Change; //Need for smooth change XDAS_Int32 Hist[HISTORY]; //History array XDAS_Int32 HistC; //History count XDAS_Int32 NewA; //Avarage of value IAEWBF_Range Range; //The range of value changes }IAEWBF_Param; int add_history(IAEWBF_Param *p) { int diff = 0; p->Avrg += p->New; p->Avrg -= p->Hist[p->HistC]; if(p->New) diff = abs(p->Hist[p->HistC] - p->New)*100/p->New; p->Hist[p->HistC] = p->New; p->HistC = (p->HistC == (HISTORY - 1)) ? 0 : p->HistC + 1; p->NewA = (history < HISTORY) ? p->Avrg/history : p->Avrg/HISTORY; return diff; } history++; add_history(&hn->Hmax); add_history(&hn->Hmin); add_history(&hn->Y);
//Change the offset and gain hn->Offset.New = hn->Hmin.NewA; if(hn->Y.NewA - hn->Offset.New) hn->GIFIF.New = ((hn->HmaxTh/4)*512)/(hn->Y.NewA - hn->Offset.New); up = hn->Hmax.NewA*hn->GIFIF.New>>9; if((up < hn->HmaxTh) && (hn->Y.NewA - hn->Offset.New)) if(hn->Y.NewA - hn->Offset.New) hn->GIFIF.New = (((hn->HmaxTh*2 - up)/4)*512)/(hn->Y.NewA - hn->Offset.New); //Check gain range hn->GIFIF.New = hn->GIFIF.New > hn->GIFIF.Range.max ? hn->GIFIF.Range.max : hn->GIFIF.New; hn->GIFIF.New = hn->GIFIF.New < hn->GIFIF.Range.min ? hn->GIFIF.Range.min : hn->GIFIF.New;
if(IRcutClose){ min = GR[0]; minr = 0; for(j=1; j < ns; j++){ if(GR[j] < min) { min = GR[j]; minr = j; } } min = GB[0]; minb = 0; for(j=1; j < ns; j++){ if(GB[j] < min) { min = GB[j]; minb = j; } } if(minr != 1) hn->Rgain.New = hn->Rgain.Old + (GN[minr]*hn->Rgain.Old/512); if(minb != 1) hn->Bgain.New = hn->Bgain.Old + (GN[minb]*hn->Bgain.Old/512); } else { //Night AW mode if(RR) hn->Rgain.New = GG*hn->Rgain.Old/RR; if(BB) hn->Bgain.New = GG*hn->Bgain.Old/BB; }
Source: https://habr.com/ru/post/220141/
All Articles