1 |
3 |
hidemi |
//---------------------------------------------------------------------------
|
2 |
|
|
// File Name : jpeg_hm_decode.v
|
3 |
|
|
// Module Name : jpeg_hm_decode
|
4 |
|
|
// Description : Decode of Haffuman data
|
5 |
|
|
// Project : JPEG Decoder
|
6 |
|
|
// Belong to :
|
7 |
|
|
// Author : H.Ishihara
|
8 |
|
|
// E-Mail : hidemi@sweetcafe.jp
|
9 |
|
|
// HomePage : http://www.sweetcafe.jp/
|
10 |
|
|
// Date : 2006/10/01
|
11 |
|
|
// Rev. : 1.1
|
12 |
|
|
//---------------------------------------------------------------------------
|
13 |
|
|
// Rev. Date Description
|
14 |
|
|
//---------------------------------------------------------------------------
|
15 |
|
|
// 1.01 2006/10/01 1st Release
|
16 |
|
|
// 1.02 2006/10/04 move for a comment widh OutData,OutDhtNumber register.
|
17 |
|
|
// remove a ProcessColorNumber,tempPlace register.
|
18 |
|
|
//---------------------------------------------------------------------------
|
19 |
|
|
// $Id:
|
20 |
|
|
//---------------------------------------------------------------------------
|
21 |
|
|
`timescale 1ps / 1ps
|
22 |
|
|
|
23 |
|
|
module jpeg_hm_decode
|
24 |
|
|
(
|
25 |
|
|
rst, // Reset
|
26 |
|
|
clk, // Clock
|
27 |
|
|
|
28 |
|
|
// Haffuman Table
|
29 |
|
|
HaffumanTableEnable, // Table Data In Enable
|
30 |
|
|
HaffumanTableColor, // Haffuman Table Color Number
|
31 |
|
|
HaffumanTableCount, // Table Number
|
32 |
|
|
HaffumanTableCode, // Haffuman Table Code
|
33 |
|
|
HaffumanTableStart, // Haffuman Table Start Number
|
34 |
|
|
|
35 |
|
|
// Haffuman Decode
|
36 |
|
|
DataInRun, // Data In Start
|
37 |
|
|
DataInEnable, // Data In Enable
|
38 |
|
|
DataIn, // Data In
|
39 |
|
|
|
40 |
|
|
// DHT table
|
41 |
|
|
DhtColor, // Color Number
|
42 |
|
|
DhtNumber, // Decode Dht Number
|
43 |
|
|
DhtZero, // Zero Count of Dht Number
|
44 |
|
|
DhtWidth, // Data Width of Dht Number
|
45 |
|
|
|
46 |
|
|
// DQT Table
|
47 |
|
|
DqtColor, // Color Number
|
48 |
|
|
DqtNumber, // Dqt Number
|
49 |
|
|
DqtData, // Dqt Data
|
50 |
|
|
|
51 |
|
|
//
|
52 |
|
|
DataOutIdle,
|
53 |
|
|
DataOutEnable,
|
54 |
|
|
DataOutColor,
|
55 |
|
|
|
56 |
|
|
// Output decode data
|
57 |
|
|
DecodeUseBit, // Used Data Bit
|
58 |
|
|
DecodeUseWidth, // Used Data Width
|
59 |
|
|
DecodeEnable, // Data Out Enable
|
60 |
|
|
DecodeColor, // Data Out Enable
|
61 |
|
|
DecodeCount, // Data Out Enable
|
62 |
|
|
DecodeZero, // Data Out with Zero Count
|
63 |
|
|
DecodeCode // Data Out with Code
|
64 |
|
|
);
|
65 |
|
|
|
66 |
|
|
//--------------------------------------------------------------------------
|
67 |
|
|
// Input/Output
|
68 |
|
|
//--------------------------------------------------------------------------
|
69 |
|
|
input rst,clk; // Reset and Clock
|
70 |
|
|
input HaffumanTableEnable; // Table Data In Enable
|
71 |
|
|
input [1:0] HaffumanTableColor;
|
72 |
|
|
input [3:0] HaffumanTableCount; // Table Number
|
73 |
|
|
input [15:0] HaffumanTableCode; // Haffuman Table Data
|
74 |
|
|
input [7:0] HaffumanTableStart; // Haffuman Table Start Number
|
75 |
|
|
|
76 |
|
|
input DataInRun;
|
77 |
|
|
input DataInEnable; // Data In Enable
|
78 |
|
|
input [31:0] DataIn; // Data In
|
79 |
|
|
|
80 |
|
|
output [1:0] DhtColor;
|
81 |
|
|
output [7:0] DhtNumber; // Decode Dht Number
|
82 |
|
|
input [3:0] DhtZero; // Zero Count of Dht Number
|
83 |
|
|
input [3:0] DhtWidth; // Data Width of Dht Number
|
84 |
|
|
|
85 |
|
|
output DqtColor;
|
86 |
|
|
output [5:0] DqtNumber;
|
87 |
|
|
input [7:0] DqtData;
|
88 |
|
|
|
89 |
|
|
input DataOutIdle;
|
90 |
|
|
output DataOutEnable;
|
91 |
|
|
output [2:0] DataOutColor;
|
92 |
|
|
|
93 |
|
|
|
94 |
|
|
output DecodeUseBit;
|
95 |
|
|
output [6:0] DecodeUseWidth; // Used Data Width
|
96 |
|
|
output DecodeEnable; // Data Out Enable
|
97 |
|
|
output [2:0] DecodeColor;
|
98 |
|
|
output [5:0] DecodeCount;
|
99 |
|
|
output [3:0] DecodeZero; // Data Out with Zero Count
|
100 |
|
|
output [15:0] DecodeCode; // Data Out with Code
|
101 |
|
|
|
102 |
|
|
//--------------------------------------------------------------------------
|
103 |
|
|
// Register Haffuman Table(YCbCr)
|
104 |
|
|
//--------------------------------------------------------------------------
|
105 |
|
|
// Y-DC Haffuman Table
|
106 |
|
|
reg [15:0] HaffumanTable0r [0:15]; // Y-DC Haffuman Table
|
107 |
|
|
reg [15:0] HaffumanTable1r [0:15]; // Y-AC Haffuman Table
|
108 |
|
|
reg [15:0] HaffumanTable2r [0:15]; // C-DC Haffuman Table
|
109 |
|
|
reg [15:0] HaffumanTable3r [0:15]; // C-AC Haffuman Table
|
110 |
|
|
|
111 |
|
|
reg [15:0] HaffumanNumber0r [0:15]; // Y-DC Haffuman Number
|
112 |
|
|
reg [15:0] HaffumanNumber1r [0:15]; // Y-AC Haffuman Number
|
113 |
|
|
reg [15:0] HaffumanNumber2r [0:15]; // C-DC Haffuman Number
|
114 |
|
|
reg [15:0] HaffumanNumber3r [0:15]; // C-AC Haffuman Number
|
115 |
|
|
|
116 |
|
|
integer i;
|
117 |
|
|
|
118 |
|
|
always @(posedge clk or negedge rst) begin
|
119 |
|
|
if(!rst) begin
|
120 |
|
|
for(i=0;i<16;i=i+1) begin
|
121 |
|
|
HaffumanTable0r[0] <= 16'h0000;
|
122 |
|
|
HaffumanNumber0r[0] <= 8'h00;
|
123 |
|
|
HaffumanTable1r[0] <= 16'h0000;
|
124 |
|
|
HaffumanNumber1r[0] <= 8'h00;
|
125 |
|
|
HaffumanTable2r[0] <= 16'h0000;
|
126 |
|
|
HaffumanNumber2r[0] <= 8'h00;
|
127 |
|
|
HaffumanTable3r[0] <= 16'h0000;
|
128 |
|
|
HaffumanNumber3r[0] <= 8'h00;
|
129 |
|
|
end
|
130 |
|
|
end else begin // if (!rst)
|
131 |
|
|
if(HaffumanTableEnable ==2'b1) begin
|
132 |
|
|
if(HaffumanTableColor ==2'b00) begin
|
133 |
|
|
HaffumanTable0r[HaffumanTableCount] <= HaffumanTableCode;
|
134 |
|
|
HaffumanNumber0r[HaffumanTableCount] <= HaffumanTableStart;
|
135 |
|
|
end else if(HaffumanTableColor ==2'b01) begin
|
136 |
|
|
HaffumanTable1r[HaffumanTableCount] <= HaffumanTableCode;
|
137 |
|
|
HaffumanNumber1r[HaffumanTableCount] <= HaffumanTableStart;
|
138 |
|
|
end else if(HaffumanTableColor ==2'b10) begin
|
139 |
|
|
HaffumanTable2r[HaffumanTableCount] <= HaffumanTableCode;
|
140 |
|
|
HaffumanNumber2r[HaffumanTableCount] <= HaffumanTableStart;
|
141 |
|
|
end else begin
|
142 |
|
|
HaffumanTable3r[HaffumanTableCount] <= HaffumanTableCode;
|
143 |
|
|
HaffumanNumber3r[HaffumanTableCount] <= HaffumanTableStart;
|
144 |
|
|
end
|
145 |
|
|
end // if (HaffumanTableEnable ==2'b1)
|
146 |
|
|
end // else: !if(!rst)
|
147 |
|
|
end // always @ (posedge clk or negedge rst)
|
148 |
|
|
|
149 |
|
|
//--------------------------------------------------------------------------
|
150 |
|
|
// Decode Process
|
151 |
|
|
//--------------------------------------------------------------------------
|
152 |
|
|
reg [3:0] Process; // Process State
|
153 |
|
|
reg [31:0] ProcessData; // Data
|
154 |
|
|
|
155 |
|
|
// Haffuman Table
|
156 |
|
|
reg [15:0] HaffumanTable [0:15];
|
157 |
|
|
// Haffuman Table Number
|
158 |
|
|
reg [7:0] HaffumanNumber [0:15];
|
159 |
|
|
|
160 |
|
|
reg [15:0] Place; // Place bit
|
161 |
|
|
reg [15:0] TableCode; // Table Code
|
162 |
|
|
reg [7:0] NumberCode; // Start Number of Table Code
|
163 |
|
|
reg [3:0] CodeNumber; // Haffuman code width
|
164 |
|
|
reg [15:0] DataNumber; // Haffuman code
|
165 |
|
|
//reg [15:0] SubData; // Haffuman Dht Number
|
166 |
|
|
|
167 |
|
|
//reg [7:0] OutDhtNumber; // Output Dht Number
|
168 |
|
|
|
169 |
|
|
reg [2:0] ProcessColor;
|
170 |
|
|
reg [6:0] ProcessCount;
|
171 |
|
|
reg [6:0] NextProcessCount;
|
172 |
|
|
|
173 |
|
|
reg OutEnable; // Output Enable
|
174 |
|
|
reg [3:0] OutZero; // Output Zero Count
|
175 |
|
|
reg [15:0] OutCode; // Output Data Code
|
176 |
|
|
reg [15:0] OutCodeP; // Output Data Code
|
177 |
|
|
|
178 |
|
|
reg [4:0] UseWidth; // Output used width
|
179 |
|
|
|
180 |
|
|
//reg [23:0] OutData;
|
181 |
|
|
|
182 |
|
|
reg DataOutEnable;
|
183 |
|
|
reg [2:0] DataOutColor;
|
184 |
|
|
|
185 |
|
|
reg signed [31:0] PreData [0:2];
|
186 |
|
|
|
187 |
|
|
reg [15:0] SubCode;
|
188 |
|
|
|
189 |
|
|
parameter ProcIdle = 4'h0;
|
190 |
|
|
parameter Phase1 = 4'h1;
|
191 |
|
|
parameter Phase2 = 4'h2;
|
192 |
|
|
parameter Phase3 = 4'h3;
|
193 |
|
|
parameter Phase4 = 4'h4;
|
194 |
|
|
parameter Phase5 = 4'h5;
|
195 |
|
|
parameter Phase6 = 4'h6;
|
196 |
|
|
parameter Phase7 = 4'h7;
|
197 |
|
|
parameter Phase8 = 4'h8;
|
198 |
|
|
parameter Phase9 = 4'h9;
|
199 |
|
|
parameter Phase10 = 4'hA;
|
200 |
|
|
parameter Phase11 = 4'hB;
|
201 |
|
|
|
202 |
|
|
always @(*) begin
|
203 |
|
|
case (DhtWidth)
|
204 |
|
|
4'h0: OutCodeP <= 16'h0000;
|
205 |
|
|
4'h1: OutCodeP <= {15'h0000,ProcessData[31]};
|
206 |
|
|
4'h2: OutCodeP <= {14'h0000,ProcessData[31:30]};
|
207 |
|
|
4'h3: OutCodeP <= {13'h0000,ProcessData[31:29]};
|
208 |
|
|
4'h4: OutCodeP <= {12'h000, ProcessData[31:28]};
|
209 |
|
|
4'h5: OutCodeP <= {11'h000, ProcessData[31:27]};
|
210 |
|
|
4'h6: OutCodeP <= {10'h000, ProcessData[31:26]};
|
211 |
|
|
4'h7: OutCodeP <= {9'h000, ProcessData[31:25]};
|
212 |
|
|
4'h8: OutCodeP <= {8'h00, ProcessData[31:24]};
|
213 |
|
|
4'h9: OutCodeP <= {7'h00, ProcessData[31:23]};
|
214 |
|
|
4'hA: OutCodeP <= {6'h00, ProcessData[31:22]};
|
215 |
|
|
4'hB: OutCodeP <= {5'h00, ProcessData[31:21]};
|
216 |
|
|
4'hC: OutCodeP <= {4'h0, ProcessData[31:20]};
|
217 |
|
|
4'hD: OutCodeP <= {3'h0, ProcessData[31:19]};
|
218 |
|
|
4'hE: OutCodeP <= {2'h0, ProcessData[31:18]};
|
219 |
|
|
4'hF: OutCodeP <= {1'h0, ProcessData[31:17]};
|
220 |
|
|
endcase // case(DhtWidth)
|
221 |
|
|
case (DhtWidth)
|
222 |
|
|
4'h0: SubCode <= 16'hFFFF;
|
223 |
|
|
4'h1: SubCode <= 16'hFFFE;
|
224 |
|
|
4'h2: SubCode <= 16'hFFFC;
|
225 |
|
|
4'h3: SubCode <= 16'hFFF8;
|
226 |
|
|
4'h4: SubCode <= 16'hFFF0;
|
227 |
|
|
4'h5: SubCode <= 16'hFFE0;
|
228 |
|
|
4'h6: SubCode <= 16'hFFC0;
|
229 |
|
|
4'h7: SubCode <= 16'hFF80;
|
230 |
|
|
4'h8: SubCode <= 16'hFF00;
|
231 |
|
|
4'h9: SubCode <= 16'hFE00;
|
232 |
|
|
4'hA: SubCode <= 16'hFC00;
|
233 |
|
|
4'hB: SubCode <= 16'hF800;
|
234 |
|
|
4'hC: SubCode <= 16'hF000;
|
235 |
|
|
4'hD: SubCode <= 16'hE000;
|
236 |
|
|
4'hE: SubCode <= 16'hC000;
|
237 |
|
|
4'hF: SubCode <= 16'h8000;
|
238 |
|
|
endcase // case(DhtWidth)
|
239 |
|
|
end // always @ (*)
|
240 |
|
|
|
241 |
|
|
|
242 |
|
|
always @(posedge clk or negedge rst) begin
|
243 |
|
|
if(!rst) begin
|
244 |
|
|
Process <= ProcIdle;
|
245 |
|
|
ProcessData <= 32'h00000000;
|
246 |
|
|
OutEnable <= 1'b0;
|
247 |
|
|
DataOutEnable <= 1'b0;
|
248 |
|
|
DataOutColor <= 3'b000;
|
249 |
|
|
PreData[0] <= 32'h00000000;
|
250 |
|
|
PreData[1] <= 32'h00000000;
|
251 |
|
|
PreData[2] <= 32'h00000000;
|
252 |
|
|
UseWidth <= 7'h00;
|
253 |
|
|
end else begin // if (!rst)
|
254 |
|
|
case (Process)
|
255 |
|
|
ProcIdle: begin
|
256 |
|
|
if(DataInRun == 1'b1) begin
|
257 |
|
|
Process <= Phase1;
|
258 |
|
|
end else begin
|
259 |
|
|
// Reset DC code
|
260 |
|
|
PreData[0] <= 32'h00000000;
|
261 |
|
|
PreData[1] <= 32'h00000000;
|
262 |
|
|
PreData[2] <= 32'h00000000;
|
263 |
|
|
end
|
264 |
|
|
OutEnable <= 1'b0;
|
265 |
|
|
ProcessColor <= 3'b000;
|
266 |
|
|
ProcessCount <= 0;
|
267 |
|
|
DataOutEnable <= 1'b0;
|
268 |
|
|
DataOutColor <= 3'b000;
|
269 |
|
|
end // case: ProcIdle
|
270 |
|
|
// get a table-data and table-number
|
271 |
|
|
Phase1: begin
|
272 |
|
|
if(DataInEnable ==1'b1 & DataOutIdle == 1'b1) begin
|
273 |
|
|
Process <= Phase2;
|
274 |
|
|
ProcessData <= DataIn;
|
275 |
|
|
end
|
276 |
|
|
OutEnable <= 1'b0;
|
277 |
|
|
DataOutEnable <= 1'b0;
|
278 |
|
|
if(ProcessColor[2] == 1'b0) begin
|
279 |
|
|
if(ProcessCount == 0) begin
|
280 |
|
|
for(i=0;i<16;i=i+1) begin
|
281 |
|
|
HaffumanTable[i] <= HaffumanTable0r[i];
|
282 |
|
|
HaffumanNumber[i] <= HaffumanNumber0r[i];
|
283 |
|
|
end
|
284 |
|
|
end else begin
|
285 |
|
|
for(i=0;i<16;i=i+1) begin
|
286 |
|
|
HaffumanTable[i] <= HaffumanTable1r[i];
|
287 |
|
|
HaffumanNumber[i] <= HaffumanNumber1r[i];
|
288 |
|
|
end
|
289 |
|
|
end // else: !if(ProcessCount == 0)
|
290 |
|
|
end else begin // if (ProcessColor[2] == 1'b0)
|
291 |
|
|
if(ProcessCount == 0) begin
|
292 |
|
|
for(i=0;i<16;i=i+1) begin
|
293 |
|
|
HaffumanTable[i] <= HaffumanTable2r[i];
|
294 |
|
|
HaffumanNumber[i] <= HaffumanNumber2r[i];
|
295 |
|
|
end
|
296 |
|
|
end else begin
|
297 |
|
|
for(i=0;i<16;i=i+1) begin
|
298 |
|
|
HaffumanTable[i] <= HaffumanTable3r[i];
|
299 |
|
|
HaffumanNumber[i] <= HaffumanNumber3r[i];
|
300 |
|
|
end
|
301 |
|
|
end // else: !if(ProcessCount == 0)
|
302 |
|
|
end // else: !if(ProcessColor[2] == 1'b0)
|
303 |
|
|
end // case: Phase1
|
304 |
|
|
// compare table
|
305 |
|
|
Phase2: begin
|
306 |
|
|
Process <= Phase4;
|
307 |
|
|
for(i=0;i<16;i=i+1) begin
|
308 |
|
|
if(ProcessData[31:16] >= HaffumanTable[i])
|
309 |
|
|
Place[i] <= 1'b1;
|
310 |
|
|
else
|
311 |
|
|
Place[i] <= 1'b0;
|
312 |
|
|
end
|
313 |
|
|
end
|
314 |
|
|
// shift code
|
315 |
|
|
Phase4: begin
|
316 |
|
|
Process <= Phase6;
|
317 |
|
|
case (Place)
|
318 |
|
|
16'b0000000000000001: begin
|
319 |
|
|
TableCode <= {15'h0000,HaffumanTable[0][15]};
|
320 |
|
|
NumberCode <= HaffumanNumber[0];
|
321 |
|
|
CodeNumber <= 4'h0;
|
322 |
|
|
DataNumber <= {15'h0000,ProcessData[31]};
|
323 |
|
|
ProcessData <= {ProcessData[30:0],1'b0};
|
324 |
|
|
end
|
325 |
|
|
16'b0000000000000011: begin
|
326 |
|
|
TableCode <= {14'h0000,HaffumanTable[1][15:14]};
|
327 |
|
|
NumberCode <= HaffumanNumber[1];
|
328 |
|
|
CodeNumber <= 4'h1;
|
329 |
|
|
DataNumber <= {14'h0000,ProcessData[31:30]};
|
330 |
|
|
ProcessData <= {ProcessData[29:0],2'b00};
|
331 |
|
|
end
|
332 |
|
|
16'b0000000000000111: begin
|
333 |
|
|
TableCode <= {13'h0000,HaffumanTable[2][15:13]};
|
334 |
|
|
NumberCode <= HaffumanNumber[2];
|
335 |
|
|
CodeNumber <= 4'h2;
|
336 |
|
|
DataNumber <= {13'h0000,ProcessData[31:29]};
|
337 |
|
|
ProcessData <= {ProcessData[28:0],3'b000};
|
338 |
|
|
end
|
339 |
|
|
16'b0000000000001111: begin
|
340 |
|
|
TableCode <= {12'h000,HaffumanTable[3][15:12]};
|
341 |
|
|
NumberCode <= HaffumanNumber[3];
|
342 |
|
|
CodeNumber <= 4'h3;
|
343 |
|
|
DataNumber <= {12'h000,ProcessData[31:28]};
|
344 |
|
|
ProcessData <= {ProcessData[27:0],4'h0};
|
345 |
|
|
end
|
346 |
|
|
16'b0000000000011111: begin
|
347 |
|
|
TableCode <= {11'h000,HaffumanTable[4][15:11]};
|
348 |
|
|
NumberCode <= HaffumanNumber[4];
|
349 |
|
|
CodeNumber <= 4'h4;
|
350 |
|
|
DataNumber <= {11'h000,ProcessData[31:27]};
|
351 |
|
|
ProcessData <= {ProcessData[26:0],5'h00};
|
352 |
|
|
end
|
353 |
|
|
16'b0000000000111111: begin
|
354 |
|
|
TableCode <= {10'h000,HaffumanTable[5][15:10]};
|
355 |
|
|
NumberCode <= HaffumanNumber[5];
|
356 |
|
|
CodeNumber <= 4'h5;
|
357 |
|
|
DataNumber <= {10'h000,ProcessData[31:26]};
|
358 |
|
|
ProcessData <= {ProcessData[25:0],6'h00};
|
359 |
|
|
end
|
360 |
|
|
16'b0000000001111111: begin
|
361 |
|
|
TableCode <= {9'h000,HaffumanTable[6][15:9]};
|
362 |
|
|
NumberCode <= HaffumanNumber[6];
|
363 |
|
|
CodeNumber <= 4'h6;
|
364 |
|
|
DataNumber <= {9'h000,ProcessData[31:25]};
|
365 |
|
|
ProcessData <= {ProcessData[24:0],7'h00};
|
366 |
|
|
end
|
367 |
|
|
16'b0000000011111111: begin
|
368 |
|
|
TableCode <= {8'h00,HaffumanTable[7][15:8]};
|
369 |
|
|
NumberCode <= HaffumanNumber[7];
|
370 |
|
|
CodeNumber <= 4'h7;
|
371 |
|
|
DataNumber <= {8'h00,ProcessData[31:24]};
|
372 |
|
|
ProcessData <= {ProcessData[23:0],8'h00};
|
373 |
|
|
end
|
374 |
|
|
16'b0000000111111111: begin
|
375 |
|
|
TableCode <= {7'h00,HaffumanTable[8][15:7]};
|
376 |
|
|
NumberCode <= HaffumanNumber[8];
|
377 |
|
|
CodeNumber <= 4'h8;
|
378 |
|
|
DataNumber <= {7'h00,ProcessData[31:23]};
|
379 |
|
|
ProcessData <= {ProcessData[22:0],9'h000};
|
380 |
|
|
end
|
381 |
|
|
16'b0000001111111111: begin
|
382 |
|
|
TableCode <= {6'h00,HaffumanTable[9][15:6]};
|
383 |
|
|
NumberCode <= HaffumanNumber[9];
|
384 |
|
|
CodeNumber <= 4'h9;
|
385 |
|
|
DataNumber <= {6'h00,ProcessData[31:22]};
|
386 |
|
|
ProcessData <= {ProcessData[21:0],10'h000};
|
387 |
|
|
end
|
388 |
|
|
16'b0000011111111111: begin
|
389 |
|
|
TableCode <= {5'h00,HaffumanTable[10][15:5]};
|
390 |
|
|
NumberCode <= HaffumanNumber[10];
|
391 |
|
|
CodeNumber <= 4'hA;
|
392 |
|
|
DataNumber <= {5'h00,ProcessData[31:21]};
|
393 |
|
|
ProcessData <= {ProcessData[20:0],11'h000};
|
394 |
|
|
end
|
395 |
|
|
16'b0000111111111111: begin
|
396 |
|
|
TableCode <= {4'h0,HaffumanTable[11][15:4]};
|
397 |
|
|
NumberCode <= HaffumanNumber[11];
|
398 |
|
|
CodeNumber <= 4'hB;
|
399 |
|
|
DataNumber <= {4'h0,ProcessData[31:20]};
|
400 |
|
|
ProcessData <= {ProcessData[19:0],12'h000};
|
401 |
|
|
end
|
402 |
|
|
16'b0001111111111111: begin
|
403 |
|
|
TableCode <= {3'h0,HaffumanTable[12][15:3]};
|
404 |
|
|
NumberCode <= HaffumanNumber[12];
|
405 |
|
|
CodeNumber <= 4'hC;
|
406 |
|
|
DataNumber <= {3'h0,ProcessData[31:19]};
|
407 |
|
|
ProcessData <= {ProcessData[18:0],13'h0000};
|
408 |
|
|
end
|
409 |
|
|
16'b0011111111111111: begin
|
410 |
|
|
TableCode <= {2'h0,HaffumanTable[13][15:2]};
|
411 |
|
|
NumberCode <= HaffumanNumber[13];
|
412 |
|
|
CodeNumber <= 4'hD;
|
413 |
|
|
DataNumber <= {2'h0,ProcessData[31:18]};
|
414 |
|
|
ProcessData <= {ProcessData[17:0],14'h0000};
|
415 |
|
|
end
|
416 |
|
|
16'b0111111111111111: begin
|
417 |
|
|
TableCode <= {1'h0,HaffumanTable[14][15:1]};
|
418 |
|
|
NumberCode <= HaffumanNumber[14];
|
419 |
|
|
CodeNumber <= 4'hE;
|
420 |
|
|
DataNumber <= {1'h0,ProcessData[31:17]};
|
421 |
|
|
ProcessData <= {ProcessData[16:0],15'h0000};
|
422 |
|
|
end
|
423 |
|
|
16'b1111111111111111: begin
|
424 |
|
|
TableCode <= HaffumanTable[15];
|
425 |
|
|
NumberCode <= HaffumanNumber[15];
|
426 |
|
|
CodeNumber <= 4'hF;
|
427 |
|
|
DataNumber <= ProcessData[31:16] ;
|
428 |
|
|
ProcessData <= {ProcessData[15:0],16'h0000};
|
429 |
|
|
end
|
430 |
|
|
endcase // case(Place)
|
431 |
|
|
end // case: Phase4
|
432 |
|
|
Phase5: begin
|
433 |
|
|
Process <= Phase6;
|
434 |
|
|
//SubData <= DataNumber - TableCode;
|
435 |
|
|
//OutDhtNumber <= DataNumber - TableCode + NumberCode;
|
436 |
|
|
end
|
437 |
|
|
Phase6: begin
|
438 |
|
|
if(DataOutIdle == 1'b1) Process <= Phase7;
|
439 |
|
|
//DhtNumber <= SubData[7:0] + NumberCode;
|
440 |
|
|
end
|
441 |
|
|
Phase7: begin
|
442 |
|
|
Process <= Phase9;
|
443 |
|
|
OutZero <= DhtZero;
|
444 |
|
|
UseWidth <= CodeNumber + DhtWidth +1;
|
445 |
|
|
if(ProcessCount == 0) begin
|
446 |
|
|
NextProcessCount <= 7'd1;
|
447 |
|
|
OutEnable <= 1'b1;
|
448 |
|
|
end else begin
|
449 |
|
|
if(DhtZero == 4'h0 & DhtWidth == 4'h0) begin
|
450 |
|
|
ProcessCount <= 7'd64;
|
451 |
|
|
NextProcessCount <= 7'd64;
|
452 |
|
|
OutEnable <= 1'b0;
|
453 |
|
|
end else if(DhtZero == 4'hF & DhtWidth == 4'h0) begin
|
454 |
|
|
ProcessCount <= ProcessCount + 4'hF;
|
455 |
|
|
NextProcessCount <= ProcessCount + 4'hF;
|
456 |
|
|
OutEnable <= 1'b0;
|
457 |
|
|
end else begin
|
458 |
|
|
ProcessCount <= ProcessCount + DhtZero;
|
459 |
|
|
NextProcessCount <= ProcessCount + DhtZero +1;
|
460 |
|
|
OutEnable <= 1'b1;
|
461 |
|
|
end
|
462 |
|
|
end // else: !if(ProcessCount == 0)
|
463 |
|
|
|
464 |
|
|
if(ProcessData[31] == 1'b0 & DhtWidth != 0) begin
|
465 |
|
|
OutCode <= (OutCodeP | SubCode) + 16'h0001;
|
466 |
|
|
end else begin
|
467 |
|
|
OutCode <= OutCodeP;
|
468 |
|
|
end
|
469 |
|
|
end // case: Phase7
|
470 |
|
|
Phase8: begin
|
471 |
|
|
Process <= Phase9;
|
472 |
|
|
end
|
473 |
|
|
Phase9: begin
|
474 |
|
|
Process <= Phase11;
|
475 |
|
|
if(ProcessCount == 0) begin
|
476 |
|
|
if(ProcessColor[2] == 1'b0) begin
|
477 |
|
|
OutCode <= OutCode + PreData[0];
|
478 |
|
|
PreData[0] <= OutCode + PreData[0];
|
479 |
|
|
end else begin
|
480 |
|
|
if(ProcessColor[0] == 1'b0) begin
|
481 |
|
|
OutCode <= OutCode + PreData[1];
|
482 |
|
|
PreData[1] <= OutCode + PreData[1];
|
483 |
|
|
end else begin
|
484 |
|
|
OutCode <= OutCode + PreData[2];
|
485 |
|
|
PreData[2] <= OutCode + PreData[2];
|
486 |
|
|
end
|
487 |
|
|
end // else: !if(ProcessColor[2] == 1'b0)
|
488 |
|
|
end // if (ProcessCount == 0)
|
489 |
|
|
end // case: Phase9
|
490 |
|
|
Phase10: begin
|
491 |
|
|
Process <= Phase11;
|
492 |
|
|
//OutData <= DqtData * OutCode;
|
493 |
|
|
end
|
494 |
|
|
Phase11: begin
|
495 |
|
|
OutEnable <= 1'b0;
|
496 |
|
|
if(NextProcessCount <64) begin
|
497 |
|
|
Process <= Phase1;
|
498 |
|
|
ProcessCount <= NextProcessCount;
|
499 |
|
|
end else begin
|
500 |
|
|
ProcessCount <= 7'd0;
|
501 |
|
|
DataOutEnable <= 1'b1;
|
502 |
|
|
DataOutColor <= ProcessColor;
|
503 |
|
|
if(ProcessColor == 5) begin
|
504 |
|
|
ProcessColor <= 3'b000;
|
505 |
|
|
if(DataInRun == 1'b0) Process <= ProcIdle;
|
506 |
|
|
else Process <= Phase1;
|
507 |
|
|
end else begin
|
508 |
|
|
Process <= Phase1;
|
509 |
|
|
ProcessColor <= ProcessColor +1;
|
510 |
|
|
end
|
511 |
|
|
end // else: !if(NextProcessCount <64)
|
512 |
|
|
end // case: Phase11
|
513 |
|
|
endcase // case(Process)
|
514 |
|
|
end // else: !if(!rst)
|
515 |
|
|
end // always @ (posedge clk or negedge rst)
|
516 |
|
|
|
517 |
|
|
assign DhtColor[1] = ProcessColor[2];
|
518 |
|
|
assign DhtColor[0] = ProcessCount != 0;
|
519 |
|
|
//assign DhtNumber = OutDhtNumber[7:0];
|
520 |
|
|
assign DhtNumber = DataNumber - TableCode + NumberCode;
|
521 |
|
|
|
522 |
|
|
assign DqtColor = ProcessColor[2];
|
523 |
|
|
assign DqtNumber = ProcessCount[5:0];
|
524 |
|
|
|
525 |
|
|
//assign DecodeUseBit = Process == Phase8;
|
526 |
|
|
assign DecodeUseBit = Process == Phase9;
|
527 |
|
|
assign DecodeUseWidth = UseWidth;
|
528 |
|
|
|
529 |
|
|
assign DecodeEnable = OutEnable == 1'b1 & Process == Phase11;
|
530 |
|
|
assign DecodeColor = ProcessColor;
|
531 |
|
|
assign DecodeCount = ProcessCount[5:0];
|
532 |
|
|
assign DecodeZero = OutZero;
|
533 |
|
|
//assign DecodeCode = OutData[15:0];
|
534 |
|
|
assign DecodeCode = DqtData * OutCode;
|
535 |
|
|
|
536 |
|
|
endmodule // jpeg_hm_decode
|