Пример #1
0
void tex::make_accent ()
	{
	fnt	f;
	qcell	i;
	ptr	p, q, r;
	scal	a, h, w, x;
	float	s, t;
	scal	delta;

	scan_char_num();
	f = cur_font;
	p = new_character(f, cur_val);
	if (p != null) {
		x = x_height(f);
		s = (float) slant(f) / 65536.0;
		a = char_width(f, char_info(f, character(p)));
		do_assignments();
		q = null;
		f = cur_font;
		if (cur_cmd == LETTER
		|| cur_cmd == OTHER_CHAR
		|| cur_cmd ==  CHAR_GIVEN) {
			q = new_character(f, cur_chr);
		} else if (cur_cmd ==  CHAR_NUM) {
			scan_char_num();
			q = new_character(f, cur_val);
		} else {
			back_input();
		}
		if (q != null) {
			t = (float) slant(f) / 65536.0;
			i = char_info(f, character(q));
			w = char_width(f, i); 
			h = char_height(f, height_depth(i));
			if (h != x) {
				p = hpack(p, 0, ADDITIONAL);
				shift_amount(p) = x - h;
			}
			delta = round((float) (w - a) / 2.0 + h * t - x * s);
			r = new_kern(delta);
			subtype(r) = ACC_KERN;
			link(tail) = r;
			link(r) = p;
			tail = new_kern(-a - delta);
			subtype(tail) = ACC_KERN;
			link(p) = tail;
			p = q;
		}
		tail_append(p);
		space_factor = 1000;
		}
	}
