List Info

Thread: libmpeg2 IDCT implementation




libmpeg2 IDCT implementation
user name
2007-11-30 12:54:17
Hi,
    I see in pratice and in emails of the past
([mpeg2-dev] Re: mpeg2-dev Scan order - 2004-02-19, and
Re: [mpeg2-dev] about the idct! - 2004-04-30)
that the IDCT of two dimensions performed by idct_row and idct_col operating
together (how we can see in mpeg2_idct_copy_c and mpeg2_idct_copy_add), in
libmpeg2 are different of a "default" IDCT (DCT type-3). But in a experiment
that I have to do, I would like to use the "default" IDCT. So I need
by pass the modifications done in a block before do the IDCT or apply a
function that remove this modifications. But I don't know what modifications
exist, strictly speaking. I see that mpeg2_idct_init changes the order of
mpeg2_scan_norm and mpeg2_scan_alt, and functions that "reconstructs" the
block, like get_intra_block_B14 use this vectors. So I can see a reordering of
block in here. Where are and who are the others modifications?
    Another question, the values of block parameter in mpeg2_idct_copy_c and
mpeg2_idct_add_c functions, after the loop that do the IDCT:
&quot; for (i = 0; i < 8; i++)
 ;   idct_row (block + 8 * i);
   ; for (i = 0; i < 8; i++)
&nbsp;   idct_col (block + i); "
are the same if I use a "default" IDCT, right? Because the IDCTs "at the end"
must be the same, right?

Thanks!

Mateus Krepsky Ludwich.
Re: libmpeg2 IDCT implementation
user name
2008-01-17 10:50:21
Hello,
&nbsp; &nbsp; I finally discovered the answer to my previous question:

"what modifications libmpeg2 does in a block before it enter in the IDCT functions?"

So, the 64 values of a block are multiplied by 16 and reordered. And the IDCT
functions of libmpeg2 know this and its output are the same of a "default" IDCT
(DCT type-3), of course. I would like to thank Dmitriy Startsev that tell me
about the scaled by 16. And the reordering I discovered by myself. And only
after this I saw a email of Matthew Fullerton that answering a question of Uros damnjanovic
(Re: [mpeg2-dev] Extracting DCT coefficients for each frame - coefficient order)
and brought the inverse reorder that I was looking for... ;p
 ; &nbsp; Below are the mapping to reorder libmpeg2 IDCT input to the "default" IDCT
input, and the inverse reorder mapping ("default" IDCT input to libmpeg2 IDCT input).

