>>>>> "Zdenek" == Zdenek Kabelac <[EMAIL PROTECTED]> writes:
Zdenek> 
Zdenek> Also instead of asking to send a patch it's always better to
Zdenek> post it.
Zdenek> 

Ok, here it is:

-------------------------- cut ----------------------------
? avirecompress_scaling.patch
Index: filters.cpp
===================================================================
RCS file: /cvsroot/avifile/avifile-0.6/samples/qtrecompress/filters.cpp,v
retrieving revision 1.15
diff -c -r1.15 filters.cpp
*** filters.cpp 16 Nov 2001 20:51:22 -0000      1.15
--- filters.cpp 8 Mar 2002 14:23:40 -0000
***************
*** 16,21 ****
--- 16,22 ----
  
  #include <strstream>
  #include <cstdio>
+ #include <cmath>
  #include <iostream.h>
  
  using namespace avm;
***************
*** 331,337 ****
        unsigned char* p = data+i;
        unsigned char* refp = refdata+i-3-3*xd;
        int brightness;
!       if (((i-3*_dist)%(3*xd)<2.6*xd) || ((i%(3*xd)>xd)))
            //brightness=(refp[-3*dist+0]+refp[-3*dist+1]+refp[-3*dist+2])/3;
            
//brightness=(.114*refp[-3*dist+0]+.586*refp[-3*dist+1]+.300*refp[-3*dist+2]);
            //brightness=((col*)(refp-3*dist))->Y();
--- 332,338 ----
        unsigned char* p = data+i;
        unsigned char* refp = refdata+i-3-3*xd;
        int brightness;
!       if (((i-3*_dist)%(3*xd)<(unsigned int)(2.6*xd)) || ((i%(3*xd)>(unsigned 
int)xd)))
            //brightness=(refp[-3*dist+0]+refp[-3*dist+1]+refp[-3*dist+2])/3;
            
//brightness=(.114*refp[-3*dist+0]+.586*refp[-3*dist+1]+.300*refp[-3*dist+2]);
            //brightness=((col*)(refp-3*dist))->Y();
***************
*** 787,798 ****
--- 788,934 ----
   }
   */
  
