OpenCores
URL https://opencores.org/ocsvn/djpeg/djpeg/trunk

Subversion Repositories djpeg

[/] [djpeg/] [trunk/] [src/] [jpeg_hm_decode.v] - Blame information for rev 6

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
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
            HaffumanTable0r[0]  <= 16'h0000;
121
            HaffumanNumber0r[0] <=  8'h00;
122
            HaffumanTable1r[0]  <= 16'h0000;
123
            HaffumanNumber1r[0] <=  8'h00;
124
            HaffumanTable2r[0]  <= 16'h0000;
125
            HaffumanNumber2r[0] <=  8'h00;
126
            HaffumanTable3r[0]  <= 16'h0000;
127
            HaffumanNumber3r[0] <=  8'h00;
128 5 hidemi
 
129
            HaffumanTable0r[1]  <= 16'h0000;
130
            HaffumanNumber0r[1] <=  8'h00;
131
            HaffumanTable1r[1]  <= 16'h0000;
132
            HaffumanNumber1r[1] <=  8'h00;
133
            HaffumanTable2r[1]  <= 16'h0000;
134
            HaffumanNumber2r[1] <=  8'h00;
135
            HaffumanTable3r[1]  <= 16'h0000;
136
            HaffumanNumber3r[1] <=  8'h00;
137
 
138
            HaffumanTable0r[2]  <= 16'h0000;
139
            HaffumanNumber0r[2] <=  8'h00;
140
            HaffumanTable1r[2]  <= 16'h0000;
141
            HaffumanNumber1r[2] <=  8'h00;
142
            HaffumanTable2r[2]  <= 16'h0000;
143
            HaffumanNumber2r[2] <=  8'h00;
144
            HaffumanTable3r[2]  <= 16'h0000;
145
            HaffumanNumber3r[2] <=  8'h00;
146
 
147
            HaffumanTable0r[3]  <= 16'h0000;
148
            HaffumanNumber0r[3] <=  8'h00;
149
            HaffumanTable1r[3]  <= 16'h0000;
150
            HaffumanNumber1r[3] <=  8'h00;
151
            HaffumanTable2r[3]  <= 16'h0000;
152
            HaffumanNumber2r[3] <=  8'h00;
153
            HaffumanTable3r[3]  <= 16'h0000;
154
            HaffumanNumber3r[3] <=  8'h00;
155
 
156
            HaffumanTable0r[4]  <= 16'h0000;
157
            HaffumanNumber0r[4] <=  8'h00;
158
            HaffumanTable1r[4]  <= 16'h0000;
159
            HaffumanNumber1r[4] <=  8'h00;
160
            HaffumanTable2r[4]  <= 16'h0000;
161
            HaffumanNumber2r[4] <=  8'h00;
162
            HaffumanTable3r[4]  <= 16'h0000;
163
            HaffumanNumber3r[4] <=  8'h00;
164
 
165
            HaffumanTable0r[5]  <= 16'h0000;
166
            HaffumanNumber0r[5] <=  8'h00;
167
            HaffumanTable1r[5]  <= 16'h0000;
168
            HaffumanNumber1r[5] <=  8'h00;
169
            HaffumanTable2r[5]  <= 16'h0000;
170
            HaffumanNumber2r[5] <=  8'h00;
171
            HaffumanTable3r[5]  <= 16'h0000;
172
            HaffumanNumber3r[5] <=  8'h00;
173
 
174
            HaffumanTable0r[6]  <= 16'h0000;
175
            HaffumanNumber0r[6] <=  8'h00;
176
            HaffumanTable1r[6]  <= 16'h0000;
177
            HaffumanNumber1r[6] <=  8'h00;
178
            HaffumanTable2r[6]  <= 16'h0000;
179
            HaffumanNumber2r[6] <=  8'h00;
180
            HaffumanTable3r[6]  <= 16'h0000;
181
            HaffumanNumber3r[6] <=  8'h00;
182
 
183
            HaffumanTable0r[7]  <= 16'h0000;
184
            HaffumanNumber0r[7] <=  8'h00;
185
            HaffumanTable1r[7]  <= 16'h0000;
186
            HaffumanNumber1r[7] <=  8'h00;
187
            HaffumanTable2r[7]  <= 16'h0000;
188
            HaffumanNumber2r[7] <=  8'h00;
189
            HaffumanTable3r[7]  <= 16'h0000;
190
            HaffumanNumber3r[7] <=  8'h00;
191
 
192
            HaffumanTable0r[8]  <= 16'h0000;
193
            HaffumanNumber0r[8] <=  8'h00;
194
            HaffumanTable1r[8]  <= 16'h0000;
195
            HaffumanNumber1r[8] <=  8'h00;
196
            HaffumanTable2r[8]  <= 16'h0000;
197
            HaffumanNumber2r[8] <=  8'h00;
198
            HaffumanTable3r[8]  <= 16'h0000;
199
            HaffumanNumber3r[8] <=  8'h00;
200
 
201
            HaffumanTable0r[9]  <= 16'h0000;
202
            HaffumanNumber0r[9] <=  8'h00;
203
            HaffumanTable1r[9]  <= 16'h0000;
204
            HaffumanNumber1r[9] <=  8'h00;
205
            HaffumanTable2r[9]  <= 16'h0000;
206
            HaffumanNumber2r[9] <=  8'h00;
207
            HaffumanTable3r[9]  <= 16'h0000;
208
            HaffumanNumber3r[9] <=  8'h00;
209
 
