示例#1
0
int BlockRenderer::consume(const VideoFrame* vf)
{
	if (!samesize(vf))
		resize(vf->width_, vf->height_);
	YuvFrame* p = (YuvFrame*)vf;

	if (update_interval_ != 0) {
		if (need_update_ == 0)
			return (0);
		need_update_ = 0;
	}

#ifdef HAVE_SWSCALE
	render(vf->bp_, 0, 0, 0, 0);
	
	// put the image to display
	// in WindowRenderer::push
	push(NULL, 0, 0, 0, 0);
	sync();
#else
	
	
	/*
	 * check how many blocks we need to update.  If more than
	 * 12%, do a single image push call for them.  Otherwise,
	 * only push the ones that change.
	 */	
	u_int now = now_;
	const u_int8_t* ts = p->crvec_;
	u_int bcnt = 0;
	int w = width_ >> 3;
	int y;
	for (y = height_ >> 3; --y >= 0; ) {
		for (int x = 0; x < w; ++x)
示例#2
0
int VLOutboard::consume(const VideoFrame* vf)
{
	if (update_interval_ != 0) {
		if (need_update_ == 0)
			return (0);
		need_update_ = 0;
	}
	if (!samesize(vf))
		resize(vf->width_, vf->height_);
	VLInfoPtr vip;
	vip = vlGetNextFree(vl_, rb_, xfersize_);
	if (vip == 0) {
#ifdef notdef
		fprintf(stderr, "vl outboard render: no buffer!\n");
#endif
		return (0);
	}
	/* Get a pointer to where the data will go */
	u_char* bp = (u_char*)vlGetActiveRegion(vl_, rb_, vip);
	if (scale_)
		upscaleframe(bp, vf->bp_);
	else
		scaleframe(bp, vf->bp_);

	vlPutValid(vl_, rb_);

	return (0);
}
示例#3
0
/*XXX*/
int BvcEncoder::consume(const VideoFrame* vf)
{
	if (!samesize(vf))
		size(vf->width_, vf->height_);
	YuvFrame* p = (YuvFrame*)vf;
	tx_->flush();
	int layer = p->layer_;

	u_char* frm = (u_char*)p->bp_;
	const u_char* chm = frm + framesize_;
	blkno_ = -1;
	pktbuf* pb = getpkt(p->ts_, layer);
	const u_int8_t* crv = p->crvec_;
	memset(&b, 0, sizeof(b));

#ifdef SBC_STAT
	if (f[0] == 0) {
		f[0] = fopen("sbc0", "w");
		f[1] = fopen("sbc1", "w");
		f[2] = fopen("sbc2", "w");
		f[3] = fopen("sbc3", "w");
	}
#endif
	int cc = 0;
	int blkw = width_ >> 4;
	int blkh = height_ >> 4;
	int blkno = 0;
	for (int y = 0; y < blkh; ++y) {
		for (int x = 0; x < blkw; ++blkno, frm += 16, chm += 8,
		     ++x, ++crv) {
			int s = crv[0];
			if ((s & CR_SEND) == 0)
				continue;

#define MAXMBSIZE (16*16+2*8*8+4)
			if (bs_ + MAXMBSIZE >= es_) {
				cc += flush(pb, 0);
				pb = getpkt(p->ts_, layer);
			}

			int dblk = blkno - blkno_;
			blkno_ = blkno;
			if (dblk <= 0)
				abort();

			if (dblk == 1) {
				PUT_BITS(1, 1, nbb_, bb_, bs_);
b.mba += 1;
			} else if (dblk <= 17) {
				PUT_BITS(0x10 | (dblk - 2), 6, nbb_, bb_, bs_);
b.mba += 6;
			} else {
				PUT_BITS(dblk, 13, nbb_, bb_, bs_);
b.mba += 13;
			}
			/*
			 * Deal with boundaries of image.  This is
			 * simply ugly, but it's the price we have
			 * to pay for using a four tap filter stage.
			 * For the 1-3-3-1 filter set, we use symmetric
			 * extension at both analysis and synthesis
			 * to give perfect reconstruction.
			 * If we're at the top of the image, we simply
			 * copy the top row up (since the grabber's
			 * reserve one line of extra space).  Otherwise,
			 * we save pixels, do the symmetrization,
			 * encode the block, then restore the pixels.
			 */
			u_char ysave[16];
			u_char xsave[16];
			if (y == 0)
				memcpy(frm - width_, frm, 16);
			else if (y == blkh - 1) {
				u_char* p = frm + (width_ << 4);
				memcpy(ysave, p, 16);
				memcpy(p, p - width_, 16);
			}
			if (x == 0) {
				u_char* s = xsave;
				u_char* p = frm;
				for (int k = 0; k < 16; ++k) {
					*s++ = p[-1];
					p[-1] = p[0];
					p += width_;
				}
			} else if (x == blkw - 1) {
				u_char* s = xsave;
				u_char* p = frm + 16;
				for (int k = 0; k < 16; ++k) {
					*s++ = p[0];
					p[0] = p[-1];
					p += width_;
				}
			}
			encode_block(frm);
			encode_color(chm);
			encode_color(chm + (framesize_ >> 2));
			/*
			 * Now restore the pixels.  We don't bother
			 * with the "y = 0" case because the affected
			 * memory will not be used.
			 */
			if (y == blkh - 1) {
				u_char* p = frm + (width_ << 4);
				memcpy(p, ysave, 16);
			}
			if (x == 0) {
				u_char* s = xsave;
				u_char* p = frm;
				for (int k = 0; k < 16; ++k) {
					p[-1] = *s++;
					p += width_;
				}
			} else if (x == blkw - 1) {
				u_char* s = xsave;
				u_char* p = frm + 16;
				for (int k = 0; k < 16; ++k) {
					p[0] = *s++;
					p += width_;
				}
			}
		}
		frm += 15 * width_;
		chm += 7 * (width_ >> 1);
	}
#ifdef notdef
	double t = b.dc + b.mba;
	for (int i = 0; i < 4; ++i)
		t += b.zt[i] + b.sbc[i] + b.sbz[i];
	printf("dc\t%.3f\n", b.dc / t);
	printf("mba\t%.3f\n", b.mba / t);
	for (i = 0; i < 4; ++i) {
		printf("sbc%d\t%.3f (%.3f)\n", i, (b.sbc[i] + b.sbz[i]) / t,
		       b.sbz[i] / double(b.sbc[i] + b.sbz[i]));
		printf("zt%d\t%.3f\n", i, b.zt[i] / t);
	}
#endif
	cc += flush(pb, 1);
	return (cc);
}
示例#4
0
void FnirtFileWriter::common_field_construction(const string&            fname,
                                                const volume<float>&     ref,
                                                const volume<float>&     fieldx,
                                                const volume<float>&     fieldy,
                                                const volume<float>&     fieldz, 
                                                const Matrix&            aff)
{
  volume4D<float>   fields(ref.xsize(),ref.ysize(),ref.zsize(),3);
  fields.copyproperties(ref); 

  Matrix M;
  bool   add_affine = false;
  if (add_affine = ((aff-IdentityMatrix(4)).MaximumAbsoluteValue() > 1e-6)) { // Add affine part to fields
    M = (aff.i() - IdentityMatrix(4))*ref.sampling_mat();
  }

  if (samesize(ref,fieldx,true)) { // If ref is same size as the original field
    fields[0] = fieldx; fields[1] = fieldy; fields[2] = fieldz;
    fields.copyproperties(ref);    // Put qform/sform and stuff back.
    if (add_affine) {
      ColumnVector xv(4), xo(4);
      int zs = ref.zsize(), ys = ref.ysize(), xs = ref.xsize();
      xv(4) = 1.0;
      for (int z=0; z<zs; z++) {
        xv(3) = double(z);
        for (int y=0; y<ys; y++) {
          xv(2) = double(y);
          for (int x=0; x<xs; x++) {
            xv(1) = double(x);
            xo = M*xv;
            fields(x,y,z,0) += xo(1);
            fields(x,y,z,1) += xo(2);
            fields(x,y,z,2) += xo(3);
	  }
        }
      }
    } 
  }
  else {
    fieldx.setextrapolationmethod(extraslice);
    fieldy.setextrapolationmethod(extraslice);
    fieldz.setextrapolationmethod(extraslice);
    Matrix R2F = fieldx.sampling_mat().i() * ref.sampling_mat();
    ColumnVector xv(4), xo(4), xr(4);
    int zs = ref.zsize(), ys = ref.ysize(), xs = ref.xsize();
    xv(4) = 1.0;
    for (int z=0; z<zs; z++) {
      xv(3) = double(z);
      for (int y=0; y<ys; y++) {
        xv(2) = double(y);
        for (int x=0; x<xs; x++) {
          xv(1) = double(x);
          xr = R2F*xv;
          fields(x,y,z,0) = fieldx.interpolate(xr(1),xr(2),xr(3));
          fields(x,y,z,1) = fieldy.interpolate(xr(1),xr(2),xr(3));
          fields(x,y,z,2) = fieldz.interpolate(xr(1),xr(2),xr(3));
          if (add_affine) {
            xo = M*xv;
            fields(x,y,z,0) += xo(1);
            fields(x,y,z,1) += xo(2);
            fields(x,y,z,2) += xo(3);
	  }
        }
      }
    }
  }

  fields.set_intent(FSL_FNIRT_DISPLACEMENT_FIELD,fields.intent_param(0),fields.intent_param(1),fields.intent_param(2));
  fields.setDisplayMaximum(0.0);
  fields.setDisplayMinimum(0.0);

  // Save resulting field
  save_volume4D(fields,fname);
}