Эх сурвалжийг харах

awesome late evening bugfixing with Johannes

Erik Rodner 11 жил өмнө
parent
commit
7c98aed0e3

+ 3 - 17
core/image/ColorImageT.tcc

@@ -23,22 +23,15 @@ ColorImageT<P>& ColorImageT<P>::operator=(const ColorT<P> &color)
                 ippiSize);
 #else
   //Ipp8u* pos=reinterpret_cast<Ipp8u*>(this->getPixelPointer());
-  P* pos=reinterpret_cast<P*>(this->getPixelPointer());
-  P **row = new P*[this->height()];
-    for(int y=0;y<this->height(); ++y) {
-    row[y]=reinterpret_cast<P*>(pos);
-    pos+=this->getStepsize();
-  }
     P *p;
     for(int y=0;y<this->height(); ++y) {
-        p=row[y];
+        p = this->getPixelPointerY(y);
         for(int x=0;x<this->width(); ++x) {
             for(int chan=0;chan<3; ++chan,p++) {
           *p=color[chan];
         }
-        }
+    }
   }
-	delete [] p;
 #endif
     return *this;
 }
@@ -51,22 +44,15 @@ ColorImageT<P>& ColorImageT<P>::operator=(const P c[3])
   ippiSet_C3R(c, this->getPixelPointer(), this->getStepsize(),
               ippiSize);
 #else
-  Ipp8u* pos=reinterpret_cast<Ipp8u*>(this->getPixelPointer());
-  P *row = new P[this->height()];
-  for(int y=0;y<this->height(); ++y) {
-    row[y]=reinterpret_cast<P*>(pos);
-    pos+=this->getStepsize();
-  }
   P *p;
   for(int y=0;y<this->height(); ++y) {
-    p=row[y];
+    p = this->getPixelPointerY(y);
     for(int x=0;x<this->width(); ++x) {
       for(int chan=0;chan<3; ++chan,p++) {
         *p=c[chan];
       }
     }
   }
-  delete [] p;
 #endif
   return *this;
 }

+ 22 - 8
core/image/Filter.tcc

@@ -59,7 +59,7 @@ ImageT<P>* filterY ( const ImageT<P>& src, const FloatVector& kernel,
                      ImageT<P>* dst, const int& anchor )
 {
   ImageT<P>* result = createResultBuffer ( src, dst );
-  uint kernelanch       = ( anchor < 0 ) ? ( kernel.size() / 2 ) : anchor;
+  int kernelanch       = ( anchor < 0 ) ? ( kernel.size() / 2 ) : anchor;
 
 #ifdef NICE_USELIB_IPP
   IppiSize ippiSize = {src.width(), src.height() - ( kernel.size() - 1 ) };
@@ -79,8 +79,6 @@ ImageT<P>* filterY ( const ImageT<P>& src, const FloatVector& kernel,
   const P* pSrcStart = src.getPixelPointerXY ( 0, kernelanch );
   P*       pDstStart = result->getPixelPointerXY ( 0, kernelanch );
 
-  int i;
-
   const P* pSrc;
   P*       pDst;
   for ( uint y = kernelanch; y < src.height() - ( kernel.size() - 1 - kernelanch ); ++y ) {
@@ -90,11 +88,27 @@ ImageT<P>* filterY ( const ImageT<P>& src, const FloatVector& kernel,
     for ( int x = 0; x < src.width(); ++x, ++pSrc, ++pDst ) {
       sum = 0;
 
-      i = kernel.size() - 1;
-      do {
-        sum += * ( pSrc - ( kernelanch - i ) * ss ) * kernel[ks-i];
-        --i;
-      } while ( i >= 0 );
+      /////
+      for(int i = 0; i < kernel.size(); i++)
+      {
+          const P* pSrcPix = pSrc - ( kernelanch - i ) * ss;
+          // pointer to coordinates
+          // pSrc -> (x,y)
+          // pSrc - (kernelanch -i ) * ss  -> (x, y-kernelanch+i)
+          // the old code used the wrong upper bound, because
+          // the maximum value of y-kernelanch + i is
+          // height() - kernel.size() + 1 + kernelanch - 1 - kernelanch + kernel.size() - 1
+          // = height()
+          // the minimum value of y - kernelanch + i
+          sum +=  (*pSrcPix) * kernel[i];
+      }
+      ////
+//      i = kernel.size() - 1;
+//      do {
+//        const P* pSrcPix = pSrc - ( kernelanch - i ) * ss;
+//        sum += (*pSrcPix) * kernel[ks-i];
+//        --i;
+//      } while ( i >= 0 );
 
       *pDst = static_cast<P> ( sum );
     }

+ 5 - 4
core/image/ImageTools.cpp

@@ -115,7 +115,8 @@ Image* And ( const Image& src0, const Image& src1, Image *dst )
 
 #else // NICE_USELIB_IPP
   int bwidth = src0.width() / sizeof ( Ipp32u );
-  int bwidthr = src0.width() - bwidth;
+  int bwidth_remainder = src0.width() % sizeof ( Ipp32u );
+  //int bwidthr = src0.width() - bwidth;
 
   for ( int y = 0; y < src0.height(); ++y )
   {
@@ -130,7 +131,7 @@ Image* And ( const Image& src0, const Image& src1, Image *dst )
     const Ipp8u *ps2 = ( const Ipp8u* ) ( --s2 );
     Ipp8u *pd = ( Ipp8u* ) ( --d );
 
-    for ( int x = 0; x < bwidthr; ++x, ++ps1, ++ps2, ++pd )
+    for ( int x = 0; x < bwidth_remainder; ++x, ++ps1, ++ps2, ++pd )
       *pd = *ps1 & *ps2;
   }
 #endif // NICE_USELIB_IPP
@@ -155,7 +156,7 @@ ColorImage* And ( const ColorImage& src0, const ColorImage& src1, ColorImage* ds
 
 #else // NICE_USELIB_IPP
   int bwidth = ( src0.width() * 3 ) / sizeof ( Ipp32u );
-  int bwidthr = ( src0.width() * 3 ) - bwidth;
+  int bwidth_remainder = ( src0.width() * 3 ) % sizeof ( Ipp32u );
 
   for ( int y = 0; y < src0.height(); ++y )
   {
@@ -170,7 +171,7 @@ ColorImage* And ( const ColorImage& src0, const ColorImage& src1, ColorImage* ds
     const Ipp8u *ps2 = ( const Ipp8u* ) ( --s2 );
     Ipp8u *pd = ( Ipp8u* ) ( --d );
 
-    for ( int x = 0; x < bwidthr; ++x, ++ps1, ++ps2, ++pd )
+    for ( int x = 0; x < bwidth_remainder; ++x, ++ps1, ++ps2, ++pd )
       *pd = *ps1 & *ps2;
   }
 #endif // NICE_USELIB_IPP