210
            HaffumanTable0r[10]  <= 16'h0000;
211
            HaffumanNumber0r[10] <=  8'h00;
212
            HaffumanTable1r[10]  <= 16'h0000;
213
            HaffumanNumber1r[10] <=  8'h00;
214
            HaffumanTable2r[10]  <= 16'h0000;
215
            HaffumanNumber2r[10] <=  8'h00;
216
            HaffumanTable3r[10]  <= 16'h0000;
217
            HaffumanNumber3r[10] <=  8'h00;
218
 
219
            HaffumanTable0r[11]  <= 16'h0000;
220
            HaffumanNumber0r[11] <=  8'h00;
221
            HaffumanTable1r[11]  <= 16'h0000;
222
            HaffumanNumber1r[11] <=  8'h00;
223
            HaffumanTable2r[11]  <= 16'h0000;
224
            HaffumanNumber2r[11] <=  8'h00;
225
            HaffumanTable3r[11]  <= 16'h0000;
226
            HaffumanNumber3r[11] <=  8'h00;
227
 
228
            HaffumanTable0r[12]  <= 16'h0000;
229
            HaffumanNumber0r[12] <=  8'h00;
230
            HaffumanTable1r[12]  <= 16'h0000;
231
            HaffumanNumber1r[12] <=  8'h00;
232
            HaffumanTable2r[12]  <= 16'h0000;
233
            HaffumanNumber2r[12] <=  8'h00;
234
            HaffumanTable3r[12]  <= 16'h0000;
235
            HaffumanNumber3r[12] <=  8'h00;
236
 
237
            HaffumanTable0r[13]  <= 16'h0000;
238
            HaffumanNumber0r[13] <=  8'h00;
239
            HaffumanTable1r[13]  <= 16'h0000;
240
            HaffumanNumber1r[13] <=  8'h00;
241
            HaffumanTable2r[13]  <= 16'h0000;
242
            HaffumanNumber2r[13] <=  8'h00;
243
            HaffumanTable3r[13]  <= 16'h0000;
244
            HaffumanNumber3r[13] <=  8'h00;
245
 
246
            HaffumanTable0r[14]  <= 16'h0000;
247
            HaffumanNumber0r[14] <=  8'h00;
248
            HaffumanTable1r[14]  <= 16'h0000;
249
            HaffumanNumber1r[14] <=  8'h00;
250
            HaffumanTable2r[14]  <= 16'h0000;
251
            HaffumanNumber2r[14] <=  8'h00;
252
            HaffumanTable3r[14]  <= 16'h0000;
253
            HaffumanNumber3r[14] <=  8'h00;
254
 
255
            HaffumanTable0r[15]  <= 16'h0000;
256
            HaffumanNumber0r[15] <=  8'h00;
257
            HaffumanTable1r[15]  <= 16'h0000;
258
            HaffumanNumber1r[15] <=  8'h00;
259
            HaffumanTable2r[15]  <= 16'h0000;
260
            HaffumanNumber2r[15] <=  8'h00;
261
            HaffumanTable3r[15]  <= 16'h0000;
262
            HaffumanNumber3r[15] <=  8'h00;
263 3 hidemi
      end else begin // if (!rst)
