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 48

Go to most recent revision | 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
  logger_class log;
31
  rand int  frame_id;
32
  rand int  pixels_per_line;
33
  rand int  lines_per_frame;
34
  rand int  bits_per_pixel;
35
  int bytes_per_pixel;
36
  rand int  pixels_per_clk;
37
  line_s    lines[];
38
  string    name = "";
39
  string    pattern = "";
40
 
41
  constraint default_pixels_per_line
42
  {
43
    pixels_per_line >= 4;
44
    pixels_per_line % 2 == 0;
45
    pixels_per_line <= 16384;
46
  }
47
 
48
  constraint default_lines_per_frame
49
  {
50
    lines_per_frame >= 4;
51
    lines_per_frame % 2 == 0;
52
    lines_per_frame <= 16384;
53
  }
54
 
55
  constraint default_bits_per_pixel
56
  {
57
    bits_per_pixel >= 1 && bits_per_pixel <= 32;
58
  }
59
 
60
  //--------------------------------------------------------------------
61
  function new;
62
    this.log = new;
63
    this.frame_id = 0;
64
  endfunction: new
65
 
66
  // --------------------------------------------------------------------
67
  function void init
68
  (
69
    int pixels_per_line,
70
    int lines_per_frame,
71
    int bits_per_pixel,
72
    int pixels_per_clk = 1,
73
    string name = ""
74
 );
75
    log.info($sformatf("%m"));
76
    this.pixels_per_line  = pixels_per_line;
77
    this.lines_per_frame  = lines_per_frame;
78
    this.bits_per_pixel   = bits_per_pixel;
79
    this.pixels_per_clk   = pixels_per_clk;
80
    this.name             = name;
81
    this.bytes_per_pixel  = (bits_per_pixel % 8 == 0)
82
                          ? (bits_per_pixel / 8)
83
                          : (bits_per_pixel / 8) + 1;
84
 
85
    this.make_constant(0);
86
  endfunction: init
87
 
88
  // --------------------------------------------------------------------
89
  task write_pixel(frame_coordinate_t coordinate, int pixel);
90
    this.lines[coordinate.y].pixel[coordinate.x] = pixel;
91
  endtask: write_pixel
92
 
93
  // --------------------------------------------------------------------
94
  function int read_pixel(frame_coordinate_t coordinate);
95
    read_pixel = this.lines[coordinate.y].pixel[coordinate.x];
96
  endfunction: read_pixel
97
 
98
  // --------------------------------------------------------------------
99
  function flattened_frame_t flatten_frame();
100
    int i = 0;
101
    log.info($sformatf("%m"));
102
    flatten_frame = new[lines_per_frame*pixels_per_line];
103
 
104
    foreach(this.lines[l])
105
      foreach(this.lines[l].pixel[p])
106
      begin
107
        flatten_frame[i] = this.lines[l].pixel[p];
108
        i++;
109
      end
110
  endfunction: flatten_frame
111
 
112
  // --------------------------------------------------------------------
113
  function void make_constant(int pixel);
114
    log.info($sformatf("%m"));
115
    this.lines = new[lines_per_frame];
116
 
117
    foreach(this.lines[l])
118
    begin
119
      this.lines[l].pixel = new[pixels_per_line];
120
 
121
      foreach(this.lines[l].pixel[p])
122
        this.lines[l].pixel[p] = pixel;
123
    end
124
 
125
    pattern = "constant";
126
  endfunction: make_constant
127
 
128
  // --------------------------------------------------------------------
129
  function void make_counting(int offset = 0);
130
    log.info($sformatf("%m"));
131
    this.lines = new[lines_per_frame];
132
 
133
    foreach(this.lines[l])
134
    begin
135
      this.lines[l].pixel = new[pixels_per_line];
136
 
137
      foreach(this.lines[l].pixel[p])
138
        this.lines[l].pixel[p] = (pixels_per_line * l) + p + offset;
139
    end
140
 
141
    pattern = "counting";
142
  endfunction: make_counting
143
 
144
  // --------------------------------------------------------------------
145
  function void make_horizontal();
146
    log.info($sformatf("%m"));
147
    this.lines = new[lines_per_frame];
148
 
149
    foreach(this.lines[l])