+ namespace {
+   typedef int myGLint;
+   typedef unsigned int myGLuint;
+   typedef unsigned short int myGLushort;
+   typedef char myGLbyte;
+   typedef unsigned char myGLubyte;
+ 
+ void halveImage(myGLint components, myGLuint width, myGLuint height, 
+                      const myGLubyte *datain, myGLubyte *dataout)
+ {
+     int i, j, k;
+     int newwidth, newheight;
+     int delta;
+     myGLubyte *s;
+     const myGLubyte *t;
+ 
+     newwidth = width / 2;
+     newheight = height / 2;
+     delta = width * components;
+     s = dataout;
+     t = datain;
+ 
+     /* Piece o' cake! */
+     for (i = 0; i < newheight; ++i) {
+       for (j = 0; j < newwidth; ++j) {
+         for (k = 0; k < components; ++k) {
+           s[0] = (t[0] + t[components] + t[delta] + 
+                   t[delta+components] + 2) / 4;
+           ++s; ++t;
+         }
+         t += components;
+       }
+       t += delta;
+     }
+ }
+ 
+ void scale_internal(myGLint components, myGLint widthin, myGLint heightin, 
+                          const myGLubyte *datain, 
+                          myGLint widthout, myGLint heightout, 
+                          myGLubyte *dataout)
+ {
+   float x, lowx, highx, convx, halfconvx;
+   float y, lowy, highy, convy, halfconvy;
+   float xpercent,ypercent;
+   float percent;
+   /* Max components in a format is 4, so... */
+   float totals[4];
+   float area;
+   int i,j,k,yint,xint,xindex,yindex;
+   int temp;
+ 
+   if (widthin == widthout*2 && heightin == heightout*2) {
+     halveImage(components, widthin, heightin, datain, dataout);
+     return;
+   }
+   convy = (float) heightin/heightout;
+   convx = (float) widthin/widthout;
+   halfconvx = convx/2;
+   halfconvy = convy/2;
+   for (i = 0; i < heightout; i++) {
+     y = convy * (i+0.5);
+     if (heightin > heightout) {
+           highy = y + halfconvy;
+           lowy = y - halfconvy;
+     } else {
+           highy = y + 0.5;
+           lowy = y - 0.5;
+     }
+     for (j = 0; j < widthout; j++) {
+           x = convx * (j+0.5);
+           if (widthin > widthout) {
+         highx = x + halfconvx;
+         lowx = x - halfconvx;
+           } else {
+         highx = x + 0.5;
+         lowx = x - 0.5;
+           }
+ 
+           /*
+           ** Ok, now apply box filter to box that goes from (lowx, lowy)
+           ** to (highx, highy) on input data into this pixel on output
+           ** data.
+           */
+           totals[0] = totals[1] = totals[2] = totals[3] = 0.0;
+           area = 0.0;
+ 
+           y = lowy;
+           yint = (int)floor(y);
+           while (y < highy) {
+         yindex = (yint + heightin) % heightin;
+         if (highy < yint+1) {
+           ypercent = highy - y;
+         } else {
+           ypercent = yint+1 - y;
+         }
+ 
+         x = lowx;
+         xint = (int)floor(x);
+ 
+         while (x < highx) {
+           xindex = (xint + widthin) % widthin;
+           if (highx < xint+1) {
+             xpercent = highx - x;
+           } else {
+             xpercent = xint+1 - x;
+           }
+ 
+           percent = xpercent * ypercent;
+           area += percent;
+           temp = (xindex + (yindex * widthin)) * components;
+           for (k = 0; k < components; k++) {
+             totals[k] += datain[temp + k] * percent;
+           }
+ 
+           xint++;
+           x = xint;
+         }
+         yint++;
+         y = yint;
+           }
+ 
+           temp = (j + (i * widthout)) * components;
+           for (k = 0; k < components; k++) {
+         /* totals[] should be rounded in the case of enlarging an RGB
+          * ramp when the type is 332 or 4444
+          */
+         dataout[temp + k] = (short unsigned int)((totals[k]+0.5)/area);
+           }
+     }
+   }
+ }
+ 
+ };
+ 
  void ScaleFilter::config()
  {
      bool old_aspect = m_bAspect;
      bool old_percent = m_bPercent;
      double old_width = m_dWidth;
      double old_height = m_dHeight;
+     QString s;
  
      OkCancelDialog d("Scale filter");
  
***************
*** 813,867 ****
      QDoubleValidator qv( 0.0, 1000.0, 3, &d );
      m_pLew = new QLineEdit( &d, "scale_width" );
      m_pLew->setValidator( &qv );
      d.m_pGl->addWidget( m_pLew, 1, 1 );
  
      connect(m_pLew, SIGNAL(returnPressed()), this, SLOT(valueChangedW()));
  
      m_pLeh = new QLineEdit( &d, "scale_height" );
      m_pLeh->setValidator( &qv );
      d.m_pGl->addWidget( m_pLeh, 2, 1 );
  
      connect(m_pLeh, SIGNAL(returnPressed()), this, SLOT(valueChangedH()));
  
      if (d.exec() == QDialog::Rejected)
      {
!       m_bAspect = old_aspect;
!       m_bPercent = old_percent;
!       m_dWidth = old_width;
!       m_dHeight = old_height;
      }
      kernel->redraw();
  }
  
  CImage* ScaleFilter::process(CImage* im, int pos)
  {
!     if (im->Depth()!=24)
!     {
!       im->AddRef();
!       return im;
!     }
!     im->AddRef();
!     return im;
! 
!     int w=im->Width()/2;
!     int h=im->Height()/2;
!     col* ptr=(col*)(im->Data());
! 
!     BitmapInfo info=*(im->GetFmt());
!     adjust(info);
!     CImage* result=new CImage(&info);
!     col* dest=(col*)(result->Data());
!     for(int i=0; i<h; i++)
      {
!       for(int j=0; j<w; j++)
!       {
!           *dest=*ptr;
!           dest++;
!           ptr+=2;
!       }
!       ptr+=2*w;
      }
!     return result;
  }
  
  void ScaleFilter::adjust(BITMAPINFOHEADER& bh)
--- 949,995 ----
      QDoubleValidator qv( 0.0, 1000.0, 3, &d );
      m_pLew = new QLineEdit( &d, "scale_width" );
      m_pLew->setValidator( &qv );
+     m_pLew->setText(s.sprintf("%f",m_dWidth));
      d.m_pGl->addWidget( m_pLew, 1, 1 );
  
      connect(m_pLew, SIGNAL(returnPressed()), this, SLOT(valueChangedW()));
  
      m_pLeh = new QLineEdit( &d, "scale_height" );
      m_pLeh->setValidator( &qv );
+     m_pLeh->setText(s.sprintf("%f",m_dHeight));
      d.m_pGl->addWidget( m_pLeh, 2, 1 );
  
      connect(m_pLeh, SIGNAL(returnPressed()), this, SLOT(valueChangedH()));
  
      if (d.exec() == QDialog::Rejected)
      {
!       cerr << "tb:config> QDialog::Rejected" << endl;
!       m_bAspect = old_aspect;
!       m_bPercent = old_percent;
!       m_dWidth = old_width;
!       m_dHeight = old_height;
!     }else{
!       valueChangedW();
!       valueChangedH();
      }
      kernel->redraw();
  }
  
  CImage* ScaleFilter::process(CImage* im, int pos)
  {
!   if (im->Depth()!=24)
      {
!       im->AddRef();
!       return im;
      }
!   
!   BitmapInfo info=*(im->GetFmt());
!   adjust(info);
!   CImage* result=new CImage(&info);
!   
!   scale_internal(3,im->Width(),im->Height(),(myGLubyte *)(im->Data()),
!                  result->Width(),result->Height(),(myGLubyte *)(result->Data()));
!   return result;
  }
  
  void ScaleFilter::adjust(BITMAPINFOHEADER& bh)
