static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){ int cw= mpi->w >> mpi->chroma_x_shift; int ch= mpi->h >> mpi->chroma_y_shift; int W = mpi->w, H = mpi->h; mp_image_t *dmpi=ff_vf_get_image(vf->next,mpi->imgfmt, MP_IMGTYPE_IP, MP_IMGFLAG_ACCEPT_STRIDE | MP_IMGFLAG_PRESERVE | MP_IMGFLAG_READABLE, mpi->w,mpi->h); if(!dmpi) return 0; if (!vf->priv->pmpi) vf->priv->pmpi=mpi; deNoise(mpi->planes[0], vf->priv->pmpi->planes[0], dmpi->planes[0], vf->priv->Line, W, H, mpi->stride[0], vf->priv->pmpi->stride[0], dmpi->stride[0], vf->priv->Coefs[0] + 256, vf->priv->Coefs[0] + 256, vf->priv->Coefs[1] + 256); deNoise(mpi->planes[1], vf->priv->pmpi->planes[1], dmpi->planes[1], vf->priv->Line, cw, ch, mpi->stride[1], vf->priv->pmpi->stride[1], dmpi->stride[1], vf->priv->Coefs[2] + 256, vf->priv->Coefs[2] + 256, vf->priv->Coefs[3] + 256); deNoise(mpi->planes[2], vf->priv->pmpi->planes[2], dmpi->planes[2], vf->priv->Line, cw, ch, mpi->stride[2], vf->priv->pmpi->stride[2], dmpi->stride[2], vf->priv->Coefs[2] + 256, vf->priv->Coefs[2] + 256, vf->priv->Coefs[3] + 256); vf->priv->pmpi=dmpi; // save reference image return ff_vf_next_put_image(vf,dmpi, pts); }
static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){ mp_image_t *dmpi; if(!(mpi->flags&MP_IMGFLAG_DIRECT)){ // no DR, so get a new image! hope we'll get DR buffer: dmpi=ff_vf_get_image(vf->next,mpi->imgfmt, MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_PREFER_ALIGNED_STRIDE, mpi->width,mpi->height); ff_vf_clone_mpi_attributes(dmpi, mpi); }else{ dmpi=vf->dmpi; } vf->priv->mpeg2= mpi->qscale_type; if(vf->priv->log2_count || !(mpi->flags&MP_IMGFLAG_DIRECT)){ if(mpi->qscale || vf->priv->qp){ filter(vf->priv, dmpi->planes, mpi->planes, dmpi->stride, mpi->stride, mpi->w, mpi->h, mpi->qscale, mpi->qstride); }else{ memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h, dmpi->stride[0], mpi->stride[0]); memcpy_pic(dmpi->planes[1], mpi->planes[1], mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, dmpi->stride[1], mpi->stride[1]); memcpy_pic(dmpi->planes[2], mpi->planes[2], mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, dmpi->stride[2], mpi->stride[2]); } } #if HAVE_MMX if(ff_gCpuCaps.hasMMX) __asm__ volatile ("emms\n\t"); #endif #if HAVE_MMX2 if(ff_gCpuCaps.hasMMX2) __asm__ volatile ("sfence\n\t"); #endif return ff_vf_next_put_image(vf,dmpi, pts); }
static void get_image(struct vf_instance *vf, mp_image_t *mpi){ if(mpi->flags&MP_IMGFLAG_PRESERVE) return; // don't change // ok, we can do pp in-place (or pp disabled): vf->dmpi=ff_vf_get_image(vf->next,mpi->imgfmt, mpi->type, mpi->flags | MP_IMGFLAG_READABLE, mpi->width, mpi->height); mpi->planes[0]=vf->dmpi->planes[0]; mpi->stride[0]=vf->dmpi->stride[0]; mpi->width=vf->dmpi->width; if(mpi->flags&MP_IMGFLAG_PLANAR){ mpi->planes[1]=vf->dmpi->planes[1]; mpi->planes[2]=vf->dmpi->planes[2]; mpi->stride[1]=vf->dmpi->stride[1]; mpi->stride[2]=vf->dmpi->stride[2]; } mpi->flags|=MP_IMGFLAG_DIRECT; }
static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){ int cw= mpi->w >> mpi->chroma_x_shift; int ch= mpi->h >> mpi->chroma_y_shift; mp_image_t *dmpi=ff_vf_get_image(vf->next,mpi->imgfmt, MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE, mpi->w,mpi->h); assert(mpi->flags&MP_IMGFLAG_PLANAR); blur(dmpi->planes[0], mpi->planes[0], mpi->w,mpi->h, dmpi->stride[0], mpi->stride[0], &vf->priv->luma); blur(dmpi->planes[1], mpi->planes[1], cw , ch , dmpi->stride[1], mpi->stride[1], &vf->priv->chroma); blur(dmpi->planes[2], mpi->planes[2], cw , ch , dmpi->stride[2], mpi->stride[2], &vf->priv->chroma); return ff_vf_next_put_image(vf,dmpi, pts); }
static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts) { int ret = 0; mp_image_t *dmpi; switch (vf->priv->mode) { case 0: dmpi = vf->priv->dmpi; if (dmpi == NULL) { dmpi = ff_vf_get_image(vf->next, mpi->imgfmt, MP_IMGTYPE_STATIC, MP_IMGFLAG_ACCEPT_STRIDE | MP_IMGFLAG_PRESERVE, mpi->width, mpi->height*2); vf->priv->dmpi = dmpi; memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h, dmpi->stride[0]*2, mpi->stride[0]); if (mpi->flags & MP_IMGFLAG_PLANAR) { memcpy_pic(dmpi->planes[1], mpi->planes[1], mpi->chroma_width, mpi->chroma_height, dmpi->stride[1]*2, mpi->stride[1]); memcpy_pic(dmpi->planes[2], mpi->planes[2], mpi->chroma_width, mpi->chroma_height, dmpi->stride[2]*2, mpi->stride[2]); } } else { vf->priv->dmpi = NULL; memcpy_pic(dmpi->planes[0]+dmpi->stride[0], mpi->planes[0], mpi->w, mpi->h, dmpi->stride[0]*2, mpi->stride[0]); if (mpi->flags & MP_IMGFLAG_PLANAR) { memcpy_pic(dmpi->planes[1]+dmpi->stride[1], mpi->planes[1], mpi->chroma_width, mpi->chroma_height, dmpi->stride[1]*2, mpi->stride[1]); memcpy_pic(dmpi->planes[2]+dmpi->stride[2], mpi->planes[2], mpi->chroma_width, mpi->chroma_height, dmpi->stride[2]*2, mpi->stride[2]); } ret = ff_vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE); } break; case 1: if (vf->priv->frame & 1) ret = ff_vf_next_put_image(vf, mpi, MP_NOPTS_VALUE); break; case 2: if ((vf->priv->frame & 1) == 0) ret = ff_vf_next_put_image(vf, mpi, MP_NOPTS_VALUE); break; case 3: dmpi = ff_vf_get_image(vf->next, mpi->imgfmt, MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE, mpi->width, mpi->height*2); /* fixme, just clear alternate lines */ ff_vf_mpi_clear(dmpi, 0, 0, dmpi->w, dmpi->h); if ((vf->priv->frame & 1) == 0) { memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h, dmpi->stride[0]*2, mpi->stride[0]); if (mpi->flags & MP_IMGFLAG_PLANAR) { memcpy_pic(dmpi->planes[1], mpi->planes[1], mpi->chroma_width, mpi->chroma_height, dmpi->stride[1]*2, mpi->stride[1]); memcpy_pic(dmpi->planes[2], mpi->planes[2], mpi->chroma_width, mpi->chroma_height, dmpi->stride[2]*2, mpi->stride[2]); } } else { memcpy_pic(dmpi->planes[0]+dmpi->stride[0], mpi->planes[0], mpi->w, mpi->h, dmpi->stride[0]*2, mpi->stride[0]); if (mpi->flags & MP_IMGFLAG_PLANAR) { memcpy_pic(dmpi->planes[1]+dmpi->stride[1], mpi->planes[1], mpi->chroma_width, mpi->chroma_height, dmpi->stride[1]*2, mpi->stride[1]); memcpy_pic(dmpi->planes[2]+dmpi->stride[2], mpi->planes[2], mpi->chroma_width, mpi->chroma_height, dmpi->stride[2]*2, mpi->stride[2]); } } ret = ff_vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE); break; case 4: // Interleave even lines (only) from Frame 'i' with odd // lines (only) from Frame 'i+1', halving the Frame // rate and preserving image height. dmpi = vf->priv->dmpi; // @@ Need help: Should I set dmpi->fields to indicate // that the (new) frame will be interlaced!? E.g. ... // dmpi->fields |= MP_IMGFIELD_INTERLACED; // dmpi->fields |= MP_IMGFIELD_TOP_FIRST; // etc. if (dmpi == NULL) { dmpi = ff_vf_get_image(vf->next, mpi->imgfmt, MP_IMGTYPE_STATIC, MP_IMGFLAG_ACCEPT_STRIDE | MP_IMGFLAG_PRESERVE, mpi->width, mpi->height); vf->priv->dmpi = dmpi; my_memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h/2, dmpi->stride[0]*2, mpi->stride[0]*2); if (mpi->flags & MP_IMGFLAG_PLANAR) { my_memcpy_pic(dmpi->planes[1], mpi->planes[1], mpi->chroma_width, mpi->chroma_height/2, dmpi->stride[1]*2, mpi->stride[1]*2); my_memcpy_pic(dmpi->planes[2], mpi->planes[2], mpi->chroma_width, mpi->chroma_height/2, dmpi->stride[2]*2, mpi->stride[2]*2); } } else { vf->priv->dmpi = NULL; my_memcpy_pic(dmpi->planes[0]+dmpi->stride[0], mpi->planes[0]+mpi->stride[0], mpi->w, mpi->h/2, dmpi->stride[0]*2, mpi->stride[0]*2); if (mpi->flags & MP_IMGFLAG_PLANAR) { my_memcpy_pic(dmpi->planes[1]+dmpi->stride[1], mpi->planes[1]+mpi->stride[1], mpi->chroma_width, mpi->chroma_height/2, dmpi->stride[1]*2, mpi->stride[1]*2); my_memcpy_pic(dmpi->planes[2]+dmpi->stride[2], mpi->planes[2]+mpi->stride[2], mpi->chroma_width, mpi->chroma_height/2, dmpi->stride[2]*2, mpi->stride[2]*2); } ret = ff_vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE); } break; } vf->priv->frame++; return ret; }
static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts) { struct pullup_context *c = vf->priv->ctx; struct pullup_buffer *b; struct pullup_frame *f; mp_image_t *dmpi; int ret; int p; int i; if (!vf->priv->init) init_pullup(vf, mpi); if (mpi->flags & MP_IMGFLAG_DIRECT) { b = mpi->priv; mpi->priv = 0; } else { b = ff_pullup_get_buffer(c, 2); if (!b) { ff_mp_msg(MSGT_VFILTER,MSGL_ERR,"Could not get buffer from pullup!\n"); f = ff_pullup_get_frame(c); ff_pullup_release_frame(f); return 0; } memcpy_pic(b->planes[0], mpi->planes[0], mpi->w, mpi->h, c->stride[0], mpi->stride[0]); if (mpi->flags & MP_IMGFLAG_PLANAR) { memcpy_pic(b->planes[1], mpi->planes[1], mpi->chroma_width, mpi->chroma_height, c->stride[1], mpi->stride[1]); memcpy_pic(b->planes[2], mpi->planes[2], mpi->chroma_width, mpi->chroma_height, c->stride[2], mpi->stride[2]); } } if (mpi->qscale) { fast_memcpy(b->planes[3], mpi->qscale, c->w[3]); fast_memcpy(b->planes[3]+c->w[3], mpi->qscale, c->w[3]); } p = mpi->fields & MP_IMGFIELD_TOP_FIRST ? 0 : (mpi->fields & MP_IMGFIELD_ORDERED ? 1 : 0); ff_pullup_submit_field(c, b, p); ff_pullup_submit_field(c, b, p^1); if (mpi->fields & MP_IMGFIELD_REPEAT_FIRST) ff_pullup_submit_field(c, b, p); ff_pullup_release_buffer(b, 2); f = ff_pullup_get_frame(c); /* Fake yes for first few frames (buffer depth) to keep from * breaking A/V sync with G1's bad architecture... */ if (!f) return vf->priv->fakecount ? (--vf->priv->fakecount,1) : 0; if (f->length < 2) { ff_pullup_release_frame(f); f = ff_pullup_get_frame(c); if (!f) return 0; if (f->length < 2) { ff_pullup_release_frame(f); if (!(mpi->fields & MP_IMGFIELD_REPEAT_FIRST)) return 0; f = ff_pullup_get_frame(c); if (!f) return 0; if (f->length < 2) { ff_pullup_release_frame(f); return 0; } } } #if 0 /* Average qscale tables from both frames. */ if (mpi->qscale) { for (i=0; i<c->w[3]; i++) { vf->priv->qbuf[i] = (f->ofields[0]->planes[3][i] + f->ofields[1]->planes[3][i+c->w[3]])>>1; } } #else /* Take worst of qscale tables from both frames. */ if (mpi->qscale) { for (i=0; i<c->w[3]; i++) { vf->priv->qbuf[i] = MAX(f->ofields[0]->planes[3][i], f->ofields[1]->planes[3][i+c->w[3]]); } } #endif /* If the frame isn't already exportable... */ while (!f->buffer) { dmpi = ff_vf_get_image(vf->next, mpi->imgfmt, MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE, mpi->width, mpi->height); /* FIXME: Is it ok to discard dmpi if it's not direct? */ if (!(dmpi->flags & MP_IMGFLAG_DIRECT)) { ff_pullup_pack_frame(c, f); break; } /* Direct render fields into output buffer */ my_memcpy_pic(dmpi->planes[0], f->ofields[0]->planes[0], mpi->w, mpi->h/2, dmpi->stride[0]*2, c->stride[0]*2); my_memcpy_pic(dmpi->planes[0] + dmpi->stride[0], f->ofields[1]->planes[0] + c->stride[0], mpi->w, mpi->h/2, dmpi->stride[0]*2, c->stride[0]*2); if (mpi->flags & MP_IMGFLAG_PLANAR) { my_memcpy_pic(dmpi->planes[1], f->ofields[0]->planes[1], mpi->chroma_width, mpi->chroma_height/2, dmpi->stride[1]*2, c->stride[1]*2); my_memcpy_pic(dmpi->planes[1] + dmpi->stride[1], f->ofields[1]->planes[1] + c->stride[1], mpi->chroma_width, mpi->chroma_height/2, dmpi->stride[1]*2, c->stride[1]*2); my_memcpy_pic(dmpi->planes[2], f->ofields[0]->planes[2], mpi->chroma_width, mpi->chroma_height/2, dmpi->stride[2]*2, c->stride[2]*2); my_memcpy_pic(dmpi->planes[2] + dmpi->stride[2], f->ofields[1]->planes[2] + c->stride[2], mpi->chroma_width, mpi->chroma_height/2, dmpi->stride[2]*2, c->stride[2]*2); } ff_pullup_release_frame(f); if (mpi->qscale) { dmpi->qscale = vf->priv->qbuf; dmpi->qstride = mpi->qstride; dmpi->qscale_type = mpi->qscale_type; } return ff_vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE); } dmpi = ff_vf_get_image(vf->next, mpi->imgfmt, MP_IMGTYPE_EXPORT, MP_IMGFLAG_ACCEPT_STRIDE, mpi->width, mpi->height); dmpi->planes[0] = f->buffer->planes[0]; dmpi->planes[1] = f->buffer->planes[1]; dmpi->planes[2] = f->buffer->planes[2]; dmpi->stride[0] = c->stride[0]; dmpi->stride[1] = c->stride[1]; dmpi->stride[2] = c->stride[2]; if (mpi->qscale) { dmpi->qscale = vf->priv->qbuf; dmpi->qstride = mpi->qstride; dmpi->qscale_type = mpi->qscale_type; } ret = ff_vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE); ff_pullup_release_frame(f); return ret; }
static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){ int cw= mpi->w >> mpi->chroma_x_shift; int ch= mpi->h >> mpi->chroma_y_shift; int W = mpi->w, H = mpi->h; const unsigned char *prvp, *prvpp, *prvpn, *prvpnn, *prvppp, *prvp4p, *prvp4n; const unsigned char *srcp_saved; const unsigned char *srcp, *srcpp, *srcpn, *srcpnn, *srcppp, *srcp3p, *srcp3n, *srcp4p, *srcp4n; unsigned char *dstp, *dstp_saved; int src_pitch; int psrc_pitch; int dst_pitch; int x, y, z; int n = vf->priv->frame++; int val, hi, lo, w, h; double valf; int plane; int threshold = vf->priv->thresh; int order = vf->priv->order; int map = vf->priv->map; int sharp = vf->priv->sharp; int twoway = vf->priv->twoway; mp_image_t *dmpi, *pmpi; if(!vf->priv->do_deinterlace) return ff_vf_next_put_image(vf, mpi, pts); dmpi=ff_vf_get_image(vf->next,mpi->imgfmt, MP_IMGTYPE_IP, MP_IMGFLAG_ACCEPT_STRIDE, mpi->w,mpi->h); pmpi=ff_vf_get_image(vf->next,mpi->imgfmt, MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE, mpi->w,mpi->h); if(!dmpi) return 0; for (z=0; z<mpi->num_planes; z++) { if (z == 0) plane = PLANAR_Y; else if (z == 1) plane = PLANAR_U; else plane = PLANAR_V; h = plane == PLANAR_Y ? H : ch; w = plane == PLANAR_Y ? W : cw; srcp = srcp_saved = mpi->planes[z]; src_pitch = mpi->stride[z]; psrc_pitch = pmpi->stride[z]; dstp = dstp_saved = dmpi->planes[z]; dst_pitch = dmpi->stride[z]; srcp = srcp_saved + (1-order) * src_pitch; dstp = dstp_saved + (1-order) * dst_pitch; for (y=0; y<h; y+=2) { fast_memcpy(dstp, srcp, w); srcp += 2*src_pitch; dstp += 2*dst_pitch; } // Copy through the lines that will be missed below. fast_memcpy(dstp_saved + order*dst_pitch, srcp_saved + (1-order)*src_pitch, w); fast_memcpy(dstp_saved + (2+order)*dst_pitch, srcp_saved + (3-order)*src_pitch, w); fast_memcpy(dstp_saved + (h-2+order)*dst_pitch, srcp_saved + (h-1-order)*src_pitch, w); fast_memcpy(dstp_saved + (h-4+order)*dst_pitch, srcp_saved + (h-3-order)*src_pitch, w); /* For the other field choose adaptively between using the previous field or the interpolant from the current field. */ prvp = pmpi->planes[z] + 5*psrc_pitch - (1-order)*psrc_pitch; prvpp = prvp - psrc_pitch; prvppp = prvp - 2*psrc_pitch; prvp4p = prvp - 4*psrc_pitch; prvpn = prvp + psrc_pitch; prvpnn = prvp + 2*psrc_pitch; prvp4n = prvp + 4*psrc_pitch; srcp = srcp_saved + 5*src_pitch - (1-order)*src_pitch; srcpp = srcp - src_pitch; srcppp = srcp - 2*src_pitch; srcp3p = srcp - 3*src_pitch; srcp4p = srcp - 4*src_pitch; srcpn = srcp + src_pitch; srcpnn = srcp + 2*src_pitch; srcp3n = srcp + 3*src_pitch; srcp4n = srcp + 4*src_pitch; dstp = dstp_saved + 5*dst_pitch - (1-order)*dst_pitch; for (y = 5 - (1-order); y <= h - 5 - (1-order); y+=2) { for (x = 0; x < w; x++) { if ((threshold == 0) || (n == 0) || (abs((int)prvp[x] - (int)srcp[x]) > threshold) || (abs((int)prvpp[x] - (int)srcpp[x]) > threshold) || (abs((int)prvpn[x] - (int)srcpn[x]) > threshold)) { if (map == 1) { int g = x & ~3; if (IsRGB(mpi) == 1) { dstp[g++] = 255; dstp[g++] = 255; dstp[g++] = 255; dstp[g] = 255; x = g; } else if (IsYUY2(mpi) == 1) { dstp[g++] = 235; dstp[g++] = 128; dstp[g++] = 235; dstp[g] = 128; x = g; } else { if (plane == PLANAR_Y) dstp[x] = 235; else dstp[x] = 128; } } else { if (IsRGB(mpi)) { hi = 255; lo = 0; } else if (IsYUY2(mpi)) { hi = (x & 1) ? 240 : 235; lo = 16; } else { hi = (plane == PLANAR_Y) ? 235 : 240; lo = 16; } if (sharp == 1) { if (twoway == 1) valf = + 0.526*((int)srcpp[x] + (int)srcpn[x]) + 0.170*((int)srcp[x] + (int)prvp[x]) - 0.116*((int)srcppp[x] + (int)srcpnn[x] + (int)prvppp[x] + (int)prvpnn[x]) - 0.026*((int)srcp3p[x] + (int)srcp3n[x]) + 0.031*((int)srcp4p[x] + (int)srcp4n[x] + (int)prvp4p[x] + (int)prvp4n[x]); else valf = + 0.526*((int)srcpp[x] + (int)srcpn[x]) + 0.170*((int)prvp[x]) - 0.116*((int)prvppp[x] + (int)prvpnn[x]) - 0.026*((int)srcp3p[x] + (int)srcp3n[x]) + 0.031*((int)prvp4p[x] + (int)prvp4p[x]); if (valf > hi) valf = hi; else if (valf < lo) valf = lo; dstp[x] = (int) valf; } else { if (twoway == 1) val = (8*((int)srcpp[x] + (int)srcpn[x]) + 2*((int)srcp[x] + (int)prvp[x]) - (int)(srcppp[x]) - (int)(srcpnn[x]) - (int)(prvppp[x]) - (int)(prvpnn[x])) >> 4; else val = (8*((int)srcpp[x] + (int)srcpn[x]) + 2*((int)prvp[x]) - (int)(prvppp[x]) - (int)(prvpnn[x])) >> 4; if (val > hi) val = hi; else if (val < lo) val = lo; dstp[x] = (int) val; } } } else { dstp[x] = srcp[x]; } } prvp += 2*psrc_pitch; prvpp += 2*psrc_pitch; prvppp += 2*psrc_pitch; prvpn += 2*psrc_pitch; prvpnn += 2*psrc_pitch; prvp4p += 2*psrc_pitch; prvp4n += 2*psrc_pitch; srcp += 2*src_pitch; srcpp += 2*src_pitch; srcppp += 2*src_pitch; srcp3p += 2*src_pitch; srcp4p += 2*src_pitch; srcpn += 2*src_pitch; srcpnn += 2*src_pitch; srcp3n += 2*src_pitch; srcp4n += 2*src_pitch; dstp += 2*dst_pitch; }