150
    begin
151
      this.lines[l].pixel = new[pixels_per_line];
152
 
153
      foreach(this.lines[l].pixel[p])
154
        this.lines[l].pixel[p] = p;
155
    end
156
 
157
    pattern = "horizontal";
158
  endfunction: make_horizontal
159
 
160
  // --------------------------------------------------------------------
161
  function void make_vertical();
162
    log.info($sformatf("%m"));
163
    this.lines = new[lines_per_frame];
164
 
165
    foreach(this.lines[l])
166
    begin
167
      this.lines[l].pixel = new[pixels_per_line];
168
 
169
      foreach(this.lines[l].pixel[p])
170
        this.lines[l].pixel[p] = l;
171
    end
172
 
173
    pattern = "vertical";
174
  endfunction: make_vertical
175
 
176
  // --------------------------------------------------------------------
177
  function void make_random();
178
    log.info($sformatf("%m"));
179
    this.lines = new[lines_per_frame];
180
 
181
    foreach(this.lines[l])
182
    begin
183
      this.lines[l].pixel = new[pixels_per_line];
184
 
185
      foreach(this.lines[l].pixel[p])
186
        this.lines[l].pixel[p] = $urandom_range(((2 ** bits_per_pixel) - 1), 0);
187
    end
188
 
189
    pattern = "random";
190
  endfunction: make_random
191
 
192
  // --------------------------------------------------------------------
193
  function void copy(video_frame_class from);
194
    log.info($sformatf("%m"));
195
    this.frame_id         = from.frame_id;
196
    this.pixels_per_line  = from.pixels_per_line;
197
    this.lines_per_frame  = from.lines_per_frame;
198
    this.bits_per_pixel   = from.bits_per_pixel;
199
    this.name             = from.name;
200
    this.lines            = new[this.lines_per_frame];
201
 
202
    foreach(this.lines[l])
203
    begin
204
      this.lines[l].pixel = new[this.pixels_per_line];
205
 
206
      foreach(this.lines[l].pixel[p])
207
        this.lines[l].pixel[p] = from.lines[l].pixel[p];
208
    end
209
  endfunction: copy
210
 
211
  // --------------------------------------------------------------------
212
  virtual function video_frame_class clone;
213
    log.info($sformatf("%m"));
214
    clone = new();
215
    clone.copy(this);
216
  endfunction: clone
217
 
218
  // --------------------------------------------------------------------
219
  function video_frame_class catenate_horizontally(video_frame_class tail);
220
    log.info($sformatf("%m"));
221
 
222
    if(this.lines_per_frame != tail.lines_per_frame)
223
      return(null);
224
 
225
    if(this.bits_per_pixel != tail.bits_per_pixel)
226
      return(null);
227
 
228
    catenate_horizontally = new();
229
    catenate_horizontally.pixels_per_line  = this.pixels_per_line + tail.pixels_per_line;
230
    catenate_horizontally.lines_per_frame  = this.lines_per_frame;
231
    catenate_horizontally.bits_per_pixel   = this.bits_per_pixel;
232
    catenate_horizontally.name             = this.name;
233
    catenate_horizontally.lines            = new[catenate_horizontally.lines_per_frame];
234
 
235
    foreach(catenate_horizontally.lines[l])
236
    begin
237
      catenate_horizontally.lines[l].pixel = new[catenate_horizontally.pixels_per_line];
238
 
239
      foreach(this.lines[l].pixel[p])
240
        catenate_horizontally.lines[l].pixel[p] = this.lines[l].pixel[p];
241
 
242
      foreach(tail.lines[l].pixel[p])
243
        catenate_horizontally.lines[l].pixel[p + this.pixels_per_line] = tail.lines[l].pixel[p];
244
    end
245
  endfunction: catenate_horizontally
246
 
247
  // --------------------------------------------------------------------
248
  function void shift_right(ref line_s column);
249
    log.info($sformatf("%m"));
250
 
251
    foreach(this.lines[l])
252
      for(int p = pixels_per_line - 1; p > 0; p--)
253
        this.lines[l].pixel[p] = this.lines[l].pixel[p - 1];
254
 
255
    foreach(this.lines[l])
256
      this.lines[l].pixel[0] = column.pixel[l];
