From 453f1c2a29e820a7fe8ae796fa02269b84088b58 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Mon, 6 Jan 2025 19:45:27 +0100 Subject: [PATCH] #12030 Fix isEqual for TextureImage When comparing two TextureImages, create a std::vector representation and use the equality operator for std::vector. Previous implementation did not test all values, and returned equality when the texture was not identical. --- Fwk/AppFwk/CommonCode/cafEffectGenerator.cpp | 23 ++++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/Fwk/AppFwk/CommonCode/cafEffectGenerator.cpp b/Fwk/AppFwk/CommonCode/cafEffectGenerator.cpp index 04d246afa1..a48f31936a 100644 --- a/Fwk/AppFwk/CommonCode/cafEffectGenerator.cpp +++ b/Fwk/AppFwk/CommonCode/cafEffectGenerator.cpp @@ -678,19 +678,18 @@ bool ScalarMapperEffectGenerator::isImagesEqual( const cvf::TextureImage* texImg { if ( texImg1 == nullptr && texImg2 == nullptr ) return true; - if ( texImg1 != nullptr && texImg2 != nullptr && texImg1->height() == texImg2->height() && - texImg1->width() == texImg2->width() && texImg1->width() > 0 && texImg1->height() > 0 && - texImg1->pixel( 0, 0 ) == texImg2->pixel( 0, 0 ) && - texImg1->pixel( texImg1->width() - 1, texImg1->height() - 1 ) == - texImg2->pixel( texImg1->width() - 1, texImg1->height() - 1 ) && - texImg1->pixel( texImg1->width() / 2, texImg1->height() / 2 ) == - texImg2->pixel( texImg1->width() / 2, texImg1->height() / 2 ) && - texImg1->pixel( texImg1->width() / 4, texImg1->height() / 4 ) == - texImg2->pixel( texImg1->width() / 4, texImg1->height() / 4 ) && - texImg1->pixel( texImg1->width() / 2 + texImg1->width() / 4, texImg1->height() / 2 + texImg1->height() / 4 ) == - texImg2->pixel( texImg1->width() / 2 + texImg1->width() / 4, texImg1->height() / 2 + texImg1->height() / 4 ) ) + if ( texImg1 && texImg2 ) { - return true; + auto bytesImg1 = texImg1->toRgb(); + std::vector rgbBytes1; + bytesImg1->toStdVector( &rgbBytes1 ); + + auto bytesImg2 = texImg2->toRgb(); + std::vector rgbBytes2; + bytesImg2->toStdVector( &rgbBytes2 ); + + // Use std::vector equals operator, and we do not have any numerical issues as the values are byte values + return rgbBytes1 == rgbBytes2; } return false;