Libmpeg2 IDCT input --> "Default" IDCT input / "Default" IDCT input --> Libmpeg2 IDCT input
0 --> 0 &nbsp;   &nbsp;   &nbsp;  / &nbsp;   &nbsp;  0 --> 0
1 --> 2 &nbsp;   &nbsp;   &nbsp;  / &nbsp;   &nbsp;  1 --> 4
2 --> 4 &nbsp;   &nbsp;   &nbsp;  / &nbsp;   &nbsp;  2 --> 1
3 --> 6 &nbsp;   &nbsp;   &nbsp;  / &nbsp;   &nbsp;  3 --> 5
4 --> 1 &nbsp;   &nbsp;   &nbsp;  / &nbsp;   &nbsp;  4 --> 2
5 --> 3 &nbsp;   &nbsp;   &nbsp;  / &nbsp;   &nbsp;  5 --> 6
6 --> 5 &nbsp;   &nbsp;   &nbsp;  / &nbsp;   &nbsp;  6 --> 3 &nbsp; 
7 --> 7 &nbsp;   &nbsp;   &nbsp;  / &nbsp;   &nbsp;  7 --> 7 &nbsp; 
8 --> 16 &nbsp;   &nbsp;  &nbsp; / &nbsp;   &nbsp;  8 --> 32 &nbsp; 
9 --> 18 &nbsp;   &nbsp; &nbsp;  / &nbsp;   &nbsp;  9 --> 36 &nbsp; 
10 --> 20 &nbsp;   &nbsp;  / &nbsp;   &nbsp;  10 --> 33
11 --> 22 &nbsp;   &nbsp;  / &nbsp;   &nbsp;  11 --> 37
12 --> 17 &nbsp;   &nbsp;  / &nbsp;   &nbsp;  12 --> 34
13 --> 19 &nbsp;   &nbsp;  / &nbsp;   &nbsp;  13 --> 38
14 --> 21 &nbsp;   &nbsp;  / &nbsp;   &nbsp;  14 --> 35
15 --> 23 &nbsp;   &nbsp;  / &nbsp;   &nbsp;  15 --> 39
16 --> 32 &nbsp;   &nbsp;  / &nbsp;   &nbsp;  16 --> 8
17 --> 34 &nbsp;   &nbsp;  / &nbsp;   &nbsp;  17 --> 12
18 --> 36 &nbsp;   &nbsp;  / &nbsp;   &nbsp;  18 --> 9
19 --> 38 &nbsp;   &nbsp;  / &nbsp;   &nbsp;  19 --> 13
20 --> 33 &nbsp;   &nbsp;  / &nbsp;   &nbsp;  20 --> 10
21 --> 35 &nbsp;   &nbsp;  / &nbsp;   &nbsp;  21 --> 14
22 --> 37 &nbsp;   &nbsp;  / &nbsp;   &nbsp;  22 --> 11
23 --> 39 &nbsp;   &nbsp;  / &nbsp;   &nbsp;  23 --> 15
24 --> 48 &nbsp;   &nbsp;  / &nbsp;   &nbsp;  24 --> 40
25 --> 50 &nbsp;   &nbsp;  / &nbsp;   &nbsp;  25 --> 44
26 --> 52 &nbsp;   &nbsp;  / &nbsp;   &nbsp;  26 --> 41
27 --> 54 &nbsp;   &nbsp;  / &nbsp;   &nbsp;  27 --> 45
28 --> 49 &nbsp;   &nbsp;  / &nbsp;   &nbsp;  28 --> 42
29 --> 51 &nbsp;   &nbsp;  / &nbsp;   &nbsp;  29 --> 46
30 --> 53 &nbsp;   &nbsp;  / &nbsp;   &nbsp;  30 --> 43
31 --> 55 &nbsp;   &nbsp;  / &nbsp;   &nbsp;  31 --> 47
32 --> 8 &nbsp;   &nbsp;  &nbsp; / &nbsp;   &nbsp;  32 --> 16
33 --> 10 &nbsp;   &nbsp;  / &nbsp;   &nbsp;  33 --> 20
34 --> 12 &nbsp;   &nbsp;  / &nbsp;   &nbsp;  34 --> 17
35 --> 14 &nbsp;   &nbsp;  / &nbsp;   &nbsp;  35 --> 21
36 --> 9 &nbsp;   &nbsp; &nbsp;  / &nbsp;   &nbsp;  36 --> 18
37 --> 11 &nbsp;   &nbsp;  / &nbsp;   &nbsp;  37 --> 22
38 --> 13 &nbsp;   &nbsp;  / &nbsp;   &nbsp;  38 --> 19
39 --> 15 &nbsp;   &nbsp;  / &nbsp;   &nbsp;  39 --> 23
40 --> 24 &nbsp;   &nbsp;  / &nbsp;   &nbsp;  40 --> 48
41 --> 26 &nbsp;   &nbsp;  / &nbsp;   &nbsp;  41 --> 52
42 --> 28 &nbsp;   &nbsp;  / &nbsp;   &nbsp;  42 --> 49
43 --> 30 &nbsp;   &nbsp;  / &nbsp;   &nbsp;  43 --> 53
44 --> 25 &nbsp;   &nbsp;  / &nbsp;   &nbsp;  44 --> 50
45 --> 27 &nbsp;   &nbsp;  / &nbsp;   &nbsp;  45 --> 54
46 --> 29 &nbsp;   &nbsp;  / &nbsp;   &nbsp;  46 --> 51
47 --> 31 &nbsp;   &nbsp;  / &nbsp;   &nbsp;  47 --> 55
48 --> 40 &nbsp;   &nbsp;  / &nbsp;   &nbsp;  48 --> 24
49 --> 42 &nbsp;   &nbsp;  / &nbsp;   &nbsp;  49 --> 28
50 --> 44 &nbsp;   &nbsp;  / &nbsp;   &nbsp;  50 --> 25
51 --> 46 &nbsp;   &nbsp;  / &nbsp;   &nbsp;  51 --> 29
52 --> 41 &nbsp;   &nbsp;  / &nbsp;   &nbsp;  52 --> 26
53 --> 43 &nbsp;   &nbsp;  / &nbsp;   &nbsp;  53 --> 30
54 --> 45 &nbsp;   &nbsp;  / &nbsp;   &nbsp;  54 --> 27
55 --> 47 &nbsp;   &nbsp;  / &nbsp;   &nbsp;  55 --> 31
56 --> 56 &nbsp;   &nbsp;  / &nbsp;   &nbsp;  56 --> 56
57 --> 58 &nbsp;   &nbsp;  / &nbsp;   &nbsp;  57 --> 60
58 --> 60 &nbsp;   &nbsp;  / &nbsp;   &nbsp;  58 --> 57
59 --> 62 &nbsp;   &nbsp;  / &nbsp;   &nbsp;  59 --> 61
60 --> 57 &nbsp;   &nbsp;  / &nbsp;   &nbsp;  60 --> 58
61 --> 59 &nbsp;   &nbsp;  / &nbsp;   &nbsp;  61 --> 62
62 --> 61 &nbsp;   &nbsp;  / &nbsp;   &nbsp;  62 --> 59
63 --> 63 &nbsp;   &nbsp;  / &nbsp;   &nbsp;  63 --> 63

   ; A function that maps a libmpeg2 IDCT input to the "default" IDCT input can
