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 34

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
  {
34
    int pixel[];
35
  } line_s;
36
 
37
  typedef struct
38
  {
39
    int x;
40
    int y;
41
  } frame_coordinate_t;
42
 
43
class video_frame_class;
44
  logger_class log;
45
  rand int  frame_id;
46
  rand int  pixels_per_line;
47
  rand int  lines_per_frame;
48
  rand int  bits_per_pixel;
49
  line_s    lines[];
50
  string    name = "";
51
  string    pattern = "";
52
 
53
  constraint default_pixels_per_line
54
  {
55
    pixels_per_line >= 4;
56
    pixels_per_line % 2 == 0;
57
    pixels_per_line <= 16384;
58
  }
59
 
60
  constraint default_lines_per_frame
61
  {
62
    lines_per_frame >= 4;
63
    lines_per_frame % 2 == 0;
64
    lines_per_frame <= 16384;
65
  }
66
 
67
  constraint default_bits_per_pixel
68
  {
69
    bits_per_pixel >= 1 && bits_per_pixel <= 32;
70
  }
71
 
72
 
73
  //--------------------------------------------------------------------
74
  function new;
75
    this.log = new;
76
    this.frame_id = 0;
77
  endfunction: new
78
 
79
 
80
  // --------------------------------------------------------------------
81
  //
82
  function void init
83
  (
84
    input int pixels_per_line,
85
    input int lines_per_frame,
86
    input int bits_per_pixel,
87
    string    name = ""
88
 );
89
 
90
    log.info($sformatf("%m"));
91
 
92
    this.pixels_per_line  = pixels_per_line;
93
    this.lines_per_frame  = lines_per_frame;
94
    this.bits_per_pixel   = bits_per_pixel;
95
    this.name             = name;
96
 
97
    this.make_constant(0);
98
 
99
  endfunction: init
100
 
101
 
102
  // --------------------------------------------------------------------
103
  //
104
  extern virtual task write_pixel
105
  (
106
    input     frame_coordinate_t coordinate,
107
    input int pixel
108
  );
109
 
110
  extern virtual function int read_pixel
111
  (
112
    input frame_coordinate_t coordinate
113
  );
114
 
115
  extern virtual function void make_constant
116
  (
117
    input int  pixel
118
  );
119
 
120
  extern virtual function void make_counting
121
  (
122
    input int  offset = 0
123
  );
124
 
125
  extern virtual function void make_horizontal();
126
 
127
  extern virtual function void make_vertical();
128
 
129
  extern virtual function void make_random();
130
 
131
  extern virtual function void copy
132
  (
133
    ref video_frame_class from
134
  );
135
 
136
  extern virtual function video_frame_class clone();
137
 
138
  extern virtual function int compare
139
  (
140
    input int max_mismatches,
141
    ref video_frame_class to
142
  );
143
 
144
  extern virtual function video_frame_class catenate_horizontally
145
  (
146
    ref video_frame_class tail
147
  );
148
 
149
  extern virtual function int compare_line
150
  (
151
    input int line,
152
    input int max_mismatches,
153
    ref video_frame_class to
154
  );
155
 
156
  extern virtual function void print_line
157
  (
158
    input int line,
159
    input int pixel,
160
    input int count
161
  );
162
 
163
  extern virtual function void print_config();
164
 
165
endclass: video_frame_class
166
 
167
 
168
  // --------------------------------------------------------------------
169
  //
170
  task
171
    video_frame_class::write_pixel
172
    (
173
      input     frame_coordinate_t coordinate,
174
      input int pixel
175
   );
176
 
177
    this.lines[coordinate.y].pixel[coordinate.x] = pixel;
178
 
179
  endtask: write_pixel
180
 
181
 
182
  // --------------------------------------------------------------------
183
  //
184
  function int video_frame_class::read_pixel
185
  (
186
    input frame_coordinate_t coordinate
187
  );
188
 
189
    read_pixel = this.lines[coordinate.y].pixel[coordinate.x];
190
 
191
  endfunction: read_pixel
192
 
193
 
194
  // --------------------------------------------------------------------
195
  //
196
  function void video_frame_class::make_constant
197
  (
198
    input int  pixel
199
  );
200
 
201
    log.info($sformatf("%m"));
202
 
203
 
204
    this.lines = new[lines_per_frame];
205
 
206
    foreach(this.lines[l])
207
    begin
208
 
209
      this.lines[l].pixel = new[pixels_per_line];
210
 
211
      foreach(this.lines[l].pixel[p])
212
        this.lines[l].pixel[p] = pixel;
213
 
214
    end
215
 
216
    pattern = "constant";
