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

Subversion Repositories qaz_libs

[/] [qaz_libs/] [trunk/] [BFM/] [src/] [video_frame/] [video_frame_class.svh] - Blame information for rev 50

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 47 qaztronic
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
//// Copyright (C) 2015 Authors and OPENCORES.ORG                 ////
4
////                                                              ////
5
//// This source file may be used and distributed without         ////
6
//// restriction provided that this copyright statement is not    ////
7
//// removed from the file and that any derivative work contains  ////
8
//// the original copyright notice and the associated disclaimer. ////
9
////                                                              ////
10
//// This source file is free software; you can redistribute it   ////
11
//// and/or modify it under the terms of the GNU Lesser General   ////
12
//// Public License as published by the Free Software Foundation; ////
13
//// either version 2.1 of the License, or (at your option) any   ////
14
//// later version.                                               ////
15
////                                                              ////
16
//// This source is distributed in the hope that it will be       ////
17
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
18
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
19
//// PURPOSE.  See the GNU Lesser General Public License for more ////
20
//// details.                                                     ////
21
////                                                              ////
22
//// You should have received a copy of the GNU Lesser General    ////
23
//// Public License along with this source; if not, download it   ////
24
//// from http://www.opencores.org/lgpl.shtml                     ////
25
////                                                              ////
26
//////////////////////////////////////////////////////////////////////
27
 
28
// --------------------------------------------------------------------
29
class video_frame_class;
30
  rand int  frame_id;
31
  rand int  pixels_per_line;
32
  rand int  lines_per_frame;
33
  rand int  bits_per_pixel;
34
  int bytes_per_pixel;
35
  rand int  pixels_per_clk;
36
  line_s    lines[];
37
  string    name = "";
38
  string    pattern = "";
39
 
40
  constraint default_pixels_per_line
41
  {
42
    pixels_per_line >= 4;
43
    pixels_per_line % 2 == 0;
44
    pixels_per_line <= 16384;
45
  }
46
 
47
  constraint default_lines_per_frame
48
  {
49
    lines_per_frame >= 4;
50
    lines_per_frame % 2 == 0;
51
    lines_per_frame <= 16384;
52
  }
53
 
54
  constraint default_bits_per_pixel
55
  {
56
    bits_per_pixel >= 1 && bits_per_pixel <= 32;
57
  }
58
 
59
  //--------------------------------------------------------------------
60
  function new;
61
    this.frame_id = 0;
62
  endfunction: new
63
 
64
  // --------------------------------------------------------------------
65
  function void init
66
  (
67
    int pixels_per_line,
68
    int lines_per_frame,
69
    int bits_per_pixel,
70
    int pixels_per_clk = 1,
71
    string name = ""
72
 );
73
    this.pixels_per_line  = pixels_per_line;
74
    this.lines_per_frame  = lines_per_frame;
75
    this.bits_per_pixel   = bits_per_pixel;
76
    this.pixels_per_clk   = pixels_per_clk;
77
    this.name             = name;
78
    this.bytes_per_pixel  = (bits_per_pixel % 8 == 0)
79
                          ? (bits_per_pixel / 8)
80
                          : (bits_per_pixel / 8) + 1;
81
 
82
    this.make_constant(0);
83
  endfunction: init
84
 
85
  // --------------------------------------------------------------------
86
  task write_pixel(frame_coordinate_t coordinate, int pixel);
87
    this.lines[coordinate.y].pixel[coordinate.x] = pixel;
88
  endtask: write_pixel
89
 
90
  // --------------------------------------------------------------------
91
  function int read_pixel(frame_coordinate_t coordinate);
92
    read_pixel = this.lines[coordinate.y].pixel[coordinate.x];
93
  endfunction: read_pixel
94
 
95
  // --------------------------------------------------------------------
96
  function flattened_frame_t flatten_frame();
97
    flatten_frame = new[lines_per_frame*pixels_per_line];
98
    foreach(this.lines[l])
99
      foreach(this.lines[l].pixel[p])
100 49 qaztronic
        flatten_frame[(l*pixels_per_line)+p] = this.lines[l].pixel[p];