be:

// Hard-coded way:
void libmpeg2ToNormal(short * block) {
 &nbsp;  short aux[64];
&nbsp;  
 &nbsp;  aux[0] = block[0];
  ;  aux[1] = block[4];
  ;  aux[2] = block[1];
  ;  aux[3] = block[5];
  ;  aux[4] = block[2];
 &nbsp;  aux[5] = block[6];
  ;  aux[6] = block[3];
  ;  aux[7] = block[7];
  ;  aux[8] = block[32];
 &nbsp;  aux[9] = block[36];
 &nbsp;  aux[10] = block[33];
 &nbsp;  aux[11] = block[37];
 &nbsp;  aux[12] = block[34];
 &nbsp;  aux[13] = block[38];
 &nbsp;  aux[14] = block[35];
 &nbsp;  aux[15] = block[39];
 &nbsp;  aux[16] = block[8];
  ;  aux[17] = block[12];
 &nbsp;  aux[18] = block[9];
  ;  aux[19] = block[13];
 &nbsp;  aux[20] = block[10];
 &nbsp;  aux[21] = block[14];
 &nbsp;  aux[22] = block[11];
 &nbsp;  aux[23] = block[15];
 &nbsp;  aux[24] = block[40];
 &nbsp;  aux[25] = block[44];
 &nbsp;  aux[26] = block[41];
 &nbsp;  aux[27] = block[45];
 &nbsp;  aux[28] = block[42];
 &nbsp;  aux[29] = block[46];
 &nbsp;  aux[30] = block[43];
 &nbsp;  aux[31] = block[47];
 &nbsp;  aux[32] = block[16];
 &nbsp;  aux[33] = block[20];
 &nbsp;  aux[34] = block[17];
 &nbsp;  aux[35] = block[21];
 &nbsp;  aux[36] = block[18];
 &nbsp;  aux[37] = block[22];
 &nbsp;  aux[38] = block[19];
 &nbsp;  aux[39] = block[23];
 &nbsp;  aux[40] = block[48];
 &nbsp;  aux[41] = block[52];
 &nbsp;  aux[42] = block[49];
 &nbsp;  aux[43] = block[53];
 &nbsp;  aux[44] = block[50];
 &nbsp;  aux[45] = block[54];
 &nbsp;  aux[46] = block[51];
 &nbsp;  aux[47] = block[55];
 &nbsp;  aux[48] = block[24];
 &nbsp;  aux[49] = block[28];
 &nbsp;  aux[50] = block[25];
 &nbsp;  aux[51] = block[20];
 &nbsp;  aux[52] = block[26];
 &nbsp;  aux[53] = block[30];
 &nbsp;  aux[54] = block[27];
 &nbsp;  aux[55] = block[31];
 &nbsp;  aux[56] = block[56];
 &nbsp;  aux[57] = block[60];
 &nbsp;  aux[58] = block[57];
 &nbsp;  aux[59] = block[61];
 &nbsp;  aux[60] = block[58];
 &nbsp;  aux[61] = block[62];
 &nbsp;  aux[62] = block[59];
 &nbsp;  aux[63] = block[63];
 &nbsp; 
 &nbsp;  int i;
 &nbsp;  for (i = 0; i < 64; ++ i) {
 &nbsp;   &nbsp;  block[i] = aux[i] / 16;
   ; }
}

2007/11/30, Mateus Krepsky Ludwich < mkludwichgmail.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">mkludwichgmail.com>:
Hi,
&nbsp;   I see in pratice and in emails of the past
([mpeg2-dev] Re: mpeg2-dev Scan order - 2004-02-19, and
Re: [mpeg2-dev] about the idct! - 2004-04-30)
that the IDCT of two dimensions performed by idct_row and idct_col operating
together (how we can see in mpeg2_idct_copy_c and mpeg2_idct_copy_add), in
libmpeg2 are different of a "default" IDCT (DCT type-3). But in a experiment
that I have to do, I would like to use the "default" IDCT. So I need
by pass the modifications done in a block before do the IDCT or apply a
function that remove this modifications. But I don't know what modifications
exist, strictly speaking. I see that mpeg2_idct_init changes the order of
mpeg2_scan_norm and mpeg2_scan_alt, and functions that "reconstructs&quot; the
block, like get_intra_block_B14 use this vectors. So I can see a reordering of
block in here. Where are and who are the others modifications?
&nbsp;   Another question, the values of block parameter in mpeg2_idct_copy_c and
mpeg2_idct_add_c functions, after the loop that do the IDCT:
&quot; for (i = 0; i < 8; i++)
 ;   idct_row (block + 8 * i);
   ; for (i = 0; i < 8; i++)
&nbsp;   idct_col (block + i); "
are the same if I use a "default" IDCT, right? Because the IDCTs "at the end"
must be the same, right?

Thanks!

Mateus Krepsky Ludwich.

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )