Exemple #1
0
bool GrAtlas::addSubImage(int width, int height, const void* image,
                          GrIPoint16* loc) {
    if (!fRects->addRect(width + BORDER, height + BORDER, loc)) {
        return false;
    }

    GrAutoSMalloc<1024> storage;
    int dstW = width + 2*BORDER;
    int dstH = height + 2*BORDER;
    if (BORDER) {
        const int bpp = GrMaskFormatBytesPerPixel(fMaskFormat);
        const size_t dstRB = dstW * bpp;
        uint8_t* dst = (uint8_t*)storage.realloc(dstH * dstRB);
        Gr_bzero(dst, dstRB);                // zero top row
        dst += dstRB;
        for (int y = 0; y < height; y++) {
            dst = zerofill(dst, bpp);   // zero left edge
            memcpy(dst, image, width * bpp);
            dst += width * bpp;
            dst = zerofill(dst, bpp);   // zero right edge
            image = (const void*)((const char*)image + width * bpp);
        }
        Gr_bzero(dst, dstRB);                // zero bottom row
        image = storage.get();
    }
    adjustForPlot(loc, fPlot);
    fTexture->uploadTextureData(loc->fX, loc->fY, dstW, dstH, image);

    // now tell the caller to skip the top/left BORDER
    loc->fX += BORDER;
    loc->fY += BORDER;
    return true;
}
Exemple #2
0
void Cipher::Key::clear(void)
{
    algotype = NULL;
    hashtype = NULL;
    algoid = hashid = 0;
    keysize = blksize = 0;

    zerofill(keybuf, sizeof(keybuf));
    zerofill(ivbuf, sizeof(ivbuf));
}
Exemple #3
0
bool GrAtlas::addSubImage(int width, int height, const void* image,
                          GrIPoint16* loc) {
    if (!fRects->addRect(width + BORDER, height + BORDER, loc)) {
        return false;
    }

    SkAutoSMalloc<1024> storage;
    int dstW = width + 2*BORDER;
    int dstH = height + 2*BORDER;
    if (BORDER) {
        const int bpp = GrMaskFormatBytesPerPixel(fMaskFormat);
        const size_t dstRB = dstW * bpp;
        uint8_t* dst = (uint8_t*)storage.reset(dstH * dstRB);
        Gr_bzero(dst, dstRB);                // zero top row
        dst += dstRB;
        for (int y = 0; y < height; y++) {
            dst = zerofill(dst, bpp);   // zero left edge
            memcpy(dst, image, width * bpp);
            dst += width * bpp;
            dst = zerofill(dst, bpp);   // zero right edge
            image = (const void*)((const char*)image + width * bpp);
        }
        Gr_bzero(dst, dstRB);                // zero bottom row
        image = storage.get();
    }
    adjustForPlot(loc, fPlot);
    GrContext* context = fTexture->getContext();
    // We pass the flag that does not force a flush. We assume our caller is
    // smart and hasn't referenced the part of the texture we're about to update
    // since the last flush.
    context->writeTexturePixels(fTexture,
                                loc->fX, loc->fY, dstW, dstH,
                                fTexture->config(), image, 0,
                                GrContext::kDontFlush_PixelOpsFlag);

    // now tell the caller to skip the top/left BORDER
    loc->fX += BORDER;
    loc->fY += BORDER;

#if FONT_CACHE_STATS
    ++g_UploadCount;
#endif

    return true;
}
Exemple #4
0
size_t Cipher::puts(const char *text)
{
    char padbuf[64];
    if(!text || !bufaddr)
        return 0;

    size_t len = strlen(text) + 1;
    size_t pad = len % keys.iosize();

    put((const uint8_t *)text, len - pad);
    if(pad) {
        memcpy(padbuf, text + len - pad, pad);
        memset(padbuf + pad, 0, keys.iosize() - pad);
        put((const uint8_t *)padbuf, keys.iosize());
        zerofill(padbuf, sizeof(padbuf));
    }
    return flush();
}
Exemple #5
0
static long mmap_prog_section(elf_bin_t *elf, Elf32_Phdr *p)
{
	unsigned long base = elf->base, brk_, bss, addr, pg_off, size;
	int prot = 0;

	if (p->p_flags & PF_R)
		prot |= PROT_READ;		
	if (p->p_flags & PF_W)
		prot |= PROT_WRITE;		
	if (p->p_flags & PF_X)
		prot |= PROT_EXEC;

	addr = PAGE_BASE(base+p->p_vaddr);
	size = PAGE_NEXT(base+p->p_vaddr + p->p_filesz) - addr;
	pg_off = p->p_offset/PG_SIZE;

	bss = base + p->p_vaddr + p->p_filesz;
	brk_ = base + p->p_vaddr + p->p_memsz;

	if ( ((p->p_vaddr-p->p_offset) & PG_MASK) || (bss > brk_) )
		return -1;

	addr = do_mmap2(addr, size, prot, MAP_PRIVATE|MAP_FIXED, elf->fd, pg_off);

	if (addr & PG_MASK) /* not on page boundary -> error code */
		return addr;

	if (elf->brk < brk_)
		elf->brk = brk_;

	if (elf->bss < bss)
		elf->bss = bss;

	/* linux does not fill in bss sections
	 * between load segments for interpreters;
	 * makes no difference to the standard ld.so
	 */
	addr = zerofill(bss, brk_, prot);

	if (addr & PG_MASK) /* not on page boundary -> error code */
		return addr;

	return 0;
}
Exemple #6
0
size_t Cipher::pad(const uint8_t *data, size_t size)
{
    size_t padsize = 0;
    uint8_t padbuf[64];
    const uint8_t *ep;

    if(!bufaddr)
        return 0;

    switch(bufmode) {
    case DECRYPT:
        if(size % keys.iosize())
            return 0;
        put(data, size);
        ep = data + size - 1;
        bufpos -= *ep;
        size -= *ep;
        break;
    case ENCRYPT:
        padsize = size % keys.iosize();
        put(data, size - padsize);
        if(padsize) {
            memcpy(padbuf, data + size - padsize, padsize);
            memset(padbuf + padsize, (int)(keys.iosize() - padsize), keys.iosize() - padsize);
            size = (size - padsize) + keys.iosize();
        }
        else {
            size += keys.iosize();
            memset(padbuf, (int)keys.iosize(), keys.iosize());
        }

        put((const uint8_t *)padbuf, keys.iosize());
        zerofill(padbuf, sizeof(padbuf));
    }

    flush();
    return size;
}
Exemple #7
0
/*-----------------------------------------------
|                                               |
|               get_one_fid()/3                 |
|                                               |
|    This function returns a pointer to the     |
|    requested FID in a 1D, arrayed, or 2D      |
|    experiment.                                |
|                                               |
+----------------------------------------------*/
float *get_one_fid(int curfid, int *np, dpointers *c_block, int dcflag)
{
  char          filepath[MAXPATHL],
                dcrmv[4];
  int           res,
                lastfid,
                force_getfid,
                headok;
  float         *fidptr;
  int           cftemp;
  int           cttemp;
  double        tmp;
  vInfo         info;
  ftparInfo	ftpar;
  dfilehead	fidhead,
		phasehead;
 
 
  force_getfid = (*np < 0);
  if (force_getfid)
     *np = -(*np);
  acqflag = FALSE;
  ftpar.np0 = *np;
  ftpar.fn0 = *np;
  ftpar.hypercomplex = FALSE;	/* ==> will not work for hypercomplex
				   2D interferograms */
  D_allrelease();
 
  if ( (res = D_gethead(D_PHASFILE, &phasehead)) )
  {
     if (res == D_NOTOPEN)
     {
        if ( (res = D_getfilepath(D_PHASFILE, filepath, curexpdir)) )
        {
           D_error(res);
           return(NULL);
        }

        res = D_open(D_PHASFILE, filepath, &phasehead); /* open the file */
     }
 
     if (res)
     {
        if ( new_phasefile(&phasehead, 0, 0, 0, 0, 0, ftpar.hypercomplex) )
           return(NULL);
     }
  }
 
  cftemp = 1;
  if (!P_getreal(CURRENT, "cf", &tmp, 1))
  {
     if (!P_getVarInfo(CURRENT, "cf", &info))
     {
        if (info.active)
           cftemp = (int) tmp;
     }
  }
  cttemp = 0;
  if (!P_getreal(PROCESSED, "ct", &tmp, 1))
     cttemp = (int) (tmp + 0.5);

  ls_ph_fid("lsfid", &(ftpar.lsfid0), "phfid", &(ftpar.phfid0), "lsfrq",
		&(ftpar.lsfrq0));
  headok = ( (phasehead.status == (S_DATA|S_FLOAT|S_COMPLEX)) &&
            (phasehead.ntraces == 1) && (phasehead.np == ftpar.np0) );
 
  if (headok)
  { /* if phase file does contain fid data, open the file */
     res = D_getbuf(D_PHASFILE, phasehead.nblocks, curfid, c_block);
 
     if (!res)
     {
        if ( (c_block->head->status == (S_DATA|S_FLOAT|S_COMPLEX)) &&
             (c_block->head->rpval == (float) (ftpar.phfid0)) &&
             (c_block->head->lpval == (float) (ftpar.lsfid0/2)) &&
             (c_block->head->lvl   == (float) (cftemp)) &&
             (c_block->head->tlt   == (float) (cttemp)) &&
             !force_getfid )
        {
           long_event();
           return((float *)c_block->data);
        }
     }
  }
 
/********************************************
*  If phasefile does not contain FID data,  *
*  open phasefile with the data handler.    *
********************************************/

  ftpar.zeroflag = FALSE;
  ftpar.arraydim = dim1count();
  lastfid = ftpar.arraydim;
  ftpar.fn0 = ftpar.np0;
  if ( i_fid(&fidhead, &ftpar) )   /* open fid file with data handler */
     return(NULL);
  if (ftpar.fn0 != ftpar.np0)
     headok = 0;

  *np = ftpar.np0;
  ftpar.fn0 = ftpar.np0;
 
  if (!headok)
  {
     if (new_phasefile(&phasehead, 0, ftpar.arraydim, 2*ftpar.np0, 1,
                    (S_DATA|S_FLOAT|S_COMPLEX), ftpar.hypercomplex))
     {
        return(NULL);
     }
  }
 
  if ( (res = D_allocbuf(D_PHASFILE, curfid, c_block)) )
  {
     D_error(res);
     return(NULL);
  }
 
  fidptr = (float *)c_block->data;
 
  /*******************************************
  *   provision for baseline offset removal  *
  *   using numbers reported by noise check  *
  *******************************************/

  ftpar.offset_flag = FALSE;
  if (!P_getstring(CURRENT,"dcrmv",dcrmv,1,4))
  {
    if (dcrmv[0] == 'y')
    {
      ftpar.offset_flag = TRUE;
    }
  }
  ftpar.t2dc = dcflag;
     
  if ( getfid(curfid, fidptr, &ftpar, &fidhead, &lastfid) ||
        (lastfid <= curfid) )
  {
     return(NULL);
  }
 
  if (ftpar.lsfid0 > 0)
     zerofill(fidptr + ftpar.np0 - ftpar.lsfid0, ftpar.lsfid0);
 
  D_close(D_USERFILE);
  setheader(c_block, (S_DATA|S_FLOAT|S_COMPLEX), NP_PHMODE, curfid,
                ftpar.hypercomplex);
  c_block->head->rpval = (float) (ftpar.phfid0);
  c_block->head->lpval = (float) (ftpar.lsfid0/2);
  c_block->head->lvl   = (float) (ftpar.cf);
  c_block->head->tlt   = (float) (ftpar.dspar.ctcount);
 
  if ( ftpar.cf != cftemp)
  {  /* cf is misset or inactive - just set it = 1 */
     Werrprintf("cf = %d is inconsistent with data",cftemp);
     P_setreal(CURRENT,  "cf", 1.0, 0);
     P_setreal(PROCESSED,"cf", 1.0, 0);
  }
  if ( (res = D_markupdated(D_PHASFILE, curfid)) )
  {
     D_error(res);
     return(NULL);
  }
 
  return(fidptr);
}
Exemple #8
0
/*---------------------------------------
|                                       |
|              getfid()/5               |
|                                       |
+--------------------------------------*/
int getfid(int curfid, float *outp, ftparInfo *ftpar, dfilehead *fidhead, int *lastfid)
{
   short                *data,
                        *inp16;
   int                 *inp32;
   register int         i,
                        npx;
   int                  shift,
                        res;
   register float       *inpfloat,
                        rmult;
   register float       *tmp;
   dpointers            inblock;
   static float		xoff,
			yoff;
   int                  showMsg = 1;


/*  i_ft sets the correct values for cf and nf fields in ftpar  */

   if (curfid >= (*lastfid) || ftpar->cf > ftpar->nf)
   {
      zerofill(outp, ftpar->fn0);
   }
   else
   {
      if ( (res = D_getbuf(D_USERFILE, fidhead->nblocks,  curfid, &inblock)) )
      {
         *lastfid = curfid;
         if (ftpar->arraydim > 0)
         {
            if ( ftpar->np1 > 2*(curfid/ftpar->arraydim) )
               ftpar->np1 = 2*(curfid/ftpar->arraydim);
                                /* adjusts number of t1 points */
         }
 
         zerofill(outp, ftpar->fn0);
         D_close(D_USERFILE);

         if (*lastfid == 0)   
         {
            Werrprintf("No data in FID file");
         }
         else
         {               
            if (!acqflag)
               Winfoprintf("number of FID's used = %d", *lastfid);
         }
 
         return(COMPLETE);
      }

/************************************************************
*  Convert the data of each FID.  Check to see if FID data  *
*  are double precision or single precision and convert     *
*  appropriately.  Correct FID size for CT and scaling.     *
************************************************************/
      if (inblock.head->lpval != 0)
        ftpar->lpval = inblock.head->lpval;
/* Save this so other programs like addsub and wti can get it */
      oversamp_lp = inblock.head->lpval;
      ftpar->dspar.lvl = inblock.head->lvl;
      ftpar->dspar.tlt = inblock.head->tlt;
      ftpar->dspar.scale = inblock.head->scale;
      ftpar->dspar.ctcount = inblock.head->ctcount;

      data = (short *) (inblock.data);                        
      if (ftpar->cf > 1)
      {
         data += (ftpar->cf - 1)*ftpar->np0;
         if (ftpar->dpflag)
            data += (ftpar->cf - 1)*ftpar->np0;
      }

      if ( (ftpar->np0 - ftpar->lsfid0) > ftpar->fn0 )
         ftpar->np0 = ftpar->fn0 + ftpar->lsfid0;


      if (inblock.head->status == (S_DATA|S_FLOAT|S_COMPLEX))
      {
         inpfloat = (float *) (data);

         if (ftpar->lsfid0 < 0)
         {
            inpfloat += ftpar->np0;
            tmp = outp + ftpar->np0 - ftpar->lsfid0;
            npx = ftpar->np0;
            if ((inblock.head->ctcount > 1) || (inblock.head->scale) )
            {
               shift = 1 << abs(inblock.head->scale);
               if (inblock.head->scale < 0)
                  rmult = 1.0/(float)(shift);
               else
                  rmult = (float) shift;
               rmult /= (float)(inblock.head->ctcount);
               for (i = 0; i < npx; i++)
                  *(--tmp) = *(--inpfloat) * rmult;
            }
            else
            {
               for (i = 0; i < npx; i++)
                  *(--tmp) = *(--inpfloat);
            }

            npx = (-1)*ftpar->lsfid0;
            for (i = 0; i < npx; i++)
               *(--tmp) = 0.0;
         }
         else
         {
            inpfloat += ftpar->lsfid0;
            tmp = outp;
            npx = ftpar->np0 - ftpar->lsfid0;
            if ((inblock.head->ctcount > 1) || (inblock.head->scale) )
            {
               shift = 1 << abs(inblock.head->scale);
               if (inblock.head->scale < 0)
                  rmult = 1.0/(float)(shift);
               else
                  rmult = (float) shift;
               rmult /= (float)(inblock.head->ctcount);
               for (i = 0; i < npx; i++)
                  *tmp++ = *inpfloat++ * rmult;
            }
            else
            {
               for (i = 0; i < npx; i++)
                  *tmp++ = *inpfloat++;
            }
         }
      }
      else
      {
         if (inblock.head->ctcount == 0)
         {
            inblock.head->ctcount = 1;
            inblock.head->status = 0;
            *lastfid = curfid;
            if (ftpar->arraydim > 0)
            {
               if ( ftpar->np1 > 2*(curfid/ftpar->arraydim) )
                  ftpar->np1 = 2*(curfid/ftpar->arraydim);
            }
 
            if (!acqflag)
            {
               if ( *lastfid )
                  Winfoprintf("number of FID's used = %d", *lastfid);
               else
                  Winfoprintf("No data in FID file");
               showMsg = 0;
            }
         }

         inp16 = (short *) (inp32 = (int *) (data));
         shift = 1 << abs(inblock.head->scale);
         if (inblock.head->scale < 0)
            rmult = 1.0/(float)(shift);
         else
            rmult = (float) shift;
         rmult /= (float)(inblock.head->ctcount);
         if (inblock.head->status == (S_DATA|S_32|S_COMPLEX))
         {
            cnvrts32(rmult, inp32, outp, ftpar->np0, ftpar->lsfid0);
         }
         else if (inblock.head->status == (S_DATA|S_COMPLEX))
         {
            cnvrts16(rmult, inp16, outp, ftpar->np0, ftpar->lsfid0);
         }
         else
         {
            if (inblock.head->status != 0)
            {
               Wscrprintf("status of FID %d incorrect, status = %d\n",
                     curfid + 1, inblock.head->status);
            }
 
            zerofill(outp, ftpar->fn0);
            if (ftpar->arraydim > 0)
            {
               if ( ftpar->np1 > 2*(curfid/ftpar->arraydim) )
                  ftpar->np1 = 2*(curfid/ftpar->arraydim);
            }
 
            *lastfid = curfid;
            if ( !acqflag && showMsg )
            {
               if ( *lastfid )
                  Winfoprintf("number of FID's used = %d", *lastfid);
               else
                  Winfoprintf("No data in FID file");
            }
         }
      }

/*---------------------------------------------
|     if requested remove the baseline        |
|     supplied by noise check                 |
---------------------------------------------*/
 
     if ( ftpar->offset_flag && (inblock.head->ctcount == 1) )
     {
        if (curfid == 0)
        {
           xoff = inblock.head->lvl;
           yoff = inblock.head->tlt;
        }
 
        if (ftpar->lsfid0 < 0)
        {
           tmp = outp - ftpar->lsfid0;
           npx = ftpar->np0;
        }
        else
        {
           tmp = outp;
           npx = ftpar->np0 - ftpar->lsfid0;
        }

        i = 0;
        while (i < npx)
        {  
           *tmp++ -= xoff;
           *tmp++ -= yoff;
           i += 2;
        }
      }
/*    end of prototype baseline removal */

#ifdef XXX
      if ( !P_getreal(CURRENT, "rlmult", &rlmult, 1) )
      {
         if ( !P_getreal(CURRENT, "immult", &immult, 1) )
         {
            if (ftpar->lsfid0 < 0)
            {
               tmp = outp - ftpar->lsfid0;
               npx = ftpar->np0;
            }
            else
            {   
               tmp = outp;
               npx = ftpar->np0 - ftpar->lsfid0;
            }

            i = 0;
            while (i < npx)
            {
               *tmp++ *= rlmult;
               *tmp++ *= immult;
               i += 2;
            }
         }
      }
#endif
/* end of prototype differential channel scaling */

      if (ftpar->t2dc)
      {
        driftcorrect_fid(outp, ftpar->np0/2, ftpar->lsfid0/2, COMPLEX);
      }
 
      if ( (fabs(ftpar->phfid0) > MINDEGREE) ||
	   (fabs(ftpar->lsfrq0) > 1e-20) )
      {
         rotate_fid(outp, ftpar->phfid0, ftpar->lsfrq0,
			ftpar->np0 - ftpar->lsfid0, COMPLEX);
      }

      if (ftpar->zeroflag)
      {
         if (ftpar->zeroflag > 0)
            zeroimag(outp, ftpar->np0 - ftpar->lsfid0, TRUE);
         else
            negateimaginary(outp, (ftpar->np0 - ftpar->lsfid0) / 2, COMPLEX);
      }

      if ( (res = D_release(D_USERFILE, curfid)) )
      {
         D_error(res);
         D_close(D_USERFILE);
         return(ERROR);
      }
   }

   long_event();
   return(COMPLETE);
}
Exemple #9
0
/*  blocknum    DATA block number to store converted data    */
static int convertblock(int *curfid, int blocknum, int *lastfid, int fidincr,
                ftparInfo *ftpar, dfilehead *fidhead, int nf_firstfid)
{
  int                   status,
                        res,
                        outfile,
                        npadj,
			fidnum,
			zfnumber;
  register int          fidcnt;
  register float        *outp;
  dpointers             outblock;
 
 
  outfile = D_DATAFILE;
 
/****************************************
*  Block "blocknum+nblocks" is used in  *
*  D_DATAFILE to transpose data.        *
****************************************/
 
  if ( (res = D_allocbuf(outfile, blocknum + ftpar->nblocks, &outblock)) )
  {
     D_error(res);
     return(ERROR);
  }
 
  outp = (float *)outblock.data;
/*************************************************
*  Start filling at the beginning of the output  *
*  data buffer.                                  *
*                                                *
*  np0 = the number of actual points in the FID  *
*  fn0 = the number of actual points in the      *
*        converted file                          *
*************************************************/
 
  npadj = ( (ftpar->lsfid0 < 0) ? ftpar->np0 : (ftpar->np0 - ftpar->lsfid0) );
  if (npadj > ftpar->fn0)
     npadj = ftpar->fn0;
  zfnumber = ftpar->fn0 - npadj;
 
/*********************************************
*  DF2D of NF-arrayed 2D data will not work  *
*  at this time.                             *
*********************************************/
  *lastfid = *curfid + ftpar->sperblock0*fidincr;
  for (fidcnt = *curfid; fidcnt < *lastfid; fidcnt += fidincr)
  {
     fidnum = ( (ftpar->D_dimname & S_NF) ? nf_firstfid : fidcnt );
     if ( getfid(fidnum, outp, ftpar, fidhead, lastfid) )
        return(ERROR);
 
     if (*lastfid == 0)
        return(ERROR);
 
     if (fidcnt < (*lastfid))
     {
        if (zfnumber > 0)
           zerofill(outp + npadj, zfnumber);
        scalefid(outp,npadj);
	if (ftpar->D_dimname & S_NF)
           ftpar->cf += ftpar->cfstep;/* increment cf for NF processing */
     }
     outp += ftpar->fn0;
  }
 
  fidnum = fidcnt;
  for (fidcnt = *lastfid + fidincr; fidcnt < *curfid + ftpar->sperblock0*fidincr;
       fidcnt += fidincr)
  {
     zerofill(outp, ftpar->fn0);
     outp += ftpar->fn0;
  }
  *curfid = fidnum;
  status = (S_DATA|S_FLOAT|S_COMPLEX);
     
  setheader(&outblock, status, ftpar->D_dsplymode, blocknum,
                ftpar->hypercomplex);
  if ( (res = D_markupdated(outfile, blocknum + ftpar->nblocks)) )
  {
     D_error(res);
     return(ERROR);
  }
 
  if ( (res = D_release(outfile, blocknum + ftpar->nblocks)) )
  {
     D_error(res);
     return(ERROR);
  }
 
  return(COMPLETE);
}