101 47 qaztronic
  endfunction: flatten_frame
102
 
103
  // --------------------------------------------------------------------
104 49 qaztronic
  function void load_flatten_frame(flattened_frame_t a);
105
    make_constant(0);
106
    foreach(lines[l])
107
      foreach(lines[l].pixel[p])
108
        lines[l].pixel[p] = a[(l*pixels_per_line)+p];
109
  endfunction: load_flatten_frame
110
 
111
  // --------------------------------------------------------------------
112 47 qaztronic
  function void make_constant(int pixel);
113
    this.lines = new[lines_per_frame];
114
 
115
    foreach(this.lines[l])
116
    begin
117
      this.lines[l].pixel = new[pixels_per_line];
118
 
119
      foreach(this.lines[l].pixel[p])
120
        this.lines[l].pixel[p] = pixel;
121
    end
122
 
123
    pattern = "constant";
124
  endfunction: make_constant
125
 
126
  // --------------------------------------------------------------------
127
  function void make_counting(int offset = 0);
128
    this.lines = new[lines_per_frame];
129
 
130
    foreach(this.lines[l])
131
    begin
132
      this.lines[l].pixel = new[pixels_per_line];
133
 
134
      foreach(this.lines[l].pixel[p])
135
        this.lines[l].pixel[p] = (pixels_per_line * l) + p + offset;
136
    end
137
 
138
    pattern = "counting";
139
  endfunction: make_counting
140
 
141
  // --------------------------------------------------------------------
142
  function void make_horizontal();
143
    this.lines = new[lines_per_frame];
144
 
145
    foreach(this.lines[l])
146
    begin
147
      this.lines[l].pixel = new[pixels_per_line];
148
 
149
      foreach(this.lines[l].pixel[p])
150
        this.lines[l].pixel[p] = p;
151
    end
152
 
153
    pattern = "horizontal";
154
  endfunction: make_horizontal
155
 
156
  // --------------------------------------------------------------------
157
  function void make_vertical();
158
    this.lines = new[lines_per_frame];
159
 
160
    foreach(this.lines[l])
161
    begin
162
      this.lines[l].pixel = new[pixels_per_line];
163
 
164
      foreach(this.lines[l].pixel[p])
165
        this.lines[l].pixel[p] = l;
166
    end
167
 
168
    pattern = "vertical";
169
  endfunction: make_vertical
170
 
171
  // --------------------------------------------------------------------
172
  function void make_random();
173
    this.lines = new[lines_per_frame];
174
 
175
    foreach(this.lines[l])
176
    begin
177
      this.lines[l].pixel = new[pixels_per_line];
178
 
179
      foreach(this.lines[l].pixel[p])
180
        this.lines[l].pixel[p] = $urandom_range(((2 ** bits_per_pixel) - 1), 0);
181
    end
182
 
183
    pattern = "random";
184
  endfunction: make_random
185
 
186
  // --------------------------------------------------------------------
187
  function void copy(video_frame_class from);
188
    this.frame_id         = from.frame_id;
189
    this.pixels_per_line  = from.pixels_per_line;
190
    this.lines_per_frame  = from.lines_per_frame;
191
    this.bits_per_pixel   = from.bits_per_pixel;
192
    this.name             = from.name;
193
    this.lines            = new[this.lines_per_frame];
194
 
195
    foreach(this.lines[l])
196
    begin
197
      this.lines[l].pixel = new[this.pixels_per_line];
198
 
199
      foreach(this.lines[l].pixel[p])
200
        this.lines[l].pixel[p] = from.lines[l].pixel[p];
201
    end
202
  endfunction: copy
203
 
204
  // --------------------------------------------------------------------
205
  virtual function video_frame_class clone;
206
    clone = new();
207
    clone.copy(this);
208
  endfunction: clone
209
 
210
  // --------------------------------------------------------------------
211
  function video_frame_class catenate_horizontally(video_frame_class tail);
212
 
213
    if(this.lines_per_frame != tail.lines_per_frame)
214
      return(null);
215
 
216
    if(this.bits_per_pixel != tail.bits_per_pixel)
