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 43

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

powered by: WebSVN 2.1.0

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