Advertisement
KSSBrawl_

MakeNest

Dec 24th, 2021
1,412
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.27 KB | None | 0 0
  1. /***********************************************************************
  2.  *
  3.  * void MakeNest(HVQM2KeyFrame *header)
  4.  *
  5.  * Explanation
  6.  *
  7.  *     Builds the DC nest.  If not enough data is given to fill the
  8.  *   entire nest, the data is mirrored once horizontally and/or
  9.  *   vertically to attempt to fill the remaining space.  If there is
  10.  *   still empty space after mirroring, it is filled with zeroes.
  11.  *
  12.  ***********************************************************************/
  13. static __inline__ void
  14. MakeNest( HVQM2KeyFrame *header )
  15. {
  16.     u8 *rowP, *dstP;
  17.     u8 *v_mirrorP;
  18.     u16 nest_x, nest_y;
  19.     s32 src_w, src_h;
  20.     s32 h_mirror_size, v_mirror_size;
  21.     s32 hzeroes, vzeroes;
  22.  
  23.     int i, j;
  24.        
  25.     /*
  26.      * Get starting offset of source DC data
  27.      */
  28.     nest_x = header->nest_start_x;
  29.     nest_y = header->nest_start_y;
  30.     rowP = nest_x + ( nest_y * lum_hblocks ) + dcbufY;
  31.  
  32.     dstP = nest;
  33.  
  34.     /*
  35.      * Calculate horizontal mirror size
  36.      */
  37.     if ( lum_hblocks < nest_w )
  38.     {
  39.         src_w = lum_hblocks;
  40.         h_mirror_size = nest_w - src_w;
  41.  
  42.         if ( src_w < h_mirror_size )
  43.             h_mirror_size = src_w; /* Clamp size of horizontal mirror */
  44.  
  45.         hzeroes = nest_w - ( src_w + h_mirror_size );
  46.     } else
  47.     {
  48.         src_w = nest_w;
  49.         h_mirror_size = 0;
  50.         hzeroes = 0;
  51.     }
  52.        
  53.     /*
  54.      * Calculate vertical mirror size
  55.      */
  56.     if ( lum_vblocks < nest_h )
  57.     {
  58.         src_h = lum_vblocks;
  59.         v_mirror_size = nest_h - src_h;
  60.  
  61.         if ( src_h < v_mirror_size )
  62.             v_mirror_size = src_h; /* Clamp size of vertical mirror */
  63.  
  64.         vzeroes = nest_h - ( src_h + v_mirror_size );
  65.     } else
  66.     {
  67.         src_h = nest_h;
  68.         v_mirror_size = 0;
  69.         vzeroes = 0;
  70.     }
  71.        
  72.     /*
  73.      * Copy source DC data into the nest and create horizontal mirror
  74.      */
  75.     for ( i = src_h; i > 0; i-- )
  76.     {
  77.         u8 *srcP = rowP;
  78.         for ( j = src_w; j > 0; j-- ) *dstP++ = *srcP++;
  79.         for ( j = h_mirror_size; j > 0; j-- ) *dstP++ = *--srcP;
  80.         for ( j = hzeroes; j > 0; j-- ) *dstP++ = 0;
  81.         rowP += lum_hblocks;
  82.     }
  83.  
  84.     v_mirrorP = dstP - nest_w;
  85.        
  86.     /*
  87.      * Create vertical mirror
  88.      */
  89.     for ( i = v_mirror_size; i > 0; i-- )
  90.     {
  91.         u8 *srcP = v_mirrorP;
  92.         for ( j = nest_w; j > 0; j-- ) *dstP++ = *srcP++;
  93.         v_mirrorP -= nest_w;
  94.     }
  95.  
  96.     /*
  97.      * Fill any remaining space with zeroes
  98.      */
  99.     for ( i = vzeroes; i > 0; i-- )
  100.         for ( j = nest_w; j > 0; j-- ) *dstP++ = 0;
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement