| [723] | 1 | ///////////////////////////////////////////////////////////////////////////////////////// | 
|---|
 | 2 | // File   : iqzz.c    | 
|---|
 | 3 | // Date   : octobre 2015 | 
|---|
 | 4 | // author : Alain Greiner | 
|---|
 | 5 | ///////////////////////////////////////////////////////////////////////////////////////// | 
|---|
 | 6 | // This file define the code of the IQZZ (Invert Quantisation) thread for MJPEG. | 
|---|
 | 7 | ///////////////////////////////////////////////////////////////////////////////////////// | 
|---|
 | 8 |  | 
|---|
 | 9 | #include <stdio.h> | 
|---|
 | 10 | #include <mwmr_channel.h> | 
|---|
 | 11 | #include <stdint.h> | 
|---|
 | 12 | #include "mjpeg.h" | 
|---|
 | 13 |  | 
|---|
 | 14 | // macro to use a shared TTY | 
|---|
| [748] | 15 | #define PRINTF(...) do { lock_acquire( &tty_lock ); \ | 
|---|
 | 16 |                          giet_tty_printf(__VA_ARGS__);  \ | 
|---|
 | 17 |                          lock_release( &tty_lock ); } while(0); | 
|---|
| [723] | 18 |  | 
|---|
 | 19 | ////////////////////////////////////////////////////////////// | 
|---|
 | 20 | __attribute__ ((constructor)) void iqzz( unsigned int index ) | 
|---|
 | 21 | ////////////////////////////////////////////////////////////// | 
