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

Subversion Repositories mkjpeg

[/] [mkjpeg/] [trunk/] [tb/] [vhdl/] [GPL_V2_Image_pkg.vhd] - Blame information for rev 54

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

Line No. Rev Author Line
1 25 mikel262
-----------------------------------------------------------------
2
-- Copyright (c) 1997 Ben Cohen.   All rights reserved.
3
--     email: vhdlcohen@aol.com
4
--   
5
-- This program is free software; you can redistribute it and/or modify
6
-- it under the terms of the GNU General Public License as published
7
-- by the Free Software Foundation; either version 2 of the License,
8
-- or (at your option) any later version. 
9
 
10
-- This program is distributed in the hope that it will be useful,
11
-- but WITHOUT ANY WARRANTY; without even the implied warranty
12
-- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
-- See the GNU General Public License for more details. 
14
 
15
 
16
-- UPDATE: 8/22/02
17
-- Add to HexImage the supply of hex 'Z' 
18
-- in the case statement when a binary set of 4 bits = "ZZZZ" 
19
 
20
---------------------------------------------------------------
21
 
22
-- Note: 2006.08.11: (FB): modified package name to fit the structure of the
23
--                        project and to highlight the license.
24
 
25
library IEEE;
26
  use IEEE.Std_Logic_1164.all;
27
  use IEEE.Std_Logic_TextIO.all;
28
  use ieee.numeric_std.all;
29
  -- use IEEE.Std_Logic_Arith.all;
30
 
31
library Std;
32
  use STD.TextIO.all;
33
 
34
--package Image_Pkg is
35
package GPL_V2_Image_Pkg is
36
  function Image(In_Image : Time) return String;
37
  function Image(In_Image : Bit) return String;
38
  function Image(In_Image : Bit_Vector) return String;
39
  function Image(In_Image : Integer) return String;
40
  function Image(In_Image : Real) return String;
41
  function Image(In_Image : Std_uLogic) return String;
42
  function Image(In_Image : Std_uLogic_Vector) return String;
43
  function Image(In_Image : Std_Logic_Vector) return String;
44
  function Image(In_Image : Signed) return String;
45
  function Image(In_Image : UnSigned) return String;
46
 
47
  function HexImage(InStrg  : String) return String;
48
  function HexImage(In_Image : Bit_Vector) return String;
49
  function HexImage(In_Image : Std_uLogic_Vector) return String;
50
  function HexImage(In_Image : Std_Logic_Vector) return String;
51
  function HexImage(In_Image : Signed) return String;
52
  function HexImage(In_Image : UnSigned) return String;
53
 
54
  function DecImage(In_Image : Bit_Vector) return String;
55
  function DecImage(In_Image : Std_uLogic_Vector) return String;
56
  function DecImage(In_Image : Std_Logic_Vector) return String;
57
  function DecImage(In_Image : Signed) return String;
58
  function DecImage(In_Image : UnSigned) return String;
59
end GPL_V2_Image_Pkg;
60
--end Image_Pkg;
61
 
62
--package body Image_Pkg is
63
package body GPL_V2_Image_Pkg is
64
  function Image(In_Image : Time) return String is
65
    variable L : Line;  -- access type
66
    variable W : String(1 to 14) := (others => ' ');
67
       -- Long enough to hold a time string
68
  begin
69
    -- the WRITE procedure creates an object with "NEW".
70
    -- L is passed as an output of the procedure.
71
    Std.TextIO.WRITE(L, in_image);
72
    -- Copy L.all onto W
