1 |
3 |
hidemi |
//---------------------------------------------------------------------------
|
2 |
9 |
hidemi |
// File Name : jpeg_hm_decode.v
|
3 |
|
|
// Module Name : jpeg_hm_decode
|
4 |
|
|
// Description : Decode of Huffman 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 : 2008/03/23
|
11 |
|
|
// Rev. : 2.0
|
12 |
3 |
hidemi |
//---------------------------------------------------------------------------
|
13 |
9 |
hidemi |
// Rev. Date Description
|
14 |
3 |
hidemi |
//---------------------------------------------------------------------------
|
15 |
|
|
// 1.01 2006/10/01 1st Release
|
16 |
|
|
// 1.02 2006/10/04 move for a comment widh OutData,OutDhtNumber register.
|
17 |
9 |
hidemi |
// remove a ProcessColorNumber,tempPlace register.
|
18 |
|
|
// 2.00 2008/03/23 Replace Space.
|
19 |
|
|
// ReTiming DataOutEnable
|
20 |
3 |
hidemi |
//---------------------------------------------------------------------------
|
21 |
|
|
`timescale 1ps / 1ps
|
22 |
|
|
|
23 |
9 |
hidemi |
module jpeg_hm_decode(
|
24 |
|
|
rst, // Reset
|
25 |
|
|
clk, // Clock
|
26 |
3 |
hidemi |
|
27 |
9 |
hidemi |
// Huffman Table
|
28 |
|
|
HuffmanTableEnable, // Table Data In Enable
|
29 |
|
|
HuffmanTableColor, // Huffman Table Color Number
|
30 |
|
|
HuffmanTableCount, // Table Number
|
31 |
|
|
HuffmanTableCode, // Huffman Table Code
|
32 |
|
|
HuffmanTableStart, // Huffman Table Start Number
|
33 |
3 |
hidemi |
|
34 |
9 |
hidemi |
// Huffman Decode
|
35 |
|
|
DataInRun, // Data In Start
|
36 |
|
|
DataInEnable, // Data In Enable
|
37 |
|
|
DataIn, // Data In
|
38 |
3 |
hidemi |
|
39 |
9 |
hidemi |
// DHT table
|
40 |
|
|
DhtColor, // Color Number
|
41 |
|
|
DhtNumber, // Decode Dht Number
|
42 |
|
|
DhtZero, // Zero Count of Dht Number
|
43 |
|
|
DhtWidth, // Data Width of Dht Number
|
44 |
3 |
hidemi |
|
45 |
9 |
hidemi |
// DQT Table
|
46 |
|
|
DqtColor, // Color Number
|
47 |
|
|
DqtNumber, // Dqt Number
|
48 |
|
|
DqtData, // Dqt Data
|
49 |
3 |
hidemi |
|
50 |
9 |
hidemi |
//
|
51 |
|
|
DataOutIdle,
|
52 |
|
|
DataOutEnable,
|
53 |
|
|
DataOutColor,
|
54 |
|
|
|
55 |
|
|
// Output decode data
|
56 |
|
|
DecodeUseBit, // Used Data Bit
|
57 |
|
|
DecodeUseWidth, // Used Data Width
|
58 |
|
|
DecodeEnable, // Data Out Enable
|
59 |
|
|
DecodeColor, // Data Out Enable
|
60 |
|
|
DecodeCount, // Data Out Enable
|
61 |
|
|
DecodeZero, // Data Out with Zero Count
|
62 |
|
|
DecodeCode // Data Out with Code
|
63 |
|
|
);
|
64 |
3 |
hidemi |
|
65 |
9 |
hidemi |
//--------------------------------------------------------------------------
|
66 |
|
|
// Input/Output
|
67 |
|
|
//--------------------------------------------------------------------------
|
68 |
|
|
input rst,clk; // Reset and Clock
|
69 |
|
|
input HuffmanTableEnable; // Table Data In Enable
|
70 |
|
|
input [1:0] HuffmanTableColor;
|
71 |
|
|
input [3:0] HuffmanTableCount; // Table Number
|
72 |
|
|
input [15:0] HuffmanTableCode; // Huffman Table Data
|
73 |
|
|
input [7:0] HuffmanTableStart; // Huffman Table Start Number
|
74 |
3 |
hidemi |
|
75 |
9 |
hidemi |
input DataInRun;
|
76 |
|
|
input DataInEnable; // Data In Enable
|
77 |
|
|
input [31:0] DataIn; // Data In
|
78 |
3 |
hidemi |
|
79 |
9 |
hidemi |
output [1:0] DhtColor;
|
80 |
|
|
output [7:0] DhtNumber; // Decode Dht Number
|
81 |
|
|
input [3:0] DhtZero; // Zero Count of Dht Number
|
82 |
|
|
input [3:0] DhtWidth; // Data Width of Dht Number
|
83 |
3 |
hidemi |
|
84 |
9 |
hidemi |
output DqtColor;
|
85 |
|
|
output [5:0] DqtNumber;
|
86 |
|
|
input [7:0] DqtData;
|
87 |
3 |
hidemi |
|
88 |
9 |
hidemi |
input DataOutIdle;
|
89 |
|
|
output DataOutEnable;
|
90 |
|
|
output [2:0] DataOutColor;
|
91 |
|
|
|
92 |
|
|
output DecodeUseBit;
|
93 |
|
|
output [6:0] DecodeUseWidth; // Used Data Width
|
94 |
|
|
output DecodeEnable; // Data Out Enable
|
95 |
|
|
output [2:0] DecodeColor;
|
96 |
|
|
output [5:0] DecodeCount;
|
97 |
|
|
output [3:0] DecodeZero; // Data Out with Zero Count
|
98 |
|
|
output [15:0] DecodeCode; // Data Out with Code
|
99 |
3 |
hidemi |
|
100 |
9 |
hidemi |
//--------------------------------------------------------------------------
|
101 |
|
|
// Register Huffman Table(YCbCr)
|
102 |
|
|
//--------------------------------------------------------------------------
|
103 |
|
|
// Y-DC Huffman Table
|
104 |
|
|
reg [15:0] HuffmanTable0r [0:15]; // Y-DC Huffman Table
|
105 |
|
|
reg [15:0] HuffmanTable1r [0:15]; // Y-AC Huffman Table
|
106 |
|
|
reg [15:0] HuffmanTable2r [0:15]; // C-DC Huffman Table
|
107 |
|
|
reg [15:0] HuffmanTable3r [0:15]; // C-AC Huffman Table
|
108 |
3 |
hidemi |
|
109 |
9 |
hidemi |
reg [7:0] HuffmanNumber0r [0:15]; // Y-DC Huffman Number
|
110 |
|
|
reg [7:0] HuffmanNumber1r [0:15]; // Y-AC Huffman Number
|
111 |
|
|
reg [7:0] HuffmanNumber2r [0:15]; // C-DC Huffman Number
|
112 |
|
|
reg [7:0] HuffmanNumber3r [0:15]; // C-AC Huffman Number
|
113 |
3 |
hidemi |
|
114 |
9 |
hidemi |
always @(posedge clk or negedge rst) begin
|
115 |
|
|
if(!rst) begin
|
116 |
|
|
HuffmanTable0r[0] <= 16'h0000;
|
117 |
|
|
HuffmanNumber0r[0] <= 8'h00;
|
118 |
|
|
HuffmanTable1r[0] <= 16'h0000;
|
119 |
|
|
HuffmanNumber1r[0] <= 8'h00;
|
120 |
|
|
HuffmanTable2r[0] <= 16'h0000;
|
121 |
|
|
HuffmanNumber2r[0] <= 8'h00;
|
122 |
|
|
HuffmanTable3r[0] <= 16'h0000;
|
123 |
|
|
HuffmanNumber3r[0] <= 8'h00;
|
124 |
5 |
hidemi |
|
125 |
9 |
hidemi |
HuffmanTable0r[1] <= 16'h0000;
|
126 |
|
|
HuffmanNumber0r[1] <= 8'h00;
|
127 |
|
|
HuffmanTable1r[1] <= 16'h0000;
|
128 |
|
|
HuffmanNumber1r[1] <= 8'h00;
|
129 |
|
|
HuffmanTable2r[1] <= 16'h0000;
|
130 |
|
|
HuffmanNumber2r[1] <= 8'h00;
|
131 |
|
|
HuffmanTable3r[1] <= 16'h0000;
|
132 |
|
|
HuffmanNumber3r[1] <= 8'h00;
|
133 |
5 |
hidemi |
|
134 |
9 |
hidemi |
HuffmanTable0r[2] <= 16'h0000;
|
135 |
|
|
HuffmanNumber0r[2] <= 8'h00;
|
136 |
|
|
HuffmanTable1r[2] <= 16'h0000;
|
137 |
|
|
HuffmanNumber1r[2] <= 8'h00;
|
138 |
|
|
HuffmanTable2r[2] <= 16'h0000;
|
139 |
|
|
HuffmanNumber2r[2] <= 8'h00;
|
140 |
|
|
HuffmanTable3r[2] <= 16'h0000;
|
141 |
|
|
HuffmanNumber3r[2] <= 8'h00;
|
142 |
5 |
hidemi |
|
143 |
9 |
hidemi |
HuffmanTable0r[3] <= 16'h0000;
|
144 |
|
|
HuffmanNumber0r[3] <= 8'h00;
|
145 |
|
|
HuffmanTable1r[3] <= 16'h0000;
|
146 |
|
|
HuffmanNumber1r[3] <= 8'h00;
|
147 |
|
|
HuffmanTable2r[3] <= 16'h0000;
|
148 |
|
|
HuffmanNumber2r[3] <= 8'h00;
|
149 |
|
|
HuffmanTable3r[3] <= 16'h0000;
|
150 |
|
|
HuffmanNumber3r[3] <= 8'h00;
|
151 |
5 |
hidemi |
|
152 |
9 |
hidemi |
HuffmanTable0r[4] <= 16'h0000;
|
153 |
|
|
HuffmanNumber0r[4] <= 8'h00;
|
154 |
|
|
HuffmanTable1r[4] <= 16'h0000;
|
155 |
|
|
HuffmanNumber1r[4] <= 8'h00;
|
156 |
|
|
HuffmanTable2r[4] <= 16'h0000;
|
157 |
|
|
HuffmanNumber2r[4] <= 8'h00;
|
158 |
|
|
HuffmanTable3r[4] <= 16'h0000;
|
159 |
|
|
HuffmanNumber3r[4] <= 8'h00;
|
160 |
5 |
hidemi |
|
161 |
9 |
hidemi |
HuffmanTable0r[5] <= 16'h0000;
|
162 |
|
|
HuffmanNumber0r[5] <= 8'h00;
|
163 |
|
|
HuffmanTable1r[5] <= 16'h0000;
|
164 |
|
|
HuffmanNumber1r[5] <= 8'h00;
|
165 |
|
|
HuffmanTable2r[5] <= 16'h0000;
|
166 |
|
|
HuffmanNumber2r[5] <= 8'h00;
|
167 |
|
|
HuffmanTable3r[5] <= 16'h0000;
|
168 |
|
|
HuffmanNumber3r[5] <= 8'h00;
|
169 |
5 |
hidemi |
|
170 |
9 |
hidemi |
HuffmanTable0r[6] <= 16'h0000;
|
171 |
|
|
HuffmanNumber0r[6] <= 8'h00;
|
172 |
|
|
HuffmanTable1r[6] <= 16'h0000;
|
173 |
|
|
HuffmanNumber1r[6] <= 8'h00;
|
174 |
|
|
HuffmanTable2r[6] <= 16'h0000;
|
175 |
|
|
HuffmanNumber2r[6] <= 8'h00;
|
176 |
|
|
HuffmanTable3r[6] <= 16'h0000;
|
177 |
|
|
HuffmanNumber3r[6] <= 8'h00;
|
178 |
5 |
hidemi |
|
179 |
9 |
hidemi |
HuffmanTable0r[7] <= 16'h0000;
|
180 |
|
|
HuffmanNumber0r[7] <= 8'h00;
|
181 |
|
|
HuffmanTable1r[7] <= 16'h0000;
|
182 |
|
|
HuffmanNumber1r[7] <= 8'h00;
|
183 |
|
|
HuffmanTable2r[7] <= 16'h0000;
|
184 |
|
|
HuffmanNumber2r[7] <= 8'h00;
|
185 |
|
|
HuffmanTable3r[7] <= 16'h0000;
|
186 |
|
|
HuffmanNumber3r[7] <= 8'h00;
|
187 |
5 |
hidemi |
|
188 |
9 |
hidemi |
HuffmanTable0r[8] <= 16'h0000;
|
189 |
|
|
HuffmanNumber0r[8] <= 8'h00;
|
190 |
|
|
HuffmanTable1r[8] <= 16'h0000;
|
191 |
|
|
HuffmanNumber1r[8] <= 8'h00;
|
192 |
|
|
HuffmanTable2r[8] <= 16'h0000;
|
193 |
|
|
HuffmanNumber2r[8] <= 8'h00;
|
194 |
|
|
HuffmanTable3r[8] <= 16'h0000;
|
195 |
|
|
HuffmanNumber3r[8] <= 8'h00;
|
196 |
5 |
hidemi |
|
197 |
9 |
hidemi |
HuffmanTable0r[9] <= 16'h0000;
|
198 |
|
|
HuffmanNumber0r[9] <= 8'h00;
|
199 |
|
|
HuffmanTable1r[9] <= 16'h0000;
|
200 |
|
|
HuffmanNumber1r[9] <= 8'h00;
|
201 |
|
|
HuffmanTable2r[9] <= 16'h0000;
|
202 |
|
|
HuffmanNumber2r[9] <= 8'h00;
|
203 |
|
|
HuffmanTable3r[9] <= 16'h0000;
|
204 |
|
|
HuffmanNumber3r[9] <= 8'h00;
|
205 |
5 |
hidemi |
|
206 |
9 |
hidemi |
HuffmanTable0r[10] <= 16'h0000;
|
207 |
|
|
HuffmanNumber0r[10] <= 8'h00;
|
208 |
|
|
HuffmanTable1r[10] <= 16'h0000;
|
209 |
|
|
HuffmanNumber1r[10] <= 8'h00;
|
210 |
|
|
HuffmanTable2r[10] <= 16'h0000;
|
211 |
|
|
HuffmanNumber2r[10] <= 8'h00;
|
212 |
|
|
HuffmanTable3r[10] <= 16'h0000;
|
213 |
|
|
HuffmanNumber3r[10] <= 8'h00;
|
214 |
5 |
hidemi |
|
215 |
9 |
hidemi |
HuffmanTable0r[11] <= 16'h0000;
|
216 |
|
|
HuffmanNumber0r[11] <= 8'h00;
|
217 |
|
|
HuffmanTable1r[11] <= 16'h0000;
|
218 |
|
|
HuffmanNumber1r[11] <= 8'h00;
|
219 |
|
|
HuffmanTable2r[11] <= 16'h0000;
|
220 |
|
|
HuffmanNumber2r[11] <= 8'h00;
|
221 |
|
|
HuffmanTable3r[11] <= 16'h0000;
|
222 |
|
|
HuffmanNumber3r[11] <= 8'h00;
|
223 |
5 |
hidemi |
|
224 |
9 |
hidemi |
HuffmanTable0r[12] <= 16'h0000;
|
225 |
|
|
HuffmanNumber0r[12] <= 8'h00;
|
226 |
|
|
HuffmanTable1r[12] <= 16'h0000;
|
227 |
|
|
HuffmanNumber1r[12] <= 8'h00;
|
228 |
|
|
HuffmanTable2r[12] <= 16'h0000;
|
229 |
|
|
HuffmanNumber2r[12] <= 8'h00;
|
230 |
|
|
HuffmanTable3r[12] <= 16'h0000;
|
231 |
|
|
HuffmanNumber3r[12] <= 8'h00;
|
232 |
5 |
hidemi |
|
233 |
9 |
hidemi |
HuffmanTable0r[13] <= 16'h0000;
|
234 |
|
|
HuffmanNumber0r[13] <= 8'h00;
|
235 |
|
|
HuffmanTable1r[13] <= 16'h0000;
|
236 |
|
|
HuffmanNumber1r[13] <= 8'h00;
|
237 |
|
|
HuffmanTable2r[13] <= 16'h0000;
|
238 |
|
|
HuffmanNumber2r[13] <= 8'h00;
|
239 |
|
|
HuffmanTable3r[13] <= 16'h0000;
|
240 |
|
|
HuffmanNumber3r[13] <= 8'h00;
|
241 |
5 |
hidemi |
|
242 |
9 |
hidemi |
HuffmanTable0r[14] <= 16'h0000;
|
243 |
|
|
HuffmanNumber0r[14] <= 8'h00;
|
244 |
|
|
HuffmanTable1r[14] <= 16'h0000;
|
245 |
|
|
HuffmanNumber1r[14] <= 8'h00;
|
246 |
|
|
HuffmanTable2r[14] <= 16'h0000;
|
247 |
|
|
HuffmanNumber2r[14] <= 8'h00;
|
248 |
|
|
HuffmanTable3r[14] <= 16'h0000;
|
249 |
|
|
HuffmanNumber3r[14] <= 8'h00;
|
250 |
5 |
hidemi |
|
251 |
9 |
hidemi |
HuffmanTable0r[15] <= 16'h0000;
|
252 |
|
|
HuffmanNumber0r[15] <= 8'h00;
|
253 |
|
|
HuffmanTable1r[15] <= 16'h0000;
|
254 |
|
|
HuffmanNumber1r[15] <= 8'h00;
|
255 |
|
|
HuffmanTable2r[15] <= 16'h0000;
|
256 |
|
|
HuffmanNumber2r[15] <= 8'h00;
|
257 |
|
|
HuffmanTable3r[15] <= 16'h0000;
|
258 |
|
|
HuffmanNumber3r[15] <= 8'h00;
|
259 |
|
|
end else begin
|
260 |
|
|
if(HuffmanTableEnable ==2'b1) begin
|
261 |
|
|
if(HuffmanTableColor ==2'b00) begin
|
262 |
|
|
HuffmanTable0r[HuffmanTableCount] <= HuffmanTableCode;
|
263 |
|
|
HuffmanNumber0r[HuffmanTableCount] <= HuffmanTableStart;
|
264 |
|
|
end else if(HuffmanTableColor ==2'b01) begin
|
265 |
|
|
HuffmanTable1r[HuffmanTableCount] <= HuffmanTableCode;
|
266 |
|
|
HuffmanNumber1r[HuffmanTableCount] <= HuffmanTableStart;
|
267 |
|
|
end else if(HuffmanTableColor ==2'b10) begin
|
268 |
|
|
HuffmanTable2r[HuffmanTableCount] <= HuffmanTableCode;
|
269 |
|
|
HuffmanNumber2r[HuffmanTableCount] <= HuffmanTableStart;
|
270 |
|
|
end else begin
|
271 |
|
|
HuffmanTable3r[HuffmanTableCount] <= HuffmanTableCode;
|
272 |
|
|
HuffmanNumber3r[HuffmanTableCount] <= HuffmanTableStart;
|
273 |
|
|
end
|
274 |
3 |
hidemi |
end
|
275 |
9 |
hidemi |
end
|
276 |
|
|
end
|
277 |
|
|
|
278 |
|
|
//--------------------------------------------------------------------------
|
279 |
|
|
// Decode Process
|
280 |
|
|
//--------------------------------------------------------------------------
|
281 |
|
|
reg [3:0] Process; // Process State
|
282 |
|
|
reg [31:0] ProcessData; // Data
|
283 |
|
|
|
284 |
|
|
// Huffman Table
|
285 |
|
|
reg [15:0] HuffmanTable [0:15];
|
286 |
|
|
// Huffman Table Number
|
287 |
|
|
reg [7:0] HuffmanNumber [0:15];
|
288 |
|
|
|
289 |
|
|
reg [15:0] Place; // Place bit
|
290 |
|
|
reg [15:0] TableCode; // Table Code
|
291 |
|
|
reg [7:0] NumberCode; // Start Number of Table Code
|
292 |
|
|
reg [3:0] CodeNumber; // Huffman code width
|
293 |
|
|
reg [15:0] DataNumber; // Huffman code
|
294 |
|
|
|
295 |
|
|
reg [2:0] ProcessColor;
|
296 |
|
|
reg [5:0] ProcessCount;
|
297 |
|
|
|
298 |
|
|
reg OutEnable; // Output Enable
|
299 |
|
|
reg [3:0] OutZero; // Output Zero Count
|
300 |
|
|
reg [15:0] OutCode; // Output Data Code
|
301 |
|
|
wire [15:0] OutCodeP; // Output Data Code
|
302 |
|
|
|
303 |
|
|
reg [4:0] UseWidth; // Output used width
|
304 |
|
|
|
305 |
|
|
// reg DataOutEnable;
|
306 |
|
|
reg [2:0] DataOutColor;
|
307 |
|
|
|
308 |
|
|
reg signed [31:0] PreData [0:2];
|
309 |
|
|
|
310 |
|
|
wire [15:0] SubCode;
|
311 |
|
|
|
312 |
|
|
parameter ProcIdle = 4'h0;
|
313 |
|
|
parameter Phase1 = 4'h1;
|
314 |
|
|
parameter Phase2 = 4'h2;
|
315 |
|
|
parameter Phase3 = 4'h3;
|
316 |
|
|
parameter Phase4 = 4'h4;
|
317 |
|
|
parameter Phase5 = 4'h5;
|
318 |
|
|
parameter Phase6 = 4'h6;
|
319 |
|
|
parameter Phase7 = 4'h7;
|
320 |
|
|
parameter Phase8 = 4'h8;
|
321 |
3 |
hidemi |
|
322 |
9 |
hidemi |
function [15:0] OutCodePSel;
|
323 |
|
|
input [3:0] DhtWidth;
|
324 |
|
|
input [31:0] ProcessData;
|
325 |
|
|
begin
|
326 |
|
|
case (DhtWidth)
|
327 |
|
|
4'h0: OutCodePSel = 16'h0000;
|
328 |
|
|
4'h1: OutCodePSel = {15'h0000,ProcessData[31]};
|
329 |
|
|
4'h2: OutCodePSel = {14'h0000,ProcessData[31:30]};
|
330 |
|
|
4'h3: OutCodePSel = {13'h0000,ProcessData[31:29]};
|
331 |
|
|
4'h4: OutCodePSel = {12'h000, ProcessData[31:28]};
|
332 |
|
|
4'h5: OutCodePSel = {11'h000, ProcessData[31:27]};
|
333 |
|
|
4'h6: OutCodePSel = {10'h000, ProcessData[31:26]};
|
334 |
|
|
4'h7: OutCodePSel = {9'h000, ProcessData[31:25]};
|
335 |
|
|
4'h8: OutCodePSel = {8'h00, ProcessData[31:24]};
|
336 |
|
|
4'h9: OutCodePSel = {7'h00, ProcessData[31:23]};
|
337 |
|
|
4'hA: OutCodePSel = {6'h00, ProcessData[31:22]};
|
338 |
|
|
4'hB: OutCodePSel = {5'h00, ProcessData[31:21]};
|
339 |
|
|
4'hC: OutCodePSel = {4'h0, ProcessData[31:20]};
|
340 |
|
|
4'hD: OutCodePSel = {3'h0, ProcessData[31:19]};
|
341 |
|
|
4'hE: OutCodePSel = {2'h0, ProcessData[31:18]};
|
342 |
|
|
4'hF: OutCodePSel = {1'h0, ProcessData[31:17]};
|
343 |
|
|
endcase
|
344 |
|
|
end
|
345 |
|
|
endfunction
|
346 |
|
|
assign OutCodeP = OutCodePSel(DhtWidth, ProcessData);
|
347 |
|
|
|
348 |
|
|
function [15:0] SubCodeSel;
|
349 |
|
|
input [3:0] DhtWidth;
|
350 |
|
|
begin
|
351 |
|
|
case (DhtWidth)
|
352 |
|
|
4'h0: SubCodeSel = 16'hFFFF;
|
353 |
|
|
4'h1: SubCodeSel = 16'hFFFE;
|
354 |
|
|
4'h2: SubCodeSel = 16'hFFFC;
|
355 |
|
|
4'h3: SubCodeSel = 16'hFFF8;
|
356 |
|
|
4'h4: SubCodeSel = 16'hFFF0;
|
357 |
|
|
4'h5: SubCodeSel = 16'hFFE0;
|
358 |
|
|
4'h6: SubCodeSel = 16'hFFC0;
|
359 |
|
|
4'h7: SubCodeSel = 16'hFF80;
|
360 |
|
|
4'h8: SubCodeSel = 16'hFF00;
|
361 |
|
|
4'h9: SubCodeSel = 16'hFE00;
|
362 |
|
|
4'hA: SubCodeSel = 16'hFC00;
|
363 |
|
|
4'hB: SubCodeSel = 16'hF800;
|
364 |
|
|
4'hC: SubCodeSel = 16'hF000;
|
365 |
|
|
4'hD: SubCodeSel = 16'hE000;
|
366 |
|
|
4'hE: SubCodeSel = 16'hC000;
|
367 |
|
|
4'hF: SubCodeSel = 16'h8000;
|
368 |
|
|
endcase
|
369 |
|
|
end
|
370 |
|
|
endfunction
|
371 |
|
|
assign SubCode = SubCodeSel(DhtWidth);
|
372 |
|
|
|
373 |
|
|
always @(posedge clk or negedge rst) begin
|
374 |
|
|
if(!rst) begin
|
375 |
|
|
Process <= ProcIdle;
|
376 |
|
|
ProcessData <= 32'h00000000;
|
377 |
|
|
ProcessCount <= 6'd0;
|
378 |
|
|
OutEnable <= 1'b0;
|
379 |
|
|
// DataOutEnable <= 1'b0;
|
380 |
|
|
DataOutColor <= 3'b000;
|
381 |
|
|
PreData[0] <= 32'h00000000;
|
382 |
|
|
PreData[1] <= 32'h00000000;
|
383 |
|
|
PreData[2] <= 32'h00000000;
|
384 |
|
|
UseWidth <= 5'h00;
|
385 |
|
|
CodeNumber <= 4'd0;
|
386 |
|
|
end else begin
|
387 |
|
|
case (Process)
|
388 |
|
|
ProcIdle: begin
|
389 |
|
|
if(DataInRun == 1'b1) begin
|
390 |
|
|
Process <= Phase1;
|
391 |
|
|
end else begin
|
392 |
|
|
// Reset DC code
|
393 |
|
|
PreData[0] <= 32'h00000000;
|
394 |
|
|
PreData[1] <= 32'h00000000;
|
395 |
|
|
PreData[2] <= 32'h00000000;
|
396 |
|
|
end
|
397 |
|
|
OutEnable <= 1'b0;
|
398 |
|
|
ProcessColor <= 3'b000;
|
399 |
|
|
ProcessCount <= 6'd0;
|
400 |
|
|
// DataOutEnable <= 1'b0;
|
401 |
|
|
DataOutColor <= 3'b000;
|
402 |
3 |
hidemi |
end
|
403 |
9 |
hidemi |
// get a table-data and table-number
|
404 |
|
|
Phase1: begin
|
405 |
|
|
if(DataInRun == 1'b0) begin
|
406 |
|
|
Process <= ProcIdle;
|
407 |
|
|
end else if(DataInEnable == 1'b1 & DataOutIdle == 1'b1) begin
|
408 |
|
|
Process <= Phase2;
|
409 |
|
|
ProcessData <= DataIn;
|
410 |
|
|
end
|
411 |
|
|
OutEnable <= 1'b0;
|
412 |
|
|
// DataOutEnable <= 1'b0;
|
413 |
|
|
if(ProcessColor[2] == 1'b0) begin
|
414 |
|
|
if(ProcessCount == 0) begin
|
415 |
|
|
HuffmanTable[0] <= HuffmanTable0r[0];
|
416 |
|
|
HuffmanNumber[0] <= HuffmanNumber0r[0];
|
417 |
|
|
HuffmanTable[1] <= HuffmanTable0r[1];
|
418 |
|
|
HuffmanNumber[1] <= HuffmanNumber0r[1];
|
419 |
|
|
HuffmanTable[2] <= HuffmanTable0r[2];
|
420 |
|
|
HuffmanNumber[2] <= HuffmanNumber0r[2];
|
421 |
|
|
HuffmanTable[3] <= HuffmanTable0r[3];
|
422 |
|
|
HuffmanNumber[3] <= HuffmanNumber0r[3];
|
423 |
|
|
HuffmanTable[4] <= HuffmanTable0r[4];
|
424 |
|
|
HuffmanNumber[4] <= HuffmanNumber0r[4];
|
425 |
|
|
HuffmanTable[5] <= HuffmanTable0r[5];
|
426 |
|
|
HuffmanNumber[5] <= HuffmanNumber0r[5];
|
427 |
|
|
HuffmanTable[6] <= HuffmanTable0r[6];
|
428 |
|
|
HuffmanNumber[6] <= HuffmanNumber0r[6];
|
429 |
|
|
HuffmanTable[7] <= HuffmanTable0r[7];
|
430 |
|
|
HuffmanNumber[7] <= HuffmanNumber0r[7];
|
431 |
|
|
HuffmanTable[8] <= HuffmanTable0r[8];
|
432 |
|
|
HuffmanNumber[8] <= HuffmanNumber0r[8];
|
433 |
|
|
HuffmanTable[9] <= HuffmanTable0r[9];
|
434 |
|
|
HuffmanNumber[9] <= HuffmanNumber0r[9];
|
435 |
|
|
HuffmanTable[10] <= HuffmanTable0r[10];
|
436 |
|
|
HuffmanNumber[10] <= HuffmanNumber0r[10];
|
437 |
|
|
HuffmanTable[11] <= HuffmanTable0r[11];
|
438 |
|
|
HuffmanNumber[11] <= HuffmanNumber0r[11];
|
439 |
|
|
HuffmanTable[12] <= HuffmanTable0r[12];
|
440 |
|
|
HuffmanNumber[12] <= HuffmanNumber0r[12];
|
441 |
|
|
HuffmanTable[13] <= HuffmanTable0r[13];
|
442 |
|
|
HuffmanNumber[13] <= HuffmanNumber0r[13];
|
443 |
|
|
HuffmanTable[14] <= HuffmanTable0r[14];
|
444 |
|
|
HuffmanNumber[14] <= HuffmanNumber0r[14];
|
445 |
|
|
HuffmanTable[15] <= HuffmanTable0r[15];
|
446 |
|
|
HuffmanNumber[15] <= HuffmanNumber0r[15];
|
447 |
|
|
end else begin
|
448 |
|
|
HuffmanTable[0] <= HuffmanTable1r[0];
|
449 |
|
|
HuffmanNumber[0] <= HuffmanNumber1r[0];
|
450 |
|
|
HuffmanTable[1] <= HuffmanTable1r[1];
|
451 |
|
|
HuffmanNumber[1] <= HuffmanNumber1r[1];
|
452 |
|
|
HuffmanTable[2] <= HuffmanTable1r[2];
|
453 |
|
|
HuffmanNumber[2] <= HuffmanNumber1r[2];
|
454 |
|
|
HuffmanTable[3] <= HuffmanTable1r[3];
|
455 |
|
|
HuffmanNumber[3] <= HuffmanNumber1r[3];
|
456 |
|
|
HuffmanTable[4] <= HuffmanTable1r[4];
|
457 |
|
|
HuffmanNumber[4] <= HuffmanNumber1r[4];
|
458 |
|
|
HuffmanTable[5] <= HuffmanTable1r[5];
|
459 |
|
|
HuffmanNumber[5] <= HuffmanNumber1r[5];
|
460 |
|
|
HuffmanTable[6] <= HuffmanTable1r[6];
|
461 |
|
|
HuffmanNumber[6] <= HuffmanNumber1r[6];
|
462 |
|
|
HuffmanTable[7] <= HuffmanTable1r[7];
|
463 |
|
|
HuffmanNumber[7] <= HuffmanNumber1r[7];
|
464 |
|
|
HuffmanTable[8] <= HuffmanTable1r[8];
|
465 |
|
|
HuffmanNumber[8] <= HuffmanNumber1r[8];
|
466 |
|
|
HuffmanTable[9] <= HuffmanTable1r[9];
|
467 |
|
|
HuffmanNumber[9] <= HuffmanNumber1r[9];
|
468 |
|
|
HuffmanTable[10] <= HuffmanTable1r[10];
|
469 |
|
|
HuffmanNumber[10] <= HuffmanNumber1r[10];
|
470 |
|
|
HuffmanTable[11] <= HuffmanTable1r[11];
|
471 |
|
|
HuffmanNumber[11] <= HuffmanNumber1r[11];
|
472 |
|
|
HuffmanTable[12] <= HuffmanTable1r[12];
|
473 |
|
|
HuffmanNumber[12] <= HuffmanNumber1r[12];
|
474 |
|
|
HuffmanTable[13] <= HuffmanTable1r[13];
|
475 |
|
|
HuffmanNumber[13] <= HuffmanNumber1r[13];
|
476 |
|
|
HuffmanTable[14] <= HuffmanTable1r[14];
|
477 |
|
|
HuffmanNumber[14] <= HuffmanNumber1r[14];
|
478 |
|
|
HuffmanTable[15] <= HuffmanTable1r[15];
|
479 |
|
|
HuffmanNumber[15] <= HuffmanNumber1r[15];
|
480 |
|
|
end
|
481 |
|
|
end else begin
|
482 |
|
|
if(ProcessCount == 0) begin
|
483 |
|
|
HuffmanTable[0] <= HuffmanTable2r[0];
|
484 |
|
|
HuffmanNumber[0] <= HuffmanNumber2r[0];
|
485 |
|
|
HuffmanTable[1] <= HuffmanTable2r[1];
|
486 |
|
|
HuffmanNumber[1] <= HuffmanNumber2r[1];
|
487 |
|
|
HuffmanTable[2] <= HuffmanTable2r[2];
|
488 |
|
|
HuffmanNumber[2] <= HuffmanNumber2r[2];
|
489 |
|
|
HuffmanTable[3] <= HuffmanTable2r[3];
|
490 |
|
|
HuffmanNumber[3] <= HuffmanNumber2r[3];
|
491 |
|
|
HuffmanTable[4] <= HuffmanTable2r[4];
|
492 |
|
|
HuffmanNumber[4] <= HuffmanNumber2r[4];
|
493 |
|
|
HuffmanTable[5] <= HuffmanTable2r[5];
|
494 |
|
|
HuffmanNumber[5] <= HuffmanNumber2r[5];
|
495 |
|
|
HuffmanTable[6] <= HuffmanTable2r[6];
|
496 |
|
|
HuffmanNumber[6] <= HuffmanNumber2r[6];
|
497 |
|
|
HuffmanTable[7] <= HuffmanTable2r[7];
|
498 |
|
|
HuffmanNumber[7] <= HuffmanNumber2r[7];
|
499 |
|
|
HuffmanTable[8] <= HuffmanTable2r[8];
|
500 |
|
|
HuffmanNumber[8] <= HuffmanNumber2r[8];
|
501 |
|
|
HuffmanTable[9] <= HuffmanTable2r[9];
|
502 |
|
|
HuffmanNumber[9] <= HuffmanNumber2r[9];
|
503 |
|
|
HuffmanTable[10] <= HuffmanTable2r[10];
|
504 |
|
|
HuffmanNumber[10] <= HuffmanNumber2r[10];
|
505 |
|
|
HuffmanTable[11] <= HuffmanTable2r[11];
|
506 |
|
|
HuffmanNumber[11] <= HuffmanNumber2r[11];
|
507 |
|
|
HuffmanTable[12] <= HuffmanTable2r[12];
|
508 |
|
|
HuffmanNumber[12] <= HuffmanNumber2r[12];
|
509 |
|
|
HuffmanTable[13] <= HuffmanTable2r[13];
|
510 |
|
|
HuffmanNumber[13] <= HuffmanNumber2r[13];
|
511 |
|
|
HuffmanTable[14] <= HuffmanTable2r[14];
|
512 |
|
|
HuffmanNumber[14] <= HuffmanNumber2r[14];
|
513 |
|
|
HuffmanTable[15] <= HuffmanTable2r[15];
|
514 |
|
|
HuffmanNumber[15] <= HuffmanNumber2r[15];
|
515 |
|
|
end else begin
|
516 |
|
|
HuffmanTable[0] <= HuffmanTable3r[0];
|
517 |
|
|
HuffmanNumber[0] <= HuffmanNumber3r[0];
|
518 |
|
|
HuffmanTable[1] <= HuffmanTable3r[1];
|
519 |
|
|
HuffmanNumber[1] <= HuffmanNumber3r[1];
|
520 |
|
|
HuffmanTable[2] <= HuffmanTable3r[2];
|
521 |
|
|
HuffmanNumber[2] <= HuffmanNumber3r[2];
|
522 |
|
|
HuffmanTable[3] <= HuffmanTable3r[3];
|
523 |
|
|
HuffmanNumber[3] <= HuffmanNumber3r[3];
|
524 |
|
|
HuffmanTable[4] <= HuffmanTable3r[4];
|
525 |
|
|
HuffmanNumber[4] <= HuffmanNumber3r[4];
|
526 |
|
|
HuffmanTable[5] <= HuffmanTable3r[5];
|
527 |
|
|
HuffmanNumber[5] <= HuffmanNumber3r[5];
|
528 |
|
|
HuffmanTable[6] <= HuffmanTable3r[6];
|
529 |
|
|
HuffmanNumber[6] <= HuffmanNumber3r[6];
|
530 |
|
|
HuffmanTable[7] <= HuffmanTable3r[7];
|
531 |
|
|
HuffmanNumber[7] <= HuffmanNumber3r[7];
|
532 |
|
|
HuffmanTable[8] <= HuffmanTable3r[8];
|
533 |
|
|
HuffmanNumber[8] <= HuffmanNumber3r[8];
|
534 |
|
|
HuffmanTable[9] <= HuffmanTable3r[9];
|
535 |
|
|
HuffmanNumber[9] <= HuffmanNumber3r[9];
|
536 |
|
|
HuffmanTable[10] <= HuffmanTable3r[10];
|
537 |
|
|
HuffmanNumber[10] <= HuffmanNumber3r[10];
|
538 |
|
|
HuffmanTable[11] <= HuffmanTable3r[11];
|
539 |
|
|
HuffmanNumber[11] <= HuffmanNumber3r[11];
|
540 |
|
|
HuffmanTable[12] <= HuffmanTable3r[12];
|
541 |
|
|
HuffmanNumber[12] <= HuffmanNumber3r[12];
|
542 |
|
|
HuffmanTable[13] <= HuffmanTable3r[13];
|
543 |
|
|
HuffmanNumber[13] <= HuffmanNumber3r[13];
|
544 |
|
|
HuffmanTable[14] <= HuffmanTable3r[14];
|
545 |
|
|
HuffmanNumber[14] <= HuffmanNumber3r[14];
|
546 |
|
|
HuffmanTable[15] <= HuffmanTable3r[15];
|
547 |
|
|
HuffmanNumber[15] <= HuffmanNumber3r[15];
|
548 |
|
|
end
|
549 |
|
|
end
|
550 |
3 |
hidemi |
end
|
551 |
9 |
hidemi |
// compare table
|
552 |
|
|
Phase2: begin
|
553 |
|
|
Process <= Phase4;
|
554 |
|
|
if(ProcessData[31:16] >= HuffmanTable[0]) Place[0] <= 1'b1;
|
555 |
|
|
else Place[0] <= 1'b0;
|
556 |
|
|
if(ProcessData[31:16] >= HuffmanTable[1]) Place[1] <= 1'b1;
|
557 |
|
|
else Place[1] <= 1'b0;
|
558 |
|
|
if(ProcessData[31:16] >= HuffmanTable[2]) Place[2] <= 1'b1;
|
559 |
|
|
else Place[2] <= 1'b0;
|
560 |
|
|
if(ProcessData[31:16] >= HuffmanTable[3]) Place[3] <= 1'b1;
|
561 |
|
|
else Place[3] <= 1'b0;
|
562 |
|
|
if(ProcessData[31:16] >= HuffmanTable[4]) Place[4] <= 1'b1;
|
563 |
|
|
else Place[4] <= 1'b0;
|
564 |
|
|
if(ProcessData[31:16] >= HuffmanTable[5]) Place[5] <= 1'b1;
|
565 |
|
|
else Place[5] <= 1'b0;
|
566 |
|
|
if(ProcessData[31:16] >= HuffmanTable[6]) Place[6] <= 1'b1;
|
567 |
|
|
else Place[6] <= 1'b0;
|
568 |
|
|
if(ProcessData[31:16] >= HuffmanTable[7]) Place[7] <= 1'b1;
|
569 |
|
|
else Place[7] <= 1'b0;
|
570 |
|
|
if(ProcessData[31:16] >= HuffmanTable[8]) Place[8] <= 1'b1;
|
571 |
|
|
else Place[8] <= 1'b0;
|
572 |
|
|
if(ProcessData[31:16] >= HuffmanTable[9]) Place[9] <= 1'b1;
|
573 |
|
|
else Place[9] <= 1'b0;
|
574 |
|
|
if(ProcessData[31:16] >= HuffmanTable[10]) Place[10] <= 1'b1;
|
575 |
|
|
else Place[10] <= 1'b0;
|
576 |
|
|
if(ProcessData[31:16] >= HuffmanTable[11]) Place[11] <= 1'b1;
|
577 |
|
|
else Place[11] <= 1'b0;
|
578 |
|
|
if(ProcessData[31:16] >= HuffmanTable[12]) Place[12] <= 1'b1;
|
579 |
|
|
else Place[12] <= 1'b0;
|
580 |
|
|
if(ProcessData[31:16] >= HuffmanTable[13]) Place[13] <= 1'b1;
|
581 |
|
|
else Place[13] <= 1'b0;
|
582 |
|
|
if(ProcessData[31:16] >= HuffmanTable[14]) Place[14] <= 1'b1;
|
583 |
|
|
else Place[14] <= 1'b0;
|
584 |
|
|
if(ProcessData[31:16] >= HuffmanTable[15]) Place[15] <= 1'b1;
|
585 |
|
|
else Place[15] <= 1'b0;
|
586 |
3 |
hidemi |
end
|
587 |
9 |
hidemi |
// shift code
|
588 |
|
|
Phase4: begin
|
589 |
|
|
Process <= Phase5;
|
590 |
|
|
case (Place)
|
591 |
|
|
16'b0000000000000001: begin
|
592 |
|
|
TableCode <= {15'h0000,HuffmanTable[0][15]};
|
593 |
|
|
NumberCode <= HuffmanNumber[0];
|
594 |
|
|
CodeNumber <= 4'h0;
|
595 |
|
|
DataNumber <= {15'h0000,ProcessData[31]};
|
596 |
|
|
ProcessData <= {ProcessData[30:0],1'b0};
|
597 |
|
|
end
|
598 |
|
|
16'b0000000000000011: begin
|
599 |
|
|
TableCode <= {14'h0000,HuffmanTable[1][15:14]};
|
600 |
|
|
NumberCode <= HuffmanNumber[1];
|
601 |
|
|
CodeNumber <= 4'h1;
|
602 |
|
|
DataNumber <= {14'h0000,ProcessData[31:30]};
|
603 |
|
|
ProcessData <= {ProcessData[29:0],2'b00};
|
604 |
|
|
end
|
605 |
|
|
16'b0000000000000111: begin
|
606 |
|
|
TableCode <= {13'h0000,HuffmanTable[2][15:13]};
|
607 |
|
|
NumberCode <= HuffmanNumber[2];
|
608 |
|
|
CodeNumber <= 4'h2;
|
609 |
|
|
DataNumber <= {13'h0000,ProcessData[31:29]};
|
610 |
|
|
ProcessData <= {ProcessData[28:0],3'b000};
|
611 |
|
|
end
|
612 |
|
|
16'b0000000000001111: begin
|
613 |
|
|
TableCode <= {12'h000,HuffmanTable[3][15:12]};
|
614 |
|
|
NumberCode <= HuffmanNumber[3];
|
615 |
|
|
CodeNumber <= 4'h3;
|
616 |
|
|
DataNumber <= {12'h000,ProcessData[31:28]};
|
617 |
|
|
ProcessData <= {ProcessData[27:0],4'h0};
|
618 |
|
|
end
|
619 |
|
|
16'b0000000000011111: begin
|
620 |
|
|
TableCode <= {11'h000,HuffmanTable[4][15:11]};
|
621 |
|
|
NumberCode <= HuffmanNumber[4];
|
622 |
|
|
CodeNumber <= 4'h4;
|
623 |
|
|
DataNumber <= {11'h000,ProcessData[31:27]};
|
624 |
|
|
ProcessData <= {ProcessData[26:0],5'h00};
|
625 |
|
|
end
|
626 |
|
|
16'b0000000000111111: begin
|
627 |
|
|
TableCode <= {10'h000,HuffmanTable[5][15:10]};
|
628 |
|
|
NumberCode <= HuffmanNumber[5];
|
629 |
|
|
CodeNumber <= 4'h5;
|
630 |
|
|
DataNumber <= {10'h000,ProcessData[31:26]};
|
631 |
|
|
ProcessData <= {ProcessData[25:0],6'h00};
|
632 |
|
|
end
|
633 |
|
|
16'b0000000001111111: begin
|
634 |
|
|
TableCode <= {9'h000,HuffmanTable[6][15:9]};
|
635 |
|
|
NumberCode <= HuffmanNumber[6];
|
636 |
|
|
CodeNumber <= 4'h6;
|
637 |
|
|
DataNumber <= {9'h000,ProcessData[31:25]};
|
638 |
|
|
ProcessData <= {ProcessData[24:0],7'h00};
|
639 |
|
|
end
|
640 |
|
|
16'b0000000011111111: begin
|
641 |
|
|
TableCode <= {8'h00,HuffmanTable[7][15:8]};
|
642 |
|
|
NumberCode <= HuffmanNumber[7];
|
643 |
|
|
CodeNumber <= 4'h7;
|
644 |
|
|
DataNumber <= {8'h00,ProcessData[31:24]};
|
645 |
|
|
ProcessData <= {ProcessData[23:0],8'h00};
|
646 |
|
|
end
|
647 |
|
|
16'b0000000111111111: begin
|
648 |
|
|
TableCode <= {7'h00,HuffmanTable[8][15:7]};
|
649 |
|
|
NumberCode <= HuffmanNumber[8];
|
650 |
|
|
CodeNumber <= 4'h8;
|
651 |
|
|
DataNumber <= {7'h00,ProcessData[31:23]};
|
652 |
|
|
ProcessData <= {ProcessData[22:0],9'h000};
|
653 |
|
|
end
|
654 |
|
|
16'b0000001111111111: begin
|
655 |
|
|
TableCode <= {6'h00,HuffmanTable[9][15:6]};
|
656 |
|
|
NumberCode <= HuffmanNumber[9];
|
657 |
|
|
CodeNumber <= 4'h9;
|
658 |
|
|
DataNumber <= {6'h00,ProcessData[31:22]};
|
659 |
|
|
ProcessData <= {ProcessData[21:0],10'h000};
|
660 |
|
|
end
|
661 |
|
|
16'b0000011111111111: begin
|
662 |
|
|
TableCode <= {5'h00,HuffmanTable[10][15:5]};
|
663 |
|
|
NumberCode <= HuffmanNumber[10];
|
664 |
|
|
CodeNumber <= 4'hA;
|
665 |
|
|
DataNumber <= {5'h00,ProcessData[31:21]};
|
666 |
|
|
ProcessData <= {ProcessData[20:0],11'h000};
|
667 |
|
|
end
|
668 |
|
|
16'b0000111111111111: begin
|
669 |
|
|
TableCode <= {4'h0,HuffmanTable[11][15:4]};
|
670 |
|
|
NumberCode <= HuffmanNumber[11];
|
671 |
|
|
CodeNumber <= 4'hB;
|
672 |
|
|
DataNumber <= {4'h0,ProcessData[31:20]};
|
673 |
|
|
ProcessData <= {ProcessData[19:0],12'h000};
|
674 |
|
|
end
|
675 |
|
|
16'b0001111111111111: begin
|
676 |
|
|
TableCode <= {3'h0,HuffmanTable[12][15:3]};
|
677 |
|
|
NumberCode <= HuffmanNumber[12];
|
678 |
|
|
CodeNumber <= 4'hC;
|
679 |
|
|
DataNumber <= {3'h0,ProcessData[31:19]};
|
680 |
|
|
ProcessData <= {ProcessData[18:0],13'h0000};
|
681 |
|
|
end
|
682 |
|
|
16'b0011111111111111: begin
|
683 |
|
|
TableCode <= {2'h0,HuffmanTable[13][15:2]};
|
684 |
|
|
NumberCode <= HuffmanNumber[13];
|
685 |
|
|
CodeNumber <= 4'hD;
|
686 |
|
|
DataNumber <= {2'h0,ProcessData[31:18]};
|
687 |
|
|
ProcessData <= {ProcessData[17:0],14'h0000};
|
688 |
|
|
end
|
689 |
|
|
16'b0111111111111111: begin
|
690 |
|
|
TableCode <= {1'h0,HuffmanTable[14][15:1]};
|
691 |
|
|
NumberCode <= HuffmanNumber[14];
|
692 |
|
|
CodeNumber <= 4'hE;
|
693 |
|
|
DataNumber <= {1'h0,ProcessData[31:17]};
|
694 |
|
|
ProcessData <= {ProcessData[16:0],15'h0000};
|
695 |
|
|
end
|
696 |
|
|
16'b1111111111111111: begin
|
697 |
|
|
TableCode <= HuffmanTable[15];
|
698 |
|
|
NumberCode <= HuffmanNumber[15];
|
699 |
|
|
CodeNumber <= 4'hF;
|
700 |
|
|
DataNumber <= ProcessData[31:16] ;
|
701 |
|
|
ProcessData <= {ProcessData[15:0],16'h0000};
|
702 |
|
|
end
|
703 |
|
|
endcase
|
704 |
3 |
hidemi |
end
|
705 |
9 |
hidemi |
Phase5: begin
|
706 |
|
|
if(DataOutIdle == 1'b1) Process <= Phase6;
|
707 |
3 |
hidemi |
end
|
708 |
9 |
hidemi |
Phase6: begin
|
709 |
|
|
Process <= Phase7;
|
710 |
|
|
OutZero <= DhtZero;
|
711 |
|
|
UseWidth <= CodeNumber + DhtWidth +5'd1;
|
712 |
|
|
if(ProcessCount == 0) begin
|
713 |
|
|
OutEnable <= 1'b1;
|
714 |
|
|
end else begin
|
715 |
|
|
if(DhtZero == 4'h0 & DhtWidth == 4'h0) begin
|
716 |
|
|
ProcessCount <= 6'd63;
|
717 |
|
|
OutEnable <= 1'b0;
|
718 |
|
|
end else if(DhtZero == 4'hF & DhtWidth == 4'h0) begin
|
719 |
|
|
ProcessCount <= ProcessCount + 6'd15;
|
720 |
|
|
OutEnable <= 1'b0;
|
721 |
|
|
end else begin
|
722 |
|
|
ProcessCount <= ProcessCount + DhtZero;
|
723 |
|
|
OutEnable <= 1'b1;
|
724 |
|
|
end
|
725 |
|
|
end
|
726 |
|
|
|
727 |
|
|
if(ProcessData[31] == 1'b0 & DhtWidth != 0) begin
|
728 |
|
|
OutCode <= (OutCodeP | SubCode) + 16'h0001;
|
729 |
|
|
end else begin
|
730 |
|
|
OutCode <= OutCodeP;
|
731 |
|
|
end
|
732 |
3 |
hidemi |
end
|
733 |
9 |
hidemi |
Phase7: begin
|
734 |
|
|
Process <= Phase8;
|
735 |
|
|
if(ProcessCount == 0) begin
|
736 |
|
|
if(ProcessColor[2] == 1'b0) begin
|
737 |
|
|
OutCode <= OutCode + PreData[0][15:0];
|
738 |
|
|
PreData[0] <= OutCode + PreData[0];
|
739 |
|
|
end else begin
|
740 |
|
|
if(ProcessColor[0] == 1'b0) begin
|
741 |
|
|
OutCode <= OutCode + PreData[1][15:0];
|
742 |
|
|
PreData[1] <= OutCode + PreData[1];
|
743 |
|
|
end else begin
|
744 |
|
|
OutCode <= OutCode + PreData[2][15:0];
|
745 |
|
|
PreData[2] <= OutCode + PreData[2];
|
746 |
|
|
end
|
747 |
|
|
end
|
748 |
|
|
end
|
749 |
3 |
hidemi |
end
|
750 |
9 |
hidemi |
Phase8: begin
|
751 |
|
|
OutEnable <= 1'b0;
|
752 |
|
|
if(ProcessCount <6'd63) begin
|
753 |
|
|
Process <= Phase1;
|
754 |
|
|
ProcessCount <= ProcessCount +6'd1;
|
755 |
3 |
hidemi |
end else begin
|
756 |
9 |
hidemi |
ProcessCount <= 6'd0;
|
757 |
|
|
// DataOutEnable <= 1'b1;
|
758 |
|
|
DataOutColor <= ProcessColor;
|
759 |
|
|
if(ProcessColor == 5) begin
|
760 |
|
|
ProcessColor <= 3'b000;
|
761 |
|
|
Process <= Phase1;
|
762 |
|
|
end else begin
|
763 |
|
|
Process <= Phase1;
|
764 |
|
|
ProcessColor <= ProcessColor +3'd1;
|
765 |
|
|
end
|
766 |
3 |
hidemi |
end
|
767 |
9 |
hidemi |
end
|
768 |
|
|
endcase
|
769 |
|
|
end
|
770 |
|
|
end
|
771 |
|
|
|
772 |
|
|
assign DhtColor[1] = ProcessColor[2];
|
773 |
|
|
assign DhtColor[0] = ProcessCount != 6'd0;
|
774 |
|
|
assign DhtNumber = DataNumber - TableCode + NumberCode;
|
775 |
3 |
hidemi |
|
776 |
9 |
hidemi |
assign DqtColor = ProcessColor[2];
|
777 |
|
|
assign DqtNumber = ProcessCount[5:0];
|
778 |
3 |
hidemi |
|
779 |
9 |
hidemi |
assign DecodeUseBit = Process == Phase7;
|
780 |
|
|
assign DecodeUseWidth = UseWidth;
|
781 |
3 |
hidemi |
|
782 |
9 |
hidemi |
assign DecodeEnable = OutEnable == 1'b1 & Process == Phase8;
|
783 |
|
|
assign DecodeColor = ProcessColor;
|
784 |
|
|
assign DecodeCount = ProcessCount[5:0];
|
785 |
|
|
assign DecodeZero = OutZero;
|
786 |
|
|
assign DecodeCode = DqtData * OutCode;
|
787 |
3 |
hidemi |
|
788 |
9 |
hidemi |
assign DataOutEnable = (Process == Phase8) & (ProcessCount == 6'd63);
|
789 |
|
|
|
790 |
|
|
endmodule
|