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

📄 scale_2d_yc_doub_buf.c

📁 基于DM642平台的视频缩小放大功能 程序源代码
💻 C
📖 第 1 页 / 共 2 页
字号:

  buf_cb3 = (short *) &gp_store[store_index];
  store_index += 2*sizeof(short)*((out_c_width & ~7) + 16);
        
  /* final color buffer */
  /* this is a double buffer holding a total of 4 lines of color data */
  buf_rgb = &gp_store[store_index];


/* ========================= main scaling loop =========================== */
  /* initialise initial filter count scaled by filt length */

  y_filt_state[0] = c_filt_state[0] = l_hh*n_hh;
  y_filt_state[1] = c_filt_state[1] = 0;
  y_filt_state[2] = c_filt_state[2] = 0;
  y_filt_state[3] = c_filt_state[3] = 0;
  y_filt_state[4] = c_filt_state[4] = 0;
  y_filt_state[5] = c_filt_state[5] = 0;

  for (i=0; i < divider; i++)
  {
   total_out_y_width += out_y_width;
   if (i == divider - 1)
   {
     out_y_width += main_out_y_width - total_out_y_width;
     out_y_width &= ~3;
     out_c_width = out_y_width >> color_shift;
   }
   vpatchy = vpatch;
   vpatchc = vpatch;
   y_rd_index = c_rd_index = 0;
   y_rb_read_line = c_rb_read_line = 0;
   display_lines = 0;
   display_pixels = 0;
   hylines = hclines = 0;
   y_rb_write_line = c_rb_write_line = 0;
   first = 1;

   y_filter_no = c_filter_no = 0;
   y_scaled = c_scaled = 0;

   in_y_offset += y_filt_state[2];
   in_y_offset_1 += y_filt_state[3];

   in_c_offset += c_filt_state[2];
   in_c_offset_1 += c_filt_state[3];

   in_y_buf_size = ((in_y_width & ~15) + 48);  /* 7, 32 */
   in_c_buf_size = ((in_c_width & ~15) + 48);  /* 7, 32 */
 //  in_y_buf_size = (in_y_width+16) & ~15;  /* 7, 32 */
 //  in_c_buf_size = (in_c_width+16) & ~15;  /* 7, 32 */
 
  
  /* 1st dma transfer to get the ball rolling */
   ping_in_y = 1; pong_in_y = 0;
   ping_in_c = 1; pong_in_c = 0;

   in_id_y = DAT_copy(&image_y[(in_y_offset & ~7) + (y_rd_index & ~7)],
                 &buf_y0[pong_in_y * in_y_buf_size],
                 (unsigned short) in_y_buf_size);   

   in_id_cr = DAT_copy(&image_cr[(in_c_offset & ~7) + (c_rd_index & ~7)],
                 &buf_cr0[pong_in_c * in_c_buf_size],
                 (unsigned short) in_c_buf_size);   

   in_id_cb = DAT_copy(&image_cb[(in_c_offset & ~7) + (c_rd_index & ~7)],
                 &buf_cb0[pong_in_c * in_c_buf_size],
                 (unsigned short) in_c_buf_size);   

   ping_out = 0;
   pong_out = 0;
   write_buf = 0;
   

   while(display_lines < window_height)
   {
     if (display_lines >= (window_height - 6)) break; //JS
     
     if (hylines < l_hv)
     {  
        /* wait on previous transfer */
        DAT_wait(in_id_y);
        /* transfer data for next line */
        in_id_y = DAT_copy(&image_y[(in_y_offset & ~7) + 
                                    ((y_rd_index + y_width) & ~7)],
                           &buf_y0[ping_in_y * in_y_buf_size],
                           (unsigned short) in_y_buf_size);   

        pix_expand_asm(in_y_buf_size,
                      &buf_y0[pong_in_y * in_y_buf_size],
                      buf_y1);

        hpatch[0] = 2*(in_y_offset & 7) + 2*(y_rd_index & 7);
        hpatch[1] = 2*(in_y_offset_1 & 7) + 2*(y_rd_index & 7);
               
        scale_horz_asm(buf_y1,
                      in_y_width, 
                      &rot_buf_y2[((out_y_width & ~7)+8)*y_rb_write_line],
                      out_y_width,
                      hh,
                      l_hh,
                      n_hh,
                      hpatch, y_filt_state);
        
        pong_in_y ^= 1; ping_in_y ^= 1;
        y_rd_index += y_width;
        hylines += 1;
        y_rb_write_line += 1;
        if (y_rb_write_line == l_hv) y_rb_write_line = 0;
     }  
     
     if (hclines < l_hv)
     {
        DAT_wait(in_id_cr);
        in_id_cr = DAT_copy(&image_cr[(in_c_offset & ~7) +
                                      ((c_rd_index + c_width) & ~7)],
                            &buf_cr0[ping_in_c*in_c_buf_size],
                            (unsigned short) in_c_buf_size);   
        
        DAT_wait(in_id_cb);
        in_id_cb = DAT_copy(&image_cb[(in_c_offset & ~7) +
                                      ((c_rd_index + c_width) & ~7)],
                            &buf_cb0[ping_in_c*in_c_buf_size],
                            (unsigned short) in_c_buf_size);
        
        pix_expand_asm(in_c_buf_size,
                      &buf_cr0[pong_in_c * in_c_buf_size],
                      buf_cr1);
        pix_expand_asm(in_c_buf_size,
                      &buf_cb0[pong_in_c * in_c_buf_size],
                      buf_cb1);
        
        hpatch[0] = 2*(c_rd_index & 7) + 2*(in_c_offset & 7);      
        hpatch[1] = 2*(c_rd_index & 7) + 2*(in_c_offset_1 & 7);      
        
        scale_horz_asm(buf_cr1,
                       in_c_width, 
                       &rot_buf_cr2[((out_c_width & ~7)+8)*c_rb_write_line],
                       out_c_width,
                       hh,
                       l_hh,
                       n_hh,
                       hpatch, c_filt_state);
                        
        scale_horz_asm(buf_cb1,
                       in_c_width, 
                       &rot_buf_cb2[((out_c_width & ~7)+8)*c_rb_write_line],
                       out_c_width,
                       hh,
                       l_hh,
                       n_hh,
                       hpatch, c_filt_state);
                          
        pong_in_c ^= 1; ping_in_c ^= 1;
        hclines += 1;
        c_rd_index += c_width;

        c_rb_write_line += 1;
        if (c_rb_write_line == l_hv) c_rb_write_line = 0;
     }
     

     if (hylines >= l_hv) /* enough lines for vertical y filtering? */
     {
    	scale_vert_asm(rot_buf_y2,
                      &buf_y3[y_scaled*((out_y_width & ~7)+8)],
                      (out_y_width & ~7)+8,
                      &hv[y_filter_no*l_hv],
                      t_filt,
                      l_hv,
                      y_rb_read_line);

        y_scaled += 1;
        y_rb_read_line += ((int) (vpatchy[0]));
        y_rb_read_line = y_rb_read_line % l_hv;
        hylines -= ((int) (vpatchy[0]));

        vpatchy++;
        y_filter_no++;
        if (y_filter_no == n_hv) vpatchy = vpatch;
        if (y_filter_no == n_hv) y_filter_no = 0;
     }

     /* enough lines for vertical chroma filtering? */
     if (hclines >= l_hv && c_scaled < max_clines)  
     {
    	scale_vert_asm(rot_buf_cb2,
                      &buf_cb3[c_scaled*((out_c_width & ~7)+8)],
                      (out_c_width & ~7) + 8,
                      &hv[c_filter_no*l_hv],
                      t_filt,
                      l_hv,
                      c_rb_read_line);

    	scale_vert_asm(rot_buf_cr2,
                      &buf_cr3[c_scaled*((out_c_width & ~7)+8)],
                      (out_c_width & ~7) + 8,
                      &hv[c_filter_no*l_hv],
                      t_filt,
                      l_hv,
                      c_rb_read_line);
        c_scaled += 1;

        c_rb_read_line += ((int) (vpatchc[0]));
        c_rb_read_line = c_rb_read_line % l_hv;
        hclines -= ((int) (vpatchc[0]));

	    vpatchc++;
        c_filter_no++;
        if (c_filter_no >= n_hv) vpatchc = vpatch;
        if (c_filter_no >= n_hv) c_filter_no = 0;
     }

   /* color conversion can only occur when hylines >= l_hv and
      hcrlines >= l_hv but depending on the format c*lines should be reused */

     if (format != f4_2_0 && y_scaled == 2 && c_scaled == 2)
     {  
        ycbcr422pl16_to_rgb565_asm(cmatrix,
                &buf_y3[0],
                &buf_cr3[0],
                &buf_cb3[0],
                (unsigned short *) &buf_rgb[2*ping_out*color*out_y_width],
                out_y_width); /* in L2 */
        ycbcr422pl16_to_rgb565_asm(cmatrix,
                &buf_y3 [(out_y_width & ~7) + 8],
                &buf_cr3[(out_c_width & ~7) + 8],
                &buf_cb3[(out_c_width & ~7) + 8],
                (unsigned short *) &buf_rgb[(1+2*ping_out)*color*out_y_width],
                out_y_width); /*<-in L2 */
         ping_out ^= 1;
     }
     /* this is done to fix the anomally of red being 
        swapped for blue chrom - the api say ycbcr, I say it
        is ycrcb as is the convention */
        
     if (format == f4_2_0 && y_scaled == 2 && c_scaled == 1)
     { 
        ycbcr422pl16_to_rgb565_asm(cmatrix,
                &buf_y3[0],
                &buf_cr3[0], &buf_cb3[0],
                (unsigned short *) &buf_rgb[2*ping_out*color*out_y_width],
                out_y_width); /* in L2 */
        ycbcr422pl16_to_rgb565_asm(cmatrix,
                &buf_y3 [(out_y_width & ~7) + 8],
                &buf_cr3[0], &buf_cb3[0],
                (unsigned short *) &buf_rgb[(1 + 2*ping_out)*color*out_y_width],
                out_y_width); /*<-in L2 */

        ping_out ^= 1;
     }

     /* this doesn't need to be double buffered as it writes out */
     /* so it has no dependency as in the input buffer case */
     /* while only a 1/2 fram is being computed at once the
        output lines are wrtten into every other line so
        it increments 2lines for each 1 */

     /* first time around we do not want this to occur but everything else
        is ok to keep updateing, only the DAT_copy needs delaying */

     if (write_buf)
     {
        if (!first) DAT_wait(out_id0);   
        out_id0 = DAT_copy(&buf_rgb[2*pong_out*color*out_y_width],
                           &image_rgb[out_color_offset+display_pixels*color],
                           color*out_y_width);
        display_pixels += display_width;

        out_id0 = DAT_copy(&buf_rgb[(1+2*pong_out)*color*out_y_width], 
                           &image_rgb[out_color_offset+display_pixels*color],
                           color*out_y_width);
        display_pixels += display_width;
        first = 0;
        pong_out ^= 1;
     }

     if (y_scaled == 2 && c_scaled > 0)
     {        
        /* this becomes 2 display_pixels */
        display_lines += 2;
        y_scaled = 0; c_scaled = 0;
        write_buf = 1;
     } else {
        write_buf = 0;
     }

    
  }  /* end while */
  if (write_buf)
  {
    DAT_wait(out_id0);   
    out_id0 = DAT_copy(&buf_rgb[2*pong_out*color*out_y_width],
                       &image_rgb[out_color_offset+display_pixels*color],
                       color*out_y_width);
    display_pixels += display_width;

    out_id0 = DAT_copy(&buf_rgb[(1+2*pong_out)*color*out_y_width], 
                       &image_rgb[out_color_offset+display_pixels*color],
                       color*out_y_width);
    display_pixels += display_width;
  }

  /* clean up at end of for loop for each strip */
  DAT_wait(in_id_cr);
  DAT_wait(in_id_cb);
  DAT_wait(in_id_y);
  DAT_wait(out_id0);
  out_color_offset += color*out_y_width;

  y_filt_state[0] = y_filt_state[4];   /* y filter count */
  c_filt_state[0] = c_filt_state[4];   /* c filter count */ 

 }/* end for */                                          
} 


/* ========================================================================= */
/*              Copyright (C) 2000 Texas Instruments Incorporated.           */
/*                              All Rights Reserved                          */
/* ========================================================================= */
                                                                   

⌨️ 快捷键说明

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