217
      return(null);
218
 
219
    catenate_horizontally = new();
220
    catenate_horizontally.pixels_per_line  = this.pixels_per_line + tail.pixels_per_line;
221
    catenate_horizontally.lines_per_frame  = this.lines_per_frame;
222
    catenate_horizontally.bits_per_pixel   = this.bits_per_pixel;
223
    catenate_horizontally.name             = this.name;
224
    catenate_horizontally.lines            = new[catenate_horizontally.lines_per_frame];
225
 
226
    foreach(catenate_horizontally.lines[l])
227
    begin
228
      catenate_horizontally.lines[l].pixel = new[catenate_horizontally.pixels_per_line];
229
 
230
      foreach(this.lines[l].pixel[p])
231
        catenate_horizontally.lines[l].pixel[p] = this.lines[l].pixel[p];
232
 
233
      foreach(tail.lines[l].pixel[p])
234
        catenate_horizontally.lines[l].pixel[p + this.pixels_per_line] = tail.lines[l].pixel[p];
235
    end
236
  endfunction: catenate_horizontally
237
 
238
  // --------------------------------------------------------------------
239
  function void shift_right(ref line_s column);
240
 
241
    foreach(this.lines[l])
242
      for(int p = pixels_per_line - 1; p > 0; p--)
243
        this.lines[l].pixel[p] = this.lines[l].pixel[p - 1];
244
 
245
    foreach(this.lines[l])
246
      this.lines[l].pixel[0] = column.pixel[l];
247
  endfunction: shift_right
248
 
249 50 qaztronic
  // // --------------------------------------------------------------------
250
  // function int compare_line
251
  // ( int line
252
  // , int max_mismatches
253
  // , video_frame_class to
254
  // );
255
    // int mismatch_count = 0;
256 47 qaztronic
 
257 50 qaztronic
    // if(to.bits_per_pixel != this.bits_per_pixel)
258
    // begin
259
      // log.error($sformatf("to.bits_per_pixel != this.bits_per_pixel | %s", name));
260
      // return(-3);
261
    // end
262 47 qaztronic
 
263 50 qaztronic
      // foreach(this.lines[line].pixel[p])
264
        // if(to.lines[line].pixel[p] != this.lines[line].pixel[p])
265
        // begin
266 47 qaztronic
 
267 50 qaztronic
          // if(max_mismatches > 0)
268
            // mismatch_count++;
269 47 qaztronic
 
270 50 qaztronic
            // log.error($sformatf("mismatch @ frame[%4h][%4h] | to == %4h | this == %4h  | %s",
271
                      // line, p, to.lines[line].pixel[p], this.lines[line].pixel[p], name));
272 47 qaztronic
 
273 50 qaztronic
          // if(mismatch_count > max_mismatches)
274
            // return(mismatch_count);
275
        // end
276 47 qaztronic
 
277 50 qaztronic
      // return(mismatch_count);
278
  // endfunction: compare_line
279 47 qaztronic
 
280 50 qaztronic
  // // --------------------------------------------------------------------
281
  // function int compare(int max_mismatches, video_frame_class to);
282
    // int mismatch_count = 0;
283
    // log.info($sformatf("%m"));
284 47 qaztronic
 
285 50 qaztronic
    // if(to.pixels_per_line != this.pixels_per_line)
286
    // begin
287
      // log.error($sformatf("to.pixels_per_line != this.pixels_per_line | %s", name));
288
      // return(-1);
289
    // end
290 47 qaztronic
 
291 50 qaztronic
    // if(to.lines_per_frame != this.lines_per_frame)
292
    // begin
293
      // log.error($sformatf("to.lines_per_frame != this.lines_per_frame | %s", name));
294
      // return(-2);
295
    // end
296 47 qaztronic
 
297 50 qaztronic
    // if(to.bits_per_pixel != this.bits_per_pixel)
298
    // begin
299
      // log.error($sformatf("to.bits_per_pixel != this.bits_per_pixel | %s", name));
300
      // return(-3);
301
    // end
302 47 qaztronic
 
303 50 qaztronic
      // foreach(this.lines[l])
304
      // begin
305
        // foreach(this.lines[l].pixel[p])
306
          // if(to.lines[l].pixel[p] != this.lines[l].pixel[p])
307
          // begin
308
            // if(max_mismatches > 0)
309
              // mismatch_count++;
310 47 qaztronic
 
311 50 qaztronic
              // log.error($sformatf("mismatch @ frame[%4h][%4h] | to == %4h | this == %4h  | %s", l, p, to.lines[l].pixel[p], this.lines[l].pixel[p], name));
312 47 qaztronic
 
313 50 qaztronic
            // if(mismatch_count > max_mismatches)
314
              // return(mismatch_count);
315
          // end
316
      // end
317 47 qaztronic
 
318 50 qaztronic
      // return(mismatch_count);
319
  // endfunction: compare
320 47 qaztronic
 
321 50 qaztronic
  // // --------------------------------------------------------------------
322
  // function void print_line(int line, int pixel, int count);
323
    // log.info($sformatf("%m"));
324 47 qaztronic
 
325 50 qaztronic
    // for(int i = 0; i < count; i++)
326
      // log.display($sformatf("%4h @ frame[%4h][%4h] | %s", this.lines[line].pixel[(pixel + i)], line, (pixel + i), name));
327
  // endfunction: print_line
328 47 qaztronic
 
329 50 qaztronic
  // // --------------------------------------------------------------------
330
  // function void print_config();
331
    // log.display($sformatf("%m | frame_id         = %06d  | %s", frame_id, name));
332
    // log.display($sformatf("%m | pixels_per_line  = %06d  | %s", pixels_per_line, name));
333
    // log.display($sformatf("%m | lines_per_frame  = %06d  | %s", lines_per_frame, name));
334
    // log.display($sformatf("%m | bits_per_pixel   = %06d  | %s", bits_per_pixel, name));
335
    // log.display($sformatf("%m | pixels_per_clk   = %06d  | %s", pixels_per_clk, name));
336
    // log.display($sformatf("%m | pattern          = %s    | %s", pattern, name));
337
  // endfunction: print_config
338
 
339 47 qaztronic
  // --------------------------------------------------------------------
340
  function void print_config();
341 50 qaztronic
    $display($sformatf("%m | frame_id         = %06d  | %s", frame_id, name));
342
    $display($sformatf("%m | pixels_per_line  = %06d  | %s", pixels_per_line, name));
343
    $display($sformatf("%m | lines_per_frame  = %06d  | %s", lines_per_frame, name));
344
    $display($sformatf("%m | bits_per_pixel   = %06d  | %s", bits_per_pixel, name));
345
    $display($sformatf("%m | pixels_per_clk   = %06d  | %s", pixels_per_clk, name));
346
    $display($sformatf("%m | pattern          = %s    | %s", pattern, name));
347 47 qaztronic
  endfunction: print_config
348
 
349
  // --------------------------------------------------------------------
350 49 qaztronic
  function string convert2string(int grid=8);
351 50 qaztronic
    string s0, s1;
352 47 qaztronic
    string f ="";
353 50 qaztronic
    int nibbles = ( bits_per_pixel % 4 == 0)
354
                  ? bits_per_pixel / 4
355
                  : (bits_per_pixel / 4) + 1;
356 49 qaztronic
 
357 50 qaztronic
    foreach(this.lines[l]) begin
358
      s0 = $sformatf("[%4.d]", l);
359
      foreach(this.lines[l].pixel[p]) begin
360
        s1 = $sformatf("%.h", this.lines[l].pixel[p]);
361
        s1 = s1.substr(nibbles, s1.len()-1);
362
        s0 = {s0, (p % grid == 0) ? "!" : "|", s1};
363
      end
364
 
365
      f = {f, s0, "|\n"};
366 47 qaztronic
    end
367 50 qaztronic
 
368 47 qaztronic
    return f;
369
  endfunction: convert2string
370
 
371
// --------------------------------------------------------------------
372 50 qaztronic
endclass

powered by: WebSVN 2.1.0

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