73
    W(L.all'range) := L.all;
74
    Deallocate(L);
75
    return W;
76
  end Image;
77
 
78
  function Image(In_Image : Bit) return String is
79
    variable L : Line;  -- access type
80
    variable W : String(1 to 3) := (others => ' ');
81
  begin
82
    Std.TextIO.WRITE(L, in_image);
83
    W(L.all'range) := L.all;
84
    Deallocate(L);
85
    return W;
86
  end Image;
87
 
88
  function Image(In_Image : Bit_Vector) return String is
89
    variable L : Line;  -- access type
90
    variable W : String(1 to In_Image'length) := (others => ' ');
91
  begin
92
    Std.TextIO.WRITE(L, in_image);
93
    W(L.all'range) := L.all;
94
    Deallocate(L);
95
    return W;
96
  end Image;
97
 
98
  function Image(In_Image : Integer) return String is
99
    variable L : Line;  -- access type
100
    variable W : String(1 to 32) := (others => ' ');
101
     -- Long enough to hold a time string
102
  begin
103
    Std.TextIO.WRITE(L, in_image);
104
    W(L.all'range) := L.all;
105
    Deallocate(L);
106
    return W;
107
  end Image;
108
 
109
  function Image(In_Image : Real) return String is
110
    variable L : Line;  -- access type
111
    variable W : String(1 to 32) := (others => ' ');
112
      -- Long enough to hold a time string
113
  begin
114
    Std.TextIO.WRITE(L, in_image);
115
    W(L.all'range) := L.all;
116
    Deallocate(L);
117
    return W;
118
  end Image;
119
 
120
  function Image(In_Image : Std_uLogic) return String is
121
    variable L : Line;  -- access type
122
    variable W : String(1 to 3) := (others => ' ');
123
  begin
124
    IEEE.Std_Logic_Textio.WRITE(L, in_image);
125
    W(L.all'range) := L.all;
126
    Deallocate(L);
127
    return W;
128
  end Image;
129
 
130
  function Image(In_Image : Std_uLogic_Vector) return String is
131
    variable L : Line;  -- access type
132
    variable W : String(1 to In_Image'length) := (others => ' ');
133
  begin
134
    IEEE.Std_Logic_Textio.WRITE(L, in_image);
135
    W(L.all'range) := L.all;
136
    Deallocate(L);
137
    return W;
138
  end Image;
139
 
140
  function Image(In_Image : Std_Logic_Vector) return String is
141
    variable L : Line;  -- access type
142
    variable W : String(1 to In_Image'length) := (others => ' ');
143
  begin
144
     IEEE.Std_Logic_TextIO.WRITE(L, In_Image);
145
     W(L.all'range) := L.all;
146
     Deallocate(L);
147
     return W;
148
  end Image;
149
 
150
  function Image(In_Image : Signed) return String is
151
  begin
152
    return Image(Std_Logic_Vector(In_Image));
153
  end Image;
154
 
155
  function Image(In_Image : UnSigned) return String is
156
  begin
157
    return Image(Std_Logic_Vector(In_Image));
158
  end Image;
159
 
160
  function HexImage(InStrg  : String) return String is
161
    subtype Int03_Typ is Integer range 0 to 3;
162
    variable Result : string(1 to ((InStrg'length - 1)/4)+1) :=
163
        (others => '0');
164
    variable StrTo4 : string(1 to Result'length * 4) :=
165
        (others => '0');
166
    variable MTspace : Int03_Typ;  --  Empty space to fill in
167
    variable Str4    : String(1 to 4);
168
    variable Group_v   : Natural := 0;
169
  begin
170
    MTspace := Result'length * 4  - InStrg'length;
171
    StrTo4(MTspace + 1 to StrTo4'length) := InStrg; -- padded with '0'
172
    Cnvrt_Lbl : for I in Result'range loop
173
      Group_v := Group_v + 4;  -- identifies end of bit # in a group of 4 
174
      Str4 := StrTo4(Group_v - 3 to Group_v); -- get next 4 characters 
175
      case Str4 is
176
        when "0000"  => Result(I) := '0';
177
        when "0001"  => Result(I) := '1';
178
        when "0010"  => Result(I) := '2';
179
        when "0011"  => Result(I) := '3';
180
        when "0100"  => Result(I) := '4';
181
        when "0101"  => Result(I) := '5';
182
        when "0110"  => Result(I) := '6';
183
        when "0111"  => Result(I) := '7';
184
        when "1000"  => Result(I) := '8';
185
        when "1001"  => Result(I) := '9';
186
        when "1010"  => Result(I) := 'A';
187
        when "1011"  => Result(I) := 'B';
188
        when "1100"  => Result(I) := 'C';
189
        when "1101"  => Result(I) := 'D';
190
        when "1110"  => Result(I) := 'E';
191
        when "1111"  => Result(I) := 'F';
192
        when "ZZZZ"  => Result(I) := 'Z';  -- added 8/23/02
193
        when others  => Result(I) := 'X';
194
      end case;                          --  Str4
195
    end loop Cnvrt_Lbl;
196
 
197
    return Result;
198
  end HexImage;
199
 
200
 
201
  function HexImage(In_Image : Bit_Vector) return String is
202
  begin
203
    return HexImage(Image(In_Image));
204
  end HexImage;
205
 
206
  function HexImage(In_Image : Std_uLogic_Vector) return String is
207
  begin
208
    return HexImage(Image(In_Image));
209
  end HexImage;
210
 
211
  function HexImage(In_Image : Std_Logic_Vector) return String is
212
  begin
213
    return HexImage(Image(In_Image));
214
  end HexImage;
215
 
216
  function HexImage(In_Image : Signed) return String is
217
  begin
218
    return HexImage(Image(In_Image));
219
  end HexImage;
220
 
221
  function HexImage(In_Image : UnSigned) return String is
222
  begin
223
    return HexImage(Image(In_Image));
224
  end HexImage;
225
 
226
  function DecImage(In_Image : Bit_Vector) return String is
227
    variable In_Image_v : Bit_Vector(In_Image'length downto 1) := In_Image;
228
  begin
229
    if In_Image'length > 31 then
230
      assert False
231
        report "Number too large for Integer, clipping to 31 bits"
232
        severity Warning;
233
      return Image(To_integer
234
                    (Unsigned(To_StdLogicVector
235
                        (In_Image_v(31 downto 1)))));
236
    else
237
      return Image(To_integer(Unsigned(To_StdLogicVector(In_Image))));
238
    end if;
239
  end DecImage;
240
 
241
  function DecImage(In_Image : Std_uLogic_Vector) return String is
242
    variable In_Image_v : Std_uLogic_Vector(In_Image'length downto 1)
243
                              := In_Image;
244
  begin
245
    if In_Image'length > 31 then
246
      assert False
247
        report "Number too large for Integer, clipping to 31 bits"
248
        severity Warning;
249
       return Image(To_integer(Unsigned(In_Image_v(31 downto 1))));
250
    else
251
        return Image(To_integer(Unsigned(In_Image)));
252
    end if;
253
  end DecImage;
254
 
255
  function DecImage(In_Image : Std_Logic_Vector) return String is
256
    variable In_Image_v : Std_Logic_Vector(In_Image'length downto 1)
257
                              := In_Image;
258
  begin
259
    if In_Image'length > 31 then
260
      assert False
261
        report "Number too large for Integer, clipping to 31 bits"
262
        severity Warning;
263
       return Image(To_integer(Unsigned(In_Image_v(31 downto 1))));
264
    else
265
        return Image(To_integer(Unsigned(In_Image)));
266
    end if;
267
  end DecImage;
268
 
269
  function DecImage(In_Image : Signed) return String is
270
    variable In_Image_v : Signed(In_Image'length downto 1) := In_Image;
271
  begin
272
    if In_Image'length > 31 then
273
      assert False
274
        report "Number too large for Integer, clipping to 31 bits"
275
        severity Warning;
276
       return Image(To_integer(In_Image_v(31 downto 1)));
277
    else
278
        return Image(To_integer(In_Image));
279
    end if;
280
  end DecImage;
281
 
282
  function DecImage(In_Image : UnSigned) return String is
283
    variable In_Image_v : UnSigned(In_Image'length downto 1) := In_Image;
284
  begin
285
    if In_Image'length > 31 then
286
      assert False
287
        report "Number too large for Integer, clipping to 31 bits"
288
        severity Warning;
289
       return Image(To_integer(In_Image_v(31 downto 1)));
290
    else
291
        return Image(To_integer(In_Image));
292
    end if;
293
  end DecImage;
294
 
295
end GPL_V2_Image_Pkg;
296
--end Image_Pkg;
297
 
298
 
299
 
300
 
301
 
302
 
303
 
304
 

powered by: WebSVN 2.1.0

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