4 #include <VP_Api/vp_api.h>
5 #include <VP_Api/vp_api_thread_helper.h>
6 #include <VP_Api/vp_api_error.h>
7 #include <VP_Stages/vp_stages_configs.h>
8 #include <VP_Stages/vp_stages_io_console.h>
9 #include <VP_Stages/vp_stages_o_sdl.h>
10 #include <VP_Stages/vp_stages_io_com.h>
11 #include <VP_Stages/vp_stages_io_file.h>
12 #include <VP_Os/vp_os_print.h>
13 #include <VP_Os/vp_os_malloc.h>
14 #include <VP_Os/vp_os_delay.h>
16 #include <MJPEG/mjpeg.h>
21 #define ACQ_HEIGHT 240
24 static PIPELINE_HANDLE pipeline_handle;
27 PROTO_THREAD_ROUTINE(escaper,nomParams);
28 PROTO_THREAD_ROUTINE(app,nomParams);
31 THREAD_TABLE_ENTRY(escaper,20)
32 THREAD_TABLE_ENTRY(app,20)
36 typedef struct _mjpeg_stage_decoding_config_t
40 vp_api_picture_t* picture;
42 uint32_t out_buffer_size;
44 } mjpeg_stage_decoding_config_t;
46 C_RESULT mjpeg_stage_decoding_open(mjpeg_stage_decoding_config_t *cfg)
48 stream_new( &cfg->stream, OUTPUT_STREAM );
50 return mjpeg_init( &cfg->mjpeg, MJPEG_DECODE, cfg->picture->width, cfg->picture->height, cfg->picture->format );
53 C_RESULT mjpeg_stage_decoding_transform(mjpeg_stage_decoding_config_t *cfg, vp_api_io_data_t *in, vp_api_io_data_t *out)
58 vp_os_mutex_lock( &out->lock );
60 if(out->status == VP_API_STATUS_INIT)
62 #ifdef RECORD_MJPEG_VIDEO
63 fp = fopen("video", "wb");
64 #endif // ! RECORD_MJPEG_VIDEO
67 out->buffers = (int8_t**)cfg->picture;
71 out->status = VP_API_STATUS_PROCESSING;
74 if( in->status == VP_API_STATUS_ENDED )
76 #ifdef RECORD_MJPEG_VIDEO
78 #endif // ! RECORD_MJPEG_VIDEO
79 out->status = in->status;
82 // Several cases must be handled in this stage
83 // 1st: Input buffer is too small to decode a complete picture
84 // 2nd: Input buffer is big enough to decode 1 frame
85 // 3rd: Input buffer is so big we can decode more than 1 frame
89 if( out->status == VP_API_STATUS_PROCESSING )
91 // Reinit stream with new data
92 stream_config( &cfg->stream, in->size, in->buffers[in->indexBuffer] );
93 #ifdef RECORD_MJPEG_VIDEO
95 fwrite(in->buffers[in->indexBuffer], in->size, 1, fp);
96 #endif // ! RECORD_MJPEG_VIDEO
99 if(out->status == VP_API_STATUS_PROCESSING || out->status == VP_API_STATUS_STILL_RUNNING)
101 // If out->size == 1 it means picture is ready
103 out->status = VP_API_STATUS_PROCESSING;
105 res = mjpeg_decode( &cfg->mjpeg, cfg->picture, &cfg->stream, &got_image );
108 if( FAILED(stream_is_empty( &cfg->stream )) )
110 // Some data are still in stream
111 // Next time we run this stage we don't want this data to be lost
113 out->status = VP_API_STATUS_STILL_RUNNING;
118 // we got one picture (handle case 1)
121 PRINT( "%d picture decoded\n", cfg->mjpeg.num_frames );
126 vp_os_mutex_unlock( &out->lock );
131 C_RESULT mjpeg_stage_decoding_close(mjpeg_stage_decoding_config_t *cfg)
133 stream_delete( &cfg->stream );
135 return mjpeg_release( &cfg->mjpeg );
139 const vp_api_stage_funcs_t mjpeg_decoding_funcs = {
140 (vp_api_stage_handle_msg_t) NULL,
141 (vp_api_stage_open_t) mjpeg_stage_decoding_open,
142 (vp_api_stage_transform_t) mjpeg_stage_decoding_transform,
143 (vp_api_stage_close_t) mjpeg_stage_decoding_close
147 main(int argc, char **argv)
149 START_THREAD(escaper, NO_PARAM);
150 START_THREAD(app, argv);
152 JOIN_THREAD(escaper);
158 PROTO_THREAD_ROUTINE(app,argv)
160 vp_api_picture_t picture;
162 vp_api_io_pipeline_t pipeline;
163 vp_api_io_data_t out;
164 vp_api_io_stage_t stages[NB_STAGES];
166 vp_stages_input_com_config_t icc;
167 mjpeg_stage_decoding_config_t dec;
168 vp_stages_output_sdl_config_t osc;
171 vp_com_bluetooth_connection_t connection;
172 vp_com_bluetooth_config_t config;
174 /// Picture configuration
175 picture.format = PIX_FMT_YUV420P;
177 picture.width = ACQ_WIDTH;
178 picture.height = ACQ_HEIGHT;
179 picture.framerate = 15;
181 picture.y_buf = vp_os_malloc( ACQ_WIDTH*ACQ_HEIGHT );
182 picture.cr_buf = vp_os_malloc( ACQ_WIDTH*ACQ_HEIGHT/4 );
183 picture.cb_buf = vp_os_malloc( ACQ_WIDTH*ACQ_HEIGHT/4 );
185 picture.y_line_size = ACQ_WIDTH;
186 picture.cb_line_size = ACQ_WIDTH / 2;
187 picture.cr_line_size = ACQ_WIDTH / 2;
192 dec.picture = &picture;
193 dec.out_buffer_size = 4096;
195 vp_os_memset( &icc, 0, sizeof(vp_stages_input_com_config_t) );
196 vp_os_memset( &osc, 0, sizeof(vp_stages_output_sdl_config_t) );
197 vp_os_memset( &connection, 0, sizeof(vp_com_bluetooth_connection_t) );
198 vp_os_memset( &config, 0, sizeof(vp_com_bluetooth_config_t) );
199 vp_os_memset( &com, 0, sizeof(vp_com_t) );
201 vp_com_str_to_address("08:75:48:03:60:34",&connection.address);
202 // vp_com_str_to_address("00:12:1C:FF:A4:EE",&connection.address);
204 strcpy(config.itfName, "bnep0");
205 strcpy(config.localHost, "192.168.2.58");
206 strcpy(config.netmask, "255.255.255.0");
207 strcpy(config.broadcast, "192.168.2.255");
208 strcpy(config.gateway, "192.168.2.0");
209 strcpy(config.server, "192.168.2.0");
210 strcpy(config.passkey, "1234" );
213 com.type = VP_COM_BLUETOOTH;
216 icc.config = (vp_com_config_t*)&config;
217 icc.connection = (vp_com_connection_t*)&connection;
218 icc.socket.type = VP_COM_CLIENT;
219 icc.socket.protocol = VP_COM_TCP;
220 icc.socket.port = 5555;
221 icc.buffer_size = 1600;
222 // icc.sockopt = VP_COM_NON_BLOCKING;
224 strcpy(icc.socket.serverHost,"192.168.2.23");
229 osc.window_width = 320;
230 osc.window_height = 240;
231 osc.pic_width = ACQ_WIDTH;
232 osc.pic_height = ACQ_HEIGHT;
233 osc.y_size = ACQ_WIDTH*ACQ_HEIGHT;
234 osc.c_size = (ACQ_WIDTH*ACQ_HEIGHT) >> 2;
236 stages[0].type = VP_API_INPUT_SOCKET;
237 stages[0].cfg = (void *)&icc;
238 stages[0].funcs = vp_stages_input_com_funcs;
240 stages[1].type = VP_API_FILTER_DECODER;
241 stages[1].cfg = (void*)&dec;
242 stages[1].funcs = mjpeg_decoding_funcs;
244 stages[2].type = VP_API_OUTPUT_SDL;
245 stages[2].cfg = (void *)&osc;
246 stages[2].funcs = vp_stages_output_sdl_funcs;
248 pipeline.nb_stages = NB_STAGES;
249 pipeline.stages = &stages[0];
251 vp_api_open(&pipeline, &pipeline_handle);
252 out.status = VP_API_STATUS_PROCESSING;
253 while(SUCCEED(vp_api_run(&pipeline, &out)) && (out.status == VP_API_STATUS_PROCESSING || out.status == VP_API_STATUS_STILL_RUNNING));
255 vp_api_close(&pipeline, &pipeline_handle);
260 ///*******************************************************************************************************************///
263 // static THREAD_HANDLE dct_thread_handle;
265 static dct_io_buffer_t* current_io_buffer;
266 static dct_io_buffer_t* result_io_buffer;
268 static void fdct(const unsigned short* in, short* out);
269 static void idct(const short* in, unsigned short* out);
272 //-----------------------------------------------------------------------------
274 //-----------------------------------------------------------------------------
277 bool_t dct_init(void)
279 current_io_buffer = NULL;
280 result_io_buffer = NULL;
285 bool_t dct_compute( dct_io_buffer_t* io_buffer )
289 assert(io_buffer != NULL);
291 if( current_io_buffer == NULL && result_io_buffer == NULL )
293 current_io_buffer = io_buffer;
301 dct_io_buffer_t* dct_result( void )
304 dct_io_buffer_t* io_buffer;
308 if( current_io_buffer != NULL)
310 if( current_io_buffer->dct_mode == DCT_MODE_FDCT )
312 for( i = 0; i < current_io_buffer->num_total_blocks; i++ )
314 fdct(current_io_buffer->input[i], current_io_buffer->output[i]);
317 else if( current_io_buffer->dct_mode == DCT_MODE_IDCT )
319 for( i = 0; i < current_io_buffer->num_total_blocks; i++ )
321 idct(current_io_buffer->input[i], current_io_buffer->output[i]);
325 io_buffer = current_io_buffer;
326 current_io_buffer = NULL;
333 //-----------------------------------------------------------------------------
335 //-----------------------------------------------------------------------------
338 #define FIX_0_298631336 ((INT32) 2446) /* FIX(0.298631336) */
339 #define FIX_0_390180644 ((INT32) 3196) /* FIX(0.390180644) */
340 #define FIX_0_541196100 ((INT32) 4433) /* FIX(0.541196100) */
341 #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
342 #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
343 #define FIX_1_175875602 ((INT32) 9633) /* FIX(1.175875602) */
344 #define FIX_1_501321110 ((INT32) 12299) /* FIX(1.501321110) */
345 #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
346 #define FIX_1_961570560 ((INT32) 16069) /* FIX(1.961570560) */
347 #define FIX_2_053119869 ((INT32) 16819) /* FIX(2.053119869) */
348 #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
349 #define FIX_3_072711026 ((INT32) 25172) /* FIX(3.072711026) */
355 #define CONST_BITS 13
357 #define ONE ((INT32) 1)
358 #define MULTIPLY(var,const) ((var) * (const))
359 #define DESCALE(x,n) RIGHT_SHIFT((x) + (ONE << ((n)-1)), n)
360 #define RIGHT_SHIFT(x,shft) ((x) >> (shft))
362 static void fdct(const unsigned short* in, short* out)
364 INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
365 INT32 tmp10, tmp11, tmp12, tmp13;
366 INT32 z1, z2, z3, z4, z5;
370 int data[DCTSIZE * DCTSIZE];
374 for( i = 0; i < DCTSIZE; i++ )
376 for( j = 0; j < DCTSIZE; j++ )
380 temp = in[i*DCTSIZE + j];
381 dataptr[i*DCTSIZE + j] = temp;
385 /* Pass 1: process rows. */
386 /* Note results are scaled up by sqrt(8) compared to a true DCT; */
387 /* furthermore, we scale the results by 2**PASS1_BITS. */
390 for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
391 tmp0 = dataptr[0] + dataptr[7];
392 tmp7 = dataptr[0] - dataptr[7];
393 tmp1 = dataptr[1] + dataptr[6];
394 tmp6 = dataptr[1] - dataptr[6];
395 tmp2 = dataptr[2] + dataptr[5];
396 tmp5 = dataptr[2] - dataptr[5];
397 tmp3 = dataptr[3] + dataptr[4];
398 tmp4 = dataptr[3] - dataptr[4];
400 /* Even part per LL&M figure 1 --- note that published figure is faulty;
401 * rotator "sqrt(2)*c1" should be "sqrt(2)*c6".
409 dataptr[0] = (DCTELEM) ((tmp10 + tmp11) << PASS1_BITS);
410 dataptr[4] = (DCTELEM) ((tmp10 - tmp11) << PASS1_BITS);
412 z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
413 dataptr[2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865), CONST_BITS-PASS1_BITS);
414 dataptr[6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065), CONST_BITS-PASS1_BITS);
416 /* Odd part per figure 8 --- note paper omits factor of sqrt(2).
417 * cK represents cos(K*pi/16).
418 * i0..i3 in the paper are tmp4..tmp7 here.
425 z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
427 tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
428 tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
429 tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
430 tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
431 z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
432 z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
433 z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
434 z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
439 dataptr[7] = (DCTELEM) DESCALE(tmp4 + z1 + z3, CONST_BITS-PASS1_BITS);
440 dataptr[5] = (DCTELEM) DESCALE(tmp5 + z2 + z4, CONST_BITS-PASS1_BITS);
441 dataptr[3] = (DCTELEM) DESCALE(tmp6 + z2 + z3, CONST_BITS-PASS1_BITS);
442 dataptr[1] = (DCTELEM) DESCALE(tmp7 + z1 + z4, CONST_BITS-PASS1_BITS);
444 dataptr += DCTSIZE; /* advance pointer to next row */
447 /* Pass 2: process columns.
448 * We remove the PASS1_BITS scaling, but leave the results scaled up
449 * by an overall factor of 8.
453 for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
454 tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
455 tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
456 tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
457 tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
458 tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
459 tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
460 tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
461 tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
463 /* Even part per LL&M figure 1 --- note that published figure is faulty;
464 * rotator "sqrt(2)*c1" should be "sqrt(2)*c6".
472 dataptr[DCTSIZE*0] = (DCTELEM) DESCALE(tmp10 + tmp11, PASS1_BITS);
473 dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(tmp10 - tmp11, PASS1_BITS);
475 z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
476 dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865), CONST_BITS+PASS1_BITS);
477 dataptr[DCTSIZE*6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065), CONST_BITS+PASS1_BITS);
479 /* Odd part per figure 8 --- note paper omits factor of sqrt(2).
480 * cK represents cos(K*pi/16).
481 * i0..i3 in the paper are tmp4..tmp7 here.
488 z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
490 tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
491 tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
492 tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
493 tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
494 z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
495 z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
496 z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
497 z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
502 dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp4 + z1 + z3, CONST_BITS+PASS1_BITS);
503 dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp5 + z2 + z4, CONST_BITS+PASS1_BITS);
504 dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp6 + z2 + z3, CONST_BITS+PASS1_BITS);
505 dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp7 + z1 + z4, CONST_BITS+PASS1_BITS);
507 dataptr++; /* advance pointer to next column */
510 for( i = 0; i < DCTSIZE; i++ )
511 for( j = 0; j < DCTSIZE; j++ )
512 out[i*DCTSIZE + j] = data[i*DCTSIZE + j] >> 3;
515 static void idct(const short* in, unsigned short* out)
517 INT32 tmp0, tmp1, tmp2, tmp3;
518 INT32 tmp10, tmp11, tmp12, tmp13;
519 INT32 z1, z2, z3, z4, z5;
524 int workspace[DCTSIZE2]; /* buffers data between passes */
528 /* Pass 1: process columns from input, store into work array. */
529 /* Note results are scaled up by sqrt(8) compared to a true IDCT; */
530 /* furthermore, we scale the results by 2**PASS1_BITS. */
534 for (ctr = DCTSIZE; ctr > 0; ctr--) {
535 /* Due to quantization, we will usually find that many of the input
536 * coefficients are zero, especially the AC terms. We can exploit this
537 * by short-circuiting the IDCT calculation for any column in which all
538 * the AC terms are zero. In that case each output is equal to the
539 * DC coefficient (with scale factor as needed).
540 * With typical images and quantization tables, half or more of the
541 * column DCT calculations can be simplified this way.
544 if( inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
545 inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
546 inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
547 inptr[DCTSIZE*7] == 0 ) {
548 /* AC terms all zero */
549 int dcval = inptr[DCTSIZE*0] << PASS1_BITS;
551 wsptr[DCTSIZE*0] = dcval;
552 wsptr[DCTSIZE*1] = dcval;
553 wsptr[DCTSIZE*2] = dcval;
554 wsptr[DCTSIZE*3] = dcval;
555 wsptr[DCTSIZE*4] = dcval;
556 wsptr[DCTSIZE*5] = dcval;
557 wsptr[DCTSIZE*6] = dcval;
558 wsptr[DCTSIZE*7] = dcval;
560 inptr++; /* advance pointers to next column */
565 /* Even part: reverse the even part of the forward DCT. */
566 /* The rotator is sqrt(2)*c(-6). */
568 z2 = inptr[DCTSIZE*2];
569 z3 = inptr[DCTSIZE*6];
571 z1 = MULTIPLY(z2 + z3, FIX_0_541196100);
572 tmp2 = z1 + MULTIPLY(z3, - FIX_1_847759065);
573 tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865);
575 z2 = inptr[DCTSIZE*0];
576 z3 = inptr[DCTSIZE*4];
578 tmp0 = (z2 + z3) << CONST_BITS;
579 tmp1 = (z2 - z3) << CONST_BITS;
586 /* Odd part per figure 8; the matrix is unitary and hence its
587 * transpose is its inverse. i0..i3 are y7,y5,y3,y1 respectively.
590 tmp0 = inptr[DCTSIZE*7];
591 tmp1 = inptr[DCTSIZE*5];
592 tmp2 = inptr[DCTSIZE*3];
593 tmp3 = inptr[DCTSIZE*1];
599 z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
601 tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
602 tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
603 tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
604 tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
605 z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
606 z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
607 z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
608 z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
618 /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */
620 wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp3, CONST_BITS-PASS1_BITS);
621 wsptr[DCTSIZE*7] = (int) DESCALE(tmp10 - tmp3, CONST_BITS-PASS1_BITS);
622 wsptr[DCTSIZE*1] = (int) DESCALE(tmp11 + tmp2, CONST_BITS-PASS1_BITS);
623 wsptr[DCTSIZE*6] = (int) DESCALE(tmp11 - tmp2, CONST_BITS-PASS1_BITS);
624 wsptr[DCTSIZE*2] = (int) DESCALE(tmp12 + tmp1, CONST_BITS-PASS1_BITS);
625 wsptr[DCTSIZE*5] = (int) DESCALE(tmp12 - tmp1, CONST_BITS-PASS1_BITS);
626 wsptr[DCTSIZE*3] = (int) DESCALE(tmp13 + tmp0, CONST_BITS-PASS1_BITS);
627 wsptr[DCTSIZE*4] = (int) DESCALE(tmp13 - tmp0, CONST_BITS-PASS1_BITS);
629 inptr++; /* advance pointers to next column */
633 /* Pass 2: process rows from work array, store into output array. */
634 /* Note that we must descale the results by a factor of 8 == 2**3, */
635 /* and also undo the PASS1_BITS scaling. */
639 for (ctr = 0; ctr < DCTSIZE; ctr++) {
640 /* Even part: reverse the even part of the forward DCT. */
641 /* The rotator is sqrt(2)*c(-6). */
643 z2 = (INT32) wsptr[2];
644 z3 = (INT32) wsptr[6];
646 z1 = MULTIPLY(z2 + z3, FIX_0_541196100);
647 tmp2 = z1 + MULTIPLY(z3, - FIX_1_847759065);
648 tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865);
650 tmp0 = ((INT32) wsptr[0] + (INT32) wsptr[4]) << CONST_BITS;
651 tmp1 = ((INT32) wsptr[0] - (INT32) wsptr[4]) << CONST_BITS;
658 /* Odd part per figure 8; the matrix is unitary and hence its
659 * transpose is its inverse. i0..i3 are y7,y5,y3,y1 respectively.
662 tmp0 = (INT32) wsptr[7];
663 tmp1 = (INT32) wsptr[5];
664 tmp2 = (INT32) wsptr[3];
665 tmp3 = (INT32) wsptr[1];
671 z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
673 tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
674 tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
675 tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
676 tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
677 z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
678 z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
679 z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
680 z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
690 /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */
692 outptr[0] = (tmp10 + tmp3) >> ( CONST_BITS+PASS1_BITS+3 );
693 outptr[7] = (tmp10 - tmp3) >> ( CONST_BITS+PASS1_BITS+3 );
694 outptr[1] = (tmp11 + tmp2) >> ( CONST_BITS+PASS1_BITS+3 );
695 outptr[6] = (tmp11 - tmp2) >> ( CONST_BITS+PASS1_BITS+3 );
696 outptr[2] = (tmp12 + tmp1) >> ( CONST_BITS+PASS1_BITS+3 );
697 outptr[5] = (tmp12 - tmp1) >> ( CONST_BITS+PASS1_BITS+3 );
698 outptr[3] = (tmp13 + tmp0) >> ( CONST_BITS+PASS1_BITS+3 );
699 outptr[4] = (tmp13 - tmp0) >> ( CONST_BITS+PASS1_BITS+3 );
701 wsptr += DCTSIZE; /* advance pointer to next row */
705 for(ctr = 0; ctr < DCTSIZE2; ctr++)
706 out[ctr] = data[ctr];