comparison OrthancFramework/Sources/DicomParsing/Internals/DicomImageDecoder.cpp @ 4278:9279de56a405

avoid multiple calls to GetWidth() and GetHeight() on pixel loops
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 03 Nov 2020 20:05:55 +0100
parents 0034f855c023
children 785a2713323e
comparison
equal deleted inserted replaced
4277:c5ca798b158a 4278:9279de56a405
352 // WARNING - "::min()" should be replaced by "::lowest()" if 352 // WARNING - "::min()" should be replaced by "::lowest()" if
353 // dealing with float or double (which is not the case so far) 353 // dealing with float or double (which is not the case so far)
354 const PixelType minValue = std::numeric_limits<PixelType>::min(); 354 const PixelType minValue = std::numeric_limits<PixelType>::min();
355 const PixelType maxValue = std::numeric_limits<PixelType>::max(); 355 const PixelType maxValue = std::numeric_limits<PixelType>::max();
356 356
357 for (unsigned int y = 0; y < source.GetInformation().GetHeight(); y++) 357 const unsigned int height = source.GetInformation().GetHeight();
358 const unsigned int width = source.GetInformation().GetWidth();
359 const unsigned int channels = source.GetInformation().GetChannelCount();
360
361 for (unsigned int y = 0; y < height; y++)
358 { 362 {
359 PixelType* pixel = reinterpret_cast<PixelType*>(target.GetRow(y)); 363 PixelType* pixel = reinterpret_cast<PixelType*>(target.GetRow(y));
360 for (unsigned int x = 0; x < source.GetInformation().GetWidth(); x++) 364 for (unsigned int x = 0; x < width; x++)
361 { 365 {
362 for (unsigned int c = 0; c < source.GetInformation().GetChannelCount(); c++, pixel++) 366 for (unsigned int c = 0; c < channels; c++, pixel++)
363 { 367 {
364 int32_t v = source.GetValue(x, y, c); 368 int32_t v = source.GetValue(x, y, c);
365 if (v < static_cast<int32_t>(minValue)) 369 if (v < static_cast<int32_t>(minValue))
366 { 370 {
367 *pixel = minValue; 371 *pixel = minValue;
435 { 439 {
436 throw OrthancException(ErrorCode_NotImplemented); 440 throw OrthancException(ErrorCode_NotImplemented);
437 } 441 }
438 442
439 const uint8_t* source = reinterpret_cast<const uint8_t*>(pixelData); 443 const uint8_t* source = reinterpret_cast<const uint8_t*>(pixelData);
444 const unsigned int width = target->GetWidth();
445 const unsigned int height = target->GetHeight();
440 446
441 for (unsigned int y = 0; y < target->GetHeight(); y++) 447 for (unsigned int y = 0; y < height; y++)
442 { 448 {
443 uint8_t* p = reinterpret_cast<uint8_t*>(target->GetRow(y)); 449 uint8_t* p = reinterpret_cast<uint8_t*>(target->GetRow(y));
444 450
445 for (unsigned int x = 0; x < target->GetWidth(); x++) 451 for (unsigned int x = 0; x < width; x++)
446 { 452 {
447 p[0] = lutRed[*source] >> 8; 453 p[0] = lutRed[*source] >> 8;
448 p[1] = lutGreen[*source] >> 8; 454 p[1] = lutGreen[*source] >> 8;
449 p[2] = lutBlue[*source] >> 8; 455 p[2] = lutBlue[*source] >> 8;
450 source++; 456 source++;
465 { 471 {
466 throw OrthancException(ErrorCode_NotImplemented); 472 throw OrthancException(ErrorCode_NotImplemented);
467 } 473 }
468 474
469 const uint16_t* source = reinterpret_cast<const uint16_t*>(pixelData); 475 const uint16_t* source = reinterpret_cast<const uint16_t*>(pixelData);
476 const unsigned int width = target->GetWidth();
477 const unsigned int height = target->GetHeight();
470 478
471 for (unsigned int y = 0; y < target->GetHeight(); y++) 479 for (unsigned int y = 0; y < height; y++)
472 { 480 {
473 uint16_t* p = reinterpret_cast<uint16_t*>(target->GetRow(y)); 481 uint16_t* p = reinterpret_cast<uint16_t*>(target->GetRow(y));
474 482
475 for (unsigned int x = 0; x < target->GetWidth(); x++) 483 for (unsigned int x = 0; x < width; x++)
476 { 484 {
477 p[0] = lutRed[*source]; 485 p[0] = lutRed[*source];
478 p[1] = lutGreen[*source]; 486 p[1] = lutGreen[*source];
479 p[2] = lutBlue[*source]; 487 p[2] = lutBlue[*source];
480 source++; 488 source++;