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

Subversion Repositories qaz_libs

[/] [qaz_libs/] [trunk/] [BFM/] [src/] [video_frame/] [video_frame_pkg.sv] - Blame information for rev 45

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

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

powered by: WebSVN 2.1.0

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