| 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 |
|
|
flatten_frame = new[lines_per_frame*pixels_per_line];
|
| 101 |
|
|
foreach(this.lines[l])
|
| 102 |
|
|
foreach(this.lines[l].pixel[p])
|
| 103 |
49 |
qaztronic |
flatten_frame[(l*pixels_per_line)+p] = this.lines[l].pixel[p];
|
| 104 |
47 |
qaztronic |
endfunction: flatten_frame
|
| 105 |
|
|
|
| 106 |
|
|
// --------------------------------------------------------------------
|
| 107 |
49 |
qaztronic |
function void load_flatten_frame(flattened_frame_t a);
|
| 108 |
|
|
make_constant(0);
|
| 109 |
|
|
foreach(lines[l])
|
| 110 |
|
|
foreach(lines[l].pixel[p])
|
| 111 |
|
|
lines[l].pixel[p] = a[(l*pixels_per_line)+p];
|
| 112 |
|
|
endfunction: load_flatten_frame
|
| 113 |
|
|
|
| 114 |
|
|
// --------------------------------------------------------------------
|
| 115 |
47 |
qaztronic |
function void make_constant(int pixel);
|
| 116 |
|
|
log.info($sformatf("%m"));
|
| 117 |
|
|
this.lines = new[lines_per_frame];
|
| 118 |
|
|
|
| 119 |
|
|
foreach(this.lines[l])
|
| 120 |
|
|
begin
|
| 121 |
|
|
this.lines[l].pixel = new[pixels_per_line];
|
| 122 |
|
|
|
| 123 |
|
|
foreach(this.lines[l].pixel[p])
|
| 124 |
|
|
this.lines[l].pixel[p] = pixel;
|
| 125 |
|
|
end
|
| 126 |
|
|
|
| 127 |
|
|
pattern = "constant";
|
| 128 |
|
|
endfunction: make_constant
|
| 129 |
|
|
|
| 130 |
|
|
// --------------------------------------------------------------------
|
| 131 |
|
|
function void make_counting(int offset = 0);
|
| 132 |
|
|
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] = (pixels_per_line * l) + p + offset;
|
| 141 |
|
|
end
|
| 142 |
|
|
|
| 143 |
|
|
pattern = "counting";
|
| 144 |
|
|
endfunction: make_counting
|
| 145 |
|
|
|
| 146 |
|
|
// --------------------------------------------------------------------
|
| 147 |
|
|
function void make_horizontal();
|
| 148 |
|
|
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] = p;
|
| 157 |
|
|
end
|
| 158 |
|
|
|
| 159 |
|
|
pattern = "horizontal";
|
| 160 |
|
|
endfunction: make_horizontal
|
| 161 |
|
|
|
| 162 |
|
|
// --------------------------------------------------------------------
|
| 163 |
|
|
function void make_vertical();
|
| 164 |
|
|
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] = l;
|
| 173 |
|
|
end
|
| 174 |
|
|
|
| 175 |
|
|
pattern = "vertical";
|
| 176 |
|
|
endfunction: make_vertical
|
| 177 |
|
|
|
| 178 |
|
|
// --------------------------------------------------------------------
|
| 179 |
|
|
function void make_random();
|
| 180 |
|
|
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] = $urandom_range(((2 ** bits_per_pixel) - 1), 0);
|
| 189 |
|
|
end
|
| 190 |
|
|
|
| 191 |
|
|
pattern = "random";
|
| 192 |
|
|
endfunction: make_random
|
| 193 |
|
|
|
| 194 |
|
|
// --------------------------------------------------------------------
|
| 195 |
|
|
function void copy(video_frame_class from);
|
| 196 |
|
|
log.info($sformatf("%m"));
|
| 197 |
|
|
this.frame_id = from.frame_id;
|
| 198 |
|
|
this.pixels_per_line = from.pixels_per_line;
|
| 199 |
|
|
this.lines_per_frame = from.lines_per_frame;
|
| 200 |
|
|
this.bits_per_pixel = from.bits_per_pixel;
|
| 201 |
|
|
this.name = from.name;
|
| 202 |
|
|
this.lines = new[this.lines_per_frame];
|
| 203 |
|
|
|
| 204 |
|
|
foreach(this.lines[l])
|
| 205 |
|
|
begin
|
| 206 |
|
|
this.lines[l].pixel = new[this.pixels_per_line];
|
| 207 |
|
|
|
| 208 |
|
|
foreach(this.lines[l].pixel[p])
|
| 209 |
|
|
this.lines[l].pixel[p] = from.lines[l].pixel[p];
|
| 210 |
|
|
end
|
| 211 |
|
|
endfunction: copy
|
| 212 |
|
|
|
| 213 |
|
|
// --------------------------------------------------------------------
|
| 214 |
|
|
virtual function video_frame_class clone;
|
| 215 |
|
|
log.info($sformatf("%m"));
|
| 216 |
|
|
clone = new();
|
| 217 |
|
|
clone.copy(this);
|
| 218 |
|
|
endfunction: clone
|
| 219 |
|
|
|
| 220 |
|
|
// --------------------------------------------------------------------
|
| 221 |
|
|
function video_frame_class catenate_horizontally(video_frame_class tail);
|
| 222 |
|
|
log.info($sformatf("%m"));
|
| 223 |
|
|
|
| 224 |
|
|
if(this.lines_per_frame != tail.lines_per_frame)
|
| 225 |
|
|
return(null);
|
| 226 |
|
|
|
| 227 |
|
|
if(this.bits_per_pixel != tail.bits_per_pixel)
|
| 228 |
|
|
return(null);
|
| 229 |
|
|
|
| 230 |
|
|
catenate_horizontally = new();
|
| 231 |
|
|
catenate_horizontally.pixels_per_line = this.pixels_per_line + tail.pixels_per_line;
|
| 232 |
|
|
catenate_horizontally.lines_per_frame = this.lines_per_frame;
|
| 233 |
|
|
catenate_horizontally.bits_per_pixel = this.bits_per_pixel;
|
| 234 |
|
|
catenate_horizontally.name = this.name;
|
| 235 |
|
|
catenate_horizontally.lines = new[catenate_horizontally.lines_per_frame];
|
| 236 |
|
|
|
| 237 |
|
|
foreach(catenate_horizontally.lines[l])
|
| 238 |
|
|
begin
|
| 239 |
|
|
catenate_horizontally.lines[l].pixel = new[catenate_horizontally.pixels_per_line];
|
| 240 |
|
|
|
| 241 |
|
|
foreach(this.lines[l].pixel[p])
|
| 242 |
|
|
catenate_horizontally.lines[l].pixel[p] = this.lines[l].pixel[p];
|
| 243 |
|
|
|
| 244 |
|
|
foreach(tail.lines[l].pixel[p])
|
| 245 |
|
|
catenate_horizontally.lines[l].pixel[p + this.pixels_per_line] = tail.lines[l].pixel[p];
|
| 246 |
|
|
end
|
| 247 |
|
|
endfunction: catenate_horizontally
|
| 248 |
|
|
|
| 249 |
|
|
// --------------------------------------------------------------------
|
| 250 |
|
|
function void shift_right(ref line_s column);
|
| 251 |
|
|
log.info($sformatf("%m"));
|
| 252 |
|
|
|
| 253 |
|
|
foreach(this.lines[l])
|
| 254 |
|
|
for(int p = pixels_per_line - 1; p > 0; p--)
|
| 255 |
|
|
this.lines[l].pixel[p] = this.lines[l].pixel[p - 1];
|
| 256 |
|
|
|
| 257 |
|
|
foreach(this.lines[l])
|
| 258 |
|
|
this.lines[l].pixel[0] = column.pixel[l];
|
| 259 |
|
|
endfunction: shift_right
|
| 260 |
|
|
|
| 261 |
|
|
// --------------------------------------------------------------------
|
| 262 |
|
|
function int compare_line
|
| 263 |
|
|
( int line
|
| 264 |
|
|
, int max_mismatches
|
| 265 |
|
|
, video_frame_class to
|
| 266 |
|
|
);
|
| 267 |
|
|
int mismatch_count = 0;
|
| 268 |
|
|
|
| 269 |
|
|
if(to.bits_per_pixel != this.bits_per_pixel)
|
| 270 |
|
|
begin
|
| 271 |
|
|
log.error($sformatf("to.bits_per_pixel != this.bits_per_pixel | %s", name));
|
| 272 |
|
|
return(-3);
|
| 273 |
|
|
end
|
| 274 |
|
|
|
| 275 |
|
|
foreach(this.lines[line].pixel[p])
|
| 276 |
|
|
if(to.lines[line].pixel[p] != this.lines[line].pixel[p])
|
| 277 |
|
|
begin
|
| 278 |
|
|
|
| 279 |
|
|
if(max_mismatches > 0)
|
| 280 |
|
|
mismatch_count++;
|
| 281 |
|
|
|
| 282 |
|
|
log.error($sformatf("mismatch @ frame[%4h][%4h] | to == %4h | this == %4h | %s",
|
| 283 |
|
|
line, p, to.lines[line].pixel[p], this.lines[line].pixel[p], name));
|
| 284 |
|
|
|
| 285 |
|
|
if(mismatch_count > max_mismatches)
|
| 286 |
|
|
return(mismatch_count);
|
| 287 |
|
|
end
|
| 288 |
|
|
|
| 289 |
|
|
return(mismatch_count);
|
| 290 |
|
|
endfunction: compare_line
|
| 291 |
|
|
|
| 292 |
|
|
// --------------------------------------------------------------------
|
| 293 |
|
|
function int compare(int max_mismatches, video_frame_class to);
|
| 294 |
|
|
int mismatch_count = 0;
|
| 295 |
|
|
log.info($sformatf("%m"));
|
| 296 |
|
|
|
| 297 |
|
|
if(to.pixels_per_line != this.pixels_per_line)
|
| 298 |
|
|
begin
|
| 299 |
|
|
log.error($sformatf("to.pixels_per_line != this.pixels_per_line | %s", name));
|
| 300 |
|
|
return(-1);
|
| 301 |
|
|
end
|
| 302 |
|
|
|
| 303 |
|
|
if(to.lines_per_frame != this.lines_per_frame)
|
| 304 |
|
|
begin
|
| 305 |
|
|
log.error($sformatf("to.lines_per_frame != this.lines_per_frame | %s", name));
|
| 306 |
|
|
return(-2);
|
| 307 |
|
|
end
|
| 308 |
|
|
|
| 309 |
|
|
if(to.bits_per_pixel != this.bits_per_pixel)
|
| 310 |
|
|
begin
|
| 311 |
|
|
log.error($sformatf("to.bits_per_pixel != this.bits_per_pixel | %s", name));
|
| 312 |
|
|
return(-3);
|
| 313 |
|
|
end
|
| 314 |
|
|
|
| 315 |
|
|
foreach(this.lines[l])
|
| 316 |
|
|
begin
|
| 317 |
|
|
foreach(this.lines[l].pixel[p])
|
| 318 |
|
|
if(to.lines[l].pixel[p] != this.lines[l].pixel[p])
|
| 319 |
|
|
begin
|
| 320 |
|
|
if(max_mismatches > 0)
|
| 321 |
|
|
mismatch_count++;
|
| 322 |
|
|
|
| 323 |
|
|
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));
|
| 324 |
|
|
|
| 325 |
|
|
if(mismatch_count > max_mismatches)
|
| 326 |
|
|
return(mismatch_count);
|
| 327 |
|
|
end
|
| 328 |
|
|
end
|
| 329 |
|
|
|
| 330 |
|
|
return(mismatch_count);
|
| 331 |
|
|
endfunction: compare
|
| 332 |
|
|
|
| 333 |
|
|
// --------------------------------------------------------------------
|
| 334 |
|
|
function void print_line(int line, int pixel, int count);
|
| 335 |
|
|
log.info($sformatf("%m"));
|
| 336 |
|
|
|
| 337 |
|
|
for(int i = 0; i < count; i++)
|
| 338 |
|
|
log.display($sformatf("%4h @ frame[%4h][%4h] | %s", this.lines[line].pixel[(pixel + i)], line, (pixel + i), name));
|
| 339 |
|
|
endfunction: print_line
|
| 340 |
|
|
|
| 341 |
|
|
// --------------------------------------------------------------------
|
| 342 |
|
|
function void print_config();
|
| 343 |
|
|
log.display($sformatf("%m | frame_id = %06d | %s", frame_id, name));
|
| 344 |
|
|
log.display($sformatf("%m | pixels_per_line = %06d | %s", pixels_per_line, name));
|
| 345 |
|
|
log.display($sformatf("%m | lines_per_frame = %06d | %s", lines_per_frame, name));
|
| 346 |
|
|
log.display($sformatf("%m | bits_per_pixel = %06d | %s", bits_per_pixel, name));
|
| 347 |
|
|
log.display($sformatf("%m | pixels_per_clk = %06d | %s", pixels_per_clk, name));
|
| 348 |
|
|
log.display($sformatf("%m | pattern = %s | %s", pattern, name));
|
| 349 |
|
|
endfunction: print_config
|
| 350 |
|
|
|
| 351 |
|
|
// --------------------------------------------------------------------
|
| 352 |
49 |
qaztronic |
function string convert2string(int grid=8);
|
| 353 |
47 |
qaztronic |
string s;
|
| 354 |
|
|
string f ="";
|
| 355 |
49 |
qaztronic |
string fs = $sformatf("%%s%%%0d.h" , (bits_per_pixel % 4 == 0)
|
| 356 |
|
|
? bits_per_pixel / 4
|
| 357 |
|
|
: (bits_per_pixel / 4) + 1
|
| 358 |
|
|
);
|
| 359 |
47 |
qaztronic |
foreach(this.lines[l])
|
| 360 |
|
|
begin
|
| 361 |
|
|
s = $sformatf("[%4.d]", l);
|
| 362 |
|
|
foreach(this.lines[l].pixel[p])
|
| 363 |
49 |
qaztronic |
s = {s, $sformatf(fs, (p % grid == 0) ? "!" : "|", this.lines[l].pixel[p])};
|
| 364 |
|
|
|
| 365 |
47 |
qaztronic |
f = {f, s, "|\n"};
|
| 366 |
|
|
end
|
| 367 |
|
|
return f;
|
| 368 |
|
|
endfunction: convert2string
|
| 369 |
|
|
|
| 370 |
|
|
// --------------------------------------------------------------------
|
| 371 |
|
|
endclass: video_frame_class
|