views:

100

answers:

2

I have the code here working fine except that all the non-power of 2 images are flipped in the y direction. In the wxImageLoader file there is this loop which I believe is the culprit:

 for(int y=0; y<newHeight; y++)
 {
  for(int x=0; x<newWidth; x++)
  {

   if( x<(*imageWidth) && y<(*imageHeight) ){
    imageData[(x+y*newWidth)*bytesPerPixel+0]=
    bitmapData[( x+(rev_val-y)*(*imageWidth))*old_bytesPerPixel + 0];

    imageData[(x+y*newWidth)*bytesPerPixel+1]=
     bitmapData[( x+(rev_val-y)*(*imageWidth))*old_bytesPerPixel + 1];

    imageData[(x+y*newWidth)*bytesPerPixel+2]=
     bitmapData[( x+(rev_val-y)*(*imageWidth))*old_bytesPerPixel + 2];

    if(bytesPerPixel==4) imageData[(x+y*newWidth)*bytesPerPixel+3]=
     alphaData[ x+(rev_val-y)*(*imageWidth) ];

   }
   else
   {

    imageData[(x+y*newWidth)*bytesPerPixel+0] = 0;
    imageData[(x+y*newWidth)*bytesPerPixel+1] = 0;
    imageData[(x+y*newWidth)*bytesPerPixel+2] = 0;
    if(bytesPerPixel==4) imageData[(x+y*newWidth)*bytesPerPixel+3] = 0;
   }

  }//next
 }//next

But I can't figure out how to un-flip the images.

A: 

In your loop you use (rev_val - y) for the index of the pixels of your "old" image. This will cause the image to flip. Try to find an alternative. From your code you posted it is difficult to know what the function of rev_val is.

Dani van der Meer
the full code is in the link I posted in the question
DShook
OK. I missed it. The code flips the image on purpose. But it seems to do the same for power of two images. Try to debug it by replacing rev_val-y with y, and see what happens.
Dani van der Meer
A: 

The correct for loop is:

for(int y=0; y<newHeight; y++)
 {
  for(int x=0; x<newWidth; x++)
  {

   if( x<(*imageWidth) && y<(*imageHeight) ){
    imageData[(x+y*newWidth)*bytesPerPixel+0]=
    bitmapData[( x+y*(*imageWidth))*old_bytesPerPixel + 0];

    imageData[(x+y*newWidth)*bytesPerPixel+1]=
     bitmapData[( x+y*(*imageWidth))*old_bytesPerPixel + 1];

    imageData[(x+y*newWidth)*bytesPerPixel+2]=
     bitmapData[( x+y*(*imageWidth))*old_bytesPerPixel + 2];

    if(bytesPerPixel==4) imageData[(x+y*newWidth)*bytesPerPixel+3]=
     alphaData[ x+y*(*imageWidth) ];

   }
   else
   {

    imageData[(x+y*newWidth)*bytesPerPixel+0] = 0;
    imageData[(x+y*newWidth)*bytesPerPixel+1] = 0;
    imageData[(x+y*newWidth)*bytesPerPixel+2] = 0;
    if(bytesPerPixel==4) imageData[(x+y*newWidth)*bytesPerPixel+3] = 0;
   }

  }//next
 }//next
DShook
Did you solve your own problem?? Or do you mean that the above is what you meant to post originally??
ParoXoN
this solved the flipping problem
DShook