|---|
 | 22 | { | 
|---|
 | 23 |     const uint8_t G_ZZ[64] =  | 
|---|
 | 24 |     { | 
|---|
 | 25 |         0 ,  1,  8, 16,  9,  2,  3, 10, | 
|---|
 | 26 |         17, 24, 32, 25, 18, 11,  4,  5, | 
|---|
 | 27 |         12, 19, 26, 33, 40, 48, 41, 34, | 
|---|
 | 28 |         27, 20, 13,  6,  7, 14, 21, 28, | 
|---|
 | 29 |         35, 42, 49, 56, 57, 50, 43, 36, | 
|---|
 | 30 |         29, 22, 15, 23, 30, 37, 44, 51, | 
|---|
 | 31 |         58, 59, 52, 45, 38, 31, 39, 46, | 
|---|
 | 32 |         53, 60, 61, 54, 47, 55, 62, 63 | 
|---|
 | 33 |     }; | 
|---|
 | 34 |  | 
|---|
 | 35 |     mwmr_channel_t*   mwmr_in_data   = vld_2_iqzz[index]; | 
|---|
 | 36 |     mwmr_channel_t*   mwmr_in_quanti = demux_2_iqzz[index]; | 
|---|
 | 37 |     mwmr_channel_t*   mwmr_out_data  = iqzz_2_idct[index]; | 
|---|
 | 38 |  | 
|---|
 | 39 |     uint32_t    block; | 
|---|
 | 40 |     uint32_t    i; | 
|---|
| [736] | 41 |     uint8_t     QT[64];      // Quantisation Table / 1 byte per pixel | 
|---|
 | 42 |     int16_t     bin[64];     // Input data buffer  / 2 bytes per pixel | 
|---|
 | 43 |     int32_t     bout[64];    // Output data buffer / 4 bytes per pixel  | 
|---|
| [723] | 44 |  | 
|---|
 | 45 |     uint32_t    nblocks = nblocks_w * nblocks_h; | 
|---|
 | 46 |  | 
|---|
 | 47 |     // get platform parameters | 
|---|
 | 48 |     uint32_t  x_size; | 
|---|
 | 49 |     uint32_t  y_size; | 
|---|
 | 50 |     uint32_t  nprocs; | 
|---|
 | 51 |     giet_procs_number( &x_size , &y_size , &nprocs ); | 
|---|
 | 52 |  | 
|---|
 | 53 |     // get processor coordinates | 
|---|
 | 54 |     uint32_t    x, y, p; | 
|---|
 | 55 |     giet_proc_xyp( &x , &y , &p ); | 
|---|
 | 56 |  | 
|---|
| [736] | 57 |     PRINTF("\n[MJPEG] thread IQZZ[%d] starts on P[%d,%d,%d] / trdid = %x\n", | 
|---|
| [748] | 58 |            index , x , y , p, (uint32_t)trdid_iqzz[index] ); | 
|---|
| [723] | 59 |  | 
|---|
| [736] | 60 |  | 
|---|
| [723] | 61 |     uint32_t image = index; | 
|---|
 | 62 |  | 
|---|
 | 63 |     while ( image < MAX_IMAGES ) // one image per iteration | 
|---|
 | 64 |     { | 
|---|
 | 65 |         // read the quantization coefs from mwmr_in_quanti (one byte per coef)  | 
|---|
| [736] | 66 |         mwmr_read( mwmr_in_quanti , (uint32_t*)QT , 16 ); | 
|---|
| [723] | 67 |  | 
|---|
 | 68 | #if (DEBUG_IQZZ > 1) | 
|---|
| [736] | 69 | if ( (index == DEBUG_CLUSTER_INDEX) || (DEBUG_CLUSTER_INDEX == 0XFFFFFFFF) ) | 
|---|
| [748] | 70 | PRINTF("\nIQZZ[%d] get quantisation coefs for image %d\n" | 
|---|
| [736] | 71 |          "%d  %d  %d  %d  %d  %d  %d  %d\n" | 
|---|
 | 72 |          "%d  %d  %d  %d  %d  %d  %d  %d\n" | 
|---|
 | 73 |          "%d  %d  %d  %d  %d  %d  %d  %d\n" | 
|---|
 | 74 |          "%d  %d  %d  %d  %d  %d  %d  %d\n" | 
|---|
 | 75 |          "%d  %d  %d  %d  %d  %d  %d  %d\n" | 
|---|
 | 76 |          "%d  %d  %d  %d  %d  %d  %d  %d\n" | 
|---|
 | 77 |          "%d  %d  %d  %d  %d  %d  %d  %d\n" | 
|---|
 | 78 |          "%d  %d  %d  %d  %d  %d  %d  %d\n", | 
|---|
 | 79 |          index , image , | 
|---|
 | 80 |          QT[ 0],QT[ 1],QT[ 2],QT[ 3],QT[ 4],QT[ 5],QT[ 6],QT[ 7], | 
|---|
 | 81 |          QT[ 8],QT[ 9],QT[10],QT[11],QT[12],QT[13],QT[14],QT[15], | 
|---|
 | 82 |          QT[16],QT[17],QT[18],QT[19],QT[20],QT[21],QT[22],QT[23], | 
|---|
 | 83 |          QT[24],QT[25],QT[26],QT[27],QT[28],QT[29],QT[30],QT[31], | 
|---|
 | 84 |          QT[32],QT[33],QT[34],QT[35],QT[36],QT[37],QT[38],QT[39], | 
|---|
 | 85 |          QT[40],QT[41],QT[42],QT[43],QT[44],QT[45],QT[46],QT[47], | 
|---|
 | 86 |          QT[48],QT[49],QT[50],QT[51],QT[52],QT[53],QT[54],QT[55], | 
|---|
| [748] | 87 |          QT[56],QT[57],QT[58],QT[59],QT[60],QT[61],QT[62],QT[63] ); | 
|---|
| [723] | 88 | #endif | 
|---|
 | 89 |  | 
|---|
 | 90 |         for ( block = 0 ; block < nblocks ; ++block )  | 
|---|
 | 91 |         { | 
|---|
 | 92 |             // read one block from mwmr_in_data (2 bytes per pixel) | 
|---|
| [736] | 93 |             mwmr_read( mwmr_in_data , (uint32_t*)bin , 32 ); | 
|---|
| [723] | 94 |  | 
|---|
 | 95 |             // unquantify & UnZZ each pixel | 
|---|
 | 96 |             for ( i = 0 ; i < 64 ; ++i )  | 
|---|
 | 97 |             { | 
|---|
| [736] | 98 |                 bout[G_ZZ[i]] = bin[i] * QT[i]; | 
|---|
| [723] | 99 |             } | 
|---|
| [736] | 100 |  | 
|---|
| [723] | 101 |             // write one block to IDCT / 4 bytes per pixel | 
|---|
| [736] | 102 |             mwmr_write( mwmr_out_data , (uint32_t*)bout , 64 ); | 
|---|
| [723] | 103 |  | 
|---|
 | 104 | #if (DEBUG_IQZZ > 1)  | 
|---|
| [736] | 105 | if ( (index == DEBUG_CLUSTER_INDEX) || (DEBUG_CLUSTER_INDEX == 0XFFFFFFFF) ) | 
|---|
| [748] | 106 | PRINTF("\nIQZZ[%d] completes block %d/%d in image %d\n"  | 
|---|
| [736] | 107 |          "  %d  %d  %d  %d  %d  %d  %d  %d\n" | 
|---|
 | 108 |          "  %d  %d  %d  %d  %d  %d  %d  %d\n" | 
|---|
 | 109 |          "  %d  %d  %d  %d  %d  %d  %d  %d\n" | 
|---|
 | 110 |          "  %d  %d  %d  %d  %d  %d  %d  %d\n" | 
|---|
 | 111 |          "  %d  %d  %d  %d  %d  %d  %d  %d\n" | 
|---|
 | 112 |          "  %d  %d  %d  %d  %d  %d  %d  %d\n" | 
|---|
 | 113 |          "  %d  %d  %d  %d  %d  %d  %d  %d\n" | 
|---|
 | 114 |          "  %d  %d  %d  %d  %d  %d  %d  %d\n", | 
|---|
 | 115 |          index , block , nblocks , image , | 
|---|
 | 116 |          bout[0] , bout[1] , bout[2] , bout[3] , bout[4] , bout[5] , bout[6] , bout[7] , | 
|---|
 | 117 |          bout[8] , bout[9] , bout[10], bout[11], bout[12], bout[13], bout[14], bout[15], | 
|---|
 | 118 |          bout[16], bout[17], bout[18], bout[19], bout[20], bout[21], bout[22], bout[23], | 
|---|
 | 119 |          bout[24], bout[25], bout[26], bout[27], bout[28], bout[29], bout[30], bout[31], | 
|---|
 | 120 |          bout[32], bout[33], bout[34], bout[35], bout[36], bout[37], bout[38], bout[39], | 
|---|
 | 121 |          bout[40], bout[41], bout[42], bout[43], bout[44], bout[45], bout[46], bout[47], | 
|---|
 | 122 |          bout[48], bout[49], bout[50], bout[51], bout[52], bout[53], bout[54], bout[55], | 
|---|
| [748] | 123 |          bout[56], bout[57], bout[58], bout[59], bout[60], bout[61], bout[62], bout[63]); | 
|---|
| [723] | 124 | #endif | 
|---|
 | 125 |         }  // end for blocks | 
|---|
 | 126 |  | 
|---|
 | 127 | #if DEBUG_IQZZ | 
|---|
| [736] | 128 | if ( (index == DEBUG_CLUSTER_INDEX) || (DEBUG_CLUSTER_INDEX == 0XFFFFFFFF) ) | 
|---|
| [748] | 129 | PRINTF("\nIQZZ[%d] completes image %d at cycle %d\n", index , image , giet_proctime() ); | 
|---|
| [723] | 130 | #endif | 
|---|
 | 131 |  | 
|---|
 | 132 |         image = image + x_size* y_size; | 
|---|
 | 133 |  | 
|---|
 | 134 |     } // end while(1) on images | 
|---|
 | 135 |  | 
|---|
| [736] | 136 |     giet_pthread_exit( "IQZZ completed" ); | 
|---|
| [723] | 137 |  | 
|---|
 | 138 | } // end iqzz() | 
|---|
 | 139 |  | 
|---|