comparison Core/Images/ImageProcessing.cpp @ 2904:0dd54ee073db

float to integer grayscale conversion
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 30 Oct 2018 10:46:17 +0100
parents e80b38fb22c6
children 7791eac62572
comparison
equal deleted inserted replaced
2903:1153b1a128fe 2904:0dd54ee073db
51 const ImageAccessor& source) 51 const ImageAccessor& source)
52 { 52 {
53 const TargetType minValue = std::numeric_limits<TargetType>::min(); 53 const TargetType minValue = std::numeric_limits<TargetType>::min();
54 const TargetType maxValue = std::numeric_limits<TargetType>::max(); 54 const TargetType maxValue = std::numeric_limits<TargetType>::max();
55 55
56 for (unsigned int y = 0; y < source.GetHeight(); y++) 56 const unsigned int width = source.GetWidth();
57 const unsigned int height = source.GetHeight();
58
59 for (unsigned int y = 0; y < height; y++)
57 { 60 {
58 TargetType* t = reinterpret_cast<TargetType*>(target.GetRow(y)); 61 TargetType* t = reinterpret_cast<TargetType*>(target.GetRow(y));
59 const SourceType* s = reinterpret_cast<const SourceType*>(source.GetConstRow(y)); 62 const SourceType* s = reinterpret_cast<const SourceType*>(source.GetConstRow(y));
60 63
61 for (unsigned int x = 0; x < source.GetWidth(); x++, t++, s++) 64 for (unsigned int x = 0; x < width; x++, t++, s++)
62 { 65 {
63 if (static_cast<int32_t>(*s) < static_cast<int32_t>(minValue)) 66 if (static_cast<int32_t>(*s) < static_cast<int32_t>(minValue))
64 { 67 {
65 *t = minValue; 68 *t = minValue;
66 } 69 }
81 static void ConvertGrayscaleToFloat(ImageAccessor& target, 84 static void ConvertGrayscaleToFloat(ImageAccessor& target,
82 const ImageAccessor& source) 85 const ImageAccessor& source)
83 { 86 {
84 assert(sizeof(float) == 4); 87 assert(sizeof(float) == 4);
85 88
86 for (unsigned int y = 0; y < source.GetHeight(); y++) 89 const unsigned int width = source.GetWidth();
90 const unsigned int height = source.GetHeight();
91
92 for (unsigned int y = 0; y < height; y++)
87 { 93 {
88 float* t = reinterpret_cast<float*>(target.GetRow(y)); 94 float* t = reinterpret_cast<float*>(target.GetRow(y));
89 const SourceType* s = reinterpret_cast<const SourceType*>(source.GetConstRow(y)); 95 const SourceType* s = reinterpret_cast<const SourceType*>(source.GetConstRow(y));
90 96
91 for (unsigned int x = 0; x < source.GetWidth(); x++, t++, s++) 97 for (unsigned int x = 0; x < width; x++, t++, s++)
92 { 98 {
93 *t = static_cast<float>(*s); 99 *t = static_cast<float>(*s);
100 }
101 }
102 }
103
104
105 template <PixelFormat TargetFormat>
106 static void ConvertFloatToGrayscale(ImageAccessor& target,
107 const ImageAccessor& source)
108 {
109 typedef typename PixelTraits<TargetFormat>::PixelType TargetType;
110
111 assert(sizeof(float) == 4);
112
113 const unsigned int width = source.GetWidth();
114 const unsigned int height = source.GetHeight();
115
116 for (unsigned int y = 0; y < height; y++)
117 {
118 TargetType* q = reinterpret_cast<TargetType*>(target.GetRow(y));
119 const float* p = reinterpret_cast<const float*>(source.GetConstRow(y));
120
121 for (unsigned int x = 0; x < width; x++, p++, q++)
122 {
123 PixelTraits<TargetFormat>::FloatToPixel(*q, *p);
94 } 124 }
95 } 125 }
96 } 126 }
97 127
98 128
103 assert(source.GetFormat() == PixelFormat_RGB24); 133 assert(source.GetFormat() == PixelFormat_RGB24);
104 134
105 const TargetType minValue = std::numeric_limits<TargetType>::min(); 135 const TargetType minValue = std::numeric_limits<TargetType>::min();
106 const TargetType maxValue = std::numeric_limits<TargetType>::max(); 136 const TargetType maxValue = std::numeric_limits<TargetType>::max();
107 137
108 for (unsigned int y = 0; y < source.GetHeight(); y++) 138 const unsigned int width = source.GetWidth();
139 const unsigned int height = source.GetHeight();
140
141 for (unsigned int y = 0; y < height; y++)
109 { 142 {
110 TargetType* t = reinterpret_cast<TargetType*>(target.GetRow(y)); 143 TargetType* t = reinterpret_cast<TargetType*>(target.GetRow(y));
111 const uint8_t* s = reinterpret_cast<const uint8_t*>(source.GetConstRow(y)); 144 const uint8_t* s = reinterpret_cast<const uint8_t*>(source.GetConstRow(y));
112 145
113 for (unsigned int x = 0; x < source.GetWidth(); x++, t++, s += 3) 146 for (unsigned int x = 0; x < width; x++, t++, s += 3)
114 { 147 {
115 // Y = 0.2126 R + 0.7152 G + 0.0722 B 148 // Y = 0.2126 R + 0.7152 G + 0.0722 B
116 int32_t v = (2126 * static_cast<int32_t>(s[0]) + 149 int32_t v = (2126 * static_cast<int32_t>(s[0]) +
117 7152 * static_cast<int32_t>(s[1]) + 150 7152 * static_cast<int32_t>(s[1]) +
118 0722 * static_cast<int32_t>(s[2])) / 10000; 151 0722 * static_cast<int32_t>(s[2])) / 10000;
196 } 229 }
197 230
198 minValue = std::numeric_limits<PixelType>::max(); 231 minValue = std::numeric_limits<PixelType>::max();
199 maxValue = std::numeric_limits<PixelType>::min(); 232 maxValue = std::numeric_limits<PixelType>::min();
200 233
234 const unsigned int height = source.GetHeight();
201 const unsigned int width = source.GetWidth(); 235 const unsigned int width = source.GetWidth();
202 236
203 for (unsigned int y = 0; y < source.GetHeight(); y++) 237 for (unsigned int y = 0; y < height; y++)
204 { 238 {
205 const PixelType* p = reinterpret_cast<const PixelType*>(source.GetConstRow(y)); 239 const PixelType* p = reinterpret_cast<const PixelType*>(source.GetConstRow(y));
206 240
207 for (unsigned int x = 0; x < width; x++, p++) 241 for (unsigned int x = 0; x < width; x++, p++)
208 { 242 {
231 } 265 }
232 266
233 const int64_t minValue = std::numeric_limits<PixelType>::min(); 267 const int64_t minValue = std::numeric_limits<PixelType>::min();
234 const int64_t maxValue = std::numeric_limits<PixelType>::max(); 268 const int64_t maxValue = std::numeric_limits<PixelType>::max();
235 269
236 for (unsigned int y = 0; y < image.GetHeight(); y++) 270 const unsigned int width = image.GetWidth();
271 const unsigned int height = image.GetHeight();
272
273 for (unsigned int y = 0; y < height; y++)
237 { 274 {
238 PixelType* p = reinterpret_cast<PixelType*>(image.GetRow(y)); 275 PixelType* p = reinterpret_cast<PixelType*>(image.GetRow(y));
239 276
240 for (unsigned int x = 0; x < image.GetWidth(); x++, p++) 277 for (unsigned int x = 0; x < width; x++, p++)
241 { 278 {
242 int64_t v = static_cast<int64_t>(*p) + constant; 279 int64_t v = static_cast<int64_t>(*p) + constant;
243 280
244 if (v > maxValue) 281 if (v > maxValue)
245 { 282 {
269 return; 306 return;
270 } 307 }
271 308
272 const int64_t minValue = std::numeric_limits<PixelType>::min(); 309 const int64_t minValue = std::numeric_limits<PixelType>::min();
273 const int64_t maxValue = std::numeric_limits<PixelType>::max(); 310 const int64_t maxValue = std::numeric_limits<PixelType>::max();
311
274 const unsigned int width = image.GetWidth(); 312 const unsigned int width = image.GetWidth();
275 313 const unsigned int height = image.GetHeight();
276 for (unsigned int y = 0; y < image.GetHeight(); y++) 314
315 for (unsigned int y = 0; y < height; y++)
277 { 316 {
278 PixelType* p = reinterpret_cast<PixelType*>(image.GetRow(y)); 317 PixelType* p = reinterpret_cast<PixelType*>(image.GetRow(y));
279 318
280 for (unsigned int x = 0; x < width; x++, p++) 319 for (unsigned int x = 0; x < width; x++, p++)
281 { 320 {
383 target.GetHeight() != source.GetHeight()) 422 target.GetHeight() != source.GetHeight())
384 { 423 {
385 throw OrthancException(ErrorCode_IncompatibleImageSize); 424 throw OrthancException(ErrorCode_IncompatibleImageSize);
386 } 425 }
387 426
427 const unsigned int width = source.GetWidth();
428 const unsigned int height = source.GetHeight();
429
388 if (source.GetFormat() == target.GetFormat()) 430 if (source.GetFormat() == target.GetFormat())
389 { 431 {
390 Copy(target, source); 432 Copy(target, source);
391 return; 433 return;
392 } 434 }
480 { 522 {
481 ConvertGrayscaleToFloat<int16_t>(target, source); 523 ConvertGrayscaleToFloat<int16_t>(target, source);
482 return; 524 return;
483 } 525 }
484 526
527
485 if (target.GetFormat() == PixelFormat_Grayscale8 && 528 if (target.GetFormat() == PixelFormat_Grayscale8 &&
486 source.GetFormat() == PixelFormat_RGBA32) 529 source.GetFormat() == PixelFormat_RGBA32)
487 { 530 {
488 for (unsigned int y = 0; y < source.GetHeight(); y++) 531 for (unsigned int y = 0; y < height; y++)
489 { 532 {
490 const uint8_t* p = reinterpret_cast<const uint8_t*>(source.GetConstRow(y)); 533 const uint8_t* p = reinterpret_cast<const uint8_t*>(source.GetConstRow(y));
491 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y)); 534 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y));
492 for (unsigned int x = 0; x < source.GetWidth(); x++, q++) 535 for (unsigned int x = 0; x < width; x++, q++)
493 { 536 {
494 *q = static_cast<uint8_t>((2126 * static_cast<uint32_t>(p[0]) + 537 *q = static_cast<uint8_t>((2126 * static_cast<uint32_t>(p[0]) +
495 7152 * static_cast<uint32_t>(p[1]) + 538 7152 * static_cast<uint32_t>(p[1]) +
496 0722 * static_cast<uint32_t>(p[2])) / 10000); 539 0722 * static_cast<uint32_t>(p[2])) / 10000);
497 p += 4; 540 p += 4;
502 } 545 }
503 546
504 if (target.GetFormat() == PixelFormat_Grayscale8 && 547 if (target.GetFormat() == PixelFormat_Grayscale8 &&
505 source.GetFormat() == PixelFormat_BGRA32) 548 source.GetFormat() == PixelFormat_BGRA32)
506 { 549 {
507 for (unsigned int y = 0; y < source.GetHeight(); y++) 550 for (unsigned int y = 0; y < height; y++)
508 { 551 {
509 const uint8_t* p = reinterpret_cast<const uint8_t*>(source.GetConstRow(y)); 552 const uint8_t* p = reinterpret_cast<const uint8_t*>(source.GetConstRow(y));
510 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y)); 553 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y));
511 for (unsigned int x = 0; x < source.GetWidth(); x++, q++) 554 for (unsigned int x = 0; x < width; x++, q++)
512 { 555 {
513 *q = static_cast<uint8_t>((2126 * static_cast<uint32_t>(p[2]) + 556 *q = static_cast<uint8_t>((2126 * static_cast<uint32_t>(p[2]) +
514 7152 * static_cast<uint32_t>(p[1]) + 557 7152 * static_cast<uint32_t>(p[1]) +
515 0722 * static_cast<uint32_t>(p[0])) / 10000); 558 0722 * static_cast<uint32_t>(p[0])) / 10000);
516 p += 4; 559 p += 4;
521 } 564 }
522 565
523 if (target.GetFormat() == PixelFormat_RGB24 && 566 if (target.GetFormat() == PixelFormat_RGB24 &&
524 source.GetFormat() == PixelFormat_RGBA32) 567 source.GetFormat() == PixelFormat_RGBA32)
525 { 568 {
526 for (unsigned int y = 0; y < source.GetHeight(); y++) 569 for (unsigned int y = 0; y < height; y++)
527 { 570 {
528 const uint8_t* p = reinterpret_cast<const uint8_t*>(source.GetConstRow(y)); 571 const uint8_t* p = reinterpret_cast<const uint8_t*>(source.GetConstRow(y));
529 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y)); 572 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y));
530 for (unsigned int x = 0; x < source.GetWidth(); x++) 573 for (unsigned int x = 0; x < width; x++)
531 { 574 {
532 q[0] = p[0]; 575 q[0] = p[0];
533 q[1] = p[1]; 576 q[1] = p[1];
534 q[2] = p[2]; 577 q[2] = p[2];
535 p += 4; 578 p += 4;
541 } 584 }
542 585
543 if (target.GetFormat() == PixelFormat_RGB24 && 586 if (target.GetFormat() == PixelFormat_RGB24 &&
544 source.GetFormat() == PixelFormat_BGRA32) 587 source.GetFormat() == PixelFormat_BGRA32)
545 { 588 {
546 for (unsigned int y = 0; y < source.GetHeight(); y++) 589 for (unsigned int y = 0; y < height; y++)
547 { 590 {
548 const uint8_t* p = reinterpret_cast<const uint8_t*>(source.GetConstRow(y)); 591 const uint8_t* p = reinterpret_cast<const uint8_t*>(source.GetConstRow(y));
549 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y)); 592 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y));
550 for (unsigned int x = 0; x < source.GetWidth(); x++) 593 for (unsigned int x = 0; x < width; x++)
551 { 594 {
552 q[0] = p[2]; 595 q[0] = p[2];
553 q[1] = p[1]; 596 q[1] = p[1];
554 q[2] = p[0]; 597 q[2] = p[0];
555 p += 4; 598 p += 4;
561 } 604 }
562 605
563 if (target.GetFormat() == PixelFormat_RGBA32 && 606 if (target.GetFormat() == PixelFormat_RGBA32 &&
564 source.GetFormat() == PixelFormat_RGB24) 607 source.GetFormat() == PixelFormat_RGB24)
565 { 608 {
566 for (unsigned int y = 0; y < source.GetHeight(); y++) 609 for (unsigned int y = 0; y < height; y++)
567 { 610 {
568 const uint8_t* p = reinterpret_cast<const uint8_t*>(source.GetConstRow(y)); 611 const uint8_t* p = reinterpret_cast<const uint8_t*>(source.GetConstRow(y));
569 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y)); 612 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y));
570 for (unsigned int x = 0; x < source.GetWidth(); x++) 613 for (unsigned int x = 0; x < width; x++)
571 { 614 {
572 q[0] = p[0]; 615 q[0] = p[0];
573 q[1] = p[1]; 616 q[1] = p[1];
574 q[2] = p[2]; 617 q[2] = p[2];
575 q[3] = 255; // Set the alpha channel to full opacity 618 q[3] = 255; // Set the alpha channel to full opacity
582 } 625 }
583 626
584 if (target.GetFormat() == PixelFormat_RGB24 && 627 if (target.GetFormat() == PixelFormat_RGB24 &&
585 source.GetFormat() == PixelFormat_Grayscale8) 628 source.GetFormat() == PixelFormat_Grayscale8)
586 { 629 {
587 for (unsigned int y = 0; y < source.GetHeight(); y++) 630 for (unsigned int y = 0; y < height; y++)
588 { 631 {
589 const uint8_t* p = reinterpret_cast<const uint8_t*>(source.GetConstRow(y)); 632 const uint8_t* p = reinterpret_cast<const uint8_t*>(source.GetConstRow(y));
590 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y)); 633 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y));
591 for (unsigned int x = 0; x < source.GetWidth(); x++) 634 for (unsigned int x = 0; x < width; x++)
592 { 635 {
593 q[0] = *p; 636 q[0] = *p;
594 q[1] = *p; 637 q[1] = *p;
595 q[2] = *p; 638 q[2] = *p;
596 p += 1; 639 p += 1;
603 646
604 if ((target.GetFormat() == PixelFormat_RGBA32 || 647 if ((target.GetFormat() == PixelFormat_RGBA32 ||
605 target.GetFormat() == PixelFormat_BGRA32) && 648 target.GetFormat() == PixelFormat_BGRA32) &&
606 source.GetFormat() == PixelFormat_Grayscale8) 649 source.GetFormat() == PixelFormat_Grayscale8)
607 { 650 {
608 for (unsigned int y = 0; y < source.GetHeight(); y++) 651 for (unsigned int y = 0; y < height; y++)
609 { 652 {
610 const uint8_t* p = reinterpret_cast<const uint8_t*>(source.GetConstRow(y)); 653 const uint8_t* p = reinterpret_cast<const uint8_t*>(source.GetConstRow(y));
611 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y)); 654 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y));
612 for (unsigned int x = 0; x < source.GetWidth(); x++) 655 for (unsigned int x = 0; x < width; x++)
613 { 656 {
614 q[0] = *p; 657 q[0] = *p;
615 q[1] = *p; 658 q[1] = *p;
616 q[2] = *p; 659 q[2] = *p;
617 q[3] = 255; 660 q[3] = 255;
624 } 667 }
625 668
626 if (target.GetFormat() == PixelFormat_BGRA32 && 669 if (target.GetFormat() == PixelFormat_BGRA32 &&
627 source.GetFormat() == PixelFormat_Grayscale16) 670 source.GetFormat() == PixelFormat_Grayscale16)
628 { 671 {
629 for (unsigned int y = 0; y < source.GetHeight(); y++) 672 for (unsigned int y = 0; y < height; y++)
630 { 673 {
631 const uint16_t* p = reinterpret_cast<const uint16_t*>(source.GetConstRow(y)); 674 const uint16_t* p = reinterpret_cast<const uint16_t*>(source.GetConstRow(y));
632 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y)); 675 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y));
633 for (unsigned int x = 0; x < source.GetWidth(); x++) 676 for (unsigned int x = 0; x < width; x++)
634 { 677 {
635 uint8_t value = (*p < 256 ? *p : 255); 678 uint8_t value = (*p < 256 ? *p : 255);
636 q[0] = value; 679 q[0] = value;
637 q[1] = value; 680 q[1] = value;
638 q[2] = value; 681 q[2] = value;
646 } 689 }
647 690
648 if (target.GetFormat() == PixelFormat_BGRA32 && 691 if (target.GetFormat() == PixelFormat_BGRA32 &&
649 source.GetFormat() == PixelFormat_SignedGrayscale16) 692 source.GetFormat() == PixelFormat_SignedGrayscale16)
650 { 693 {
651 for (unsigned int y = 0; y < source.GetHeight(); y++) 694 for (unsigned int y = 0; y < height; y++)
652 { 695 {
653 const int16_t* p = reinterpret_cast<const int16_t*>(source.GetConstRow(y)); 696 const int16_t* p = reinterpret_cast<const int16_t*>(source.GetConstRow(y));
654 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y)); 697 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y));
655 for (unsigned int x = 0; x < source.GetWidth(); x++) 698 for (unsigned int x = 0; x < width; x++)
656 { 699 {
657 uint8_t value; 700 uint8_t value;
658 if (*p < 0) 701 if (*p < 0)
659 { 702 {
660 value = 0; 703 value = 0;
681 } 724 }
682 725
683 if (target.GetFormat() == PixelFormat_BGRA32 && 726 if (target.GetFormat() == PixelFormat_BGRA32 &&
684 source.GetFormat() == PixelFormat_RGB24) 727 source.GetFormat() == PixelFormat_RGB24)
685 { 728 {
686 for (unsigned int y = 0; y < source.GetHeight(); y++) 729 for (unsigned int y = 0; y < height; y++)
687 { 730 {
688 const uint8_t* p = reinterpret_cast<const uint8_t*>(source.GetConstRow(y)); 731 const uint8_t* p = reinterpret_cast<const uint8_t*>(source.GetConstRow(y));
689 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y)); 732 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y));
690 for (unsigned int x = 0; x < source.GetWidth(); x++) 733 for (unsigned int x = 0; x < width; x++)
691 { 734 {
692 q[0] = p[2]; 735 q[0] = p[2];
693 q[1] = p[1]; 736 q[1] = p[1];
694 q[2] = p[0]; 737 q[2] = p[0];
695 q[3] = 255; 738 q[3] = 255;
702 } 745 }
703 746
704 if (target.GetFormat() == PixelFormat_RGB24 && 747 if (target.GetFormat() == PixelFormat_RGB24 &&
705 source.GetFormat() == PixelFormat_RGB48) 748 source.GetFormat() == PixelFormat_RGB48)
706 { 749 {
707 for (unsigned int y = 0; y < source.GetHeight(); y++) 750 for (unsigned int y = 0; y < height; y++)
708 { 751 {
709 const uint16_t* p = reinterpret_cast<const uint16_t*>(source.GetConstRow(y)); 752 const uint16_t* p = reinterpret_cast<const uint16_t*>(source.GetConstRow(y));
710 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y)); 753 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y));
711 for (unsigned int x = 0; x < source.GetWidth(); x++) 754 for (unsigned int x = 0; x < width; x++)
712 { 755 {
713 q[0] = p[0] >> 8; 756 q[0] = p[0] >> 8;
714 q[1] = p[1] >> 8; 757 q[1] = p[1] >> 8;
715 q[2] = p[2] >> 8; 758 q[2] = p[2] >> 8;
716 p += 3; 759 p += 3;
717 q += 3; 760 q += 3;
718 } 761 }
719 } 762 }
720 763
764 return;
765 }
766
767 if (target.GetFormat() == PixelFormat_Grayscale16 &&
768 source.GetFormat() == PixelFormat_Float32)
769 {
770 ConvertFloatToGrayscale<PixelFormat_Grayscale16>(target, source);
771 return;
772 }
773
774 if (target.GetFormat() == PixelFormat_Grayscale8 &&
775 source.GetFormat() == PixelFormat_Float32)
776 {
777 ConvertFloatToGrayscale<PixelFormat_Grayscale8>(target, source);
721 return; 778 return;
722 } 779 }
723 780
724 throw OrthancException(ErrorCode_NotImplemented); 781 throw OrthancException(ErrorCode_NotImplemented);
725 } 782 }
798 855
799 default: 856 default:
800 throw OrthancException(ErrorCode_NotImplemented); 857 throw OrthancException(ErrorCode_NotImplemented);
801 } 858 }
802 859
803 for (unsigned int y = 0; y < image.GetHeight(); y++) 860 const unsigned int width = image.GetWidth();
861 const unsigned int height = image.GetHeight();
862
863 for (unsigned int y = 0; y < height; y++)
804 { 864 {
805 uint8_t* q = reinterpret_cast<uint8_t*>(image.GetRow(y)); 865 uint8_t* q = reinterpret_cast<uint8_t*>(image.GetRow(y));
806 866
807 for (unsigned int x = 0; x < image.GetWidth(); x++) 867 for (unsigned int x = 0; x < width; x++)
808 { 868 {
809 for (unsigned int i = 0; i < size; i++) 869 for (unsigned int i = 0; i < size; i++)
810 { 870 {
811 q[i] = p[i]; 871 q[i] = p[i];
812 } 872 }
1017 } 1077 }
1018 1078
1019 1079
1020 void ImageProcessing::Invert(ImageAccessor& image) 1080 void ImageProcessing::Invert(ImageAccessor& image)
1021 { 1081 {
1082 const unsigned int width = image.GetWidth();
1083 const unsigned int height = image.GetHeight();
1084
1022 switch (image.GetFormat()) 1085 switch (image.GetFormat())
1023 { 1086 {
1024 case PixelFormat_Grayscale8: 1087 case PixelFormat_Grayscale8:
1025 { 1088 {
1026 for (unsigned int y = 0; y < image.GetHeight(); y++) 1089 for (unsigned int y = 0; y < height; y++)
1027 { 1090 {
1028 uint8_t* p = reinterpret_cast<uint8_t*>(image.GetRow(y)); 1091 uint8_t* p = reinterpret_cast<uint8_t*>(image.GetRow(y));
1029 1092
1030 for (unsigned int x = 0; x < image.GetWidth(); x++, p++) 1093 for (unsigned int x = 0; x < width; x++, p++)
1031 { 1094 {
1032 *p = 255 - (*p); 1095 *p = 255 - (*p);
1033 } 1096 }
1034 } 1097 }
1035 1098