⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 c_test_zt.c

📁 adi blackfin 图象mpeg4 压缩解压缩
💻 C
字号:
/*******************************************************************************
Copyright(c) 2000 - 2002 Analog Devices. All Rights Reserved.
Developed by Joint Development Software Application Team, IPDC, Bangalore, India
for Blackfin DSPs  ( Micro Signal Architecture 1.0 specification).

By using this module you agree to the terms of the Analog Devices License
Agreement for DSP Software. 
********************************************************************************
File Name   :   c_test_zt.c

Description :   This function generates the expected output that is
                compared with the one generated by the asm. It is used
                to test the validity of the asm function output. The
                functions in this module are almost similar to the
                ones used in the open source MPEG4 VTC encoder C code.                  
*******************************************************************************/

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include "tztw_mpeg4.h"
//#include "zt_header.h"

static char *test_ztmap;
static int count;

int findchild(int x, int y, int xc[], int yc[]);
int mark_coeffs(int x, int y);
void codeBlocks(int y,int x, int n, char *bitstream);
void encode_pixel(int y, int x, char *bitstream);
void mark_ZTR_D(int y, int x);

    
int test_zero_tree_scan(char bitstream[])
{
    int i, j,k, stream_cnt,tw,sh,sw;
    int xc[3], yc[3], n, allzero;
    
    allzero=1;
    fprintf(stderr,"start of testfunc dc_height=%d dc_width=%d\n",dc_height,dc_width);
    
    for( i = 0 ; i < dc_height ; i++){ 
        for( j = 0 ; j < dc_width ; j++){
            
            findchild(i,j,yc,xc);
            
            allzero *= mark_coeffs(yc[0],xc[0]);
            allzero *= mark_coeffs(yc[1],xc[1]);
            allzero *= mark_coeffs(yc[2],xc[2]);
//            if(allzero==0)
  //              fprintf(stderr,"all children of (%d,%d) are zero\n",i,j);
        
        }
    }
   
   
/*    for( i = 0 ; i < height ; i++){ 
        for( j = 0 ; j < width ; j++){ 

            if((j!=0)&&(j%(width/2)==0)){
                fprintf(out_test_zt," | ");
            }
    
            fprintf(out_test_zt,"%2d ",test_ztmap[i*width+j]);
        }
    
        fprintf(out_test_zt,"\n");
    
        if((i!=0)&&((i+1)%(height/2)==0)){
            for(k=0;k<width;k++){
            fprintf(out_test_zt,"--");
            }
    
            fprintf(out_test_zt,"\n");

        }
    }*/
    
    count=0;
    
    for( i = 0 ; i < dc_height ; i++){ 
        for( j = 0 ; j < dc_width ; j++){
           
            // LH
            n = 0;
            for (tw=dc_width; tw < width; tw<<=1)
            {
                sh = i << n;
                sw = (j+dc_width) << n;
                codeBlocks(sh,sw,n,bitstream);
                n++;
            }
    
            // HL
            n = 0;
            for (tw=dc_width; tw < width; tw<<=1)
            {
                sh = (i+dc_height) << n;
                sw = j << n;
                codeBlocks(sh,sw,n,bitstream);
                n++;
            }
    
            // HH
            n = 0;
            for (tw=dc_width; tw < width; tw<<=1)
            {
                sh = (i+dc_height) << n;
                sw = (j+dc_width) << n;
                codeBlocks(sh,sw,n,bitstream);
                n++;
            }
        }
    }
   fprintf(stderr,"completed test func\n"); 
   return count; 

}
    
    
int findchild(int y, int x, int yc[], int xc[])
{
    
   int numChildren;

   if (x < dc_width && y < dc_height)
   {
     /*------------------- DC Band ---------------------*/ 
     numChildren = 3;

     xc[0] = x + dc_width;
     yc[0] = y;
     
     xc[1] = x;
     yc[1] = y + dc_height;
     
     xc[2] = x + dc_width;
     yc[2] = y + dc_height;
   }
   else if((x *= 2) < width && 
       (y *= 2) < height) 
   { 
     /*------------------- Non-Leaf AC Band ---------------------*/ 
     numChildren = 4;
     
     xc[0] = x;
     yc[0] = y;
     
     xc[1] = x+1;
     yc[1] = y  ;
     
     xc[2] = x  ;
     yc[2] = y+1;
     
     xc[3] = x+1;
     yc[3] = y+1;
   }
   else
     /*------------------- Leaf AC Band ---------------------*/ 
     numChildren = 0;
    
   return numChildren;
}

int mark_coeffs(int y, int x)
{
    int i, j, nc, isLeaf;
    int xc[4], yc[4]; /* coords of children */
    unsigned char valDes, valDesOneBranch;
    
    valDes = 0;
    
    if ((nc = findchild(y, x, yc, xc)) == 0)
      isLeaf = 1;
    
    else
    {
      isLeaf = 0;
      /* No - mark descendents in all branches */
      for (i = 0; i < nc; ++i)
      {
        valDesOneBranch = mark_coeffs(yc[i], xc[i]);
        valDes = valDes || valDesOneBranch;
      }
    }
      
    if(isLeaf==0){
        if (q_image[y*width + x])
            {
              if (valDes)
                test_ztmap[y*width + x] = VAL;
              else
                test_ztmap[y*width + x] = VZTR;
            }
        else
            {
              if (valDes)
                test_ztmap[y*width + x] = IZ;
              else
                 test_ztmap[y*width + x] = ZTR;
            }
    }
    else
    {
        if (q_image[y*width + x])
            test_ztmap[y*width + x] = VZTR;
        else
            test_ztmap[y*width + x] = ZTR;
    }
              
   
   return q_image[y*width + x]||valDes; 

}

void codeBlocks(int y,int x, int n, char *bitstream)
{
    int k;

    if (n == 0)
    {
        encode_pixel(y,x,bitstream);
    }
    else
    {

      --n;
      k = 1<<n;

      codeBlocks(y,x,n,bitstream);
      x += k;
      codeBlocks(y,x,n,bitstream);
      x -= k;
      y += k;
      codeBlocks(y,x,n,bitstream);
      x += k;
      codeBlocks(y,x,n,bitstream);
    }
}

void encode_pixel(int y, int x, char *bitstream)
{
    int zt_type;
    
    zt_type=test_ztmap[y*width + x];
    
    if(zt_type==ZTR_D)
        return;
    
    bitstream[count++] = zt_type;
    
    if((zt_type==ZTR)||(zt_type==VZTR))
        mark_ZTR_D(y,x);
}

void mark_ZTR_D(int y, int x)
{
    int i,j;
    
    i=y<<1; 
    j=x<<1;
  
    if(i<height && j<width){
      test_ztmap[i*width + j]     = ZTR_D;
      test_ztmap[(i+1)*width + j]   = ZTR_D; 
      test_ztmap[i*width + j+1]   = ZTR_D; 
      test_ztmap[(i+1)*width + j+1] = ZTR_D; 
      mark_ZTR_D(i,j);
      mark_ZTR_D(i+1,j);
      mark_ZTR_D(i,j+1);
      mark_ZTR_D(i+1,j+1);
    }
}


    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -