x393  1.0
FPGAcodeforElphelNC393camera
cmprs_tile_mode2_decode.v
Go to the documentation of this file.
1 
40 `timescale 1ns/1ps
41 
43  parameter CMPRS_COLOR18 = 0, // JPEG 4:2:0 with 18x18 overlapping tiles for de-bayer
44  parameter CMPRS_COLOR20 = 1, // JPEG 4:2:0 with 18x18 overlapping tiles for de-bayer (not implemented)
45  parameter CMPRS_MONO16 = 2, // JPEG 4:2:0 with 16x16 non-overlapping tiles, color components zeroed
46  parameter CMPRS_JP4 = 3, // JP4 mode with 16x16 macroblocks
47  parameter CMPRS_JP4DIFF = 4, // JP4DIFF mode TODO: see if correct
48  parameter CMPRS_MONO8 = 7 // Regular JPEG monochrome with 8x8 macroblocks (not yet implemented)
49 )(
50  input xclk,
51  input pre_first_in, // marks the first input pixel
52  input [2:0] converter_type,
53  input [ 1:0] bayer_phase,
55  input hdr,
57  input first_mb_in, // valid @ pre_first_in - reading first macroblock
58  input last_mb_in, // valid @ pre_first_in - reading last macroblock
59 
60 
61  output reg four_blocks, // 1 - 4 blocks, 0 - 6 blocks
62  output reg subtract_dc, // enable subtracting DC components
63  output reg first_mb, // valid @ pre_first_in - reading first macroblock
64  output reg last_mb, // valid @ pre_first_in - reading last macroblock
65 
66  output reg color_enable, // prevent JPEG random colors
67  output reg [5:0] component_numsL, // component_num [0]
68  output reg [5:0] component_numsM, // component_num [1]
69  output reg [5:0] component_numsH, // component_num [2]
70  output reg [5:0] component_colors, // use color quantization table (YCbCR, jp4diff)
71  output reg [5:0] component_first // first_r this component in a frame (DC absolute, otherwise - difference to previous)
72 );
73 
74  reg [2:0] converter_type_r;
76  reg hdr_r;
77  reg [3:0] bayer_phase_onehot;
78  reg first_in;
79  always @ (posedge xclk) begin
81  if (pre_first_in)begin
82  converter_type_r [2:0] <= converter_type[2:0];
84  hdr_r <= hdr;
88  bayer_phase_onehot[3:0]<={(bayer_phase[1:0]==2'h3)?1'b1:1'b0,
89  (bayer_phase[1:0]==2'h2)?1'b1:1'b0,
90  (bayer_phase[1:0]==2'h1)?1'b1:1'b0,
91  (bayer_phase[1:0]==2'h0)?1'b1:1'b0};
92  end
93  if (first_in) begin
94  case (converter_type_r)
95  CMPRS_COLOR18: begin
96  component_numsL <= 6'h10; // component_num [0]
97  component_numsM <= 6'h20; // component_num [1]
98  component_numsH <= 6'h00; // component_num [2]
99  component_colors <= 6'h30; // use color quantization table (YCbCR, jp4diff)
100  component_first <= 6'h31; // first_r this component in a frame (DC absolute, otherwise - difference to previous)
101  four_blocks <= 0; // 6 blocks/maceoblock mode
102  color_enable <= 1'b1;
103  end
104  CMPRS_COLOR20: begin
105  component_numsL <= 6'h10; // component_num [0]
106  component_numsM <= 6'h20; // component_num [1]
107  component_numsH <= 6'h3f; // component_num [2]
108  component_colors <= 6'h30; // use color quantization table (YCbCR, jp4diff)
109  component_first <= 6'h31; // first_r this component in a frame (DC absolute, otherwise - difference to previous)
110  four_blocks <= 0; // 6 blocks/maceoblock mode
111  color_enable <= 1'b1;
112  end
113  CMPRS_MONO16: begin
114  component_numsL <= 6'h10; // component_num [0]
115  component_numsM <= 6'h20; // component_num [1]
116  component_numsH <= 6'h30; // component_num [2]
117  component_colors <= 6'h30; // use color quantization table (YCbCR, jp4diff)
118  component_first <= 6'h31; // first_r this component in a frame (DC absolute, otherwise - difference to previous)
119  four_blocks <= 0; // 6 blocks/maceoblock mode
120  color_enable <= 1'b0;
121  end
122  CMPRS_JP4: begin
123  component_numsL <= jp4_dc_improved_r?6'h0a:6'h10; // LSb of component_num
124  component_numsM <= jp4_dc_improved_r?6'h0c:6'h20; // MSb of component_num
125  component_numsH <= 6'h30; // component_num [2]
126  component_colors <= 6'h30; // use color quantization table (YCbCR, jp4diff)
127  component_first <= jp4_dc_improved_r?6'h3f:6'h31; // first_r this component in a frame (DC absolute, otherwise - difference to previous)
128  four_blocks <= 1; // 4 blocks/maceoblock mode
129  color_enable <= 1'b0;
130  end
131  CMPRS_JP4DIFF: begin
132  component_numsL <= 6'h0a; // LSb of component_num
133  component_numsM <= 6'h0c; // MSb of component_num
134  component_numsH <= 6'h30; // component_num [2]
135  component_colors <= {2'h3,~bayer_phase_onehot[3:0] | (hdr_r? {~bayer_phase_onehot[1:0],~bayer_phase_onehot[3:2]} : 4'h0)}; // use color quantization table (YCbCR, jp4diff)
136  component_first <= 6'h3f; // first_r this component in a frame (DC absolute, otherwise - difference to previous)
137  four_blocks <= 1; // 4 blocks/maceoblock mode
138  color_enable <= 1'b0;
139  end
140 
141  CMPRS_MONO8: begin
142  /*
143  component_numsL <= 6'h00; // TODO: Implement, put actuqal data in this and other fields
144  component_numsM <= 6'h00;
145  component_numsH <= 6'h30;
146  component_colors <= 6'h30;
147  component_first <= 6'h31;
148  color_enable <= 1'b0;
149  */
150  end
151 
152  default: begin
153  component_numsL <= 'bx;
154  component_numsM <= 'bx;
155  component_numsH <= 'bx;
156  component_colors <= 'bx;
157  component_first <= 'bx;
158  four_blocks <= 'bx;
159  color_enable <= 'bx;
160  end
161  endcase
162  end
163  end
164 
165 endmodule
166