217
 
218
  endfunction: make_constant
219
 
220
 
221
  // --------------------------------------------------------------------
222
  //
223
  function void video_frame_class::make_counting
224
  (
225
    input int  offset = 0
226
  );
227
 
228
    log.info($sformatf("%m"));
229
 
230
    this.lines = new[lines_per_frame];
231
 
232
    foreach(this.lines[l])
233
    begin
234
 
235
      this.lines[l].pixel = new[pixels_per_line];
236
 
237
      foreach(this.lines[l].pixel[p])
238
        this.lines[l].pixel[p] = (pixels_per_line * l) + p + offset;
239
 
240
    end
241
 
242
    pattern = "counting";
243
 
244
  endfunction: make_counting
245
 
246
 
247
  // --------------------------------------------------------------------
248
  //
249
  function void video_frame_class::make_horizontal();
250
 
251
    log.info($sformatf("%m"));
252
 
253
    this.lines = new[lines_per_frame];
254
 
255
    foreach(this.lines[l])
256
    begin
257
 
258
      this.lines[l].pixel = new[pixels_per_line];
259
 
260
      foreach(this.lines[l].pixel[p])
261
        this.lines[l].pixel[p] = p;
262
 
263
    end
264
 
265
    pattern = "horizontal";
266
 
267
  endfunction: make_horizontal
268
 
269
 
270
  // --------------------------------------------------------------------
271
  //
272
  function void video_frame_class::make_vertical();
273
 
274
    log.info($sformatf("%m"));
275
 
276
    this.lines = new[lines_per_frame];
277
 
278
    foreach(this.lines[l])
279
    begin
280
 
281
      this.lines[l].pixel = new[pixels_per_line];
282
 
283
      foreach(this.lines[l].pixel[p])
284
        this.lines[l].pixel[p] = l;
285
 
286
    end
287
 
288
    pattern = "vertical";
289
 
290
  endfunction: make_vertical
291
 
292
 
293
  // --------------------------------------------------------------------
294
  //
295
  function void video_frame_class::make_random();
296
 
297
    log.info($sformatf("%m"));
298
 
299
    this.lines = new[lines_per_frame];
300
 
301
    foreach(this.lines[l])
302
    begin
303
 
304
      this.lines[l].pixel = new[pixels_per_line];
305
 
306
      foreach(this.lines[l].pixel[p])
307
        this.lines[l].pixel[p] = $urandom_range(((2 ** bits_per_pixel) - 1), 0);
308
 
309
    end
310
 
311
    pattern = "random";
312
 
313
  endfunction: make_random
314
 
315
 
316
  // --------------------------------------------------------------------
317
  //
318
  function void video_frame_class::copy
319
  (
320
    ref video_frame_class from
321
  );
322
 
323
    log.info($sformatf("%m"));
324
 
325
    this.frame_id         = from.frame_id;
326
    this.pixels_per_line  = from.pixels_per_line;
327
    this.lines_per_frame  = from.lines_per_frame;
328
    this.bits_per_pixel   = from.bits_per_pixel;
329
    this.name             = from.name;
330
    this.lines            = new[this.lines_per_frame];
331
 
332
    foreach(this.lines[l])
333
    begin
334
      this.lines[l].pixel = new[this.pixels_per_line];
335
 
336
      foreach(this.lines[l].pixel[p])
337
        this.lines[l].pixel[p] = from.lines[l].pixel[p];
338
    end
339
  endfunction: copy
340
 
341
 
342
  // --------------------------------------------------------------------
343
  //
344
  function video_frame_class video_frame_class::clone();
345
 
346
    log.info($sformatf("%m"));
347
 
348
    clone = new();
349
    clone.copy(this);
350
 
351
  endfunction: clone
352
 
353
 
354
  // --------------------------------------------------------------------
355
  //
356
  function video_frame_class video_frame_class::catenate_horizontally
357
  (
358
    ref video_frame_class tail
359
  );
360
 
361
    log.info($sformatf("%m"));
362
 
363
    if(this.lines_per_frame != tail.lines_per_frame)
364
      return(null);
365
 
366
    if(this.bits_per_pixel != tail.bits_per_pixel)
367
      return(null);
368
 
369
    catenate_horizontally = new();
370
 
371
    catenate_horizontally.pixels_per_line  = this.pixels_per_line + tail.pixels_per_line;
372
    catenate_horizontally.lines_per_frame  = this.lines_per_frame;
373
    catenate_horizontally.bits_per_pixel   = this.bits_per_pixel;
374
    catenate_horizontally.name             = this.name;
375
    catenate_horizontally.lines            = new[catenate_horizontally.lines_per_frame];
