Renamed package to Jirac
[jirac.git] / org / diracvideo / Jirac / Parameters.java
blob405fbe4a10e0800df7875c74b01483a9ce2a0523
1 package org.diracvideo.Jirac;
2 import java.awt.Dimension;
4 class Parameters {
5 /* static array of wavelets */
6 private static Wavelet[] wavs = {
7 new DeslauriesDebuc9_7(),
8 new LeGall5_3(),
9 new DeslauriesDebuc13_7(),
10 new HaarNoShift(),
11 new HaarSingleShift(),
12 new Fidelity(),
13 new Daubechies9_7(),
14 new Wavelet()
17 /* Wavelet transform parameters */
18 public int transformDepth = 4, wavelet_index;
19 public int codeblock_mode_index = 0;
20 public boolean no_ac, is_ref, is_lowdelay, is_intra;
21 public int[] horiz_codeblocks = new int[7],
22 vert_codeblocks = new int[7];
23 public int num_refs;
24 public Dimension iwtLumaSize, iwtChromaSize;
25 /* Motion prediction parametrs */
26 public int xblen_luma, yblen_luma,
27 xbsep_luma, ybsep_luma;
28 public int x_num_blocks, y_num_blocks,
29 x_offset, y_offset;
30 public boolean have_global_motion;
31 public int picture_prediction_mode, mv_precision;
32 public int picture_weight_bits = 1,
33 picture_weight_1 = 1,picture_weight_2 = 1;
34 public Global global[] = new Global[2];
36 public Parameters(int c) {
37 no_ac = !((c & 0x48) == 0x8);
38 num_refs = (c & 0x3);
39 is_ref = (c & 0x0c) == 0x0c;
40 is_lowdelay = ((c & 0x88) == 0x88);
41 is_intra = (num_refs == 0);
44 public void calculateIwtSizes(VideoFormat format) {
45 int size[] = {0,0};
46 format.getPictureLumaSize(size);
47 iwtLumaSize = new Dimension(Util.roundUpPow2(size[0], transformDepth),
48 Util.roundUpPow2(size[1], transformDepth));
49 format.getPictureChromaSize(size);
50 iwtChromaSize = new Dimension(Util.roundUpPow2(size[0], transformDepth),
51 Util.roundUpPow2(size[1], transformDepth));
54 public void verifyBlockParams() throws Exception {
55 boolean ok = true;
56 ok = ok && xblen_luma >= 0;
57 ok = ok && yblen_luma >= 0;
58 ok = ok && xbsep_luma >= 0;
59 ok = ok && ybsep_luma >= 0;
60 if(!ok) {
61 throw new Exception("Block Paramters incorrect");
65 public void setBlockParams(int i)
66 throws Exception {
67 switch(i) {
68 case 1:
69 xblen_luma = yblen_luma = 8;
70 xbsep_luma = ybsep_luma = 4;
71 break;
72 case 2:
73 xblen_luma = yblen_luma = 12;
74 xbsep_luma = ybsep_luma = 8;
75 break;
76 case 3:
77 xblen_luma = yblen_luma = 16;
78 xbsep_luma = ybsep_luma = 12;
79 break;
80 case 4:
81 xblen_luma = yblen_luma = 24;
82 xbsep_luma = ybsep_luma = 16;
83 break;
84 default:
85 throw new Exception("Unsupported Block Parameters index");
90 public void calculateMCSizes() {
91 x_num_blocks = 4*Util.divideRoundUp(iwtLumaSize.width, 4*xbsep_luma);
92 y_num_blocks = 4*Util.divideRoundUp(iwtLumaSize.height, 4*ybsep_luma);
93 x_offset = (xblen_luma - xbsep_luma)/2;
94 y_offset = (yblen_luma - ybsep_luma)/2;
97 public Wavelet getWavelet() {
98 return wavs[wavelet_index];
101 public String toString() {
102 StringBuilder sb = new StringBuilder();
103 sb.append("\nParameters:\n");
104 sb.append(String.format("Transform depth: %d\n", transformDepth));
105 sb.append(String.format("Using ac: %c\n", (no_ac ? 'n' : 'y')));
106 sb.append(String.format("Is ref: %c", (is_ref ? 'y' : 'n')));
107 for(int i = 0; i < transformDepth; i++) {
108 sb.append(String.format("\nHorizBlocks: %d\tVertBlocks: %d",
109 horiz_codeblocks[i], vert_codeblocks[i]));
111 sb.append(String.format("\nxblen: %d\t yblen: %d", xblen_luma, yblen_luma));
112 sb.append(String.format("\nxbsep: %d\t ybsep: %d", xbsep_luma, ybsep_luma));
113 return sb.toString();