264
         if(HaffumanTableEnable ==2'b1) begin
265
            if(HaffumanTableColor ==2'b00) begin
266
               HaffumanTable0r[HaffumanTableCount]  <= HaffumanTableCode;
267
               HaffumanNumber0r[HaffumanTableCount] <= HaffumanTableStart;
268
            end else if(HaffumanTableColor ==2'b01) begin
269
               HaffumanTable1r[HaffumanTableCount]  <= HaffumanTableCode;
270
               HaffumanNumber1r[HaffumanTableCount] <= HaffumanTableStart;
271
            end else if(HaffumanTableColor ==2'b10) begin
272
               HaffumanTable2r[HaffumanTableCount]  <= HaffumanTableCode;
273
               HaffumanNumber2r[HaffumanTableCount] <= HaffumanTableStart;
274
            end else begin
275
               HaffumanTable3r[HaffumanTableCount]  <= HaffumanTableCode;
276
               HaffumanNumber3r[HaffumanTableCount] <= HaffumanTableStart;
277
            end
278
         end // if (HaffumanTableEnable ==2'b1)
279
      end // else: !if(!rst)
280
   end // always @ (posedge clk or negedge rst)
281
 
282
   //--------------------------------------------------------------------------
283
   // Decode Process
284
   //--------------------------------------------------------------------------
285
   reg [3:0]       Process;            // Process State
286
   reg [31:0]       ProcessData;        // Data
287
 
288
   // Haffuman Table
289
   reg [15:0]       HaffumanTable [0:15];
290
   // Haffuman Table Number
291
   reg [7:0]        HaffumanNumber [0:15];
292
 
293
   reg [15:0]       Place;           // Place bit
294
   reg [15:0]       TableCode;       // Table Code
295
   reg [7:0]        NumberCode;      // Start Number of Table Code
296
   reg [3:0]        CodeNumber;      // Haffuman code width
297
   reg [15:0]       DataNumber;      // Haffuman code
298
   //reg [15:0]    SubData;         // Haffuman Dht Number
299
 
300
   //reg [7:0]     OutDhtNumber;    // Output Dht Number
301
 
302
   reg [2:0]        ProcessColor;
303
   reg [6:0]        ProcessCount;
304
   reg [6:0]        NextProcessCount;
305
 
306
   reg             OutEnable;       // Output Enable
307
   reg [3:0]        OutZero;         // Output Zero Count
308
   reg [15:0]       OutCode;         // Output Data Code
309 5 hidemi
   wire [15:0]      OutCodeP;        // Output Data Code
310 3 hidemi
 
311
   reg [4:0]        UseWidth;        // Output used width
312
 
313
   //reg [23:0]            OutData;
314
 
315
   reg             DataOutEnable;
316
   reg [2:0]        DataOutColor;
317
 
318
   reg signed [31:0] PreData [0:2];
319
 
320 5 hidemi
   wire [15:0]        SubCode;
321 3 hidemi
 
322
   parameter         ProcIdle = 4'h0;
323
   parameter         Phase1   = 4'h1;
324
   parameter         Phase2   = 4'h2;
325
   parameter         Phase3   = 4'h3;
326
   parameter         Phase4   = 4'h4;
327
   parameter         Phase5   = 4'h5;
328
   parameter         Phase6   = 4'h6;
329
   parameter         Phase7   = 4'h7;
330
   parameter         Phase8   = 4'h8;
331
   parameter         Phase9   = 4'h9;
332
   parameter         Phase10  = 4'hA;
333
   parameter         Phase11  = 4'hB;
334
 
335 5 hidemi
/*
336 3 hidemi
   always @(*) begin
337
      case (DhtWidth)
338
        4'h0: OutCodeP <= 16'h0000;
339
        4'h1: OutCodeP <= {15'h0000,ProcessData[31]};
340
        4'h2: OutCodeP <= {14'h0000,ProcessData[31:30]};
341
        4'h3: OutCodeP <= {13'h0000,ProcessData[31:29]};
342
        4'h4: OutCodeP <= {12'h000, ProcessData[31:28]};
343
        4'h5: OutCodeP <= {11'h000, ProcessData[31:27]};
344
        4'h6: OutCodeP <= {10'h000, ProcessData[31:26]};
345
        4'h7: OutCodeP <= {9'h000,  ProcessData[31:25]};
346
        4'h8: OutCodeP <= {8'h00,   ProcessData[31:24]};
347
        4'h9: OutCodeP <= {7'h00,   ProcessData[31:23]};
348
        4'hA: OutCodeP <= {6'h00,   ProcessData[31:22]};
349
        4'hB: OutCodeP <= {5'h00,   ProcessData[31:21]};
350
        4'hC: OutCodeP <= {4'h0,    ProcessData[31:20]};
351
        4'hD: OutCodeP <= {3'h0,    ProcessData[31:19]};
352
        4'hE: OutCodeP <= {2'h0,    ProcessData[31:18]};
353
        4'hF: OutCodeP <= {1'h0,    ProcessData[31:17]};
354
      endcase // case(DhtWidth)
355
      case (DhtWidth)
356
        4'h0: SubCode <= 16'hFFFF;
357
        4'h1: SubCode <= 16'hFFFE;
358
        4'h2: SubCode <= 16'hFFFC;
359
        4'h3: SubCode <= 16'hFFF8;
360
        4'h4: SubCode <= 16'hFFF0;
361
        4'h5: SubCode <= 16'hFFE0;
362
        4'h6: SubCode <= 16'hFFC0;
363
        4'h7: SubCode <= 16'hFF80;
364
        4'h8: SubCode <= 16'hFF00;
365
        4'h9: SubCode <= 16'hFE00;
366
        4'hA: SubCode <= 16'hFC00;
367
        4'hB: SubCode <= 16'hF800;
368
        4'hC: SubCode <= 16'hF000;
369
        4'hD: SubCode <= 16'hE000;
370
        4'hE: SubCode <= 16'hC000;
371
        4'hF: SubCode <= 16'h8000;
372
      endcase // case(DhtWidth)
373
   end // always @ (*)
374 5 hidemi
*/
375 3 hidemi
 
376 5 hidemi
        function [15:0] OutCodePSel;
377
                input [3:0]      DhtWidth;
378
                input [31:0]     ProcessData;
379
        begin
380
                case (DhtWidth)
381
        4'h0: OutCodePSel = 16'h0000;
382
        4'h1: OutCodePSel = {15'h0000,ProcessData[31]};
383
        4'h2: OutCodePSel = {14'h0000,ProcessData[31:30]};
384
        4'h3: OutCodePSel = {13'h0000,ProcessData[31:29]};
385
        4'h4: OutCodePSel = {12'h000, ProcessData[31:28]};
386
        4'h5: OutCodePSel = {11'h000, ProcessData[31:27]};
387
        4'h6: OutCodePSel = {10'h000, ProcessData[31:26]};
388
        4'h7: OutCodePSel = {9'h000,  ProcessData[31:25]};
389
        4'h8: OutCodePSel = {8'h00,   ProcessData[31:24]};
390
        4'h9: OutCodePSel = {7'h00,   ProcessData[31:23]};
391
        4'hA: OutCodePSel = {6'h00,   ProcessData[31:22]};
392
        4'hB: OutCodePSel = {5'h00,   ProcessData[31:21]};
393
        4'hC: OutCodePSel = {4'h0,    ProcessData[31:20]};
394
        4'hD: OutCodePSel = {3'h0,    ProcessData[31:19]};
395
        4'hE: OutCodePSel = {2'h0,    ProcessData[31:18]};
396
        4'hF: OutCodePSel = {1'h0,    ProcessData[31:17]};
397
                endcase // case(DhtWidth)
398
        end
399
        endfunction