376
 
377
    foreach(catenate_horizontally.lines[l])
378
    begin
379
      catenate_horizontally.lines[l].pixel = new[catenate_horizontally.pixels_per_line];
380
 
381
      foreach(this.lines[l].pixel[p])
382
        catenate_horizontally.lines[l].pixel[p] = this.lines[l].pixel[p];
383
 
384
      foreach(tail.lines[l].pixel[p])
385
        catenate_horizontally.lines[l].pixel[p + this.pixels_per_line] = tail.lines[l].pixel[p];
386
 
387
    end
388
 
389
  endfunction: catenate_horizontally
390
 
391
 
392
  // --------------------------------------------------------------------
393
  //
394
  function int video_frame_class::compare_line
395
  (
396
    input int line,
397
    input int max_mismatches,
398
    ref video_frame_class to
399
 );
400
 
401
    int mismatch_count = 0;
402
 
403
    if(to.bits_per_pixel != this.bits_per_pixel)
404
    begin
405
      log.error($sformatf("to.bits_per_pixel != this.bits_per_pixel | %s", name));
406
      return(-3);
407
    end
408
 
409
      foreach(this.lines[line].pixel[p])
410
        if(to.lines[line].pixel[p] != this.lines[line].pixel[p])
411
        begin
412
 
413
          if(max_mismatches > 0)
414
            mismatch_count++;
415
 
416
            log.error($sformatf("mismatch @ frame[%4h][%4h] | to == %4h | this == %4h  | %s",
417
                      line, p, to.lines[line].pixel[p], this.lines[line].pixel[p], name));
418
 
419
          if(mismatch_count > max_mismatches)
420
            return(mismatch_count);
421
 
422
        end
423
 
424
      return(mismatch_count);
425
 
426
  endfunction: compare_line
427
 
428
 
429
  // --------------------------------------------------------------------
430
  //
431
  function int video_frame_class::compare
432
  (
433
    input int max_mismatches,
434
    ref video_frame_class to
435
 );
436
 
437
    int mismatch_count = 0;
438
 
439
    log.info($sformatf("%m"));
440
 
441
    if(to.pixels_per_line != this.pixels_per_line)
442
    begin
443
      log.error($sformatf("to.pixels_per_line != this.pixels_per_line | %s", name));
444
      return(-1);
445
    end
446
 
447
    if(to.lines_per_frame != this.lines_per_frame)
448
    begin
449
      log.error($sformatf("to.lines_per_frame != this.lines_per_frame | %s", name));
450
      return(-2);
451
    end
452
 
453
    if(to.bits_per_pixel != this.bits_per_pixel)
454
    begin
455
      log.error($sformatf("to.bits_per_pixel != this.bits_per_pixel | %s", name));
456
      return(-3);
457
    end
458
 
459
      foreach(this.lines[l])
460
      begin
461
        foreach(this.lines[l].pixel[p])
462
          if(to.lines[l].pixel[p] != this.lines[l].pixel[p])
463
          begin
464
 
465
            if(max_mismatches > 0)
466
              mismatch_count++;
467
 
468
              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));
469
 
470
            if(mismatch_count > max_mismatches)
471
              return(mismatch_count);
472
 
473
          end
474
      end
475
 
476
      return(mismatch_count);
477
 
478
  endfunction: compare
479
 
480
 
481
  // --------------------------------------------------------------------
482
  //
483
  function void video_frame_class::print_line
484
  (
485
    input int line,
486
    input int pixel,
487
    input int count
488
  );
489
 
490
    log.info($sformatf("%m"));
491
 
492
    for(int i = 0; i < count; i++)
493
      log.display($sformatf("%4h @ frame[%4h][%4h] | %s", this.lines[line].pixel[(pixel + i)], line, (pixel + i), name));
494
 
495
  endfunction: print_line
496
 
497
 
498
  // --------------------------------------------------------------------
499
  //
500
  function void video_frame_class::print_config();
501
 
502
    log.display($sformatf("%m | frame_id         = %06d  | %s", frame_id, name));
503
    log.display($sformatf("%m | pixels_per_line  = %06d  | %s", pixels_per_line, name));
504
    log.display($sformatf("%m | lines_per_frame  = %06d  | %s", lines_per_frame, name));
505
    log.display($sformatf("%m | bits_per_pixel   = %06d  | %s", bits_per_pixel, name));
506
    log.display($sformatf("%m | pattern          = %s    | %s", pattern, name));
507
 
508
  endfunction: print_config
509
 
510
 
511
endpackage: video_frame_pkg
512
 

powered by: WebSVN 2.1.0

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