Пример #2
0
SkTypeface* OsmAnd::EmbeddedFontFinder::findFontForCharacterUCS4(
    const uint32_t character,
    const SkFontStyle style /*= SkFontStyle()*/) const
{
    SkPaint paint;
    paint.setTextEncoding(SkPaint::kUTF32_TextEncoding);

    SkTypeface* bestMatch = nullptr;
    auto bestMatchDifference = std::numeric_limits<float>::quiet_NaN();
    for (const auto font : constOf(_fonts))
    {
        paint.setTypeface(font);

        // If font doesn't contain requested character, it should be completely ignored
        if (!paint.containsText(&character, sizeof(uint32_t)))
            continue;

        // Calculate difference between this font style and requested style
        auto difference = 0.0f;
        const auto fontStyle = font->fontStyle();
        if (fontStyle.slant() != style.slant())
            difference += 1.0f;
        if (fontStyle.width() != style.width())
            difference += static_cast<float>(qAbs(fontStyle.width() - style.width())) / SkFontStyle::kUltaExpanded_Width;
        if (fontStyle.weight() != style.weight())
            difference += static_cast<float>(qAbs(fontStyle.weight() - style.weight())) / SkFontStyle::kBlack_Weight;

        // If there was previous best match, check if this match is better
        if (bestMatch && bestMatchDifference < difference)
            continue;
        
        bestMatch = font;
        bestMatchDifference = difference;

        // In case difference is 0, there won't be better match
        if (qFuzzyIsNull(bestMatchDifference))
            break;
    }

    return bestMatch;
}
Пример #3
0
int main(int argc, char* argv[])
{


  int nt, nx, it, ix, niter, iter, ntfft, nxfft,np, ip, ikt, ikx, iktn, ikxn, ifsnr; /* iktn, ikxn, iNyquist*/
  float dt, dx, pmin, pmax, dp, p, cmax, scalar, sembpmax, num, den;
  float *sembp, *mask, *gy, *fden, *fshift, *SNR;
  float **fdata, **taup, **odata, **tdata, **odatat, **semb; /* tdata is the true data */
  kiss_fft_cpx **cdata, **cdatat;
  char *type;
  sf_file inp, outp, m, spec1, spec2, trued, snr; 


  sf_init(argc,argv);

  inp=sf_input("in");
  m=sf_input("mask");
  outp=sf_output("out");

  if(!sf_histint(inp,"n1",&nt)) sf_warning("No n1 in input");
  if(!sf_histint(inp,"n2",&nx)) sf_warning("No n2 in input");
  if(!sf_histfloat(inp,"d1",&dt)) sf_warning("No n1 in input");
  if(!sf_histfloat(inp,"d2",&dx)) sf_warning("No n2 in input");

  ntfft = 2*kiss_fft_next_fast_size((nt+1)/2);
  nxfft = 2*kiss_fft_next_fast_size((nx+1)/2);
  scalar = 1./(ntfft*nxfft);
  iktn=ntfft/2; ikxn=nxfft/2;
  float dkt = 1.0/(ntfft*dt), fkt = 0.0,kt;
  float dkx = 1.0/(nxfft*dx), fkx = 0.0,kx;

    if (NULL == (type=sf_getstring("type"))) type="amplitude";
    /* [amplitude, semblance] thresholding type, the default is amplitude thresholding  */ 

  	if(!sf_getint("niter",&niter)) niter = 10;
	/* Get the number of iterations */

  	if(!sf_getint("ifsnr",&ifsnr)) ifsnr = 0;
	/* If compute SNR during iteration */


	if(type[0]=='s')
	{

  		if(!sf_getfloat("pmin",&pmin)) pmin=-2;
        /* minimum p */		
  		if(!sf_getfloat("pmax",&pmin)) pmax=2;
        /* maximum p */			
  		if(!sf_getint("np",&np)) np=nx;
        /* number of p */
		dp=(pmax-pmin)/(np-1);		
  		sembp =sf_floatalloc(np);
  		semb  =sf_floatalloc2(nt,np);
 		taup  =sf_floatalloc2(nt,np);	
	}

	/* output files */
  	if (NULL!=sf_getstring("spec2")) 
  	{
		spec2=sf_output("spec2");
		sf_putint(spec2, "n1", ntfft);
		sf_putint(spec2, "n2", nxfft);
	}	       		
  	if (NULL!=sf_getstring("spec1")) 
  	{
		spec1=sf_output("spec1");
		sf_putint(spec1, "n1", ntfft);
		sf_putint(spec1, "n2", nxfft);
	}	  
  	if (ifsnr==1 && (NULL!=sf_getstring("true"))) 
  	{
		snr=sf_output("snr");
		trued=sf_input("true");
		tdata=sf_floatalloc2(nt,nx);
		SNR=sf_floatalloc(niter);
		sf_floatread(tdata[0],nt*nx,trued);

		sf_putint(snr,"n1",niter);
		sf_putint(snr,"d1",1);
		sf_putint(snr,"n2",1);
	}	

  /* Allocate memory */
  cdata =(kiss_fft_cpx**) sf_complexalloc2(ntfft,nxfft);
  cdatat =(kiss_fft_cpx**) sf_complexalloc2(ntfft,nxfft); /* temporary file */
  fshift= sf_floatalloc(ntfft);
  fden 	= sf_floatalloc(ntfft);
  gy 	= sf_floatalloc(nxfft);
  mask  =sf_floatalloc(nx);

  odata =sf_floatalloc2(nt,nx); 
  odatat =sf_floatalloc2(ntfft,nxfft); 
  fdata =sf_floatalloc2(ntfft,nxfft);
  memset(&odata[0][0],0,ntfft*nxfft*sizeof(float)); 

  /* Read data */
  sf_floatread(odata[0],nt*nx,inp);
  sf_floatread(mask,nx,m);

	if(type[0]=='s')
	{
   	 slant(dt,nt,nx,gy,pmin,dp,np,odata,taup,semb,sembp,&sembpmax,fshift,fden);
	}

  for (iter=niter-1; iter>=0; iter--) {
    tfft(odata, cdatat, nx, ntfft);
    xfft(cdatat, cdata, ntfft, nxfft);
    cmax = findmax(nxfft,ntfft,cdata);

    if (iter==0 || iter==niter-1) { // beginning and ending spectra
  		for (ix=0; ix<nxfft; ix++)
  		for (it=0; it<ntfft; it++)
    	fdata[ix][it] = sf_cabsf(cdata[ix][it]);

  		if (iter==0 && (NULL!=sf_getstring("spec2")))        		sf_floatwrite(fdata[0],ntfft*nxfft,spec2);
  		if (iter==niter-1 && (NULL!=sf_getstring("spec1")))   	sf_floatwrite(fdata[0],ntfft*nxfft,spec1);

    }



	if(type[0]=='a')
	{
    	for (ix=0; ix<nxfft; ix++) // Abma Kabir FT amplitude thresholding
    		for (it=0; it<ntfft; it++)
      			if (sf_cabsf(cdata[ix][it])<iter*1./niter*cmax) cdata[ix][it] = cmplx(0.,0.);
	}
	else
	{
    	for (ix=0; ix<nxfft; ix++) // Abma Kabir FT amplitude thresholding
    		for (it=0; it<ntfft; it++)
      			if (sf_cabsf(cdata[ix][it])<iter*1./niter*cmax) cdata[ix][it] = cmplx(0.,0.);


   		for (ikx=0,kx=fkx; ikx<=ikxn; ++ikx,kx+=dkx) {
    		for (ikt=0,kt=fkt; ikt<=iktn; ++ikt,kt+=dkt) {
      		if (kx==0) {
        		if (sf_cabsf(cdata[ikx][ikt])<iter*1./niter*cmax) cdata[ikx][ikt] = cmplx(0.,0.);
        		continue;
      		}

      p = -kx/kt; ip = round((p-pmin)/dp);
      //if (ip<0 || ip>=np) { cdata[ikx][ikt] = 0.;continue; }
      if (ip<0 || ip>=np) {  }
      else if (sembp[ip] <iter*1./niter*sembpmax) cdata[ikx][ikt] = cmplx(0.,0.);

      if (ikx>0 && ikx<(nxfft+1)/2) { // kx>=0, kx<0
      p = kx/kt; ip = round((p-pmin)/dp);
      //if (ip<0 || ip>=np) { cdata[nxfft-ikx][ikt] = 0.;continue; }
      if (ip<0 || ip>=np) {  }
      else if (sembp[ip] <iter*1./niter*sembpmax) cdata[nxfft-ikx][ikt] = cmplx(0.,0.);
      }

      if (ikt>0 && ikt<(ntfft+1)/2) { // kt<0, kx>=0
      p = kx/kt; ip = round((p-pmin)/dp);
      //if (ip<0 || ip>=np) { cdata[ikx][ntfft-ikt] = 0.;continue; }
      if (ip<0 || ip>=np) {  }
      else if (sembp[ip] <iter*1./niter*sembpmax) cdata[ikx][ntfft-ikt] = cmplx(0.,0.);
      }

      if (ikx>0 && ikx<(nxfft+1)/2 && ikt>0 && ikt<(ntfft+1)/2) { // kt<0, kx<0
      p = -kx/kt; ip = round((p-pmin)/dp);
      //if (ip<0 || ip>=np) { cdata[nxfft-ikx][ntfft-ikt] = 0.;continue; }
      if (ip<0 || ip>=np) {  }
      else if (sembp[ip] <iter*1./niter*sembpmax) cdata[nxfft-ikx][ntfft-ikt] =cmplx(0.,0.);
      }
    }}
	
	}

	ixfft(cdata, cdatat, ntfft, nxfft);
	itfft(cdatat, odatat, nxfft, ntfft);

    for (ix=0; ix<nx; ix++) { // put in ORIGINAL KNOWN data
      if (mask[ix]==1) continue;
      for (it=0; it<nt; it++) odata[ix][it]=odatat[ix][it];
    }

	num=0;den=0;
	/* If output the SNR file. */
  	if (ifsnr==1 && (NULL!=sf_getstring("true"))) 
  	{
		for(ix=0;ix<nx;ix++)
			for(it=0;it<nt;it++)
			{
				num+=tdata[ix][it]*tdata[ix][it];
				den+=(tdata[ix][it]-odata[ix][it])*(tdata[ix][it]-odata[ix][it]);
			}	
		SNR[niter-iter-1]=10*logf(num/den);
	}	
  }

  	if (ifsnr==1 && (NULL!=sf_getstring("true"))) 
	{ sf_floatwrite(SNR,niter,snr);	}

  	sf_floatwrite(odata[0],nt*nx,outp);
    exit (0);
}