400
        assign OutCodeP = OutCodePSel(DhtWidth, ProcessData);
401
 
402
        function [15:0] SubCodeSel;
403
                input [3:0]      DhtWidth;
404
        begin
405
      case (DhtWidth)
406
        4'h0: SubCodeSel = 16'hFFFF;
407
        4'h1: SubCodeSel = 16'hFFFE;
408
        4'h2: SubCodeSel = 16'hFFFC;
409
        4'h3: SubCodeSel = 16'hFFF8;
410
        4'h4: SubCodeSel = 16'hFFF0;
411
        4'h5: SubCodeSel = 16'hFFE0;
412
        4'h6: SubCodeSel = 16'hFFC0;
413
        4'h7: SubCodeSel = 16'hFF80;
414
        4'h8: SubCodeSel = 16'hFF00;
415
        4'h9: SubCodeSel = 16'hFE00;
416
        4'hA: SubCodeSel = 16'hFC00;
417
        4'hB: SubCodeSel = 16'hF800;
418
        4'hC: SubCodeSel = 16'hF000;
419
        4'hD: SubCodeSel = 16'hE000;
420
        4'hE: SubCodeSel = 16'hC000;
421
        4'hF: SubCodeSel = 16'h8000;
422
      endcase // case(DhtWidth)
423
        end
424
        endfunction
425
        assign SubCode = SubCodeSel(DhtWidth);
426 3 hidemi
 
427
   always @(posedge clk or negedge rst) begin
428
      if(!rst) begin
429
         Process       <= ProcIdle;
430
         ProcessData   <= 32'h00000000;
431
         OutEnable     <= 1'b0;
432
         DataOutEnable <= 1'b0;
433
         DataOutColor  <= 3'b000;
434
         PreData[0]    <= 32'h00000000;
435
         PreData[1]    <= 32'h00000000;
436
         PreData[2]    <= 32'h00000000;
437
         UseWidth      <= 7'h00;
438 5 hidemi
         CodeNumber             <= 4'd0;
439 3 hidemi
      end else begin // if (!rst)
440
         case (Process)
441
           ProcIdle: begin
