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

Subversion Repositories djpeg

[/] [djpeg/] [trunk/] [src/] [jpeg_ycbcr2rgb.v] - Blame information for rev 9

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 hidemi
//---------------------------------------------------------------------------
2 9 hidemi
// File Name    : jpeg_ycbcr2rgb.v
3
// Module Name  : jpeg_ycbcr2rgb
4
// Description  : YCbCr2RGB
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 3 hidemi
//---------------------------------------------------------------------------
13
// Rev. Date       Description
14
//---------------------------------------------------------------------------
15
// 1.01 2006/10/01 1st Release
16
//---------------------------------------------------------------------------
17
`timescale 1ps / 1ps
18
 
19
//----------------------------------------------------------------------------
20
// JPEG YCbCr -> RGB Conveter
21
//----------------------------------------------------------------------------
22 9 hidemi
module jpeg_ycbcr2rgb(
23
    rst,
24
    clk,
25 3 hidemi
 
26 9 hidemi
    InEnable,
27
    InRead,
28
    InBlockX,
29
    InBlockY,
30
    InAddress,
31
    InY,
32
    InCb,
33
    InCr,
34 3 hidemi
 
35 9 hidemi
    OutEnable,
36
    OutPixelX,
37
    OutPixelY,
38
    OutR,
39
    OutG,
40
    OutB
41
);
42 3 hidemi
 
43 9 hidemi
    input          clk;
44
    input          rst;
45
 
46
    input          InEnable;
47
    output         InRead;
48
    input [11:0]   InBlockX;
49
    input [11:0]   InBlockY;
50
    output [7:0]   InAddress;
51
    input [8:0]    InY;
52
    input [8:0]    InCb;
53
    input [8:0]    InCr;
54
 
55
    output         OutEnable;
56
    output [15:0]  OutPixelX;
57
    output [15:0]  OutPixelY;
58
    output [7:0]   OutR;
59
    output [7:0]   OutG;
60
    output [7:0]   OutB;
61
 
62
    reg            RunActive;
63
    reg [7:0]      RunCount;
64
    reg [11:0]     RunBlockX;
65
    reg [11:0]     RunBlockY;
66
 
67
    always @(posedge clk or negedge rst) begin
68
        if(!rst) begin
69
            RunActive <= 1'b0;
70 3 hidemi
            RunCount  <= 8'h00;
71 9 hidemi
            RunBlockX <= 12'h000;
72
            RunBlockY <= 12'h000;
73
        end else begin
74
            if(RunActive == 1'b0) begin
75
                if(InEnable == 1'b1) begin
76
                    RunActive <= 1'b1;
77
                    RunBlockX <= InBlockX;
78
                    RunBlockY <= InBlockY;
79
                end
80
                RunCount  <= 8'h00;
81 3 hidemi
            end else begin
82 9 hidemi
                if(RunCount == 8'hFF) begin
83
                    RunActive <= 1'b0;
84
                    RunCount  <= 8'h00;
85
                end else begin
86
                    RunCount <= RunCount +8'd1;
87
                end
88 3 hidemi
            end
89 9 hidemi
        end
90
    end
91
 
92
    assign InRead    = RunActive;
93
    assign InAddress = RunCount;
94 3 hidemi
 
95 9 hidemi
    reg         PreEnable;
96
    reg [15:0]  PreCountX;
97
    reg [15:0]  PreCountY;
98
    reg         Phase0Enable;
99
    reg [15:0]  Phase0CountX;
100
    reg [15:0]  Phase0CountY;
101
    reg         Phase1Enable;
102
    reg [15:0]  Phase1CountX;
103
    reg [15:0]  Phase1CountY;
104
    reg         Phase2Enable;
105
    reg [15:0]  Phase2CountX;
106
    reg [15:0]  Phase2CountY;
107
    reg         Phase3Enable;
108
    reg [15:0]  Phase3CountX;
109
    reg [15:0]  Phase3CountY;
110
 
111
    reg signed [31:0] rgb00r;
112
    reg signed [31:0] r00r;
113
    reg signed [31:0] g00r;
114
    reg signed [31:0] g01r;
115
    reg signed [31:0] b00r;
116
    reg signed [31:0] r10r;
117
    reg signed [31:0] g10r;
118
    reg signed [31:0] g11r;
119
    reg signed [31:0] b10r;
120
    reg signed [31:0] r20r;
121
    reg signed [31:0] g20r;
122
    reg signed [31:0] b20r;
123
 
124
    wire signed [8:0] DataY;
125
    wire signed [8:0] DataCb;
126
    wire signed [8:0] DataCr;
127
 
128
    reg signed [8:0]  Phase0Y;
129
    reg signed [8:0]  Phase0Cb;
130
    reg signed [8:0]  Phase0Cr;
131
 
132
    wire signed [19:0] C_RR = 20'h59BA5; // R_Cr: 1.402   * 0x4000
133
    wire signed [19:0] C_GB = 20'h16066; // G_Cb: 0.34414 * 0x4000
134
    wire signed [19:0] C_GR = 20'h2DB47; // G_Cr: 0.71414 * 0x4000
135
    wire signed [19:0] C_BB = 20'h71687; // B_Cb: 1.772   * 0x4000
136
 
137
    assign             DataY  = InY;
138
    assign             DataCb = InCb;
139
    assign             DataCr = InCr;
140
 
141
    reg signed [8:0]   Phase1Y,Phase1Cb,Phase1Cr;
142
    reg signed [8:0]   Phase2Y,Phase2Cb,Phase2Cr;
143
 
144
    always @(posedge clk or negedge rst) begin
145
        if(!rst) begin
146
            rgb00r <= 0;
147
            r00r   <= 0;
148
            g00r   <= 0;
149
            g01r   <= 0;
150
            b00r   <= 0;
151
 
152
            r10r   <= 0;
153
            g10r   <= 0;
154
            g11r   <= 0;
155
            b10r   <= 0;
156
 
157
            r20r   <= 0;
158
            g20r   <= 0;
159
            b20r   <= 0;
160
 
161
            Phase0Enable <= 1'b0;
162
            Phase0CountX <= 16'h0000;
163
            Phase0CountY <= 16'h0000;
164
            Phase1Enable <= 1'b0;
165
            Phase1CountX <= 16'h0000;
166
            Phase1CountY <= 16'h0000;
167
            Phase2Enable <= 1'b0;
168
            Phase2CountX <= 16'h0000;
169
            Phase2CountY <= 16'h0000;
170
            Phase3Enable <= 1'b0;
171
            Phase3CountX <= 16'h0000;
172
            Phase3CountY <= 16'h0000;
173
        end else begin
174
            // Pre
175
            PreEnable <= RunActive;
176
            PreCountX <= {RunBlockX,RunCount[3:0]};
177
            PreCountY <= {RunBlockY,RunCount[7:4]};
178
 
179
            // Phase0
180
            Phase0Enable <= PreEnable;
181
            Phase0CountX <= PreCountX;
182
            Phase0CountY <= PreCountY;
183
            Phase0Y      <= DataY;
184
            Phase0Cb     <= DataCb;
185
            Phase0Cr     <= DataCr;
186 3 hidemi
 
187 9 hidemi
            // Phase1
188
            Phase1Enable <= Phase0Enable;
189
            Phase1CountX <= Phase0CountX;
190
            Phase1CountY <= Phase0CountY;
191
 
192
            rgb00r <= 32'h02000000 + {Phase0Y[8],Phase0Y[8],Phase0Y[8],Phase0Y[8],Phase0Y[8],Phase0Y[8:0],18'h0000};
193
            r00r   <= Phase0Cr * C_RR;
194
            g00r   <= Phase0Cb * C_GB;
195
            g01r   <= Phase0Cr * C_GR;
196
            b00r   <= Phase0Cb * C_BB;
197
 
198
            Phase1Y  <= Phase0Y;
199
            Phase1Cb <= Phase0Cb;
200
            Phase1Cr <= Phase0Cr;
201
 
202
            // Phase2
203
            Phase2Enable <= Phase1Enable;
204
            Phase2CountX <= Phase1CountX;
205
            Phase2CountY <= Phase1CountY;
206
 
207
            r10r   <= rgb00r + r00r;
208
            g10r   <= rgb00r - g00r;
209
            g11r   <= g01r;
210
            b10r   <= rgb00r + b00r;
211
 
212
            Phase2Y  <= Phase1Y;
213
            Phase2Cb <= Phase1Cb;
214
            Phase2Cr <= Phase1Cr;
215
 
216
            // Phase3
217
            Phase3Enable <= Phase2Enable;
218
            Phase3CountX <= Phase2CountX;
219
            Phase3CountY <= Phase2CountY;
220
            r20r   <= r10r;
221
            g20r   <= g10r - g11r;
222
            b20r   <= b10r;
223
        end
224
    end
225
 
226
    assign OutEnable = Phase3Enable;
227
    assign OutPixelX = Phase3CountX;
228
    assign OutPixelY = Phase3CountY;
229
    assign OutR      = (r20r[31])?8'h00:(r20r[26])?8'hFF:r20r[25:18];
230
    assign OutG      = (g20r[31])?8'h00:(g20r[26])?8'hFF:g20r[25:18];
231
    assign OutB      = (b20r[31])?8'h00:(b20r[26])?8'hFF:b20r[25:18];
232
endmodule

powered by: WebSVN 2.1.0

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