void Sequence(CCShield& brd,unsigned long int time) { byte i; unsigned long int a,b; byte c; //attachInterrupt(wakePin-2,nop,RISING); //delay(250); state = 1; for (unsigned long int cnt=0;(cnt<time) && state;cnt++) { attachInterrupt(wakePin-2,sleepInterrupt,RISING); int val = analogRead(rightDial); byte seq = val/ (ANALOG_READ_MAX/3); // Horizontal bar if (seq==0) { for (i=0;(i<19) && state;i++) { a=0;b=0;c=0; for (byte j=0;j<7;j++) setbit(cvt(j,abs(10-i)),&a,&b,&c); brd.set(a,b,c); DelayByLeftDial(); } } else if (seq==1) { // Vertical bar for (i=0;(i<12) && state;i++) { a=0;b=0;c=0; for (byte j=0;j<10;j++) setbit(cvt(abs(6-i),j),&a,&b,&c); brd.set(a,b,c); DelayByLeftDial(); } } else if (seq == 2) { for(i=0;i<70 && state; i++) { a=0;b=0;c=0; setbit(cvt(i),&a,&b,&c); brd.set(a,b,c); DelayByLeftDial(); } } } }
int main (int argc, char *argv[]) { FILE *datfile = stdin; FILE *ofile = stdout; uint16_t val16; uint32_t vals[4]; int status = 0; int entries = 0; time_t timestamp = 0; struct tm *ts; char timestr[80]; int tlen; if (argc >= 2) { if ((datfile = fopen(argv[1], "r")) == 0) { printf("error opening input file %s\n",argv[1]); exit(1); } } if (argc == 3) { if ((ofile = fopen(argv[2],"w")) == 0) { printf("error opening output file %s\n",argv[2]); exit(1); } } if (ofile != stdout) { printf("Parsing %s to %s\n",argv[1],argv[2]); } while (status == 0) { entries++; status |= getwordLE(datfile, (uint32_t *) ×tamp); status |= gethalfLE(datfile, &val16); status |= getwordLE(datfile, vals+0); status |= getwordLE(datfile, vals+1); status |= getwordLE(datfile, vals+2); status |= getwordLE(datfile, vals+3); ts = localtime(×tamp); tlen = strftime(timestr,80,"%Y-%m-%d %T", ts); // printf("%s,\t%04X,\t%08X,\t%08X,\t%08X,\t%08X\n",timestr, val16, // vals[0],vals[1],vals[2],vals[3]); fprintf(ofile,"%u,\t%s,\t%04X,\t%.2f,\t%.2f,\t%.2f,\t%.2f\n", (uint32_t) timestamp, timestr, val16, cvt(vals[0]),cvt(vals[1]),cvt(vals[2]),cvt(vals[3])); } if (ofile != stdout) { printf("%d entries\n",entries); } fclose(datfile); fclose(ofile); return 0; }
int main() { zz_p::init(2); long i; vec_GF2 v; v.SetLength(5); v[1] = 1; v[0] = v[1]; if (v[0] != v[1]) Error("BitMatTest not OK!!"); for (i=0; i < 8; i++) { mat_zz_p a, x; mat_GF2 A, X, X1; long n = RandomBnd(500) + 1; long m = RandomBnd(500) + 1; cerr << n << " " << m << "\n"; double t; random(a, n, m); t = GetTime(); kernel(x, a); t = GetTime() - t; cerr << t << "\n"; cvt(A, a); t = GetTime(); kernel(X, A); t = GetTime() - t; cerr << t << "\n"; cerr << x.NumRows() << "\n"; cvt(X1, x); if (X1 != X) Error("BitMatTest NOT OK!!"); if (!IsZero(X*A)) Error("BitMatTest NOT OK!!"); cerr << "\n"; } cerr << "BitMatTest OK\n"; }
Character::Character(int PlayerNumber, Ogre::String Name, Ogre::Vector3 Position) { mPlayerNumber = PlayerNumber; mName = Name; HealtPoint = 1000; mSceneMgr = Application::mSceneMgr; mNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(); mNode->setPosition(Position); // mNode->setInheritOrientation(false); mPhysicsBody = new PhysicsBody(PlayerNumber, cvt(Position)); mPhysicsBody->setBaseBodiesTransforms(); mGraphicBody = new GraphicBody(mNode); mGraphicBody->a_stance(); MoveVec = Ogre::Vector3::ZERO; JumpVec = Ogre::Vector3::ZERO; pushVec = Ogre::Vector3::ZERO; mPose = POSE_STAND; mState = ST_NOTHING; mMoveDir = MV_NULL; addStatus(STATUS_NORMAL, "", 0); mCombos = new Combos(mName); mSupers = new Supers(mName); }
static F2(jtfitct){D d;V*sv; RZ(a&&w); ASSERT(!AR(w),EVRANK); sv=VAV(a); RZ(w=cvt(FL,w)); d=*DAV(w); ASSERT(0<=d&&d<5.82076609134675e-11,EVDOMAIN); R CDERIV(CFIT,jtfitct1,jtfitct2,sv->mr,sv->lr,sv->rr); }
void EtchSketch(CCShield& brd,unsigned long int time) { unsigned long int a,b; byte c; byte lastEtchOn=etchOn; state=1; attachInterrupt(wakePin-2,etchInterrupt,RISING); for (unsigned long int cnt=0;(cnt<time) && state;cnt++) { if (etchOn != lastEtchOn) { lastEtchOn=etchOn; delay(100); // debounce attachInterrupt(wakePin-2,etchInterrupt,RISING); } if (lastEtchOn==0) { a=0;b=0;c=0;} unsigned int val = analogRead(leftDial); byte x = val/ (ANALOG_READ_MAX/7); val = analogRead(rightDial); byte y = val/ (ANALOG_READ_MAX/10); if (x>6) x = 6; if (y>9) y = 9; setbit(cvt(x,y),&a,&b,&c); brd.set(a,b,c); delay(100); if ((x==0)&&(y==0)) // Get out { if (digitalRead(wakePin)==HIGH) return; } } }
static struct val *__escape(struct val *val, char *(*cvt)(const char*)) { char *out; out = NULL; switch (val->type) { case VT_INT: out = str_of_int(val->i); break; case VT_STR: out = cvt(str_cstr(val->str)); break; case VT_SYM: case VT_CONS: case VT_BOOL: panic("%s called with value type %d", __func__, val->type); } val_putref(val); ASSERT(out); return VAL_ALLOC_CSTR(out); }
static REPF(jtrepzsx) { A q,x,y; I c,d,j,k=-1,m,p=0,*qv,*xv,*yv; P*ap; RZ(a&&w); ap=PAV(a); x=SPA(ap,x); m=AN(x); if(!AN(SPA(ap,a)))R repzdx(ravel(x),w,wf,wcr); y=SPA(ap,i); yv=AV(y); RZ(x=cvt(INT,vec(FL,2*m,AV(x)))); xv=AV(x); if(equ(zero,SPA(ap,e))) { k=c=*(wf+AS(w)); if(!wf&&SPARSE&AT(w)) { A a,y; I m,n,q,*v; P*wp; wp=PAV(w); a=SPA(wp,a); if(AN(a)&&!*AV(a)) { y=SPA(wp,i); v=AS(y); m=v[0]; n=v[1]; v=AV(y); k=m?v[(m-1)*n]+1:0; q=0; DO(m, if(q==*v)++q; else if(q<*v) { k=q; break; } v+=n;); }
//-------------------------------------------------------------------------- bool PyW_PyListListToIntVecVecVec(PyObject *py_list, int_3dvec_t &result) { class cvt_t { private: int_3dvec_t &v; public: cvt_t(int_3dvec_t &v): v(v) { } static int cb( PyObject *py_item, Py_ssize_t index, void *ud) { cvt_t *_this = (cvt_t *)ud; // Declare an empty 2D list int_2dvec_t lst; // Push it immediately to the vector (to avoid double copies) _this->v.push_back(lst); // Now convert the inner list directly into the vector PyW_PyListListToIntVecVec(py_item, _this->v.back()); return CIP_OK; } }; cvt_t cvt(result); return pyvar_walk_list(py_list, cvt_t::cb, &cvt) != CIP_FAILED; }
bool Character::a_combo_hit(int numberCombo, int numberHit) { if(numberHit < mCombos->getComboSize(numberCombo)) { Info_Hits::DirectHitInfo* actualHitInfo = static_cast<Info_Hits::DirectHitInfo*>(mCombos->getActualHitInfo()); mPhysicsBody->a_DirectHit(cvt(actualHitInfo->from), cvt(actualHitInfo->to), actualHitInfo->speed, actualHitInfo->postDelay, actualHitInfo->name); //mGraphicBody->setAnimationRate(1.05); mGraphicBody->a_combo_hit(mCombos->getActualAnimationName()); mState = ST_ATACK; mMoveDir = MV_NULL; return true; } else { return false; } }
void Character::a_jump(Ogre::Vector3 initVector) { Ogre::Vector3 direction = mTargetNode->getPosition() - mNode->getPosition(); //определим направление к цели direction.y = 0; direction.normalise(); JumpVec = Ogre::Vector3(direction.x * initVector.x, initVector.y, direction.z * initVector.x); //JumpVec = initVector; mPhysicsBody->a_jump(cvt(initVector)); mGraphicBody->a_jump(); mPose = POSE_JUMP; mState = ST_NOTHING; }
void Character::a_suffer_firebolt(const Ogre::String &superName) { Ogre::Vector3 initVector = Ogre::Vector3(-4,4,0); Ogre::Vector3 direction = mTargetNode->getPosition() - mNode->getPosition(); //определим направление к цели direction.y = 0; direction.normalise(); JumpVec = Ogre::Vector3(direction.x * initVector.x, initVector.y, direction.z * initVector.x); mPhysicsBody->a_jump(cvt(initVector)); mGraphicBody->a_fall(); // !!!!!!!!!!!!!! временная мера, нужна соответствующая анимация mPose = POSE_JUMP; mState = ST_SUFFER; mMoveDir = MV_NULL; }
static A jtmerge1(J jt,A w,A ind){A z;B*b;C*wc,*zc;D*wd,*zd;I c,it,j,k,m,r,*s,t,*u,*wi,*zi; RZ(w&&ind); r=MAX(0,AR(w)-1); s=1+AS(w); t=AT(w); k=bp(t); m=IC(w); c=aii(w); ASSERT(!(t&SPARSE),EVNONCE); ASSERT(r==AR(ind),EVRANK); ASSERT(!ICMP(s,AS(ind),r),EVLENGTH); GA(z,t,c,r,s); if(!(AT(ind)&B01+INT))RZ(ind=cvt(INT,ind)); it=AT(ind); u=AV(ind); b=(B*)u; ASSERT(!c||1<m||!(it&B01),EVINDEX); ASSERT(!c||1!=m||!memchr(b,C1,c),EVINDEX); zi=AV(z); zc=(C*)zi; zd=(D*)zc; wi=AV(w); wc=(C*)wi; wd=(D*)wc; switch(MCASE(it,k)){ case MCASE(B01,sizeof(C)): DO(c, *zc++=wc[*b++?i+c:i];); break; case MCASE(B01,sizeof(I)): DO(c, *zi++=wi[*b++?i+c:i];); break;
void loop() // run over and over again { unsigned long int time; byte i=0; CCShield out(myClockPin,mySerDataPin,mySerDataPin2, 11); out.setBrightness(255); //out.set(0xffffffff,0xffffffff,0xf); delay(250); if (digitalRead(wakePin)==HIGH) // Still held -- mode select { unsigned long start = millis(); while (digitalRead(wakePin)==HIGH) { unsigned long mode = (millis()-start)/500; mode = mode % NUMMODES; out.set(1UL<<cvt(mode,0),0,0); delay(50); i = mode; } } seed += analogRead(rightDial)+analogRead(leftDial); // Try to get a random starter if (1) { time = analogRead(rightDial); time = time * 4000; if (time < 5000) time = 5000; if (i==0) RandomFader(out,time); else if (i==1) Sequence(out,time); else if (i==2) EtchSketch(out,time); else if (i==3) BrightnessTest(out,time); //out.set(0xffffffff,0xffffffff,0xf); /* ALL ON */ out.set(0,0,0); /* ALL OFF */ delay(500); // Debounce reset button input //attachInterrupt(wakePin-2,sleepInterrupt,RISING); out.set(0,0,0); /* ALL OFF */ sleepNow(); } }
static F2(jttclosure){A z;B b;I an,*av,c,d,i,wn,wr,wt,*wv,*zu,*zv,*zz; RZ(a&&w); wt=AT(w); wn=AN(w); wr=AR(w); if(B01&wt)RZ(w=cvt(INT,w)); wv=AV(w); av=AV(a); an=AN(a); RZ(z=exta(INT,1+wr,wn,20L)); zv=AV(z); zz=zv+AN(z); if(1==wn){ *zv++=c=*wv; d=1+c; while(c!=d){ if(zv==zz){i=zv-AV(z); RZ(z=ext(0,z)); zv=AV(z)+i; zz=AV(z)+AN(z);} d=c; if(0>c)c+=an; ASSERT(0<=c&&c<an,EVINDEX); *zv++=c=av[c]; }}else{ ICPY(zv,wv,wn); zu=zv; zv+=wn; while(1){ if(zv==zz){i=zv-AV(z); RZ(z=ext(0,z)); zv=AV(z)+i; zz=AV(z)+AN(z); zu=zv-wn;} b=1; DO(wn, d=c=*zu++; if(0>c)c+=an; ASSERT(0<=c&&c<an,EVINDEX); *zv++=c=av[c]; if(c!=d)b=0;); if(b)break; }}
void BrightnessTest(CCShield& brd,unsigned long int time) { FlickerBrightness f(brd); unsigned long int i; #if 0 for (i=0;i<CCShield_NUMOUTS;i++) { f.brightness[cvt(i)]=i*3; } #endif brd.setBrightness(255); // By default highest brightness unless the dial is moved state = 1; // Set the trigger variable, THEN attach the interrupt attachInterrupt(wakePin-2,sleepInterrupt,RISING); unsigned long int cnt=0; for (uint8_t j=0;j<CCShield_NUMOUTS;j++) { f.brightness[j] = 0; } for (i=0;(i<time) && state;i++) { //attachInterrupt(wakePin-2,sleepInterrupt,RISING); if ((i&63)==0) { for (uint8_t j=0;j<CCShield_NUMOUTS;j++) { if ((j&3)==0) f.brightness[j]=(cnt&255); //else f.brightness[j] = 0; } cnt+=1; if ((cnt&255)==0) f.shift(); } f.loop(); } }
static DF1(breduce){A z;B b,*u,*v,*x,*xx;I c,cv,d,m;SF f2;VA*p; RZ(w); /* AN(w)&&1<IC(w) */ m=IC(w); RZ(z=tail(w)); c=AN(z); x=BAV(z); v=BAV(w); p=vap(self); switch(1<c?0:p->bf){ case V0001: *x=memchr(v,C0,m)?0:1; R z; case V0111: *x=memchr(v,C1,m)?1:0; R z; case V1110: u=memchr(v,C0,m); d=u?u-v:m; *x=d%2!=d<m-1; R z; case V1000: u=memchr(v,C1,m); d=u?u-v:m; *x=d%2==d<m-1; R z; case V0010: u=memchr(v,C0,m); *x=(u?u-v:m)%2?1:0; R z; case V1011: u=memchr(v,C1,m); *x=(u?u-v:m)%2?0:1; R z; case V0100: *x= *(v+m-1)&&!memchr(v,C1,m-1)?1:0; R z; case V1101: *x=!*(v+m-1)&&!memchr(v,C0,m-1)?0:1; R z; case V0110: b=0; DO(m, b=b!=*v++); *x=b; R z; case V1001: b=1; DO(m, b=b==*v++); *x=b; R z; } switch(p->id){I*x,*xx; case CPLUS: RZ(z=cvt(INT,z)); x=AV(z); if(1==c){d=0; DO(m, if(*v++)d++); *x=d;} else{xx=x+=c; v+=c*(m-1); DO(m-1, DO(c, --x; *x=*--v+*x); x=xx);}
/** Directly set any options starting with 'CURL.' */ static OCerror oc_set_curl_options(OCstate* state) { OCerror stat = OC_NOERR; struct OCTriplestore* store = NULL; struct OCTriple* triple = NULL; int i; char* hostport = NULL; struct OCCURLFLAG* ocflag = NULL; hostport = occombinehostport(state->uri); if(hostport == NULL) { hostport = (char*)malloc(sizeof(char)*1); *hostport = ""; } store = &ocglobalstate.rc.ocrc; triple = store->triples; /* Assume that the triple store has been properly sorted */ for(i=0;i<store->ntriples;i++,triple++) { size_t hostlen = strlen(triple->host); const char* flagname; if(ocstrncmp("CURL.",triple->key,5) != 0) continue; /* not a curl flag */ /* do hostport prefix comparison */ if(hostlen > 0) { int t = ocstrncmp(hostport,triple->host,hostlen); if(t != 0) continue; } flagname = triple->key+5; /* 5 == strlen("CURL."); */ ocflag = occurlflagbyname(flagname); if(ocflag == NULL) {stat = OC_ECURL; goto done;} stat = ocset_curlopt(state,ocflag->flag,cvt(triple->value,ocflag->type)); } done: if(hostport && strcmp(hostport,"") != 0) free(hostport); return stat; }
std::wstring IconvMgr::utf82wcs(std::string& src) { std::wstring ret; for(int i=0,len=src.size(); i<len; i+=IconvMgr::UTF8_WCS_STEP) { std::string sub = src.substr(i, IconvMgr::UTF8_WCS_STEP); const char* str = sub.c_str(); char mbsBuff[IconvMgr::BUFF_SIZE]; wchar_t wcsBuff[IconvMgr::BUFF_SIZE]; IconvMgr cvt("UTF-8", ""); cvt.convert(str, strlen(str), mbsBuff, IconvMgr::BUFF_SIZE); setlocale(LC_ALL,""); size_t cn = 0; mbstowcs_s( &cn, wcsBuff, IconvMgr::BUFF_SIZE, mbsBuff, _TRUNCATE); setlocale(LC_ALL,"C"); ret.append(wcsBuff); } return ret; }
std::string IconvMgr::wcs2utf8(std::wstring& src) { std::string ret; for(int i=0,len=src.size(); i<len; i+=IconvMgr::WCS_UTF8_STEP) { std::wstring sub = src.substr(i, IconvMgr::WCS_UTF8_STEP); const wchar_t* ws = sub.c_str(); char mbsBuff[(IconvMgr::WCS_UTF8_STEP+1)<<1]; char utfBuff[IconvMgr::BUFF_SIZE]; setlocale(LC_ALL,""); size_t cn = 0; wcstombs_s( &cn, mbsBuff, (IconvMgr::WCS_UTF8_STEP+1)<<1, ws, _TRUNCATE); setlocale(LC_ALL,"C"); IconvMgr cvt("", "UTF-8"); cvt.convert(mbsBuff, strlen(mbsBuff), utfBuff, IconvMgr::BUFF_SIZE); ret.append(utfBuff); } return ret; }
RETCODE SQL_API SQLFetch( HSTMT hstmt ) { stmt_t* pstmt = hstmt; column_t* pcol = pstmt->pcol; int ncol, i; long len, clen; char* ptr; int sqltype, sqlstat, dft_ctype, flag = 0, err; fptr_t cvt; char* ret; UNSET_ERROR( pstmt->herr ); ncol = nnsql_getcolnum(pstmt->yystmt); if ( !pstmt->refetch && (err = nnsql_fetch(pstmt->yystmt)) ) { int code; if ( err == 100 ) return SQL_NO_DATA_FOUND; code = nnsql_errcode(pstmt->yystmt); if ( code == -1 ) code = errno; PUSHSYSERR( pstmt->herr, code, nnsql_errmsg(pstmt->yystmt)); return SQL_ERROR; } if ( !pcol ) { int max; max = nnsql_max_column(); pcol = pstmt->pcol = (column_t*)MEM_ALLOC( sizeof(column_t)*(max+1) ); if ( ! pcol ) { PUSHSQLERR( pstmt->herr, en_S1001 ); return SQL_ERROR; } MEM_SET(pcol, 0, sizeof(column_t)*(max+1) ); return SQL_SUCCESS; } for (i=0;i<ncol;i++, pcol++) { len = clen = 0L; pcol->offset = 0; if ( ! pcol->userbuf ) continue; if ( nnsql_isnullcol(pstmt->yystmt, i) ) { if ( pcol->pdatalen ) *(pcol->pdatalen) = SQL_NULL_DATA; continue; } if ( pcol->pdatalen ) *(pcol->pdatalen ) = 0L; if ( nnsql_isstrcol(pstmt->yystmt, i) ) { ptr = nnsql_getstr(pstmt->yystmt, i); len = STRLEN(ptr) + 1; sqltype = SQL_CHAR; dft_ctype = SQL_C_CHAR; } else if ( nnsql_isnumcol(pstmt->yystmt, i) ) { ptr = (char*)nnsql_getnum(pstmt->yystmt, i); sqltype = SQL_INTEGER; dft_ctype = SQL_C_LONG; } else if ( nnsql_isdatecol(pstmt->yystmt, i) ) { ptr = (char*)nnsql_getdate(pstmt->yystmt, i); sqltype = SQL_DATE; dft_ctype = SQL_C_DATE; } else abort(); if ( pcol->ctype == SQL_C_DEFAULT ) pcol->ctype = dft_ctype; cvt = nnodbc_get_sql2c_cvt(sqltype, pcol->ctype); if ( ! cvt ) { pstmt->refetch = 1; PUSHSQLERR(pstmt->herr, en_07006); return SQL_ERROR; } ret = cvt( ptr, pcol->userbuf, pcol->userbufsize, &clen); if ( ret ) { pstmt->refetch = 1; if ( clen ) sqlstat = en_22003; else sqlstat = en_22005; PUSHSQLERR( pstmt->herr, sqlstat ); return SQL_ERROR; } if ( len && clen == len ) flag = 1; if ( len && pcol->pdatalen ) *(pcol->pdatalen) = clen; /* not 'len' but 'clen' */ } if ( flag ) { PUSHSQLERR( pstmt->herr, en_01004 ); return SQL_SUCCESS_WITH_INFO; } return SQL_SUCCESS; }
char * fcvt(double arg, int ndigits, int *decptp, int *signp) { return (cvt(arg, ndigits, decptp, signp, 0)); }
int main(int argc, char *argv[]) { int fa,nfa; /* argument we're looking at */ char prof_name[MAXNAMEL+1] = { '\000' }; /* ICC profile name, "" if none */ char in_name[MAXNAMEL+1]; /* TIFF input file */ char *xl = NULL, out_name[MAXNAMEL+4+1] = "locus.ts"; /* locus output file */ int verb = 0; int dovrml = 0; int doaxes = 1; int usevec = 0; double vec[3]; int rv = 0; icc *icco = NULL; xicc *xicco = NULL; icxViewCond vc; /* Viewing Condition for CIECAM */ int vc_e = -1; /* Enumerated viewing condition */ int vc_s = -1; /* Surround override */ double vc_wXYZ[3] = {-1.0, -1.0, -1.0}; /* Adapted white override in XYZ */ double vc_wxy[2] = {-1.0, -1.0}; /* Adapted white override in x,y */ double vc_a = -1.0; /* Adapted luminance */ double vc_b = -1.0; /* Background % overid */ double vc_f = -1.0; /* Flare % overid */ double vc_fXYZ[3] = {-1.0, -1.0, -1.0}; /* Flare color override in XYZ */ double vc_fxy[2] = {-1.0, -1.0}; /* Flare color override in x,y */ icxLuBase *luo = NULL; /* Generic lookup object */ icColorSpaceSignature ins = icSigLabData, outs; /* Type of input and output spaces */ int inn, outn; /* Number of components */ icmLuAlgType alg; /* Type of lookup algorithm */ icmLookupFunc func = icmFwd; /* Must be */ icRenderingIntent intent = -1; /* Default */ icColorSpaceSignature pcsor = icSigLabData; /* Default */ icmLookupOrder order = icmLuOrdNorm; /* Default */ TIFF *rh = NULL; int x, y, width, height; /* Size of image */ uint16 samplesperpixel, bitspersample; uint16 pconfig, photometric, pmtc; uint16 resunits; float resx, resy; tdata_t *inbuf; void (*cvt)(double *out, double *in); /* TIFF conversion function, NULL if none */ icColorSpaceSignature tcs; /* TIFF colorspace */ uint16 extrasamples; /* Extra "alpha" samples */ uint16 *extrainfo; /* Info about extra samples */ int sign_mask; /* Handling of encoding sign */ int i, j; int nipoints = 0; /* Number of raster sample points */ co *inp = NULL; /* Input point values */ double tdel = 0.0; /* Total delta along locus */ rspl *rr = NULL; int nopoints = 0; /* Number of raster sample points */ co *outp = NULL; error_program = argv[0]; if (argc < 2) usage(); /* Process the arguments */ for(fa = 1;fa < argc;fa++) { nfa = fa; /* skip to nfa if next argument is used */ if (argv[fa][0] == '-') { /* Look for any flags */ char *na = NULL; /* next argument after flag, null if none */ if (argv[fa][2] != '\000') na = &argv[fa][2]; /* next is directly after flag */ else { if ((fa+1) < argc) { if (argv[fa+1][0] != '-') { nfa = fa + 1; na = argv[nfa]; /* next is seperate non-flag argument */ } } } if (argv[fa][1] == '?') usage(); /* Verbosity */ else if (argv[fa][1] == 'v') { verb = 1; } /* Intent */ else if (argv[fa][1] == 'i' || argv[fa][1] == 'I') { fa = nfa; if (na == NULL) usage(); switch (na[0]) { case 'd': intent = icmDefaultIntent; break; case 'a': intent = icAbsoluteColorimetric; break; case 'p': intent = icPerceptual; break; case 'r': intent = icRelativeColorimetric; break; case 's': intent = icSaturation; break; /* Argyll special intents to check spaces underlying */ /* icxPerceptualAppearance & icxSaturationAppearance */ case 'P': intent = icmAbsolutePerceptual; break; case 'S': intent = icmAbsoluteSaturation; break; default: usage(); } } /* Search order */ else if (argv[fa][1] == 'o') { fa = nfa; if (na == NULL) usage(); switch (na[0]) { case 'n': case 'N': order = icmLuOrdNorm; break; case 'r': case 'R': order = icmLuOrdRev; break; default: usage(); } } /* PCS override */ else if (argv[fa][1] == 'p' || argv[fa][1] == 'P') { fa = nfa; if (na == NULL) usage(); switch (na[0]) { case 'l': pcsor = icSigLabData; break; case 'j': pcsor = icxSigJabData; break; default: usage(); } } /* Viewing conditions */ else if (argv[fa][1] == 'c' || argv[fa][1] == 'C') { fa = nfa; if (na == NULL) usage(); /* Switch to Jab automatically */ pcsor = icxSigJabData; /* Set the viewing conditions */ if (na[1] != ':') { if ((vc_e = xicc_enum_viewcond(NULL, NULL, -2, na, 1, NULL)) == -999) usage(); } else if (na[0] == 's' || na[0] == 'S') { if (na[1] != ':') usage(); if (na[2] == 'a' || na[2] == 'A') { vc_s = vc_average; } else if (na[2] == 'm' || na[2] == 'M') { vc_s = vc_dim; } else if (na[2] == 'd' || na[2] == 'D') { vc_s = vc_dark; } else if (na[2] == 'c' || na[2] == 'C') { vc_s = vc_cut_sheet; } else usage(); } else if (na[0] == 'w' || na[0] == 'W') { double x, y, z; if (sscanf(na+1,":%lf:%lf:%lf",&x,&y,&z) == 3) { vc_wXYZ[0] = x; vc_wXYZ[1] = y; vc_wXYZ[2] = z; } else if (sscanf(na+1,":%lf:%lf",&x,&y) == 2) { vc_wxy[0] = x; vc_wxy[1] = y; } else usage(); } else if (na[0] == 'a' || na[0] == 'A') { if (na[1] != ':') usage(); vc_a = atof(na+2); } else if (na[0] == 'b' || na[0] == 'B') { if (na[1] != ':') usage(); vc_b = atof(na+2); } else if (na[0] == 'f' || na[0] == 'F') { double x, y, z; if (sscanf(na+1,":%lf:%lf:%lf",&x,&y,&z) == 3) { vc_fXYZ[0] = x; vc_fXYZ[1] = y; vc_fXYZ[2] = z; } else if (sscanf(na+1,":%lf:%lf",&x,&y) == 2) { vc_fxy[0] = x; vc_fxy[1] = y; } else if (sscanf(na+1,":%lf",&x) == 1) { vc_f = x; } else usage(); } else usage(); } /* VRML output */ else if (argv[fa][1] == 'w' || argv[fa][1] == 'W') { dovrml = 1; } /* No axis output */ else if (argv[fa][1] == 'n' || argv[fa][1] == 'N') { doaxes = 0; } /* Vector direction for span */ else if (argv[fa][1] == 'V') { usevec = 1; if (na == NULL) usage(); fa = nfa; if (sscanf(na, " %lf , %lf , %lf ",&vec[0], &vec[1], &vec[2]) != 3) usage(); } /* Output file name */ else if (argv[fa][1] == 'O') { fa = nfa; if (na == NULL) usage(); strncpy(out_name,na,MAXNAMEL); out_name[MAXNAMEL] = '\000'; } else usage(); } else break; } if (fa >= argc || argv[fa][0] == '-') usage(); if (fa < (argc-1)) strncpy(prof_name,argv[fa++],MAXNAMEL); prof_name[MAXNAMEL] = '\000'; if (fa >= argc || argv[fa][0] == '-') usage(); strncpy(in_name,argv[fa],MAXNAMEL); in_name[MAXNAMEL] = '\000'; if ((xl = strrchr(out_name, '.')) == NULL) /* Figure where extention is */ xl = out_name + strlen(out_name); if (verb) { printf("Profile = '%s'\n",prof_name); printf("Input TIFF = '%s'\n",in_name); printf("Output file = '%s'\n",out_name); } if (intent == -1) { if (pcsor == icxSigJabData) intent = icRelativeColorimetric; /* Default to icxAppearance */ else intent = icAbsoluteColorimetric; /* Default to icAbsoluteColorimetric */ } /* - - - - - - - - - - - - - - - - */ /* If we were provided an ICC profile to use */ if (prof_name[0] != '\000') { /* Open up the profile or TIFF embedded profile for reading */ if ((icco = read_embedded_icc(prof_name)) == NULL) error ("Can't open profile in file '%s'",prof_name); if (verb) { icmFile *op; if ((op = new_icmFileStd_fp(stdout)) == NULL) error ("Can't open stdout"); icco->header->dump(icco->header, op, 1); op->del(op); } /* Check that the profile is appropriate */ if (icco->header->deviceClass != icSigInputClass && icco->header->deviceClass != icSigDisplayClass && icco->header->deviceClass != icSigOutputClass && icco->header->deviceClass != icSigColorSpaceClass) error("Profile type isn't device or colorspace"); /* Wrap with an expanded icc */ if ((xicco = new_xicc(icco)) == NULL) error ("Creation of xicc failed"); /* Setup the default viewing conditions */ if (xicc_enum_viewcond(xicco, &vc, -1, NULL, 0, NULL) == -999) error ("%d, %s",xicco->errc, xicco->err); if (vc_e != -1) if (xicc_enum_viewcond(xicco, &vc, vc_e, NULL, 0, NULL) == -999) error ("%d, %s",xicco->errc, xicco->err); if (vc_s >= 0) vc.Ev = vc_s; if (vc_wXYZ[1] > 0.0) { /* Normalise it to current media white */ vc.Wxyz[0] = vc_wXYZ[0]/vc_wXYZ[1] * vc.Wxyz[1]; vc.Wxyz[2] = vc_wXYZ[2]/vc_wXYZ[1] * vc.Wxyz[1]; } if (vc_wxy[0] >= 0.0) { double x = vc_wxy[0]; double y = vc_wxy[1]; /* If Y == 1.0, then X+Y+Z = 1/y */ double z = 1.0 - x - y; vc.Wxyz[0] = x/y * vc.Wxyz[1]; vc.Wxyz[2] = z/y * vc.Wxyz[1]; } if (vc_a >= 0.0) vc.La = vc_a; if (vc_b >= 0.0) vc.Yb = vc_b/100.0; if (vc_f >= 0.0) vc.Yf = vc_f/100.0; if (vc_fXYZ[1] > 0.0) { /* Normalise it to current media white */ vc.Fxyz[0] = vc_fXYZ[0]/vc_fXYZ[1] * vc.Fxyz[1]; vc.Fxyz[2] = vc_fXYZ[2]/vc_fXYZ[1] * vc.Fxyz[1]; } if (vc_fxy[0] >= 0.0) { double x = vc_fxy[0]; double y = vc_fxy[1]; /* If Y == 1.0, then X+Y+Z = 1/y */ double z = 1.0 - x - y; vc.Fxyz[0] = x/y * vc.Fxyz[1]; vc.Fxyz[2] = z/y * vc.Fxyz[1]; } /* Get a expanded color conversion object */ if ((luo = xicco->get_luobj(xicco, ICX_CLIP_NEAREST , func, intent, pcsor, order, &vc, NULL)) == NULL) error ("%d, %s",xicco->errc, xicco->err); luo->spaces(luo, &ins, &inn, &outs, &outn, &alg, NULL, NULL, NULL); } /* Establish the PCS range if we are filtering */ { double pcsmin[3], pcsmax[3]; /* PCS range for filter stats array */ if (luo) { gamut *csgam; if ((csgam = luo->get_gamut(luo, 20.0)) == NULL) error("Getting the gamut of the source colorspace failed"); csgam->getrange(csgam, pcsmin, pcsmax); csgam->del(csgam); } else { pcsmin[0] = 0.0; pcsmax[0] = 100.0; pcsmin[1] = -128.0; pcsmax[1] = 128.0; pcsmin[2] = -128.0; pcsmax[2] = 128.0; } if (verb) printf("PCS range = %f..%f, %f..%f. %f..%f\n\n", pcsmin[0], pcsmax[0], pcsmin[1], pcsmax[1], pcsmin[2], pcsmax[2]); /* Allocate and initialize the filter */ set_fminmax(pcsmin, pcsmax); } /* - - - - - - - - - - - - - - - */ /* Open up input tiff file ready for reading */ /* Got arguments, so setup to process the file */ if ((rh = TIFFOpen(in_name, "r")) == NULL) error("error opening read file '%s'",in_name); TIFFGetField(rh, TIFFTAG_IMAGEWIDTH, &width); TIFFGetField(rh, TIFFTAG_IMAGELENGTH, &height); TIFFGetField(rh, TIFFTAG_SAMPLESPERPIXEL, &samplesperpixel); TIFFGetField(rh, TIFFTAG_BITSPERSAMPLE, &bitspersample); if (bitspersample != 8 && bitspersample != 16) error("TIFF Input file must be 8 bit/channel"); TIFFGetFieldDefaulted(rh, TIFFTAG_EXTRASAMPLES, &extrasamples, &extrainfo); TIFFGetField(rh, TIFFTAG_PHOTOMETRIC, &photometric); if (inn != (samplesperpixel-extrasamples)) error ("TIFF Input file has %d input chanels mismatched to colorspace '%s'", samplesperpixel, icm2str(icmColorSpaceSignature, ins)); if ((tcs = TiffPhotometric2ColorSpaceSignature(&cvt, &sign_mask, photometric, bitspersample, samplesperpixel, extrasamples)) == 0) error("Can't handle TIFF file photometric %s", Photometric2str(photometric)); if (tcs != ins) { if (luo != NULL) error("TIFF photometric '%s' doesn't match ICC input colorspace '%s' !", Photometric2str(photometric), icm2str(icmColorSpaceSignature,ins)); else error("No profile provided and TIFF photometric '%s' isn't Lab !", Photometric2str(photometric)); } TIFFGetField(rh, TIFFTAG_PLANARCONFIG, &pconfig); if (pconfig != PLANARCONFIG_CONTIG) error ("TIFF Input file must be planar"); TIFFGetField(rh, TIFFTAG_RESOLUTIONUNIT, &resunits); TIFFGetField(rh, TIFFTAG_XRESOLUTION, &resx); TIFFGetField(rh, TIFFTAG_YRESOLUTION, &resy); if (verb) { printf("Input TIFF file '%s'\n",in_name); printf("TIFF file colorspace is %s\n",icm2str(icmColorSpaceSignature,tcs)); printf("TIFF file photometric is %s\n",Photometric2str(photometric)); printf("\n"); } /* - - - - - - - - - - - - - - - */ /* Process colors to translate */ /* (Should fix this to process a group of lines at a time ?) */ nipoints = width * height; // if ((inp = malloc(sizeof(co) * nipoints)) == NULL) // error("Unable to allocate co array"); inbuf = _TIFFmalloc(TIFFScanlineSize(rh)); for (i = y = 0; y < height; y++) { /* Read in the next line */ if (TIFFReadScanline(rh, inbuf, y, 0) < 0) error ("Failed to read TIFF line %d",y); /* Do floating point conversion */ for (x = 0; x < width; x++) { int e; double in[MAX_CHAN], out[MAX_CHAN]; if (bitspersample == 8) { for (e = 0; e < samplesperpixel; e++) { int v = ((unsigned char *)inbuf)[x * samplesperpixel + e]; if (sign_mask & (1 << i)) /* Treat input as signed */ v = (v & 0x80) ? v - 0x80 : v + 0x80; in[e] = v/255.0; } } else { for (e = 0; e < samplesperpixel; e++) { int v = ((unsigned short *)inbuf)[x * samplesperpixel + e]; if (sign_mask & (1 << i)) /* Treat input as signed */ v = (v & 0x8000) ? v - 0x8000 : v + 0x8000; in[e] = v/65535.0; } } if (cvt != NULL) { /* Undo TIFF encoding */ cvt(in, in); } if (luo != NULL) { if ((rv = luo->lookup(luo, out, in)) > 1) error ("%d, %s",icco->errc,icco->err); if (outs == icSigXYZData) /* Convert to Lab */ icmXYZ2Lab(&icco->header->illuminant, out, out); } else { for (e = 0; e < samplesperpixel; e++) out[e] = in[e]; } //printf("~1 %f %f %f -> %f %f %f\n", in[0], in[1], in[2], out[0], out[1], out[2]); add_fpixel(out); #ifdef NEVER /* Store PCS value in array */ inp[i].v[0] = out[0]; inp[i].v[1] = out[1]; inp[i].v[2] = out[2]; i++; #endif } } _TIFFfree(inbuf); TIFFClose(rh); /* Close Input file */ /* Done with lookup object */ if (luo != NULL) { luo->del(luo); xicco->del(xicco); /* Expansion wrapper */ icco->del(icco); /* Icc */ } nipoints = flush_filter(verb, 80.0); if ((inp = malloc(sizeof(co) * nipoints)) == NULL) error("Unable to allocate co array"); get_filter(inp); printf("~1 There are %d points\n",nipoints); //for (i = 0; i < nipoints; i++) //printf("~1 point %d = %f %f %f\n", i, inp[i].v[0], inp[i].v[1], inp[i].v[2]); del_filter(); /* Create the locus */ { double s0[3], s1[3]; double t0[3], t1[3]; double mm[3][4]; double im[3][4]; int gres[MXDI] = { 256 } ; if (usevec) { double max = -1e6; double min = 1e6; double dist; icmScale3(vec, vec, 1.0/icmNorm3(vec)); /* Locate the two furthest distant points measured along the vector */ for (i = 0; i < nipoints; i++) { double tt; tt = icmDot3(vec, inp[i].v); if (tt > max) { max = tt; icmAry2Ary(s1, inp[i].v); } if (tt < min) { min = tt; icmAry2Ary(s0, inp[i].v); } } dist = icmNorm33sq(s0, s1); printf("~1 most distant in vector %f %f %f = %f %f %f -> %f %f %f dist %f\n", vec[0], vec[1], vec[2], s0[0], s0[1], s0[2], s1[0], s1[1], s1[2], sqrt(dist)); t0[0] = 0.0; t0[1] = 0.0; t0[2] = 0.0; t1[0] = sqrt(dist); t1[1] = 0.0; t1[2] = 0.0; } else { double dist = 0.0; /* Locate the two furthest distant points (brute force) */ for (i = 0; i < (nipoints-1); i++) { for (j = i+1; j < nipoints; j++) { double tt; if ((tt = icmNorm33sq(inp[i].v, inp[j].v)) > dist) { dist = tt; icmAry2Ary(s0, inp[i].v); icmAry2Ary(s1, inp[j].v); } } } printf("~1 most distant = %f %f %f -> %f %f %f dist %f\n", s0[0], s0[1], s0[2], s1[0], s1[1], s1[2], sqrt(dist)); t0[0] = 0.0; t0[1] = 0.0; t0[2] = 0.0; t1[0] = sqrt(dist); t1[1] = 0.0; t1[2] = 0.0; } /* Transform our direction vector to the L* axis, and create inverse too */ icmVecRotMat(mm, s1, s0, t1, t0); icmVecRotMat(im, t1, t0, s1, s0); /* Setup for rspl to create smoothed locus */ for (i = 0; i < nipoints; i++) { icmMul3By3x4(inp[i].v, mm, inp[i].v); inp[i].p[0] = inp[i].v[0]; inp[i].v[0] = inp[i].v[1]; inp[i].v[1] = inp[i].v[2]; //printf("~1 point %d = %f -> %f %f\n", i, inp[i].p[0], inp[i].v[0], inp[i].v[1]); } /* Create rspl */ if ((rr = new_rspl(RSPL_NOFLAGS, 1, 2)) == NULL) error("Creating rspl failed"); rr->fit_rspl(rr, RSPL_NOFLAGS,inp, nipoints, NULL, NULL, gres, NULL, NULL, 5.0, NULL, NULL); #ifdef DEBUG_PLOT { #define XRES 100 double xx[XRES]; double y1[XRES]; double y2[XRES]; for (i = 0; i < XRES; i++) { co pp; double x; x = i/(double)(XRES-1); xx[i] = x * (t1[0] - t0[0]); pp.p[0] = xx[i]; rr->interp(rr, &pp); y1[i] = pp.v[0]; y2[i] = pp.v[1]; } do_plot(xx,y1,y2,NULL,XRES); } #endif /* DEBUG_PLOT */ free(inp); nopoints = t1[0] / DE_SPACE; if (nopoints < 2) nopoints = 2; /* Create the output points */ if ((outp = malloc(sizeof(co) * nopoints)) == NULL) error("Unable to allocate co array"); /* Setup initial division of locus */ for (i = 0; i < nopoints; i++) { double xx; xx = i/(double)(nopoints-1); xx *= (t1[0] - t0[0]); outp[i].p[0] = xx; //printf("~1 div %d = %f\n",i,outp[i].p[0]); } for (i = 0; i < (nopoints-1); i++) { outp[i].p[1] = outp[i+1].p[0] - outp[i].p[0]; //printf("~1 del div %d = %f\n",i,outp[i].p[1]); } /* Itterate until the delta between samples is even */ for (j = 0; j < 10; j++) { double alen, minl, maxl; double tdiv; alen = 0.0; minl = 1e38; maxl = -1.0; for (i = 0; i < nopoints; i++) { rr->interp(rr, &outp[i]); outp[i].v[2] = outp[i].v[1]; outp[i].v[1] = outp[i].v[0]; outp[i].v[0] = outp[i].p[0]; icmMul3By3x4(outp[i].v, im, outp[i].v); //printf("~1 locus pnt %d = %f %f %f\n", i,outp[i].v[0],outp[i].v[1],outp[i].v[1]); if (i > 0) { double tt[3], len; icmSub3(tt, outp[i].v, outp[i-1].v); len = icmNorm3(tt); outp[i-1].p[2] = len; if (len > maxl) maxl = len; if (len < minl) minl = len; alen += len; } } alen /= (nopoints-1.0); printf("~1 itter %d, alen = %f, minl = %f, maxl = %f\n",j,alen,minl,maxl); /* Adjust spacing */ tdiv = 0.0; for (i = 0; i < (nopoints-1); i++) { outp[i].p[1] *= pow(alen/outp[i].p[2], 1.0); tdiv += outp[i].p[1]; } //printf("~1 tdiv = %f\n",tdiv); for (i = 0; i < (nopoints-1); i++) { outp[i].p[1] *= (t1[0] - t0[0])/tdiv; //printf("~1 del div %d = %f\n",i,outp[i].p[1]); } tdiv = 0.0; for (i = 0; i < (nopoints-1); i++) { tdiv += outp[i].p[1]; } //printf("~1 tdiv now = %f\n",tdiv); for (i = 1; i < nopoints; i++) { outp[i].p[0] = outp[i-1].p[0] + outp[i-1].p[1]; //printf("~1 div %d = %f\n",i,outp[i].p[0]); } } /* Write the CGATS file */ { time_t clk = time(0); struct tm *tsp = localtime(&clk); char *atm = asctime(tsp); /* Ascii time */ cgats *pp; pp = new_cgats(); /* Create a CGATS structure */ pp->add_other(pp, "TS"); /* Test Set */ pp->add_table(pp, tt_other, 0); /* Add the first table for target points */ pp->add_kword(pp, 0, "DESCRIPTOR", "Argyll Test Point set",NULL); pp->add_kword(pp, 0, "ORIGINATOR", "Argyll tiffgmts", NULL); atm[strlen(atm)-1] = '\000'; /* Remove \n from end */ pp->add_kword(pp, 0, "CREATED",atm, NULL); pp->add_field(pp, 0, "SAMPLE_ID", cs_t); pp->add_field(pp, 0, "LAB_L", r_t); pp->add_field(pp, 0, "LAB_A", r_t); pp->add_field(pp, 0, "LAB_B", r_t); for (i = 0; i < nopoints; i++) { char buf[100]; cgats_set_elem ary[1 + 3]; sprintf(buf,"%d",i+1); ary[0].c = buf; ary[1 + 0].d = outp[i].v[0]; ary[1 + 1].d = outp[i].v[1]; ary[1 + 2].d = outp[i].v[2]; pp->add_setarr(pp, 0, ary); } if (pp->write_name(pp, out_name)) error("Write error : %s",pp->err); } /* Create the VRML file */ if (dovrml) { vrml *vv; strcpy(xl,".wrl"); printf("Output vrml file '%s'\n",out_name); if ((vv = new_vrml(out_name, doaxes)) == NULL) error ("Creating VRML object failed"); #ifdef NEVER vv->start_line_set(vv); for (i = 0; i < nopoints; i++) { vv->add_vertex(vv, outp[i].v); } vv->make_lines(vv, nopoints); #else for (i = 1; i < nopoints; i++) { vv->add_cone(vv, outp[i-1].v, outp[i].v, NULL, 0.5); } #endif vv->del(vv); } free(outp); } rr->del(rr); return 0; }
static char *fcvt(double arg, int ndigits, int *decpt, int *sign, char *buf) { return (cvt(arg, ndigits, decpt, sign, 0, buf)); }
char * ecvtbuf(double arg, int ndigits, int *decpt, int *sign, char *buf) { return cvt(arg, ndigits, decpt, sign, buf, 1); }
static char *fcvtbuf(double arg, int ndigits, int *decpt, int *sign, char *buf) { return cvt(arg, ndigits, decpt, sign, buf, 0); }
char* fcvt(double arg, size_t ndigits, int *decpt, int *sign) { return(cvt(arg, ndigits, decpt, sign, 0)); }
static DF2(bool2){R from(plus(duble(cvt(BOOL,a)),cvt(BOOL,w)),VAV(self)->h);}
static wchar_t *ecvtbuf(double arg, int ndigits, int *decpt, int *sign, wchar_t *buf) { return cvt(arg, ndigits, decpt, sign, buf, 1); }
RETCODE SQL_API SQLParamData( HSTMT hstmt, PTR* prgbValue) { stmt_t* pstmt = hstmt; int ipar; param_t* ppar; fptr_t cvt; char* data; date_t dt; UNSET_ERROR( pstmt->herr ); ipar = pstmt->putipar; ppar = pstmt->ppar + ipar - 1; if ( ipar ) { ppar->need = 0; pstmt->ndelay --; if ( ppar->ctype == SQL_C_CHAR ) { if ( ! ppar->putdtbuf && ! ppar->putdtlen ) data = 0; else { cvt = ppar->cvt; data= cvt(ppar->putdtbuf, ppar->putdtlen, &dt); } MEM_FREE( ppar->putdtbuf ); ppar->putdtbuf = 0; ppar->putdtlen = 0; if ( data == (char*)(-1) ) { PUSHSQLERR( pstmt->herr, en_S1000 ); return SQL_ERROR; } sqlputdata( pstmt, ipar, data ); } } if ( pstmt->ndelay ) { for (ipar++, ppar++;;) { if ( ppar->need ) { *prgbValue = (PTR)(ppar->userbuf); pstmt->putipar = ipar; return SQL_NEED_DATA; } } } if ( nnsql_execute(pstmt->yystmt) ) { int code; code = nnsql_errcode( pstmt->yystmt ); if ( code == -1 ) code = errno; PUSHSYSERR( pstmt->herr, code, nnsql_errmsg(pstmt->yystmt)); return SQL_ERROR; } if ( ! nnsql_getcolnum(pstmt->yystmt) && nnsql_getrowcount(pstmt->yystmt) > 1 ) { PUSHSQLERR( pstmt->herr, en_01S04); return SQL_SUCCESS_WITH_INFO; } return SQL_SUCCESS; }