442
              if(DataInRun == 1'b1) begin
443
                 Process <= Phase1;
444
              end else begin
445
                 // Reset DC code
446
                 PreData[0] <= 32'h00000000;
447
                 PreData[1] <= 32'h00000000;
448
                 PreData[2] <= 32'h00000000;
449
              end
450
              OutEnable     <= 1'b0;
451
              ProcessColor  <= 3'b000;
452
              ProcessCount  <= 0;
453
              DataOutEnable <= 1'b0;
454
              DataOutColor  <= 3'b000;
455
           end // case: ProcIdle
456
           // get a table-data and table-number
457
           Phase1: begin
458
              if(DataInEnable ==1'b1 & DataOutIdle == 1'b1) begin
459
                 Process     <= Phase2;
460
                 ProcessData <= DataIn;
461
              end
462
              OutEnable <= 1'b0;
463
              DataOutEnable <= 1'b0;
464
              if(ProcessColor[2] == 1'b0) begin
465
                 if(ProcessCount == 0) begin
466 5 hidemi
                       HaffumanTable[0]  <= HaffumanTable0r[0];
467
                       HaffumanNumber[0] <= HaffumanNumber0r[0];
468
                       HaffumanTable[1]  <= HaffumanTable0r[1];
469
                       HaffumanNumber[1] <= HaffumanNumber0r[1];
470
                       HaffumanTable[2]  <= HaffumanTable0r[2];
471
                       HaffumanNumber[2] <= HaffumanNumber0r[2];
472
                       HaffumanTable[3]  <= HaffumanTable0r[3];
473
                       HaffumanNumber[3] <= HaffumanNumber0r[3];
474
                       HaffumanTable[4]  <= HaffumanTable0r[4];
475
                       HaffumanNumber[4] <= HaffumanNumber0r[4];
476
                       HaffumanTable[5]  <= HaffumanTable0r[5];
477
                       HaffumanNumber[5] <= HaffumanNumber0r[5];
478
                       HaffumanTable[6]  <= HaffumanTable0r[6];
479
                       HaffumanNumber[6] <= HaffumanNumber0r[6];
480
                       HaffumanTable[7]  <= HaffumanTable0r[7];
481
                       HaffumanNumber[7] <= HaffumanNumber0r[7];
482
                       HaffumanTable[8]  <= HaffumanTable0r[8];
483
                       HaffumanNumber[8] <= HaffumanNumber0r[8];
484
                       HaffumanTable[9]  <= HaffumanTable0r[9];
485
                       HaffumanNumber[9] <= HaffumanNumber0r[9];
486
                       HaffumanTable[10]  <= HaffumanTable0r[10];
487
                       HaffumanNumber[10] <= HaffumanNumber0r[10];
488
                       HaffumanTable[11]  <= HaffumanTable0r[11];
489
                       HaffumanNumber[11] <= HaffumanNumber0r[11];
490
                       HaffumanTable[12]  <= HaffumanTable0r[12];
491
                       HaffumanNumber[12] <= HaffumanNumber0r[12];
492
                       HaffumanTable[13]  <= HaffumanTable0r[13];
493
                       HaffumanNumber[13] <= HaffumanNumber0r[13];
494
                       HaffumanTable[14]  <= HaffumanTable0r[14];
495
                       HaffumanNumber[14] <= HaffumanNumber0r[14];
496
                       HaffumanTable[15]  <= HaffumanTable0r[15];
497
                       HaffumanNumber[15] <= HaffumanNumber0r[15];
498 3 hidemi
                 end else begin
499 5 hidemi
                       HaffumanTable[0]  <= HaffumanTable1r[0];
500
                       HaffumanNumber[0] <= HaffumanNumber1r[0];
501
                       HaffumanTable[1]  <= HaffumanTable1r[1];
502
                       HaffumanNumber[1] <= HaffumanNumber1r[1];
503
                       HaffumanTable[2]  <= HaffumanTable1r[2];
504
                       HaffumanNumber[2] <= HaffumanNumber1r[2];
505
                       HaffumanTable[3]  <= HaffumanTable1r[3];
506
                       HaffumanNumber[3] <= HaffumanNumber1r[3];
507
                       HaffumanTable[4]  <= HaffumanTable1r[4];
508
                       HaffumanNumber[4] <= HaffumanNumber1r[4];
509
                       HaffumanTable[5]  <= HaffumanTable1r[5];
510
                       HaffumanNumber[5] <= HaffumanNumber1r[5];
511
                       HaffumanTable[6]  <= HaffumanTable1r[6];
512
                       HaffumanNumber[6] <= HaffumanNumber1r[6];
513
                       HaffumanTable[7]  <= HaffumanTable1r[7];
514
                       HaffumanNumber[7] <= HaffumanNumber1r[7];
515
                       HaffumanTable[8]  <= HaffumanTable1r[8];
516
                       HaffumanNumber[8] <= HaffumanNumber1r[8];
517
                       HaffumanTable[9]  <= HaffumanTable1r[9];
518
                       HaffumanNumber[9] <= HaffumanNumber1r[9];
519
                       HaffumanTable[10]  <= HaffumanTable1r[10];
520
                       HaffumanNumber[10] <= HaffumanNumber1r[10];
521
                       HaffumanTable[11]  <= HaffumanTable1r[11];
522
                       HaffumanNumber[11] <= HaffumanNumber1r[11];
523
                       HaffumanTable[12]  <= HaffumanTable1r[12];
524
                       HaffumanNumber[12] <= HaffumanNumber1r[12];
525
                       HaffumanTable[13]  <= HaffumanTable1r[13];
526
                       HaffumanNumber[13] <= HaffumanNumber1r[13];
527
                       HaffumanTable[14]  <= HaffumanTable1r[14];
528
                       HaffumanNumber[14] <= HaffumanNumber1r[14];
529
                       HaffumanTable[15]  <= HaffumanTable1r[15];
530
                       HaffumanNumber[15] <= HaffumanNumber1r[15];
531 3 hidemi
                 end // else: !if(ProcessCount == 0)
532
              end else begin // if (ProcessColor[2] == 1'b0)
533
                 if(ProcessCount == 0) begin
534 5 hidemi
                       HaffumanTable[0]  <= HaffumanTable2r[0];
535
                       HaffumanNumber[0] <= HaffumanNumber2r[0];
536
                       HaffumanTable[1]  <= HaffumanTable2r[1];
537
                       HaffumanNumber[1] <= HaffumanNumber2r[1];
538
                       HaffumanTable[2]  <= HaffumanTable2r[2];
539
                       HaffumanNumber[2] <= HaffumanNumber2r[2];
540
                       HaffumanTable[3]  <= HaffumanTable2r[3];
541
                       HaffumanNumber[3] <= HaffumanNumber2r[3];
542
                       HaffumanTable[4]  <= HaffumanTable2r[4];
543
                       HaffumanNumber[4] <= HaffumanNumber2r[4];
544
                       HaffumanTable[5]  <= HaffumanTable2r[5];
545
                       HaffumanNumber[5] <= HaffumanNumber2r[5];
546
                       HaffumanTable[6]  <= HaffumanTable2r[6];
547
                       HaffumanNumber[6] <= HaffumanNumber2r[6];
548
                       HaffumanTable[7]  <= HaffumanTable2r[7];
549
                       HaffumanNumber[7] <= HaffumanNumber2r[7];
550
                       HaffumanTable[8]  <= HaffumanTable2r[8];
551
                       HaffumanNumber[8] <= HaffumanNumber2r[8];
552
                       HaffumanTable[9]  <= HaffumanTable2r[9];
553
                       HaffumanNumber[9] <= HaffumanNumber2r[9];
554
                       HaffumanTable[10]  <= HaffumanTable2r[10];
555
                       HaffumanNumber[10] <= HaffumanNumber2r[10];
556
                       HaffumanTable[11]  <= HaffumanTable2r[11];
557
                       HaffumanNumber[11] <= HaffumanNumber2r[11];
558
                       HaffumanTable[12]  <= HaffumanTable2r[12];
559
                       HaffumanNumber[12] <= HaffumanNumber2r[12];
560
                       HaffumanTable[13]  <= HaffumanTable2r[13];
561
                       HaffumanNumber[13] <= HaffumanNumber2r[13];
562
                       HaffumanTable[14]  <= HaffumanTable2r[14];
563
                       HaffumanNumber[14] <= HaffumanNumber2r[14];
564
                       HaffumanTable[15]  <= HaffumanTable2r[15];
565
                       HaffumanNumber[15] <= HaffumanNumber2r[15];
566 3 hidemi
                 end else begin
567 5 hidemi
                       HaffumanTable[0]  <= HaffumanTable3r[0];
568
                       HaffumanNumber[0] <= HaffumanNumber3r[0];
569
                       HaffumanTable[1]  <= HaffumanTable3r[1];
570
                       HaffumanNumber[1] <= HaffumanNumber3r[1];
571
                       HaffumanTable[2]  <= HaffumanTable3r[2];
572
                       HaffumanNumber[2] <= HaffumanNumber3r[2];
573
                       HaffumanTable[3]  <= HaffumanTable3r[3];
574
                       HaffumanNumber[3] <= HaffumanNumber3r[3];
575
                       HaffumanTable[4]  <= HaffumanTable3r[4];
576
                       HaffumanNumber[4] <= HaffumanNumber3r[4];
577
                       HaffumanTable[5]  <= HaffumanTable3r[5];
578
                       HaffumanNumber[5] <= HaffumanNumber3r[5];
579
                       HaffumanTable[6]  <= HaffumanTable3r[6];
580
                       HaffumanNumber[6] <= HaffumanNumber3r[6];
581
                       HaffumanTable[7]  <= HaffumanTable3r[7];
582
                       HaffumanNumber[7] <= HaffumanNumber3r[7];
583
                       HaffumanTable[8]  <= HaffumanTable3r[8];
584
                       HaffumanNumber[8] <= HaffumanNumber3r[8];
585
                       HaffumanTable[9]  <= HaffumanTable3r[9];
586
                       HaffumanNumber[9] <= HaffumanNumber3r[9];
587
                       HaffumanTable[10]  <= HaffumanTable3r[10];
588
                       HaffumanNumber[10] <= HaffumanNumber3r[10];
589
                       HaffumanTable[11]  <= HaffumanTable3r[11];
590
                       HaffumanNumber[11] <= HaffumanNumber3r[11];
591
                       HaffumanTable[12]  <= HaffumanTable3r[12];
592
                       HaffumanNumber[12] <= HaffumanNumber3r[12];
593
                       HaffumanTable[13]  <= HaffumanTable3r[13];
594
                       HaffumanNumber[13] <= HaffumanNumber3r[13];
595
                       HaffumanTable[14]  <= HaffumanTable3r[14];
596
                       HaffumanNumber[14] <= HaffumanNumber3r[14];
597
                       HaffumanTable[15]  <= HaffumanTable3r[15];
598
                       HaffumanNumber[15] <= HaffumanNumber3r[15];
599 3 hidemi
                 end // else: !if(ProcessCount == 0)
600
              end // else: !if(ProcessColor[2] == 1'b0)
601
           end // case: Phase1
602
           // compare table
603
           Phase2: begin
604
              Process    <= Phase4;
605 5 hidemi
                                if(ProcessData[31:16] >= HaffumanTable[0])       Place[0] <= 1'b1;
606
                                else                                                                                            Place[0] <= 1'b0;
607
                                if(ProcessData[31:16] >= HaffumanTable[1])      Place[1] <= 1'b1;
608
                                else                                                                                            Place[1] <= 1'b0;
609
                                if(ProcessData[31:16] >= HaffumanTable[2])      Place[2] <= 1'b1;
610
                                else                                                                                            Place[2] <= 1'b0;
611
                                if(ProcessData[31:16] >= HaffumanTable[3])      Place[3] <= 1'b1;
612
                                else                                                                                            Place[3] <= 1'b0;
613
                                if(ProcessData[31:16] >= HaffumanTable[4])      Place[4] <= 1'b1;
614
                                else                                                                                            Place[4] <= 1'b0;
615
                                if(ProcessData[31:16] >= HaffumanTable[5])      Place[5] <= 1'b1;
616
                                else                                                                                            Place[5] <= 1'b0;
617
                                if(ProcessData[31:16] >= HaffumanTable[6])      Place[6] <= 1'b1;
618
                                else                                                                                            Place[6] <= 1'b0;
619
                                if(ProcessData[31:16] >= HaffumanTable[7])      Place[7] <= 1'b1;
620
                                else                                                                                            Place[7] <= 1'b0;
621
                                if(ProcessData[31:16] >= HaffumanTable[8])      Place[8] <= 1'b1;
622
                                else                                                                                            Place[8] <= 1'b0;
623
                                if(ProcessData[31:16] >= HaffumanTable[9])      Place[9] <= 1'b1;
624
                                else                                                                                            Place[9] <= 1'b0;
625
                                if(ProcessData[31:16] >= HaffumanTable[10])     Place[10] <= 1'b1;
626
                                else                                                                                            Place[10] <= 1'b0;
627
                                if(ProcessData[31:16] >= HaffumanTable[11])     Place[11] <= 1'b1;
628
                                else                                                                                            Place[11] <= 1'b0;
629
                                if(ProcessData[31:16] >= HaffumanTable[12])     Place[12] <= 1'b1;
630
                                else                                                                                            Place[12] <= 1'b0;
631
                                if(ProcessData[31:16] >= HaffumanTable[13])     Place[13] <= 1'b1;
632
                                else                                                                                            Place[13] <= 1'b0;
633
                                if(ProcessData[31:16] >= HaffumanTable[14])     Place[14] <= 1'b1;
634
                                else                                                                                            Place[14] <= 1'b0;
635
                                if(ProcessData[31:16] >= HaffumanTable[15])     Place[15] <= 1'b1;
636
                                else                                                                                            Place[15] <= 1'b0;
637 3 hidemi
           end
638
           // shift code
639
           Phase4: begin
640
              Process <= Phase6;
641
              case (Place)
642
                16'b0000000000000001: begin
643
                   TableCode   <= {15'h0000,HaffumanTable[0][15]};
644
                   NumberCode  <= HaffumanNumber[0];
645
                   CodeNumber  <= 4'h0;
646
                   DataNumber  <= {15'h0000,ProcessData[31]};
647
                   ProcessData <= {ProcessData[30:0],1'b0};
648
                end
649
                16'b0000000000000011: begin
650
                   TableCode   <= {14'h0000,HaffumanTable[1][15:14]};
651
                   NumberCode  <= HaffumanNumber[1];
652
                   CodeNumber  <= 4'h1;
653
                   DataNumber  <= {14'h0000,ProcessData[31:30]};
654
                   ProcessData <= {ProcessData[29:0],2'b00};
655
                end
656
                16'b0000000000000111: begin
657
                   TableCode   <= {13'h0000,HaffumanTable[2][15:13]};
658
                   NumberCode  <= HaffumanNumber[2];
659
                   CodeNumber  <= 4'h2;
660
                   DataNumber  <= {13'h0000,ProcessData[31:29]};
661
                   ProcessData <= {ProcessData[28:0],3'b000};
662
                end
663
                16'b0000000000001111: begin
664
                   TableCode   <= {12'h000,HaffumanTable[3][15:12]};
665
                   NumberCode  <= HaffumanNumber[3];
666
                   CodeNumber  <= 4'h3;
667
                   DataNumber  <= {12'h000,ProcessData[31:28]};
668
                   ProcessData <= {ProcessData[27:0],4'h0};
669
                end
670
                16'b0000000000011111: begin
671
                   TableCode   <= {11'h000,HaffumanTable[4][15:11]};
672
                   NumberCode  <= HaffumanNumber[4];
673
                   CodeNumber  <= 4'h4;
674
                   DataNumber  <= {11'h000,ProcessData[31:27]};
675
                   ProcessData <= {ProcessData[26:0],5'h00};
676
                end
677
                16'b0000000000111111: begin
678
                   TableCode   <= {10'h000,HaffumanTable[5][15:10]};
679
                   NumberCode  <= HaffumanNumber[5];
680
                   CodeNumber  <= 4'h5;
681
                   DataNumber  <= {10'h000,ProcessData[31:26]};
682
                   ProcessData <= {ProcessData[25:0],6'h00};
683
                end
684
                16'b0000000001111111: begin
685
                   TableCode   <= {9'h000,HaffumanTable[6][15:9]};
686
                   NumberCode  <= HaffumanNumber[6];
687
                   CodeNumber  <= 4'h6;
688
                   DataNumber  <= {9'h000,ProcessData[31:25]};
689
                   ProcessData <= {ProcessData[24:0],7'h00};
690
                end
691
                16'b0000000011111111: begin
692
                   TableCode   <= {8'h00,HaffumanTable[7][15:8]};
693
                   NumberCode  <= HaffumanNumber[7];
694
                   CodeNumber  <= 4'h7;
695
                   DataNumber  <= {8'h00,ProcessData[31:24]};
696
                   ProcessData <= {ProcessData[23:0],8'h00};
697
                end
698
                16'b0000000111111111: begin
699
                   TableCode   <= {7'h00,HaffumanTable[8][15:7]};
700
                   NumberCode  <= HaffumanNumber[8];
701
                   CodeNumber  <= 4'h8;
702
                   DataNumber  <= {7'h00,ProcessData[31:23]};
703
                   ProcessData <= {ProcessData[22:0],9'h000};
704
                end
705
                16'b0000001111111111: begin
706
                   TableCode   <= {6'h00,HaffumanTable[9][15:6]};
707
                   NumberCode  <= HaffumanNumber[9];
708
                   CodeNumber  <= 4'h9;
709
                   DataNumber  <= {6'h00,ProcessData[31:22]};
710
                   ProcessData <= {ProcessData[21:0],10'h000};
711
                end
712
                16'b0000011111111111: begin
713
                   TableCode   <= {5'h00,HaffumanTable[10][15:5]};
714
                   NumberCode  <= HaffumanNumber[10];
715
                   CodeNumber  <= 4'hA;
716
                   DataNumber  <= {5'h00,ProcessData[31:21]};
717
                   ProcessData <= {ProcessData[20:0],11'h000};
718
                end
719
                16'b0000111111111111: begin
720
                   TableCode   <= {4'h0,HaffumanTable[11][15:4]};
721
                   NumberCode  <= HaffumanNumber[11];
722
                   CodeNumber  <= 4'hB;
723
                   DataNumber  <= {4'h0,ProcessData[31:20]};
724
                   ProcessData <= {ProcessData[19:0],12'h000};
725
                end
726
                16'b0001111111111111: begin
727
                   TableCode   <= {3'h0,HaffumanTable[12][15:3]};
728
                   NumberCode  <= HaffumanNumber[12];
729
                   CodeNumber  <= 4'hC;
730
                   DataNumber  <= {3'h0,ProcessData[31:19]};
731
                   ProcessData <= {ProcessData[18:0],13'h0000};
732
                end
733
                16'b0011111111111111: begin
734
                   TableCode   <= {2'h0,HaffumanTable[13][15:2]};
735
                   NumberCode  <= HaffumanNumber[13];
736
                   CodeNumber  <= 4'hD;
737
                   DataNumber  <= {2'h0,ProcessData[31:18]};
738
                   ProcessData <= {ProcessData[17:0],14'h0000};
739
                end
740
                16'b0111111111111111: begin
741
                   TableCode   <= {1'h0,HaffumanTable[14][15:1]};
742
                   NumberCode  <= HaffumanNumber[14];
743
                   CodeNumber  <= 4'hE;
744
                   DataNumber  <= {1'h0,ProcessData[31:17]};
745
                   ProcessData <= {ProcessData[16:0],15'h0000};
746
                end
747
                16'b1111111111111111: begin
748
                   TableCode   <= HaffumanTable[15];
749
                   NumberCode  <= HaffumanNumber[15];
750
                   CodeNumber  <= 4'hF;
751
                   DataNumber  <= ProcessData[31:16] ;
752
                   ProcessData <= {ProcessData[15:0],16'h0000};
753
                end
754
              endcase // case(Place)
755
           end // case: Phase4
756
           Phase5: begin
757
              Process <= Phase6;
758
              //SubData <= DataNumber - TableCode;
759
              //OutDhtNumber <= DataNumber - TableCode + NumberCode;
760
           end
761
           Phase6: begin
762
              if(DataOutIdle == 1'b1) Process   <= Phase7;
763
              //DhtNumber <= SubData[7:0] + NumberCode;
764
           end
765
           Phase7: begin
766
              Process          <= Phase9;
767
              OutZero          <= DhtZero;
768
              UseWidth         <= CodeNumber   + DhtWidth +1;
769
              if(ProcessCount == 0) begin
770
                 NextProcessCount <= 7'd1;
771
                 OutEnable        <= 1'b1;
772
              end else begin
773
                 if(DhtZero == 4'h0 & DhtWidth == 4'h0) begin
774
                    ProcessCount     <= 7'd64;
775
                    NextProcessCount <= 7'd64;
776
                    OutEnable        <= 1'b0;
777
                 end else if(DhtZero == 4'hF & DhtWidth == 4'h0) begin
778
                    ProcessCount     <= ProcessCount + 4'hF;
779
                    NextProcessCount <= ProcessCount + 4'hF;
780
                    OutEnable        <= 1'b0;
781
                 end else begin
782
                    ProcessCount     <= ProcessCount + DhtZero;
783
                    NextProcessCount <= ProcessCount + DhtZero +1;
784
                    OutEnable        <= 1'b1;
785
                 end
786
              end // else: !if(ProcessCount == 0)
787
 
788
              if(ProcessData[31] == 1'b0 & DhtWidth != 0) begin
789
                 OutCode <= (OutCodeP | SubCode) + 16'h0001;
790
              end else begin
791
                 OutCode <= OutCodeP;
792
              end
793
           end // case: Phase7
794
           Phase8: begin
795
              Process <= Phase9;
796
           end
797
           Phase9: begin
798
              Process <= Phase11;
799
              if(ProcessCount == 0) begin
800
                 if(ProcessColor[2] == 1'b0) begin
801
                    OutCode    <= OutCode + PreData[0];
802
                    PreData[0] <= OutCode + PreData[0];
803
                 end else begin
804
                    if(ProcessColor[0] == 1'b0) begin
805
                       OutCode    <= OutCode + PreData[1];
806
                       PreData[1] <= OutCode + PreData[1];
807
                    end else begin
808
                       OutCode    <= OutCode + PreData[2];
809
                       PreData[2] <= OutCode + PreData[2];
810
                    end
811
                 end // else: !if(ProcessColor[2] == 1'b0)
812
              end // if (ProcessCount == 0)
813
           end // case: Phase9
814
           Phase10: begin
815
              Process   <= Phase11;
816
              //OutData   <= DqtData * OutCode;
817
           end
818
           Phase11: begin
819
              OutEnable <= 1'b0;
820
              if(NextProcessCount <64) begin
821
                 Process      <= Phase1;
822
                 ProcessCount <= NextProcessCount;
823
              end else begin
824
                 ProcessCount  <= 7'd0;
825
                 DataOutEnable <= 1'b1;
826
                 DataOutColor  <= ProcessColor;
827
                 if(ProcessColor == 5) begin
828
                    ProcessColor <= 3'b000;
829
                    if(DataInRun == 1'b0) Process <= ProcIdle;
830
                    else Process <= Phase1;
831
                 end else begin
832
                    Process <= Phase1;
833
                    ProcessColor <= ProcessColor +1;
834
                 end
835
              end // else: !if(NextProcessCount <64)
836
           end // case: Phase11
837
         endcase // case(Process)
838
      end // else: !if(!rst)
839
   end // always @ (posedge clk or negedge rst)
840
 
841
   assign DhtColor[1]    = ProcessColor[2];
842
   assign DhtColor[0]    = ProcessCount != 0;
843
   //assign DhtNumber      = OutDhtNumber[7:0];
844
   assign DhtNumber      = DataNumber - TableCode + NumberCode;
845
 
846
   assign DqtColor       = ProcessColor[2];
847
   assign DqtNumber      = ProcessCount[5:0];
848
 
849
   //assign DecodeUseBit   = Process == Phase8;
850
   assign DecodeUseBit   = Process == Phase9;
851
   assign DecodeUseWidth = UseWidth;
852
 
853
   assign DecodeEnable   = OutEnable == 1'b1 & Process == Phase11;
854
   assign DecodeColor    = ProcessColor;
855
   assign DecodeCount    = ProcessCount[5:0];
856
   assign DecodeZero     = OutZero;
857
   //assign DecodeCode     = OutData[15:0];
858
   assign DecodeCode     = DqtData * OutCode;
859
 
860
endmodule // jpeg_hm_decode

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.