|
36 | 36 | #include "private/lv_video_transform.hpp" |
37 | 37 | #include "private/lv_video_bmp.hpp" |
38 | 38 | #include "private/lv_video_png.hpp" |
| 39 | +#include <cstring> |
39 | 40 | #include <fstream> |
40 | 41 |
|
41 | 42 | namespace LV { |
@@ -292,6 +293,108 @@ namespace LV { |
292 | 293 | return true; |
293 | 294 | } |
294 | 295 |
|
| 296 | +#ifdef _LV_BUILD_PRIVATE_TEST_FUNCS |
| 297 | + bool Video::validate() const |
| 298 | + { |
| 299 | + // Validate dimensions. |
| 300 | + |
| 301 | + if (m_impl->width <= 0) { |
| 302 | + visual_log (VISUAL_LOG_ERROR, "Video has a zero or negative width (%d).", m_impl->width); |
| 303 | + return false; |
| 304 | + } |
| 305 | + |
| 306 | + if (m_impl->height <= 0) { |
| 307 | + visual_log (VISUAL_LOG_ERROR, "Video has a zero or negative height (%d).", m_impl->height); |
| 308 | + return false; |
| 309 | + } |
| 310 | + |
| 311 | + if (m_impl->pitch <= 0) { |
| 312 | + visual_log (VISUAL_LOG_ERROR, "Video has a zero or negative pitch (%d).", m_impl->pitch); |
| 313 | + return false; |
| 314 | + } |
| 315 | + |
| 316 | + // Validate extents. |
| 317 | + |
| 318 | + if (m_impl->width != m_impl->extents.width) { |
| 319 | + visual_log (VISUAL_LOG_ERROR, "Width (%d) and width of extents (%d) do not agree.", |
| 320 | + m_impl->width, m_impl->extents.width); |
| 321 | + return false; |
| 322 | + } |
| 323 | + |
| 324 | + if (m_impl->height != m_impl->extents.height) { |
| 325 | + visual_log (VISUAL_LOG_ERROR, "Height (%d) and height of extents (%d) do not agree.", |
| 326 | + m_impl->height, m_impl->extents.height); |
| 327 | + return false; |
| 328 | + } |
| 329 | + |
| 330 | + // Validate parent-child relations. |
| 331 | + |
| 332 | + if (m_impl->parent) { |
| 333 | + auto const parent_impl = m_impl->parent->m_impl.get (); |
| 334 | + if (!parent_impl->extents.contains (m_impl->extents)) { |
| 335 | + visual_log (VISUAL_LOG_ERROR, "Sub-video is not fully contained by parent."); |
| 336 | + return false; |
| 337 | + } |
| 338 | + } |
| 339 | + |
| 340 | + if (m_impl->depth != VISUAL_VIDEO_DEPTH_GL) { |
| 341 | + // Validate depth and bytes per pixel consistency. |
| 342 | + |
| 343 | + if (m_impl->bpp != visual_video_depth_bpp (m_impl->depth) / 8) { |
| 344 | + visual_log (VISUAL_LOG_ERROR, "Depth (%s) is not consistent with BPP (%d).", |
| 345 | + visual_video_depth_name (m_impl->depth), m_impl->bpp); |
| 346 | + return false; |
| 347 | + } |
| 348 | + |
| 349 | + // Validate pixel row table |
| 350 | + |
| 351 | + for (int y = 0; y < m_impl->height; y++) { |
| 352 | + auto const pixel_row_ptr = static_cast<uint8_t const*> (get_pixels ()) + y * m_impl->pitch; |
| 353 | + |
| 354 | + if (m_impl->pixel_rows[y] != pixel_row_ptr) { |
| 355 | + visual_log (VISUAL_LOG_ERROR, "Pixel row pointer table is wrong at y=%d.", y); |
| 356 | + return false; |
| 357 | + } |
| 358 | + } |
| 359 | + } |
| 360 | + |
| 361 | + return true; |
| 362 | + } |
| 363 | +#endif // defined(_LV_BUILD_PRIVATE_TEST_FUNCS) |
| 364 | + |
| 365 | + bool Video::has_same_content (VideoConstPtr const& video) const |
| 366 | + { |
| 367 | + // Comparison of GL LV::Video is not supported. |
| 368 | + if (m_impl->depth == VISUAL_VIDEO_DEPTH_GL || video->m_impl->depth == VISUAL_VIDEO_DEPTH_GL) { |
| 369 | + return false; |
| 370 | + } |
| 371 | + |
| 372 | + // Videos must have the same dimensions and pixel format. |
| 373 | + |
| 374 | + if (m_impl->width != video->m_impl->width) |
| 375 | + return false; |
| 376 | + |
| 377 | + if (m_impl->height != video->m_impl->height) |
| 378 | + return false; |
| 379 | + |
| 380 | + if (m_impl->depth != video->m_impl->depth) |
| 381 | + return false; |
| 382 | + |
| 383 | + // Videos must have the same colours at every pixel. |
| 384 | + |
| 385 | + // Determine the size (in bytes) of the blocks in each row to compare. This must exclude padding. |
| 386 | + // It must also exclude pixels outside of a subvideo's extents. |
| 387 | + std::size_t const content_bytes_per_row = m_impl->width * m_impl->bpp; |
| 388 | + |
| 389 | + for (int y = 0; y < m_impl->height; y++) { |
| 390 | + if (std::memcmp (m_impl->pixel_rows[y], video->m_impl->pixel_rows[y], content_bytes_per_row)) { |
| 391 | + return false; |
| 392 | + } |
| 393 | + } |
| 394 | + |
| 395 | + return true; |
| 396 | + } |
| 397 | + |
295 | 398 | void Video::set_palette (Palette const& palette) |
296 | 399 | { |
297 | 400 | m_impl->palette = palette; |
|
0 commit comments