static void vp8_files_block(intra_stats_ctx *_ctx,const unsigned char *_data, int _stride,int _bi,int _bj,int _mode,const unsigned char *_pred){ int j; int i; unsigned char res[B_SZ*B_SZ]; image_draw_block(&_ctx->files_vp8.raw,B_SZ*_bi,B_SZ*_bj,_data,_stride); od_rgba16_image_draw_point(&_ctx->files_vp8.map,_bi,_bj,COLORS[_mode]); image_draw_block(&_ctx->files_vp8.pred,B_SZ*_bi,B_SZ*_bj,_pred,B_SZ); for(j=0;j<B_SZ;j++){ for(i=0;i<B_SZ;i++){ res[j*B_SZ+i]=OD_CLAMP255(_data[_stride*j+i]-_pred[B_SZ*j+i]+128); } } image_draw_block(&_ctx->files_vp8.res,B_SZ*_bi,B_SZ*_bj,res,B_SZ); }
static void rgb_to_ycbcr(img_plane _ycbcr[3],png_bytep *_png){ kiss99_ctx kiss; unsigned char *ydata; unsigned char *cbdata; unsigned char *crdata; int ystride; int cbstride; int crstride; int hstep; int vstep; int w; int h; int i; int j; w=_ycbcr[0].width; h=_ycbcr[0].height; ystride=_ycbcr[0].stride; ydata=_ycbcr[0].data; cbstride=_ycbcr[1].stride; cbdata=_ycbcr[1].data; crstride=_ycbcr[2].stride; crdata=_ycbcr[2].data; hstep=pixel_format&1; vstep=pixel_format&2; kiss99_srand(&kiss,NULL,0); for(j=0;j<h;j+=2){ for(i=0;i<w;i+=2){ int32_t yd[4]; int32_t cbd[4]; int32_t crd[4]; int32_t r0; int32_t g0; int32_t b0; int32_t r1; int32_t g1; int32_t b1; int32_t r2; int32_t g2; int32_t b2; int32_t r3; int32_t g3; int32_t b3; int64_t rsum; int64_t gsum; int64_t bsum; int k; int cb; int cr; /*This often generates more dither values than we use, but keeps them in sync for the luma plane across the different pixel formats.*/ for(k=0;k<4;k++){ /*The size of the dither here is chosen to be the largest divisor of all the corresponding coefficients in the transform that still fits in 31 bits.*/ if (dither) { yd[k]=triangle_rand(&kiss,1223320000); cbd[k]=triangle_rand(&kiss,1479548743); crd[k]=triangle_rand(&kiss,1255654969); } else { yd[k] = 0; cbd[k] = 0; crd[k] = 0; } } get_dithered_pixel(&r0,&g0,&b0,_png[j]+6*i,yd[0],cbd[0],crd[0]); if(i+1<w){ get_dithered_pixel(&r1,&g1,&b1,_png[j]+6*(i+1), yd[1],cbd[hstep],crd[hstep]); } else{ r1=r0; g1=g0; b1=b0; } if(j+1<h){ get_dithered_pixel(&r2,&g2,&b2,_png[j+1]+6*i, yd[2],cbd[vstep],crd[vstep]); if(i+1<w){ get_dithered_pixel(&r3,&g3,&b3,_png[j+1]+6*(i+1), yd[3],cbd[vstep+hstep],crd[vstep+hstep]); } else{ r3=r2; g3=g2; b3=b2; } } else{ r2=r0; g2=g0; b2=b0; r3=r1; g3=g1; b3=b1; } if(pixel_format==PIXEL_FMT_420){ rsum=r0+r1+r2+r3; gsum=g0+g1+g2+g3; bsum=b0+b1+b2+b3; cb=OD_CLAMP255( OD_DIV_ROUND(-29764*rsum-100128*gsum+129892*bsum,304016865)+128); cr=OD_CLAMP255( OD_DIV_ROUND(110236*rsum-100128*gsum-10108*bsum,258011295)+128); cbdata[(j>>1)*cbstride+(i>>1)]=(unsigned char)cb; crdata[(j>>1)*crstride+(i>>1)]=(unsigned char)cr; ydata[j*ystride+i]=calc_y(r0,g0,b0,cb,cr); if(i+1<w)ydata[j*ystride+i+1]=calc_y(r1,g1,b1,cb,cr); if(j+1<h){ ydata[(j+1)*ystride+i]=calc_y(r2,g2,b2,cb,cr); if(i+1<w)ydata[(j+1)*ystride+i+1]=calc_y(r3,g3,b3,cb,cr); } } else if(pixel_format==PIXEL_FMT_422){ rsum=r0+r1; gsum=g0+g1; bsum=b0+b1; cb=OD_CLAMP255( OD_DIV_ROUND(-59528*rsum-200256*gsum+259784*bsum,304016865)+128); cr=OD_CLAMP255( OD_DIV_ROUND(220472*rsum-200256*gsum-20216*bsum,258011295)+128); cbdata[j*cbstride+(i>>1)]=(unsigned char)cb; crdata[j*crstride+(i>>1)]=(unsigned char)cr; ydata[j*ystride+i]=calc_y(r0,g0,b0,cb,cr); if(i+1<w)ydata[j*ystride+i+1]=calc_y(r1,g1,b1,cb,cr); if(j+1<h){ rsum=r2+r3; gsum=g2+g3; bsum=b2+b3; cb=OD_CLAMP255( OD_DIV_ROUND(-59528*rsum-200256*gsum+259784*bsum,304016865)+128); cr=OD_CLAMP255( OD_DIV_ROUND(220472*rsum-200256*gsum-20216*bsum,258011295)+128); cbdata[(j+1)*cbstride+(i>>1)]=(unsigned char)cb; crdata[(j+1)*crstride+(i>>1)]=(unsigned char)cr; ydata[(j+1)*ystride+i]=calc_y(r2,g2,b2,cb,cr); if(i+1<w)ydata[(j+1)*ystride+i+1]=calc_y(r3,g3,b3,cb,cr); }
void vp8_intra_predict(unsigned char *_dst,int _dst_stride, const unsigned char *_src,int _src_stride,int _mode){ const unsigned char *above; unsigned char *left; unsigned char p[4*B_SZ]; int x; int y; above=_src-_src_stride; p[2*B_SZ-1]=*(above-1); left=p+2*B_SZ; for(y=0;y<B_SZ;y++)left[y]=*(_src+_src_stride*y-1); switch(_mode){ case OD_INTRA_DC:{ int dc; dc=0; for(x=0;x<B_SZ;x++)dc+=above[x]; for(y=0;y<B_SZ;y++)dc+=left[y]; dc=dc+B_SZ>>B_SZ_LOG+1; for(y=0;y<B_SZ;y++){ for(x=0;x<B_SZ;x++){ *(_dst+y*_dst_stride+x)=(unsigned char)dc; } } }break; case OD_INTRA_TM:{ for(y=0;y<B_SZ;y++){ for(x=0;x<B_SZ;x++){ *(_dst+y*_dst_stride+x)=OD_CLAMP255(above[x]+left[y]-*(above-1)); } } }break; case OD_INTRA_HU:{ for(y=B_SZ;y<B_SZ+(B_SZ>>1)+1;y++)left[y]=left[B_SZ-1]; for(y=0;y<B_SZ;y++){ for(x=0;x<(B_SZ>>1);x++){ *(_dst+y*_dst_stride+2*x)= (unsigned char)(left[y+x]+left[y+x+1]+1>>1); *(_dst+y*_dst_stride+2*x+1)= (unsigned char)(left[y+x]+2*left[y+x+1]+left[x+y+2]+2>>2); } } }break; case OD_INTRA_HE:{ unsigned char q[B_SZ]; p[2*B_SZ-1]=*(above-1); left[B_SZ]=left[B_SZ-1]; for(y=0;y<B_SZ;y++){ q[y]=(unsigned char)(p[2*B_SZ+y-1]+2*p[2*B_SZ+y]+p[2*B_SZ+y+1]+2>>2); } for(y=0;y<B_SZ;y++)for(x=0;x<B_SZ;x++)*(_dst+y*_dst_stride+x)=q[y]; }break; case OD_INTRA_HD:{ for(x=0;x<B_SZ;x++)p[2*B_SZ-x-1]=*(above+x-1); for(y=0;y<B_SZ;y++){ for(x=0;x<(B_SZ>>1);x++){ if(y<x){ *(_dst+y*_dst_stride+2*x)=(unsigned char)( p[2*B_SZ+y-2*x+1]+2*p[2*B_SZ+y-2*x]+p[2*B_SZ+y-2*x-1]+2>>2); *(_dst+y*_dst_stride+2*x+1)=(unsigned char)( p[2*B_SZ+y-2*x]+2*p[2*B_SZ+y-2*x-1]+p[2*B_SZ+y-2*x-2]+2>>2); } else{ *(_dst+y*_dst_stride+2*x)= (unsigned char)(p[2*B_SZ+y-x-1]+p[2*B_SZ+y-x]+1>>1); *(_dst+y*_dst_stride+2*x+1)=(unsigned char)( p[2*B_SZ+y-x]+2*p[2*B_SZ+y-x-1]+p[2*B_SZ+y-x-2]+2>>2); } } } }break;