Logo Search packages:      
Sourcecode: gandalf version File versions

Gan_Image * gan_image_flip_q ( Gan_Image source,
Gan_Bool  interlaced,
Gan_Image dest 
)

Flips an image.

Parameters:
source The input image
interlaced Whether the source image is interlaced or not
dest The destination image
Returns:
Pointer to the flipped image, or NULL on failure.
Flips image source in dest. If bInterlaced is GAN_TRUE the upper and lower fields are flipped separately.

See also:
gan_image_flip_q().

Definition at line 82 of file image_flip.c.

References Gan_Image::ba, Gan_Image::format, gan_bit_array_copy_q(), gan_bit_array_form, gan_bit_array_free(), GAN_BOOL, GAN_DOUBLE, gan_err_flush_trace(), gan_err_register, GAN_FLOAT, GAN_GREY_LEVEL_IMAGE, gan_image_copy_s, gan_image_set_format_type_dims, gan_malloc_array, GAN_RGB_COLOUR_ALPHA_IMAGE, GAN_RGB_COLOUR_IMAGE, GAN_UCHAR, GAN_UINT, GAN_USHORT, Gan_Image::height, Gan_Image::offset_x, Gan_Image::offset_y, Gan_Image::type, and Gan_Image::width.

{
   int row, width=(int)source->width, height=(int)source->height;
   int evenH, oddH;

   /* interlaced frames must have a height which is a multiple of two */
   if ( interlaced && (source->height % 2) != 0 )
   {
      gan_err_flush_trace();
      gan_err_register ( "gan_image_flip_q", GAN_ERROR_INCOMPATIBLE, "" );
      return NULL;
   }

   /* calculate heights to use for computing rows */
   if ( interlaced )
   {
      evenH = height-2;
      oddH  = height;
   }
   else
      evenH = oddH = height-1;

   /* allocate/set output image */
   if ( dest == NULL )
   {
      dest = gan_image_copy_s ( source );
      if ( dest == NULL )
      {
         gan_err_register ( "gan_image_flip_q", GAN_ERROR_FAILURE, "" );
         return NULL;
      }
   }
   else if ( source != dest )
   {
      dest = gan_image_set_format_type_dims ( dest, dest->format, dest->type,
                                              dest->height, dest->width );
      if ( dest == NULL )
      {
         gan_err_register ( "gan_image_flip_q", GAN_ERROR_FAILURE, "" );
         return NULL;
      }

      dest->offset_x = source->offset_x;
      dest->offset_y = source->offset_y;
   }

   /* if the image is interlaced, the flipping is in-place and the height is
      not a multiple of four, the fields will be processed in a different
      order */
   if ( interlaced && (source == dest) && (source->height % 4) != 0 )
   {
      int tmp;

      tmp = evenH;
      evenH = oddH;
      oddH = tmp;
   }
      
   /* flip image */
   switch ( source->format )
   {
      case GAN_GREY_LEVEL_IMAGE:
        switch ( source->type )
        {
           case GAN_BOOL:
             if ( source == dest )
             {
                Gan_BitArray batmp;

                if ( gan_bit_array_form ( &batmp, source->width ) == NULL )
                {
                   gan_err_register ( "gan_image_flip_q", GAN_ERROR_FAILURE,
                                      "" );
                   return NULL;
                }

                for ( row = height/2-1; row >= 0; row -= 2 )
                {
                   if ( !gan_bit_array_copy_q ( &source->ba[row], &batmp ) ||
                        !gan_bit_array_copy_q ( &source->ba[oddH-row],
                                                &source->ba[row] ) ||
                        !gan_bit_array_copy_q ( &batmp,
                                                &source->ba[oddH-row] ))
                   {
                      gan_err_register ( "gan_image_flip_q",
                                         GAN_ERROR_FAILURE, "" );
                      return NULL;
                   }
                }
                
                for ( row = height/2-2; row >= 0; row -= 2 )
                {
                   if ( !gan_bit_array_copy_q ( &source->ba[row], &batmp ) ||
                        !gan_bit_array_copy_q ( &source->ba[evenH-row],
                                                &source->ba[row] ) ||
                        !gan_bit_array_copy_q ( &batmp,
                                                &source->ba[evenH-row] ))
                   {
                      gan_err_register ( "gan_image_flip_q",
                                         GAN_ERROR_FAILURE, "" );
                      return NULL;
                   }
                }
                
                gan_bit_array_free(&batmp);
             }
             else
             {
                for ( row = height-1; row >= 0; row -= 2 )
                   if ( !gan_bit_array_copy_q ( &source->ba[row],
                                                &dest->ba[oddH-row] ) )
                   {
                      gan_err_register ( "gan_image_flip_q", GAN_ERROR_FAILURE,
                                         "" );
                      return NULL;
                   }

                for ( row = height-2; row >= 0; row -= 2 )
                   if ( !gan_bit_array_copy_q ( &source->ba[row],
                                                &dest->ba[evenH-row] ) )
                   {
                      gan_err_register ( "gan_image_flip_q", GAN_ERROR_FAILURE,
                                         "" );
                      return NULL;
                   }
             }

             break;

           case GAN_UCHAR:
             if ( source == dest )
             {
                unsigned char *ucarr;

                ucarr = gan_malloc_array(unsigned char, width);
                if ( ucarr == NULL )
                {
                   gan_err_flush_trace();
                   gan_err_register ( "gan_image_flip_q",
                                      GAN_ERROR_MALLOC_FAILED, "" );
                   return NULL;
                }

                for ( row = height/2-1; row >= 0; row -= 2 )
                {
                   gan_copy_array_uc (
                       gan_image_get_pixptr_gl_uc(source,row,0), 1,
                       source->width, ucarr, 1 );
                   gan_copy_array_uc (
                       gan_image_get_pixptr_gl_uc(source,oddH-row,0), 1,
                       source->width,
                       gan_image_get_pixptr_gl_uc(source,row,0), 1 );
                   gan_copy_array_uc (
                       ucarr, 1, source->width,
                       gan_image_get_pixptr_gl_uc(source,oddH-row,0), 1 );
                }
                                      
                for ( row = height/2-2; row >= 0; row -= 2 )
                {
                   gan_copy_array_uc (
                       gan_image_get_pixptr_gl_uc(source,row,0), 1,
                       source->width, ucarr, 1 );
                   gan_copy_array_uc (
                       gan_image_get_pixptr_gl_uc(source,evenH-row,0), 1,
                       source->width,
                       gan_image_get_pixptr_gl_uc(source,row,0), 1 );
                   gan_copy_array_uc (
                       ucarr, 1, source->width,
                       gan_image_get_pixptr_gl_uc(source,evenH-row,0), 1 );
                }
                                      
                free(ucarr);
             }
             else
             {
                for ( row = height-1; row >= 0; row -= 2 )
                   gan_copy_array_uc (
                       gan_image_get_pixptr_gl_uc(source,row,0), 1,
                       source->width,
                       gan_image_get_pixptr_gl_uc(dest,oddH-row,0), 1 );

                for ( row = height-2; row >= 0; row -= 2 )
                   gan_copy_array_uc (
                       gan_image_get_pixptr_gl_uc(source,row,0), 1,
                       source->width,
                       gan_image_get_pixptr_gl_uc(dest,evenH-row,0), 1 );
             }
             
             break;

           case GAN_USHORT:
             if ( source == dest )
             {
                unsigned short *usarr;

                usarr = gan_malloc_array(unsigned short, width);
                if ( usarr == NULL )
                {
                   gan_err_flush_trace();
                   gan_err_register ( "gan_image_flip_q",
                                      GAN_ERROR_MALLOC_FAILED, "" );
                   return NULL;
                }

                for ( row = height/2-1; row >= 0; row -= 2 )
                {
                   gan_copy_array_us (
                       gan_image_get_pixptr_gl_us(source,row,0), 1,
                       source->width, usarr, 1 );
                   gan_copy_array_us (
                       gan_image_get_pixptr_gl_us(source,oddH-row,0), 1,
                       source->width,
                       gan_image_get_pixptr_gl_us(source,row,0), 1 );
                   gan_copy_array_us (
                       usarr, 1, source->width,
                       gan_image_get_pixptr_gl_us(source,oddH-row,0), 1 );
                }
                                      
                for ( row = height/2-2; row >= 0; row -= 2 )
                {
                   gan_copy_array_us (
                       gan_image_get_pixptr_gl_us(source,row,0), 1,
                       source->width, usarr, 1 );
                   gan_copy_array_us (
                       gan_image_get_pixptr_gl_us(source,evenH-row,0), 1,
                       source->width,
                       gan_image_get_pixptr_gl_us(source,row,0), 1 );
                   gan_copy_array_us (
                       usarr, 1, source->width,
                       gan_image_get_pixptr_gl_us(source,evenH-row,0), 1 );
                }
                                      
                free(usarr);
             }
             else
             {
                for ( row = height-1; row >= 0; row -= 2 )
                   gan_copy_array_us (
                       gan_image_get_pixptr_gl_us(source,row,0), 1,
                       source->width,
                       gan_image_get_pixptr_gl_us(dest,oddH-row,0), 1 );

                for ( row = height-2; row >= 0; row -= 2 )
                   gan_copy_array_us (
                       gan_image_get_pixptr_gl_us(source,row,0), 1,
                       source->width,
                       gan_image_get_pixptr_gl_us(dest,evenH-row,0), 1 );
             }
             
             break;

           case GAN_UINT:
             if ( source == dest )
             {
                unsigned int *uiarr;

                uiarr = gan_malloc_array(unsigned int, width);
                if ( uiarr == NULL )
                {
                   gan_err_flush_trace();
                   gan_err_register ( "gan_image_flip_q",
                                      GAN_ERROR_MALLOC_FAILED, "" );
                   return NULL;
                }

                for ( row = height/2-1; row >= 0; row -= 2 )
                {
                   gan_copy_array_ui (
                       gan_image_get_pixptr_gl_ui(source,row,0), 1,
                       source->width, uiarr, 1 );
                   gan_copy_array_ui (
                       gan_image_get_pixptr_gl_ui(source,oddH-row,0), 1,
                       source->width,
                       gan_image_get_pixptr_gl_ui(source,row,0), 1 );
                   gan_copy_array_ui (
                       uiarr, 1, source->width,
                       gan_image_get_pixptr_gl_ui(source,oddH-row,0), 1 );
                }
                                      
                for ( row = height/2-2; row >= 0; row -= 2 )
                {
                   gan_copy_array_ui (
                       gan_image_get_pixptr_gl_ui(source,row,0), 1,
                       source->width, uiarr, 1 );
                   gan_copy_array_ui (
                       gan_image_get_pixptr_gl_ui(source,evenH-row,0), 1,
                       source->width,
                       gan_image_get_pixptr_gl_ui(source,row,0), 1 );
                   gan_copy_array_ui (
                       uiarr, 1, source->width,
                       gan_image_get_pixptr_gl_ui(source,evenH-row,0), 1 );
                }
                                      
                free(uiarr);
             }
             else
             {
                for ( row = height-1; row >= 0; row -= 2 )
                   gan_copy_array_ui (
                       gan_image_get_pixptr_gl_ui(source,row,0), 1,
                       source->width,
                       gan_image_get_pixptr_gl_ui(dest,oddH-row,0), 1 );

                for ( row = height-2; row >= 0; row -= 2 )
                   gan_copy_array_ui (
                       gan_image_get_pixptr_gl_ui(source,row,0), 1,
                       source->width,
                       gan_image_get_pixptr_gl_ui(dest,evenH-row,0), 1 );
             }

             break;

           case GAN_FLOAT:
             if ( source == dest )
             {
                float *farr;

                farr = gan_malloc_array(float, width);
                if ( farr == NULL )
                {
                   gan_err_flush_trace();
                   gan_err_register ( "gan_image_flip_q",
                                      GAN_ERROR_MALLOC_FAILED, "" );
                   return NULL;
                }

                for ( row = height/2-1; row >= 0; row -= 2 )
                {
                   gan_copy_array_f (
                       gan_image_get_pixptr_gl_f(source,row,0), 1,
                       source->width, farr, 1 );
                   gan_copy_array_f (
                       gan_image_get_pixptr_gl_f(source,oddH-row,0), 1,
                       source->width,
                       gan_image_get_pixptr_gl_f(source,row,0), 1 );
                   gan_copy_array_f (
                       farr, 1, source->width,
                       gan_image_get_pixptr_gl_f(source,oddH-row,0), 1 );
                }
                                      
                for ( row = height/2-2; row >= 0; row -= 2 )
                {
                   gan_copy_array_f (
                       gan_image_get_pixptr_gl_f(source,row,0), 1,
                       source->width, farr, 1 );
                   gan_copy_array_f (
                       gan_image_get_pixptr_gl_f(source,evenH-row,0), 1,
                       source->width,
                       gan_image_get_pixptr_gl_f(source,row,0), 1 );
                   gan_copy_array_f (
                       farr, 1, source->width,
                       gan_image_get_pixptr_gl_f(source,evenH-row,0), 1 );
                }
                                      
                free(farr);
             }
             else
             {
                for ( row = height-1; row >= 0; row -= 2 )
                   gan_copy_array_f (
                       gan_image_get_pixptr_gl_f(source,row,0), 1,
                       source->width,
                       gan_image_get_pixptr_gl_f(dest,oddH-row,0), 1 );

                for ( row = height-2; row >= 0; row -= 2 )
                   gan_copy_array_f (
                       gan_image_get_pixptr_gl_f(source,row,0), 1,
                       source->width,
                       gan_image_get_pixptr_gl_f(dest,evenH-row,0), 1 );
             }

             break;

           case GAN_DOUBLE:
             if ( source == dest )
             {
                double *darr;

                darr = gan_malloc_array(double, width);
                if ( darr == NULL )
                {
                   gan_err_flush_trace();
                   gan_err_register ( "gan_image_flip_q",
                                      GAN_ERROR_MALLOC_FAILED, "" );
                   return NULL;
                }

                for ( row = height/2-1; row >= 0; row -= 2 )
                {
                   gan_copy_array_d (
                       gan_image_get_pixptr_gl_d(source,row,0), 1,
                       source->width, darr, 1 );
                   gan_copy_array_d (
                       gan_image_get_pixptr_gl_d(source,oddH-row,0), 1,
                       source->width,
                       gan_image_get_pixptr_gl_d(source,row,0), 1 );
                   gan_copy_array_d (
                       darr, 1, source->width,
                       gan_image_get_pixptr_gl_d(source,oddH-row,0), 1 );
                }
                                      
                for ( row = height/2-2; row >= 0; row -= 2 )
                {
                   gan_copy_array_d (
                       gan_image_get_pixptr_gl_d(source,row,0), 1,
                       source->width, darr, 1 );
                   gan_copy_array_d (
                       gan_image_get_pixptr_gl_d(source,evenH-row,0), 1,
                       source->width,
                       gan_image_get_pixptr_gl_d(source,row,0), 1 );
                   gan_copy_array_d (
                       darr, 1, source->width,
                       gan_image_get_pixptr_gl_d(source,evenH-row,0), 1 );
                }
                                      
                free(darr);
             }
             else
             {
                for ( row = height-1; row >= 0; row -= 2 )
                   gan_copy_array_d (
                       gan_image_get_pixptr_gl_d(source,row,0), 1,
                       source->width,
                       gan_image_get_pixptr_gl_d(dest,oddH-row,0), 1 );

                for ( row = height-2; row >= 0; row -= 2 )
                   gan_copy_array_d (
                       gan_image_get_pixptr_gl_d(source,row,0), 1,
                       source->width,
                       gan_image_get_pixptr_gl_d(dest,evenH-row,0), 1 );
             }

             break;

           default:
             gan_err_flush_trace();
             gan_err_register ( "gan_image_flip_q", GAN_ERROR_ILLEGAL_TYPE,
                                "" );
             return NULL;
        }

        break;

      case GAN_RGB_COLOUR_IMAGE:
        switch ( source->type )
        {
           case GAN_UCHAR:
             if ( source == dest )
             {
                Gan_RGBPixel_uc *rgbucarr;

                rgbucarr = gan_malloc_array(Gan_RGBPixel_uc, width);
                if ( rgbucarr == NULL )
                {
                   gan_err_flush_trace();
                   gan_err_register ( "gan_image_flip_q",
                                      GAN_ERROR_MALLOC_FAILED, "" );
                   return NULL;
                }

                for ( row = height/2-1; row >= 0; row -= 2 )
                {
                   gan_copy_array_uc (
                       (unsigned char *)
                       gan_image_get_pixptr_rgb_uc(source,row,0), 1,
                       3*source->width, (unsigned char *)rgbucarr, 1 );
                   gan_copy_array_uc (
                       (unsigned char *)
                       gan_image_get_pixptr_rgb_uc(source,oddH-row,0), 1,
                       3*source->width, (unsigned char *)
                       gan_image_get_pixptr_rgb_uc(source,row,0), 1 );
                   gan_copy_array_uc (
                       (unsigned char *)rgbucarr, 1, 3*source->width,
                       (unsigned char *)
                       gan_image_get_pixptr_rgb_uc(source,oddH-row,0), 1 );
                }
                                      
                for ( row = height/2-2; row >= 0; row -= 2 )
                {
                   gan_copy_array_uc (
                       (unsigned char *)
                       gan_image_get_pixptr_rgb_uc(source,row,0), 1,
                       3*source->width, (unsigned char *)rgbucarr, 1 );
                   gan_copy_array_uc (
                       (unsigned char *)
                       gan_image_get_pixptr_rgb_uc(source,evenH-row,0), 1,
                       3*source->width, (unsigned char *)
                       gan_image_get_pixptr_rgb_uc(source,row,0), 1 );
                   gan_copy_array_uc (
                       (unsigned char *)rgbucarr, 1, 3*source->width,
                       (unsigned char *)
                       gan_image_get_pixptr_rgb_uc(source,evenH-row,0), 1 );
                }
                                      
                free(rgbucarr);
             }
             else
             {
                for ( row = height-1; row >= 0; row -= 2 )
                   gan_copy_array_uc (
                       (unsigned char *)
                       gan_image_get_pixptr_rgb_uc(source,row,0), 1,
                       3*source->width,
                       (unsigned char *)
                       gan_image_get_pixptr_rgb_uc(dest,oddH-row,0), 1 );

                for ( row = height-2; row >= 0; row -= 2 )
                   gan_copy_array_uc (
                       (unsigned char *)
                       gan_image_get_pixptr_rgb_uc(source,row,0), 1,
                       3*source->width,
                       (unsigned char *)
                       gan_image_get_pixptr_rgb_uc(dest,evenH-row,0), 1 );
             }

             break;

           case GAN_USHORT:
             if ( source == dest )
             {
                Gan_RGBPixel_us *rgbusarr;

                rgbusarr = gan_malloc_array(Gan_RGBPixel_us, width);
                if ( rgbusarr == NULL )
                {
                   gan_err_flush_trace();
                   gan_err_register ( "gan_image_flip_q",
                                      GAN_ERROR_MALLOC_FAILED, "" );
                   return NULL;
                }

                for ( row = height/2-1; row >= 0; row -= 2 )
                {
                   gan_copy_array_us (
                       (unsigned short *)
                       gan_image_get_pixptr_rgb_us(source,row,0), 1,
                       3*source->width, (unsigned short *)rgbusarr, 1 );
                   gan_copy_array_us (
                       (unsigned short *)
                       gan_image_get_pixptr_rgb_us(source,oddH-row,0), 1,
                       3*source->width, (unsigned short *)
                       gan_image_get_pixptr_rgb_us(source,row,0), 1 );
                   gan_copy_array_us (
                       (unsigned short *)rgbusarr, 1, 3*source->width,
                       (unsigned short *)
                       gan_image_get_pixptr_rgb_us(source,oddH-row,0), 1 );
                }
                                      
                for ( row = height/2-2; row >= 0; row -= 2 )
                {
                   gan_copy_array_us (
                       (unsigned short *)
                       gan_image_get_pixptr_rgb_us(source,row,0), 1,
                       3*source->width, (unsigned short *)rgbusarr, 1 );
                   gan_copy_array_us (
                       (unsigned short *)
                       gan_image_get_pixptr_rgb_us(source,evenH-row,0), 1,
                       3*source->width, (unsigned short *)
                       gan_image_get_pixptr_rgb_us(source,row,0), 1 );
                   gan_copy_array_us (
                       (unsigned short *)rgbusarr, 1, 3*source->width,
                       (unsigned short *)
                       gan_image_get_pixptr_rgb_us(source,evenH-row,0), 1 );
                }
                                      
                free(rgbusarr);
             }
             else
             {
                for ( row = height-1; row >= 0; row -= 2 )
                   gan_copy_array_us (
                       (unsigned short *)
                       gan_image_get_pixptr_rgb_us(source,row,0), 1,
                       3*source->width,
                       (unsigned short *)
                       gan_image_get_pixptr_rgb_us(dest,oddH-row,0), 1 );

                for ( row = height-2; row >= 0; row -= 2 )
                   gan_copy_array_us (
                       (unsigned short *)
                       gan_image_get_pixptr_rgb_us(source,row,0), 1,
                       3*source->width,
                       (unsigned short *)
                       gan_image_get_pixptr_rgb_us(dest,evenH-row,0), 1 );
             }

             break;

           case GAN_UINT:
             if ( source == dest )
             {
                Gan_RGBPixel_ui *rgbuiarr;

                rgbuiarr = gan_malloc_array(Gan_RGBPixel_ui, width);
                if ( rgbuiarr == NULL )
                {
                   gan_err_flush_trace();
                   gan_err_register ( "gan_image_flip_q",
                                      GAN_ERROR_MALLOC_FAILED, "" );
                   return NULL;
                }

                for ( row = height/2-1; row >= 0; row -= 2 )
                {
                   gan_copy_array_ui (
                       (unsigned int *)
                       gan_image_get_pixptr_rgb_ui(source,row,0), 1,
                       3*source->width, (unsigned int *)rgbuiarr, 1 );
                   gan_copy_array_ui (
                       (unsigned int *)
                       gan_image_get_pixptr_rgb_ui(source,oddH-row,0), 1,
                       3*source->width, (unsigned int *)
                       gan_image_get_pixptr_rgb_ui(source,row,0), 1 );
                   gan_copy_array_ui (
                       (unsigned int *)rgbuiarr, 1, 3*source->width,
                       (unsigned int *)
                       gan_image_get_pixptr_rgb_ui(source,oddH-row,0), 1 );
                }
                                      
                for ( row = height/2-2; row >= 0; row -= 2 )
                {
                   gan_copy_array_ui (
                       (unsigned int *)
                       gan_image_get_pixptr_rgb_ui(source,row,0), 1,
                       3*source->width, (unsigned int *)rgbuiarr, 1 );
                   gan_copy_array_ui (
                       (unsigned int *)
                       gan_image_get_pixptr_rgb_ui(source,evenH-row,0), 1,
                       3*source->width, (unsigned int *)
                       gan_image_get_pixptr_rgb_ui(source,row,0), 1 );
                   gan_copy_array_ui (
                       (unsigned int *)rgbuiarr, 1, 3*source->width,
                       (unsigned int *)
                       gan_image_get_pixptr_rgb_ui(source,evenH-row,0), 1 );
                }
                                      
                free(rgbuiarr);
             }
             else
             {
                for ( row = height-1; row >= 0; row -= 2 )
                   gan_copy_array_ui (
                       (unsigned int *)
                       gan_image_get_pixptr_rgb_ui(source,row,0), 1,
                       3*source->width,
                       (unsigned int *)
                       gan_image_get_pixptr_rgb_ui(dest,oddH-row,0), 1 );

                for ( row = height-2; row >= 0; row -= 2 )
                   gan_copy_array_ui (
                       (unsigned int *)
                       gan_image_get_pixptr_rgb_ui(source,row,0), 1,
                       3*source->width,
                       (unsigned int *)
                       gan_image_get_pixptr_rgb_ui(dest,evenH-row,0), 1 );
             }

             break;

           case GAN_FLOAT:
             if ( source == dest )
             {
                Gan_RGBPixel_f *rgbfarr;

                rgbfarr = gan_malloc_array(Gan_RGBPixel_f, width);
                if ( rgbfarr == NULL )
                {
                   gan_err_flush_trace();
                   gan_err_register ( "gan_image_flip_q",
                                      GAN_ERROR_MALLOC_FAILED, "" );
                   return NULL;
                }

                for ( row = height/2-1; row >= 0; row -= 2 )
                {
                   gan_copy_array_f (
                       (float *)
                       gan_image_get_pixptr_rgb_f(source,row,0), 1,
                       3*source->width, (float *)rgbfarr, 1 );
                   gan_copy_array_f (
                       (float *)
                       gan_image_get_pixptr_rgb_f(source,oddH-row,0), 1,
                       3*source->width, (float *)
                       gan_image_get_pixptr_rgb_f(source,row,0), 1 );
                   gan_copy_array_f (
                       (float *)rgbfarr, 1, 3*source->width,
                       (float *)
                       gan_image_get_pixptr_rgb_f(source,oddH-row,0), 1 );
                }
                                      
                for ( row = height/2-2; row >= 0; row -= 2 )
                {
                   gan_copy_array_f (
                       (float *)
                       gan_image_get_pixptr_rgb_f(source,row,0), 1,
                       3*source->width, (float *)rgbfarr, 1 );
                   gan_copy_array_f (
                       (float *)
                       gan_image_get_pixptr_rgb_f(source,evenH-row,0), 1,
                       3*source->width, (float *)
                       gan_image_get_pixptr_rgb_f(source,row,0), 1 );
                   gan_copy_array_f (
                       (float *)rgbfarr, 1, 3*source->width,
                       (float *)
                       gan_image_get_pixptr_rgb_f(source,evenH-row,0), 1 );
                }
                                      
                free(rgbfarr);
             }
             else
             {
                for ( row = height-1; row >= 0; row -= 2 )
                   gan_copy_array_f (
                       (float *)
                       gan_image_get_pixptr_rgb_f(source,row,0), 1,
                       3*source->width,
                       (float *)
                       gan_image_get_pixptr_rgb_f(dest,oddH-row,0), 1 );

                for ( row = height-2; row >= 0; row -= 2 )
                   gan_copy_array_f (
                       (float *)
                       gan_image_get_pixptr_rgb_f(source,row,0), 1,
                       3*source->width,
                       (float *)
                       gan_image_get_pixptr_rgb_f(dest,evenH-row,0), 1 );
             }

             break;

           case GAN_DOUBLE:
             if ( source == dest )
             {
                Gan_RGBPixel_d *rgbdarr;

                rgbdarr = gan_malloc_array(Gan_RGBPixel_d, width);
                if ( rgbdarr == NULL )
                {
                   gan_err_flush_trace();
                   gan_err_register ( "gan_image_flip_q",
                                      GAN_ERROR_MALLOC_FAILED, "" );
                   return NULL;
                }

                for ( row = height/2-1; row >= 0; row -= 2 )
                {
                   gan_copy_array_d (
                       (double *)
                       gan_image_get_pixptr_rgb_d(source,row,0), 1,
                       3*source->width, (double *)rgbdarr, 1 );
                   gan_copy_array_d (
                       (double *)
                       gan_image_get_pixptr_rgb_d(source,oddH-row,0), 1,
                       3*source->width, (double *)
                       gan_image_get_pixptr_rgb_d(source,row,0), 1 );
                   gan_copy_array_d (
                       (double *)rgbdarr, 1, 3*source->width,
                       (double *)
                       gan_image_get_pixptr_rgb_d(source,oddH-row,0), 1 );
                }
                                      
                for ( row = height/2-2; row >= 0; row -= 2 )
                {
                   gan_copy_array_d (
                       (double *)
                       gan_image_get_pixptr_rgb_d(source,row,0), 1,
                       3*source->width, (double *)rgbdarr, 1 );
                   gan_copy_array_d (
                       (double *)
                       gan_image_get_pixptr_rgb_d(source,evenH-row,0), 1,
                       3*source->width, (double *)
                       gan_image_get_pixptr_rgb_d(source,row,0), 1 );
                   gan_copy_array_d (
                       (double *)rgbdarr, 1, 3*source->width,
                       (double *)
                       gan_image_get_pixptr_rgb_d(source,evenH-row,0), 1 );
                }
                                      
                free(rgbdarr);
             }
             else
             {
                for ( row = height-1; row >= 0; row -= 2 )
                   gan_copy_array_d (
                       (double *)
                       gan_image_get_pixptr_rgb_d(source,row,0), 1,
                       3*source->width,
                       (double *)
                       gan_image_get_pixptr_rgb_d(dest,oddH-row,0), 1 );

                for ( row = height-2; row >= 0; row -= 2 )
                   gan_copy_array_d (
                       (double *)
                       gan_image_get_pixptr_rgb_d(source,row,0), 1,
                       3*source->width,
                       (double *)
                       gan_image_get_pixptr_rgb_d(dest,evenH-row,0), 1 );
             }

             break;

           default:
             gan_err_flush_trace();
             gan_err_register ( "gan_image_flip_q", GAN_ERROR_ILLEGAL_TYPE,
                                "" );
             return NULL;
        }

        break;

      case GAN_RGB_COLOUR_ALPHA_IMAGE:
        switch ( source->type )
        {
           case GAN_UCHAR:
             if ( source == dest )
             {
                Gan_RGBAPixel_uc *rgbaucarr;

                rgbaucarr = gan_malloc_array(Gan_RGBAPixel_uc, width);
                if ( rgbaucarr == NULL )
                {
                   gan_err_flush_trace();
                   gan_err_register ( "gan_image_flip_q",
                                      GAN_ERROR_MALLOC_FAILED, "" );
                   return NULL;
                }

                for ( row = height/2-1; row >= 0; row -= 2 )
                {
                   gan_copy_array_uc (
                      (unsigned char *)
                      gan_image_get_pixptr_rgba_uc(source,row,0), 1,
                      4*source->width, (unsigned char *)rgbaucarr, 1 );
                   gan_copy_array_uc (
                      (unsigned char *)
                      gan_image_get_pixptr_rgba_uc(source,oddH-row,0), 1,
                      4*source->width, (unsigned char *)
                      gan_image_get_pixptr_rgba_uc(source,row,0), 1 );
                   gan_copy_array_uc (
                      (unsigned char *)rgbaucarr, 1, 4*source->width,
                      (unsigned char *)
                      gan_image_get_pixptr_rgba_uc(source,oddH-row,0), 1 );
                }
                                      
                for ( row = height/2-2; row >= 0; row -= 2 )
                {
                   gan_copy_array_uc (
                      (unsigned char *)
                      gan_image_get_pixptr_rgba_uc(source,row,0), 1,
                      4*source->width, (unsigned char *)rgbaucarr, 1 );
                   gan_copy_array_uc (
                      (unsigned char *)
                      gan_image_get_pixptr_rgba_uc(source,evenH-row,0), 1,
                      4*source->width, (unsigned char *)
                      gan_image_get_pixptr_rgba_uc(source,row,0), 1 );
                   gan_copy_array_uc (
                      (unsigned char *)rgbaucarr, 1, 4*source->width,
                      (unsigned char *)
                      gan_image_get_pixptr_rgba_uc(source,evenH-row,0), 1 );
                }
                                      
                free(rgbaucarr);
             }
             else
             {
                for ( row = height-1; row >= 0; row -= 2 )
                   gan_copy_array_uc (
                       (unsigned char *)
                       gan_image_get_pixptr_rgba_uc(source,row,0), 1,
                       4*source->width,
                       (unsigned char *)
                       gan_image_get_pixptr_rgba_uc(dest,oddH-row,0), 1 );

                for ( row = height-2; row >= 0; row -= 2 )
                   gan_copy_array_uc (
                       (unsigned char *)
                       gan_image_get_pixptr_rgba_uc(source,row,0), 1,
                       4*source->width,
                       (unsigned char *)
                       gan_image_get_pixptr_rgba_uc(dest,evenH-row,0), 1 );
             }

             break;

           case GAN_USHORT:
             if ( source == dest )
             {
                Gan_RGBAPixel_us *rgbausarr;

                rgbausarr = gan_malloc_array(Gan_RGBAPixel_us, width);
                if ( rgbausarr == NULL )
                {
                   gan_err_flush_trace();
                   gan_err_register ( "gan_image_flip_q",
                                      GAN_ERROR_MALLOC_FAILED, "" );
                   return NULL;
                }

                for ( row = height/2-1; row >= 0; row -= 2 )
                {
                   gan_copy_array_us (
                       (unsigned short *)
                       gan_image_get_pixptr_rgba_us(source,row,0), 1,
                       4*source->width, (unsigned short *)rgbausarr, 1 );
                   gan_copy_array_us (
                       (unsigned short *)
                       gan_image_get_pixptr_rgba_us(source,oddH-row,0), 1,
                       4*source->width, (unsigned short *)
                       gan_image_get_pixptr_rgba_us(source,row,0), 1 );
                   gan_copy_array_us (
                       (unsigned short *)rgbausarr, 1, 4*source->width,
                       (unsigned short *)
                       gan_image_get_pixptr_rgba_us(source,oddH-row,0), 1);
                }
                                      
                for ( row = height/2-2; row >= 0; row -= 2 )
                {
                   gan_copy_array_us (
                       (unsigned short *)
                       gan_image_get_pixptr_rgba_us(source,row,0), 1,
                       4*source->width, (unsigned short *)rgbausarr, 1 );
                   gan_copy_array_us (
                       (unsigned short *)
                       gan_image_get_pixptr_rgba_us(source,evenH-row,0), 1,
                       4*source->width, (unsigned short *)
                       gan_image_get_pixptr_rgba_us(source,row,0), 1 );
                   gan_copy_array_us (
                       (unsigned short *)rgbausarr, 1, 4*source->width,
                       (unsigned short *)
                       gan_image_get_pixptr_rgba_us(source,evenH-row,0), 1);
                }
                                      
                free(rgbausarr);
             }
             else
             {
                for ( row = height-1; row >= 0; row -= 2 )
                   gan_copy_array_us (
                       (unsigned short *)
                       gan_image_get_pixptr_rgba_us(source,row,0), 1,
                       4*source->width,
                       (unsigned short *)
                       gan_image_get_pixptr_rgba_us(dest,oddH-row,0), 1 );

                for ( row = height-2; row >= 0; row -= 2 )
                   gan_copy_array_us (
                       (unsigned short *)
                       gan_image_get_pixptr_rgba_us(source,row,0), 1,
                       4*source->width,
                       (unsigned short *)
                       gan_image_get_pixptr_rgba_us(dest,evenH-row,0), 1 );
             }

             break;

           case GAN_UINT:
             if ( source == dest )
             {
                Gan_RGBAPixel_ui *rgbauiarr;

                rgbauiarr = gan_malloc_array(Gan_RGBAPixel_ui, width);
                if ( rgbauiarr == NULL )
                {
                   gan_err_flush_trace();
                   gan_err_register ( "gan_image_flip_q",
                                      GAN_ERROR_MALLOC_FAILED, "" );
                   return NULL;
                }

                for ( row = height/2-1; row >= 0; row -= 2 )
                {
                   gan_copy_array_ui (
                       (unsigned int *)
                       gan_image_get_pixptr_rgba_ui(source,row,0), 1,
                       4*source->width, (unsigned int *)rgbauiarr, 1 );
                   gan_copy_array_ui (
                       (unsigned int *)
                       gan_image_get_pixptr_rgba_ui(source,oddH-row,0), 1,
                       4*source->width, (unsigned int *)
                       gan_image_get_pixptr_rgba_ui(source,row,0), 1 );
                   gan_copy_array_ui (
                       (unsigned int *)rgbauiarr, 1, 4*source->width,
                       (unsigned int *)
                       gan_image_get_pixptr_rgba_ui(source,oddH-row,0), 1);
                }
                                      
                for ( row = height/2-2; row >= 0; row -= 2 )
                {
                   gan_copy_array_ui (
                       (unsigned int *)
                       gan_image_get_pixptr_rgba_ui(source,row,0), 1,
                       4*source->width, (unsigned int *)rgbauiarr, 1 );
                   gan_copy_array_ui (
                       (unsigned int *)
                       gan_image_get_pixptr_rgba_ui(source,evenH-row,0), 1,
                       4*source->width, (unsigned int *)
                       gan_image_get_pixptr_rgba_ui(source,row,0), 1 );
                   gan_copy_array_ui (
                       (unsigned int *)rgbauiarr, 1, 4*source->width,
                       (unsigned int *)
                       gan_image_get_pixptr_rgba_ui(source,evenH-row,0), 1);
                }
                                      
                free(rgbauiarr);
             }
             else
             {
                for ( row = height-1; row >= 0; row -= 2 )
                   gan_copy_array_ui (
                       (unsigned int *)
                       gan_image_get_pixptr_rgba_ui(source,row,0), 1,
                       4*source->width,
                       (unsigned int *)
                       gan_image_get_pixptr_rgba_ui(dest,oddH-row,0), 1 );

                for ( row = height-2; row >= 0; row -= 2 )
                   gan_copy_array_ui (
                       (unsigned int *)
                       gan_image_get_pixptr_rgba_ui(source,row,0), 1,
                       4*source->width,
                       (unsigned int *)
                       gan_image_get_pixptr_rgba_ui(dest,evenH-row,0), 1 );
             }

             break;

           case GAN_FLOAT:
             if ( source == dest )
             {
                Gan_RGBAPixel_f *rgbafarr;

                rgbafarr = gan_malloc_array(Gan_RGBAPixel_f, width);
                if ( rgbafarr == NULL )
                {
                   gan_err_flush_trace();
                   gan_err_register ( "gan_image_flip_q",
                                      GAN_ERROR_MALLOC_FAILED, "" );
                   return NULL;
                }

                for ( row = height/2-1; row >= 0; row -= 2 )
                {
                   gan_copy_array_f (
                       (float *)
                       gan_image_get_pixptr_rgba_f(source,row,0), 1,
                       4*source->width, (float *)rgbafarr, 1 );
                   gan_copy_array_f (
                       (float *)
                       gan_image_get_pixptr_rgba_f(source,oddH-row,0), 1,
                       4*source->width, (float *)
                       gan_image_get_pixptr_rgba_f(source,row,0), 1 );
                   gan_copy_array_f (
                       (float *)rgbafarr, 1, 4*source->width,
                       (float *)
                       gan_image_get_pixptr_rgba_f(source,oddH-row,0), 1 );
                }
                                      
                for ( row = height/2-2; row >= 0; row -= 2 )
                {
                   gan_copy_array_f (
                       (float *)
                       gan_image_get_pixptr_rgba_f(source,row,0), 1,
                       4*source->width, (float *)rgbafarr, 1 );
                   gan_copy_array_f (
                       (float *)
                       gan_image_get_pixptr_rgba_f(source,evenH-row,0), 1,
                       4*source->width, (float *)
                       gan_image_get_pixptr_rgba_f(source,row,0), 1 );
                   gan_copy_array_f (
                       (float *)rgbafarr, 1, 4*source->width,
                       (float *)
                       gan_image_get_pixptr_rgba_f(source,evenH-row,0), 1 );
                }
                                      
                free(rgbafarr);
             }
             else
             {
                for ( row = height-1; row >= 0; row -= 2 )
                   gan_copy_array_f (
                       (float *)
                       gan_image_get_pixptr_rgba_f(source,row,0), 1,
                       4*source->width,
                       (float *)
                       gan_image_get_pixptr_rgba_f(dest,oddH-row,0), 1 );

                for ( row = height-2; row >= 0; row -= 2 )
                   gan_copy_array_f (
                       (float *)
                       gan_image_get_pixptr_rgba_f(source,row,0), 1,
                       4*source->width,
                       (float *)
                       gan_image_get_pixptr_rgba_f(dest,evenH-row,0), 1 );
             }

             break;

           case GAN_DOUBLE:
             if ( source == dest )
             {
                Gan_RGBAPixel_d *rgbadarr;

                rgbadarr = gan_malloc_array(Gan_RGBAPixel_d, width);
                if ( rgbadarr == NULL )
                {
                   gan_err_flush_trace();
                   gan_err_register ( "gan_image_flip_q",
                                      GAN_ERROR_MALLOC_FAILED, "" );
                   return NULL;
                }

                for ( row = height/2-1; row >= 0; row -= 2 )
                {
                   gan_copy_array_d (
                       (double *)
                       gan_image_get_pixptr_rgba_d(source,row,0), 1,
                       4*source->width, (double *)rgbadarr, 1 );
                   gan_copy_array_d (
                       (double *)
                       gan_image_get_pixptr_rgba_d(source,oddH-row,0), 1,
                       4*source->width, (double *)
                       gan_image_get_pixptr_rgba_d(source,row,0), 1 );
                   gan_copy_array_d (
                       (double *)rgbadarr, 1, 4*source->width,
                       (double *)
                       gan_image_get_pixptr_rgba_d(source,oddH-row,0), 1 );
                }
                                      
                for ( row = height/2-2; row >= 0; row -= 2 )
                {
                   gan_copy_array_d (
                       (double *)
                       gan_image_get_pixptr_rgba_d(source,row,0), 1,
                       4*source->width, (double *)rgbadarr, 1 );
                   gan_copy_array_d (
                       (double *)
                       gan_image_get_pixptr_rgba_d(source,evenH-row,0), 1,
                       4*source->width, (double *)
                       gan_image_get_pixptr_rgba_d(source,row,0), 1 );
                   gan_copy_array_d (
                       (double *)rgbadarr, 1, 4*source->width,
                       (double *)
                       gan_image_get_pixptr_rgba_d(source,evenH-row,0), 1 );
                }
                                      
                free(rgbadarr);
             }
             else
             {
                for ( row = height-1; row >= 0; row -= 2 )
                   gan_copy_array_d (
                       (double *)
                       gan_image_get_pixptr_rgba_d(source,row,0), 1,
                       4*source->width,
                       (double *)
                       gan_image_get_pixptr_rgba_d(dest,oddH-row,0), 1 );

                for ( row = height-2; row >= 0; row -= 2 )
                   gan_copy_array_d (
                       (double *)
                       gan_image_get_pixptr_rgba_d(source,row,0), 1,
                       4*source->width,
                       (double *)
                       gan_image_get_pixptr_rgba_d(dest,evenH-row,0), 1 );
             }

             break;

           default:
             gan_err_flush_trace();
             gan_err_register ( "gan_image_flip_q", GAN_ERROR_ILLEGAL_TYPE,
                                "" );
             return NULL;
        }

        break;

      default:
        gan_err_flush_trace();
        gan_err_register ( "gan_image_flip_q", GAN_ERROR_ILLEGAL_TYPE, "" );
        return NULL;
   }

   /* success */
   return dest;
}


Generated by  Doxygen 1.6.0   Back to index