257
  endfunction: shift_right
258
 
259
  // --------------------------------------------------------------------
260
  function int compare_line
261
  ( int line
262
  , int max_mismatches
263
  , video_frame_class to
264
  );
265
    int mismatch_count = 0;
266
 
267
    if(to.bits_per_pixel != this.bits_per_pixel)
268
    begin
269
      log.error($sformatf("to.bits_per_pixel != this.bits_per_pixel | %s", name));
270
      return(-3);
271
    end
272
 
273
      foreach(this.lines[line].pixel[p])
274
        if(to.lines[line].pixel[p] != this.lines[line].pixel[p])
275
        begin
276
 
277
          if(max_mismatches > 0)
278
            mismatch_count++;
279
 
280
            log.error($sformatf("mismatch @ frame[%4h][%4h] | to == %4h | this == %4h  | %s",
281
                      line, p, to.lines[line].pixel[p], this.lines[line].pixel[p], name));
282
 
283
          if(mismatch_count > max_mismatches)
284
            return(mismatch_count);
285
        end
286
 
287
      return(mismatch_count);
288
  endfunction: compare_line
289
 
290
  // --------------------------------------------------------------------
291
  function int compare(int max_mismatches, video_frame_class to);
292
    int mismatch_count = 0;
293
    log.info($sformatf("%m"));
294
 
295
    if(to.pixels_per_line != this.pixels_per_line)
296
    begin
297
      log.error($sformatf("to.pixels_per_line != this.pixels_per_line | %s", name));
298
      return(-1);
299
    end
300
 
301
    if(to.lines_per_frame != this.lines_per_frame)
302
    begin
303
      log.error($sformatf("to.lines_per_frame != this.lines_per_frame | %s", name));
304
      return(-2);
305
    end
306
 
307
    if(to.bits_per_pixel != this.bits_per_pixel)
308
    begin
309
      log.error($sformatf("to.bits_per_pixel != this.bits_per_pixel | %s", name));
310
      return(-3);
311
    end
312
 
313
      foreach(this.lines[l])
314
      begin
315
        foreach(this.lines[l].pixel[p])
316
          if(to.lines[l].pixel[p] != this.lines[l].pixel[p])
317
          begin
318
            if(max_mismatches > 0)
319
              mismatch_count++;
320
 
321
              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));
322
 
323
            if(mismatch_count > max_mismatches)
324
              return(mismatch_count);
325
          end
326
      end
327
 
328
      return(mismatch_count);
329
  endfunction: compare
330
 
331
  // --------------------------------------------------------------------
332
  function void print_line(int line, int pixel, int count);
333
    log.info($sformatf("%m"));
334
 
335
    for(int i = 0; i < count; i++)
336
      log.display($sformatf("%4h @ frame[%4h][%4h] | %s", this.lines[line].pixel[(pixel + i)], line, (pixel + i), name));
337
  endfunction: print_line
338
 
339
  // --------------------------------------------------------------------
340
  function void print_config();
341
    log.display($sformatf("%m | frame_id         = %06d  | %s", frame_id, name));
342
    log.display($sformatf("%m | pixels_per_line  = %06d  | %s", pixels_per_line, name));
343
    log.display($sformatf("%m | lines_per_frame  = %06d  | %s", lines_per_frame, name));
344
    log.display($sformatf("%m | bits_per_pixel   = %06d  | %s", bits_per_pixel, name));
345
    log.display($sformatf("%m | pixels_per_clk   = %06d  | %s", pixels_per_clk, name));
346
    log.display($sformatf("%m | pattern          = %s    | %s", pattern, name));
347
  endfunction: print_config
348
 
349
  // --------------------------------------------------------------------
350
  function string convert2string();
351
    string s;
352
    string f ="";
353
    foreach(this.lines[l])
354
    begin
355
      s = $sformatf("[%4.d]", l);
356
      foreach(this.lines[l].pixel[p])
357
        s = {s, $sformatf("|%4.h", this.lines[l].pixel[p])};
358
      f = {f, s, "|\n"};
359
    end
360
    return f;
361
  endfunction: convert2string
362
 
363
// --------------------------------------------------------------------
364
endclass: video_frame_class

powered by: WebSVN 2.1.0

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