***************
*** 900,905 ****
--- 1028,1034 ----
  {
      QString q = m_pLew->text();
      cout << "Width " << q << endl;
+     m_dWidth = q.toFloat();
      kernel->redraw();
  }
  
***************
*** 907,912 ****
--- 1036,1042 ----
  {
      QString q = m_pLeh->text();
      cout << "Height " << q << endl;
+     m_dHeight = q.toFloat();
      kernel->redraw();
  }
  
Index: filters.h
===================================================================
RCS file: /cvsroot/avifile/avifile-0.6/samples/qtrecompress/filters.h,v
retrieving revision 1.6
diff -c -r1.6 filters.h
*** filters.h   3 Jan 2002 17:07:58 -0000       1.6
--- filters.h   8 Mar 2002 14:23:41 -0000
***************
*** 145,151 ****
      QLineEdit* m_pLeh;
  
  public:
!     ScaleFilter(RecKernel* k):kernel(k){}
      virtual avm::string name(){return "Scale";}
      virtual avm::string fullname(){return "Scale to specified size";}
      virtual CImage* process(CImage* im, int pos);
--- 145,152 ----
      QLineEdit* m_pLeh;
  
  public:
!   ScaleFilter(RecKernel* k):kernel(k),m_dWidth(256),m_dHeight(256),
!                             m_bAspect(false),m_bPercent(false){}
      virtual avm::string name(){return "Scale";}
      virtual avm::string fullname(){return "Scale to specified size";}
      virtual CImage* process(CImage* im, int pos);
Index: qimagecontrol.cpp
===================================================================
RCS file: /cvsroot/avifile/avifile-0.6/samples/qtrecompress/qimagecontrol.cpp,v
retrieving revision 1.10
diff -c -r1.10 qimagecontrol.cpp
*** qimagecontrol.cpp   1 Feb 2002 08:01:33 -0000       1.10
--- qimagecontrol.cpp   8 Mar 2002 14:23:41 -0000
***************
*** 61,67 ****
  {
      pthread_mutex_lock(&mutex);
      if (_il)
!       _il->Release();
      _il = new CImage(src, 32);
      pthread_mutex_unlock(&mutex);
      QEvent* e = new QEvent(Type_LeftPix);
--- 61,67 ----
  {
      pthread_mutex_lock(&mutex);
      if (_il)
!       _il->Release();
      _il = new CImage(src, 32);
      pthread_mutex_unlock(&mutex);
      QEvent* e = new QEvent(Type_LeftPix);
***************
*** 73,79 ****
  {
      pthread_mutex_lock(&mutex);
      if (_ir)
!       _ir->Release();
      _ir = new CImage(src, 32);
      pthread_mutex_unlock(&mutex);
      QEvent* e = new QEvent(Type_RightPix);
--- 73,79 ----
  {
      pthread_mutex_lock(&mutex);
      if (_ir)
!       _ir->Release();
      _ir = new CImage(src, 32);
      pthread_mutex_unlock(&mutex);
      QEvent* e = new QEvent(Type_RightPix);
***************
*** 121,126 ****
--- 121,128 ----
  
  bool QImageControl::event(QEvent* ev)
  {
+   static int lastWidth=0, lastHeight=0;
+ 
      if (ev->type()==Type_LeftPix)
      {
                pthread_mutex_lock(&mutex);
***************
*** 131,137 ****
      else if (ev->type()==Type_RightPix)
      {
                pthread_mutex_lock(&mutex);
!       setPicture(_ir, _right);
                pthread_mutex_unlock(&mutex);
                return true;
      }
--- 133,147 ----
      else if (ev->type()==Type_RightPix)
      {
                pthread_mutex_lock(&mutex);
!     // first clear the destination frame if the picture size has changed
!     if(_ir->Width()!=lastWidth || _ir->Height()!=lastHeight){
!       lastWidth=_ir->Width();
!       lastHeight=_ir->Height();
!       QPainter p(_right);
!       p.eraseRect(0,0,_il->Width(),_il->Height());
!     }
!     // then set the new picture
!     setPicture(_ir, _right);
                pthread_mutex_unlock(&mutex);
                return true;
      }
-------------------------- cut ----------------------------

                           greetings  Torsten


-- 
Awaron AG, Hardtstrasse 37a, D-76185 Karlsruhe
Tel: 0721/5311583    Fax: 0721/93777-36

_______________________________________________
Avifile mailing list
[EMAIL PROTECTED]
http://prak.org/mailman/listinfo/avifile

Reply via email to