D:/Projects/CEGUI/Silly/src/SILLYImageContext.cpp

00001 /***********************************************************************
00002     filename:   SILLYImageContext.cpp
00003     created:    10 Jun 2006
00004     author:     Olivier Delannoy 
00005 
00006     purpose:    Implementation file for ImageContext class  
00007 *************************************************************************/
00008 /***************************************************************************
00009  *   Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team
00010  *
00011  *   Permission is hereby granted, free of charge, to any person obtaining
00012  *   a copy of this software and associated documentation files (the
00013  *   "Software"), to deal in the Software without restriction, including
00014  *   without limitation the rights to use, copy, modify, merge, publish,
00015  *   distribute, sublicense, and/or sell copies of the Software, and to
00016  *   permit persons to whom the Software is furnished to do so, subject to
00017  *   the following conditions:
00018  *
00019  *   The above copyright notice and this permission notice shall be
00020  *   included in all copies or substantial portions of the Software.
00021  *
00022  *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00023  *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00024  *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00025  *   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
00026  *   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
00027  *   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00028  *   OTHER DEALINGS IN THE SOFTWARE.
00029  ***************************************************************************/
00030 #ifdef HAVE_CONFIG_H
00031 #include <config.h>
00032 #endif
00033 
00034 #include "SILLYImageContext.h"
00035 #ifndef SILLY_OPT_INLINE
00036 #define inline 
00037 #include "SILLYImageContext.icpp"
00038 #undef inline
00039 #endif
00040 #include <cstring>
00041 // Start section of namespace SILLY
00042 namespace SILLY
00043 { 
00044 
00045 bool ImageContext::flipVertically()
00046 {
00047     size_t depth;
00048     switch(d_format)
00049     {
00050     case PF_A1B5G5R5:
00051         depth = 2;
00052         break;
00053     case PF_RGB:
00054         depth = 3;
00055         break;
00056     case PF_RGBA:
00057         depth = 4;
00058         break;
00059     }
00060        
00061     // Do the flipping 
00062     byte *p1,*p2,*tmp;      // tmp pointers
00063     size_t len = d_width * depth; // length of horizontal line in bytes
00064     tmp = new byte[len];    // Allocate a temporary line
00065     if ( !tmp )
00066         return false;
00067     
00068     size_t y , y2;
00069     y2 = d_height - 1;
00070     for ( y = 0; y < d_height >> 1; y++ )
00071     {
00072         p1 = (d_pixels) + len * y;
00073         p2 = (d_pixels) + len * y2;
00074         memcpy( tmp, p1, len );
00075         memcpy( p1, p2, len );
00076         memcpy( p2, tmp, len );
00077         y2--;
00078     }
00079     delete [] tmp;
00080     return true;
00081 }
00082 
00083 
00084 } // End section of namespace SILLY 

Generated on Sun Apr 6 14:47:06 2008 for Simple Image Loading LibrarY by  doxygen 1.5.2