예제 #1
0
int FrameBufferRawPixel(struct FrameBuffer *ptr,int x,int y,int sze,
                        unsigned char r,unsigned char g,unsigned char b,
                        unsigned char a,unsigned char m,
                        struct FrameBufferClip *clip) {

  /* lowest of the low - renders a pixel */

  int off;
  if (ptr==NULL) return -1;
  if (ptr->wdt==0) return -1;
  if (ptr->hgt==0) return -1;
  if (ptr->img==NULL) return -1;
  if (y<0) return 0;
  if (x<0) return 0;
  if (x>=ptr->wdt) return 0;
  if (y>=ptr->hgt) return 0;

  if (FrameBufferClip(clip,x,y)==0) return 0;

  sze=ptr->wdt*ptr->hgt;
  off=y*ptr->wdt+x;
  if (ptr->user.pixel !=NULL) 
    return (ptr->user.pixel) (ptr->wdt,ptr->hgt,ptr->img,ptr->msk,
                              x,y,ptr->depth,
                              off,sze,r,g,b,a,ptr->user.data);
  if (m & 0x04) ptr->img[off]=r;
  if (m & 0x08) ptr->msk[off]=a;
  if (ptr->depth !=8) { 
    if (m & 0x02) ptr->img[off+sze]=g;
    if (m & 0x01) ptr->img[off+2*sze]=b;
  }
  return 0;
} 
예제 #2
0
파일: line.c 프로젝트: Shirling-VT/VTRST3.5
int FrameBufferRawPixel(struct FrameBuffer *ptr,int x,int y,int sze,
                        unsigned char r,unsigned char g,unsigned char b,
                        unsigned char a,unsigned char m,
                        struct FrameBufferClip *clip) {

  /* lowest of the low - renders a pixel */

  int off;
  float c,ca,cb,t,ta,tb;

  if (ptr==NULL) return -1;
  if (ptr->wdt==0) return -1;
  if (ptr->hgt==0) return -1;
  if (ptr->img==NULL) return -1;
  if (y<0) return 0;
  if (x<0) return 0;
  if (x>=ptr->wdt) return 0;
  if (y>=ptr->hgt) return 0;

  if (FrameBufferClip(clip,x,y)==0) return 0;

  sze=ptr->wdt*ptr->hgt;
  off=y*ptr->wdt+x;
  if (ptr->user.pixel !=NULL) 
    return (ptr->user.pixel) (ptr->wdt,ptr->hgt,ptr->img,ptr->msk,
                              x,y,ptr->depth,
                              off,sze,r,g,b,a,ptr->user.data);


  /* direct over painting */


  if (m & 0x40) ptr->img[off]=r;
  if (m & 0x80) ptr->msk[off]=a;
  if (ptr->depth !=8) {
    if (m & 0x20) ptr->img[off+sze]=g;
    if (m & 0x10) ptr->img[off+2*sze]=b;
  }

  if ((m &0x0f)==0) return 0; /* nothing else to do */

  /* alpha channel to max, so simple replace */

  if (a==255) {
    if (m & 0x04) ptr->img[off]=r;
    if (m & 0x08) ptr->msk[off]=a;
    if (ptr->depth !=8) {
      if (m & 0x02) ptr->img[off+sze]=g;
      if (m & 0x01) ptr->img[off+2*sze]=b;
    }
    return 0;
  }
    
  /* simple porter-duff over compositing */

  tb=ptr->msk[off]/255.0;
  ta=a/255.0;

  t=ta+(tb-ta)*tb;

  if (m & 0x08) ptr->msk[off]=(unsigned char) (255.0*t);

   if (m & 0x04) {
    cb=ptr->img[off]/255.0;
    ca=r/255.0;
    c=ca*ta+cb*tb*(1-ta);
    ptr->img[off]= (unsigned char) (255.0*c);
  }

  if (ptr->depth==8) return 0;

  if (m & 0x02) {
    cb=ptr->img[off+sze]/255.0;
    ca=g/255.0;
    c=ca*ta+cb*tb*(1-ta);
    ptr->img[off+sze]= (unsigned char) (255.0*c);
  }

  if (m & 0x01) {
    cb=ptr->img[off+2*sze]/255.0;
    ca=b/255.0;
    c=ca*ta+cb*tb*(1-ta);
    ptr->img[off+2*sze]=(unsigned char) (255.0*c);
  }

  return 0;
}