[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 |
---|
| 15 | #define PRINTF(...) lock_acquire( &tty_lock ); \ |
---|
| 16 | giet_tty_printf(__VA_ARGS__); \ |
---|
| 17 | lock_release( &tty_lock ); |
---|
| 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; |
---|
| 41 | uint8_t QTable[64]; // Quantisation Table / 1 byte per pixel |
---|
| 42 | int16_t bufin[64]; // Input data buffer / 2 bytes per pixel |
---|
| 43 | int32_t bufout[64]; // Output data buffer / 4 bytes per pixel |
---|
| 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 | |
---|
| 57 | PRINTF("\n[MJPEG] thread IQZZ[%d] starts on P[%d,%d,%d]\n", index, x, y, p ) |
---|
| 58 | |
---|
| 59 | uint32_t image = index; |
---|
| 60 | |
---|
| 61 | while ( image < MAX_IMAGES ) // one image per iteration |
---|
| 62 | { |
---|
| 63 | // read the quantization coefs from mwmr_in_quanti (one byte per coef) |
---|
| 64 | mwmr_read( mwmr_in_quanti , (uint32_t*)QTable , 16 ); |
---|
| 65 | |
---|
| 66 | #if (DEBUG_IQZZ > 1) |
---|
| 67 | PRINTF("\nIQZZ[%d] get quantisation coefs for image %d\n", index , image ) |
---|
| 68 | #endif |
---|
| 69 | |
---|
| 70 | for ( block = 0 ; block < nblocks ; ++block ) |
---|
| 71 | { |
---|
| 72 | // read one block from mwmr_in_data (2 bytes per pixel) |
---|
| 73 | mwmr_read( mwmr_in_data , (uint32_t*)bufin , 32 ); |
---|
| 74 | |
---|
| 75 | // unquantify & UnZZ each pixel |
---|
| 76 | for ( i = 0 ; i < 64 ; ++i ) |
---|
| 77 | { |
---|
| 78 | bufout[G_ZZ[i]] = bufin[i] * QTable[i]; |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | // write one block to IDCT / 4 bytes per pixel |
---|
| 82 | mwmr_write( mwmr_out_data , (uint32_t*)bufout , 64 ); |
---|
| 83 | |
---|
| 84 | #if (DEBUG_IQZZ > 1) |
---|
| 85 | PRINTF("\nIQZZ[%d] completes block %d/%d in image %d\n", |
---|
| 86 | index , block , nblocks , image ) |
---|
| 87 | PRINTF(" %d %d %d %d %d %d %d %d\n" |
---|
| 88 | " %d %d %d %d %d %d %d %d\n" |
---|
| 89 | " %d %d %d %d %d %d %d %d\n" |
---|
| 90 | " %d %d %d %d %d %d %d %d\n" |
---|
| 91 | " %d %d %d %d %d %d %d %d\n" |
---|
| 92 | " %d %d %d %d %d %d %d %d\n" |
---|
| 93 | " %d %d %d %d %d %d %d %d\n" |
---|
| 94 | " %d %d %d %d %d %d %d %d\n", |
---|
| 95 | bufout[0] , bufout[1] , bufout[2] , bufout[3] , bufout[4] , bufout[5] , bufout[6] , bufout[7] , |
---|
| 96 | bufout[8] , bufout[9] , bufout[10], bufout[11], bufout[12], bufout[13], bufout[14], bufout[15], |
---|
| 97 | bufout[16], bufout[17], bufout[18], bufout[19], bufout[20], bufout[21], bufout[22], bufout[23], |
---|
| 98 | bufout[24], bufout[25], bufout[26], bufout[27], bufout[28], bufout[29], bufout[30], bufout[31], |
---|
| 99 | bufout[32], bufout[33], bufout[34], bufout[35], bufout[36], bufout[37], bufout[38], bufout[39], |
---|
| 100 | bufout[40], bufout[41], bufout[42], bufout[43], bufout[44], bufout[45], bufout[46], bufout[47], |
---|
| 101 | bufout[48], bufout[49], bufout[50], bufout[51], bufout[52], bufout[53], bufout[54], bufout[55], |
---|
| 102 | bufout[56], bufout[57], bufout[58], bufout[59], bufout[60], bufout[61], bufout[62], bufout[63]) |
---|
| 103 | #endif |
---|
| 104 | } // end for blocks |
---|
| 105 | |
---|
| 106 | #if DEBUG_IQZZ |
---|
| 107 | PRINTF("\nIQZZ[%d] completes image %d at cycle %d\n", index , image , giet_proctime() ) |
---|
| 108 | #endif |
---|
| 109 | |
---|
| 110 | image = image + x_size* y_size; |
---|
| 111 | |
---|
| 112 | } // end while(1) on images |
---|
| 113 | |
---|
| 114 | giet_pthread_exit( "iqzz completed" ); |
---|
| 115 | |
---|
| 116 | } // end iqzz() |
---|
| 117 | |
---|