void sPalMaker::Update(Box& x, int ii) { x.colorcount = 0; x.population = 0; int a[3][RASTER_MAP_MAX]; ZeroArray(a[R]); ZeroArray(a[G]); ZeroArray(a[B]); x.avg_r = x.avg_g = x.avg_b = 0; for(int r = x[R].l; r < x[R].h; r++) for(int g = x[G].l; g < x[G].h; g++) for(int b = x[B].l; b < x[B].h; b++) { int q = histogram[r][g][b]; a[R][r] += q; a[G][g] += q; a[B][b] += q; x.avg_r += q * r; x.avg_g += q * g; x.avg_b += q * b; #ifdef CPU_X86 x.colorcount += q > 0; #else x.colorcount += (-q >> 31) & 1; #endif x.population += q; } for(int i = 0; i < 3; i++) { Dim& d = x[i]; while(d.l < d.h && a[i][d.l] == 0) d.l++; while(d.h > d.l && a[i][d.h - 1] == 0) d.h--; } x.volume = x[R] * x[G] * x[B]; }
void BornScatteredField(float xx,float xy,float xz,float *output) /*< Born scattering field >*/ { int iw; double omega,scale; sf_complex U,dU; sf_complex val,fkern; ZeroArray(u, nt); ZeroArray(du, nt); *output=0.; for (iw=0; iw<nw; iw++) { omega=ow+dw*iw; scale =cos((SF_PI/2)*(((double) iw+1)/((double) nw+1))); scale*=scale*omega; #ifdef SF_HAS_COMPLEX_H /* background field */ U=Green(xx,xy,xz,sx,sy,sz,omega)*scale; /* scattered field */ val=Green(px,py,pz,sx,sy,sz,omega)*scale; val *= Green(xx,xy,xz,px,py,pz,omega); dU = val*(-omega*omega*dv); U += dU; fkern=cexpf(sf_cmplx(0.,-omega*0.6)); val=fkern*U; #else /* background field */ U=sf_crmul(Green(xx,xy,xz,sx,sy,sz,omega),scale); /* scattered field */ val=sf_crmul(Green(px,py,pz,sx,sy,sz,omega),scale); val=sf_cmul(val,Green(xx,xy,xz,px,py,pz,omega)); dU=sf_crmul(val,-omega*omega*dv); U=sf_cadd(U,dU); fkern=cexpf(sf_cmplx(0.,-omega*0.6)); val=sf_cmul(fkern,U); #endif *output+=crealf(val); } return; }
inline Time VfkReadTime(const char *p, void *endptr) { int fields[6]; ZeroArray(fields); int nfld = 0; for(;;) if(IsDigit(*p)) { int v = ScanInt(p, &p); if(IsNull(v) || v < 0) return Null; fields[nfld++] = v; if(nfld >= 6) break; } else if(*p == ' ' || *p == ':' || *p == '.') p++; else break; if(endptr) *(const char **)endptr = p; if(nfld < 3) return Null; if(fields[0] >= 1 && fields[0] <= 31 && fields[1] >= 1 && fields[1] <= 12 && fields[2] >= 1900 && fields[2] <= 2900 && fields[3] >= 0 && fields[3] <= 23 && fields[4] >= 0 && fields[4] <= 59 && fields[5] >= 0 && fields[5] <= 59) { Time dt(fields[2], fields[1], fields[0], fields[3], fields[4], fields[5]); if(dt.IsValid()) return dt; } return Null; }
sPalCv::sPalCv(const RGBA *palette, int ncolors, PaletteCv& cv_pal) : cv_pal(cv_pal), palette(palette), ncolors(ncolors) { byte ender[256]; for(int b = 0; b < RASTER_MAP_B; b++) { ZeroArray(ender); for(int r = 0; r < RASTER_MAP_R; r++) { SetLine(r, b); int g = 0; while(g < RASTER_MAP_G) { int ii = Get(g); int eg = max<int>(g, ender[ii]); if(Get(eg) == ii) while(eg < RASTER_MAP_G - 1 && Get(eg + 1) == ii) eg++; else while(Get(eg) != ii) eg--; ender[ii] = eg; g++; while(g <= eg - 1) { gline[g] = ii; done[g] = true; g++; } } } } }
std::wstring TreeCtrl::GetInfoTip(HTREEITEM hItem) { ZeroArray(this->infotipBuf); TVITEMW item = {0}; item.hItem = hItem; item.mask = TVIF_TEXT; item.pszText = this->infotipBuf; item.cchTextMax = dimof(this->infotipBuf); TreeView_GetItem(this->hwnd, &item); return std::wstring(this->infotipBuf); }
void RemoteDisco( void ) { int i; /* make sure last packet gets sent */ Delay( TICKS_PER_SEC/2 ); Listening = 0; _INITSPXECB( Conn, 1, 0, 0 ); _SPXTerminateConnection( Connection, &ConnECB ); #ifdef SERVER _IPXCancelEvent( &ConnECB ); #endif for( i = NUM_REC_BUFFS - 1; i >= 0; --i ) { if( RecECB[i].inUseFlag ) { _IPXCancelEvent( &RecECB[i] ); } } _IPXCancelEvent( &SendECB ); _IPXDisconnectFromTarget( &SendHead.destination.network.a[0] ); for( i = 0; i < NUM_REC_BUFFS; ++i ) { ZeroArray( RecHead[i] ); ZeroArray( RecECB[i] ); } ZeroArray( ConnHead ); ZeroArray( SendHead ); ZeroArray( ConnECB ); ZeroArray( SendECB ); }
void RemoteDisco( void ) { int i; DosSleep( 500 ); /* make sure last packet gets sent */ Listening = 0; _INITSPXECB( Conn, 1, 0, 0 ); if( SpxTerminateConnection( Connection, &ConnECB ) == 0 ) { while( InUse( ConnECB ) ) IPXRelinquishControl(); } for( i = NUM_REC_BUFFS-1; i >= 0; --i ) { if( InUse( RecECB[i] ) ) { SpxCancelPacket( &RecECB[i] ); } } if( InUse( SendECB ) ) { SpxCancelPacket( &SendECB ); } for( i = NUM_REC_BUFFS-1; i >= 0; --i ) { ZeroArray( RecHead[i] ); ZeroArray( RecECB[i] ); } ZeroArray( ConnHead ); ZeroArray( SendHead ); ZeroArray( ConnECB ); ZeroArray( SendECB ); }
void sPalCv::SetLine(int r, int b) { gline = cv_pal.At(r, b); r = 255 * r / (RASTER_MAP_R - 1); //IMPROVE! b = 255 * b / (RASTER_MAP_B - 1); for(int i = 0; i < BINS; i++) eline[i] = line[i]; for(int i = 0; i < ncolors; i++) { int dist = Sq(palette[i].r, r) + Sq(palette[i].b, b); int bini = dist >> BINSHIFT; Ginfo *t = eline[bini >= BINS ? BINS - 1 : bini]++; t->dist = dist; t->g = palette[i].g; t->ii = i; } ZeroArray(done); }
sPalMaker::sPalMaker(Raster& raster, RGBA *palette, int ncolors) { ASSERT(ncolors <= 256); ZeroArray(histogram); Size sz = raster.GetSize(); for(int y = 0; y < sz.cy; y++) { Raster::Line line = raster[y]; const RGBA *s = line; const RGBA *e = s + sz.cx; while(s < e) { histogram[s->r >> RASTER_SHIFT_R][s->g >> RASTER_SHIFT_G][s->b >> RASTER_SHIFT_B]++; s++; } } Buffer<Box> box(256); box[0][R].l = 0; box[0][R].h = RASTER_MAP_R; box[0][G].l = 0; box[0][G].h = RASTER_MAP_G; box[0][B].l = 0; box[0][B].h = RASTER_MAP_B; Update(box[0], 0); if(box[0].population == 0) return; colorcount = box[0].colorcount; int count = 1; int method = 0; while(count < ncolors) { int ii = -1; int maxv = 0; if(2 * count > ncolors) method = 1; for(int i = 0; i < count; i++) { int v = method ? box[i].volume : box[i].colorcount; if(box[i].colorcount > 1 && v > maxv) { ii = i; maxv = v; } } if(ii < 0) break; Box& b = box[ii]; int ci = b[R] > b[G] ? b[B] > b[R] ? B : R : b[B] > b[G] ? B : G; if(b[ci] == 1) { if(method == 1) break; method = 1; } else { int m = (b[ci].l + b[ci].h) >> 1; Box& b1 = box[count]; b1 = b; b[ci].h = m; b1[ci].l = m; Update(b, ii); Update(b1, count++); } } for(int i = 0; i < count; i++) { RGBA& c = palette[i]; Box& x = box[i]; c.r = sRc(x.avg_r, x.population, RASTER_MAP_R); c.g = sRc(x.avg_g, x.population, RASTER_MAP_G); c.b = sRc(x.avg_b, x.population, RASTER_MAP_B); c.a = 255; } }
void BornSensitivity(float xx,float xy,float xz,float *output) /*< Born sensitivity >*/ { int iw,it; float tt,top,bottom; double omega,scale; sf_complex val,fkern; sf_complex U,dU,Ut,Utt; ZeroArray(u, nt); ZeroArray(du, nt); ZeroArray(ut, nt); ZeroArray(utt,nt); for (iw=0; iw<nw; iw++) { omega=ow+dw*iw; scale =cos((SF_PI/2)*(((double) iw+1)/((double) nw+1))); scale*=scale; #ifdef SF_HAS_COMPLEX_H /* background field */ U=Green(rx,ry,rz,sx,sy,sz,omega)*scale; /* scattered field */ val=Green(xx,xy,xz,sx,sy,sz,omega)*scale; val*=Green(rx,ry,rz,xx,xy,xz,omega); dU=val*(-omega*omega*dv); /* field derivatives */ Ut =U*sf_cmplx(0.,omega); Utt=U*(-omega*omega); #else /* background field */ U=sf_crmul(Green(rx,ry,rz,sx,sy,sz,omega),scale); /* scattered field */ val=sf_crmul(Green(xx,xy,xz,sx,sy,sz,omega),scale); val=sf_cmul(val,Green(rx,ry,rz,xx,xy,xz,omega)); dU=sf_crmul(val,-omega*omega*dv); /* field derivatives */ Ut =sf_cmul (U,sf_cmplx(0.,omega)); Utt=sf_crmul(U,-omega*omega); #endif /* slow ifft */ for (it=0; it<nt; it++) { tt=it*dt+ot; fkern=cexpf(sf_cmplx(0.,-omega*tt)); #ifdef SF_HAS_COMPLEX_H val=fkern*U; u[it]+=crealf(val); val=fkern*dU; du[it]+=crealf(val); val=fkern*Ut; ut[it]+=crealf(val); val=fkern*Utt; utt[it]+=crealf(val); #else val=sf_cmul(fkern, U); u[it]+=crealf(val); val=sf_cmul(fkern, dU); du[it]+=crealf(val); val=sf_cmul(fkern, Ut); ut[it]+=crealf(val); val=sf_cmul(fkern,Utt); utt[it]+=crealf(val); #endif } } top=0; bottom=0.; for (it=0; it<nt; it++) { top += ut [it]*du[it]*dt; bottom += utt[it]* u[it]*dt; } *output=top/bottom; return; }