Re: how to achieve fast image 90 deg rotation in C

From: Richard Zhu (yzhu_at_algis.ca)
Date: 06/16/04


Date: Wed, 16 Jun 2004 09:27:20 -0700

I have tested, that's great !, it's truely improved as you said,

 for(y0=0;y0<o_h;y0++)
 {
  offset=y0*o_w;
   for(x0=0;x0<o_w;x0++)
   {
    x1=o_h-1-y0;
    y1=x0;
    chR_side[y1*n_w+x1]=chR1[offset+x0];
    chG_side[y1*n_w+x1]=chG1[offset+x0];
    chB_side[y1*n_w+x1]=chB1[offset+x0];
   }
 }

use offset in read,
now the time reduced to 40ms from from60-70ms.

I think I still need to try IPL.

"Severian" <severian@chlamydia-is-not-a-flower.com> wrote in message
news:6t2sc0hm8m2a9smih74dqaeb9l8shv94dr@4ax.com...
> On Mon, 14 Jun 2004 11:11:31 -0700, "Richard Zhu" <yzhu@algis.ca>
> wrote:
>
> >I have the following code to implement a 90 deg rot over an Image in VC,
> >the speed can't reach what is required,
> >what can I do to speed up, for width =1024, height =768 color image
grabbed
> >from the camera, there is no hardware rotation inside, so I need a real
> >time rotation, on my 2.4G intel I need less than 10ms , but the following
> >code gives about 60ms, I wonder if there still the possibilies to get
there
> >?
> >
> >I have checked, the slowing caused by locating chR1[y0*o_w+x0], ....
> >
> >
> >int x1,y1,x0,y0,i;
> > int n_w,n_h,o_w,o_h;
> > int offset;
> > n_w=img_height;
> > n_h=img_width;
> > o_w=img_width;
> > o_h=img_height;
> >
> > for(y1=0;y1<n_h;y1++)
> > {
> > offset=y1*n_w;
> > for(x1=0;x1<n_w;x1++)
> > {
> > x0=y1;
> > y0=o_h-1-x1;
> > chR_rot[offset+x1]=chR1[y0*o_w+x0];
> > chG_rot[offset+x1]=chG1[y0*o_w+x0];
> > chB_rot[offset+x1]=chB1[y0*o_w+x0];
> > }
> > }
> > *new_width=n_w;
> > *new_height=n_h;
>
> I am not a cache expert, but it may be quicker to read rows and write
> columns. You're reading columns, so you will have a lot more cache
> misses.
>
> My program does a 1024x768 24-bit rotation in around 60-70ms on a P3
> 800, so that should put you in the ballpark on your faster machine.
>
> If you have other image-oriented stuff to do, it might be worthwhile
> to investigate the Intel performance libraries, which will do things
> like this with highly-optimized MMX, SSE and SSE2 code.
>
> IPL requires 10-20ms to rotate a 1024x768 image in on my P3 800.
>
> --
> Sev


Quantcast