[Prev][Next][Index][Thread]

This is fun!




Made some changes to Scott's qcam.c, and I believe Scott will have a lot 
of fun with people sending him patches to do various things.

PGM files don't have to be greyscaled to 255 levels, so that cuts out a 
lot of multiplication...  just output 15 or 63 for greyscale levels.

Secondly... I cloned qc_writepgm() and made a qc_writepgm_p5, the 
RAWBITS format of PGM.  xv seems to like the files so I'll post the 
function here.  If anything, the disk space used by PGM files is cut by 
quite a bit.

Heat of the hack... I feel good.  This is so much fun.  Makes the camera 
useful again.

void qc_writepgm_p5(FILE *f,unsigned char *scan,int x, int y, int bpp)
{
  int i;
  unsigned n,a,b,c,d;
  unsigned char xchar;

  fprintf(f,"P5\n");
  fprintf(f,"%d %d\n",x,y);

  if (bpp == 4)
    {
      fprintf(f,"15\n");
    }
  else
    {
      fprintf(f,"63\n");
    }

  if(bpp==4) {
    for(i=0;i<y*x/2;i++) {
      n=scan[i];
      a=(n>>4)&0xf;
      b=n&0xf;
      xchar = 16-a-1;
      fwrite(&xchar, 1, 1, f);
      xchar = 16-b-1;
      fwrite(&xchar, 1, 1, f);
    }
  } else {
    for(i=0;i<y*x*3/4;i+=3) {
      a=scan[i]>>2;;
      b=(scan[i]&3)<<4|(scan[i+1]>>4);
      c=(scan[i+1]&0xf)<<2|(scan[i+2]>>6);
      d=(scan[i+2]&0x3f);
      xchar = 64-a-1;
      fwrite(&xchar, 1, 1, f);
      xchar = 64-b-1;
      fwrite(&xchar, 1, 1, f);
      xchar = 64-c-1;
      fwrite(&xchar, 1, 1, f);
      xchar = 64-d-1;
      fwrite(&xchar, 1, 1, f);
    }
  }
}

--
Simon Janes
NCM



Follow-Ups: