- Main Page
- Data Structures
- Files

- File List

# E:/DevIL/src-IL/src/il_fastconv.c

    00001 //-----------------------------------------------------------------------------
    00002 //
    00003 // ImageLib Sources
    00004 // Copyright (C) 2000-2008 by Denton Woods
    00005 // Last modified: 07/07/2006
    00006 //
    00007 // Filename: src-IL/src/il_fastconv.c
    00008 //
    00009 // Description: Converts between several image formats
    00010 //
    00011 //-----------------------------------------------------------------------------
    00012
    00013
    00014 #include "il_internal.h"
    00015 #ifdef ALTIVEC_GCC
    00016 #include "altivec_typeconversion.h"
    00017 #endif
    00018
    00019 ILboolean iFastConvert(ILenum DestFormat)
    00020 {
    00021         ILubyte         *BytePtr = iCurImage->Data;
    00022         ILushort        *ShortPtr = (ILushort*)iCurImage->Data;
    00023         ILuint          *IntPtr = (ILuint*)iCurImage->Data;
    00024         ILfloat         *FloatPtr = (ILfloat*)iCurImage->Data;
    00025         ILdouble        *DblPtr = (ILdouble*)iCurImage->Data;
    00026
    00027 #ifndef ALTIVEC_GCC
    00028         ILuint          SizeOfData, i=0;
    00029         ILubyte TempByte = 0;
    00030         ILushort TempShort = 0;
    00031         ILuint TempInt = 0;
    00032         ILfloat TempFloat = 0;
    00033         ILdouble TempDbl = 0;
    00034 #endif
    00035
    00036         switch (DestFormat)
    00037         {
    00038                 case IL_RGB:
    00039                 case IL_BGR:
    00040                         if (iCurImage->Format != IL_RGB && iCurImage->Format != IL_BGR)
    00041                                 return IL_FALSE;
    00042
    00043                         switch (iCurImage->Type)
    00044                         {
    00045                                 case IL_BYTE:
    00046                                 case IL_UNSIGNED_BYTE:
    00047                                 #ifdef ALTIVEC_GCC
    00048                                         abc2cba_byte(BytePtr,iCurImage->SizeOfData,BytePtr);
    00049                                 #else
    00050                                         SizeOfData = iCurImage->SizeOfData / 3;
    00051                                         #ifdef USE_WIN32_ASM
    00052                                                 __asm
    00053                                                 {
    00054                                                         mov ebx, BytePtr
    00055                                                         mov ecx, SizeOfData
    00056                                                         L1:
    00057                                                                 mov al,[ebx+0]
    00058                                                                 xchg al,[ebx+2]
    00059                                                                 mov [ebx+0],al
    00060                                                                 add ebx,3
    00061                                                                 loop L1
    00062                                                 }
    00063                                         #else
    00064                                                 for (i = 0; i < SizeOfData; i++) {
    00065                                                         TempByte = BytePtr[0];
    00066                                                         BytePtr[0] = BytePtr[2];
    00067                                                         BytePtr[2] = TempByte;
    00068                                                         BytePtr += 3;
    00069                                                 }
    00070                                         #endif//USE_WIN32_ASM
    00071                                 #endif
    00072                                         return IL_TRUE;
    00073
    00074                                 case IL_SHORT:
    00075                                 case IL_UNSIGNED_SHORT:
    00076                                 #ifdef ALTIVEC_GCC
    00077                                         abc2cba_short(ShortPtr,iCurImage->SizeOfData,ShortPtr);
    00078                                 #else
    00079                                         SizeOfData = iCurImage->SizeOfData / 6;  // 3*2
    00080                                         #ifdef USE_WIN32_ASM
    00081                                                 __asm
    00082                                                 {
    00083                                                         mov ebx, ShortPtr
    00084                                                         mov ecx, SizeOfData
    00085                                                         L2:
    00086                                                                 mov ax,[ebx+0]
    00087                                                                 xchg ax,[ebx+4]
    00088                                                                 mov [ebx+0],ax
    00089                                                                 add ebx,6
    00090                                                                 loop L2
    00091                                                 }
    00092                                         #else
    00093                                                 for (i = 0; i < SizeOfData; i++) {
    00094                                                         TempShort = ShortPtr[0];
    00095                                                         ShortPtr[0] = ShortPtr[2];
    00096                                                         ShortPtr[2] = TempShort;
    00097                                                         ShortPtr += 3;
    00098                                                 }
    00099                                         #endif//USE_WIN32_ASM
    00100                                 #endif
    00101                                         return IL_TRUE;
    00102
    00103                                 case IL_INT:
    00104                                 case IL_UNSIGNED_INT:
    00105                                 #ifdef ALTIVEC_GCC
    00106                                         abc2cba_int(IntPtr,iCurImage->SizeOfData,IntPtr);
    00107                                 #else
    00108                                         SizeOfData = iCurImage->SizeOfData / 12;  // 3*4
    00109                                         #ifdef USE_WIN32_ASM
    00110                                                 __asm
    00111                                                 {
    00112                                                         mov ebx, IntPtr
    00113                                                         mov ecx, SizeOfData
    00114                                                         L3:
    00115                                                                 mov eax,[ebx+0]
    00116                                                                 xchg eax,[ebx+8]
    00117                                                                 mov [ebx+0],ax
    00118                                                                 add ebx,12
    00119                                                                 loop L3
    00120                                                 }
    00121                                         #else
    00122                                                 for (i = 0; i < SizeOfData; i++) {
    00123                                                         TempInt = IntPtr[0];
    00124                                                         IntPtr[0] = IntPtr[2];
    00125                                                         IntPtr[2] = TempInt;
    00126                                                         IntPtr += 3;
    00127                                                 }
    00128                                         #endif//USE_WIN32_ASM
    00129                                 #endif
    00130                                         return IL_TRUE;
    00131
    00132                                 case IL_FLOAT:
    00133                                 #ifdef ALTIVEC_GCC
    00134                                         abc2cba_float(FloatPtr,iCurImage->SizeOfData,FloatPtr);
    00135                                 #else
    00136                                         SizeOfData = iCurImage->SizeOfData / 12;  // 3*4
    00137                                         for (i = 0; i < SizeOfData; i++) {
    00138                                                 TempFloat = FloatPtr[0];
    00139                                                 FloatPtr[0] = FloatPtr[2];
    00140                                                 FloatPtr[2] = TempFloat;
    00141                                                 FloatPtr += 3;
    00142                                         }
    00143                                 #endif
    00144                                         return IL_TRUE;
    00145
    00146                                 case IL_DOUBLE:
    00147                                 #ifdef ALTIVEC_GCC
    00148                                         abc2cba_double(DblPtr,iCurImage->SizeOfData,DblPtr);
    00149                                 #else
    00150                                         SizeOfData = iCurImage->SizeOfData / 24;  // 3*8
    00151                                         for (i = 0; i < SizeOfData; i++) {
    00152                                                 TempDbl = DblPtr[0];
    00153                                                 DblPtr[0] = DblPtr[2];
    00154                                                 DblPtr[2] = TempDbl;
    00155                                                 DblPtr += 3;
    00156                                         }
    00157                                 #endif
    00158                                         return IL_TRUE;
    00159                         }
    00160                         break;
    00161
    00162                 case IL_RGBA:
    00163                 case IL_BGRA:
    00164                         if (iCurImage->Format != IL_RGBA && iCurImage->Format != IL_BGRA)
    00165                                 return IL_FALSE;
    00166
    00167                         switch (iCurImage->Type)
    00168                         {
    00169                                 case IL_BYTE:
    00170                                 case IL_UNSIGNED_BYTE:
    00171                                 #ifdef ALTIVEC_GCC
    00172                                         abcd2cbad_byte(BytePtr,iCurImage->SizeOfData,BytePtr);
    00173                                 #else
    00174                                         SizeOfData = iCurImage->SizeOfData / 4;
    00175                                         #ifdef USE_WIN32_ASM
    00176                                                 __asm
    00177                                                 {
    00178                                                         mov ebx, BytePtr
    00179                                                         mov ecx, SizeOfData
    00180                                                         L4:
    00181                                                                 mov eax,[ebx]
    00182                                                                 bswap eax
    00183                                                                 ror eax,8
    00184                                                                 mov [ebx], eax
    00185                                                                 add ebx,4
    00186                                                                 loop L4
    00187                                                 }
    00188                                         #else
    00189                                                 for (i = 0; i < SizeOfData; i++) {
    00190                                                         TempByte = BytePtr[0];
    00191                                                         BytePtr[0] = BytePtr[2];
    00192                                                         BytePtr[2] = TempByte;
    00193                                                         BytePtr += 4;
    00194                                                 }
    00195                                         #endif//USE_WIN32_ASM
    00196                                 #endif
    00197                                         return IL_TRUE;
    00198
    00199                                 case IL_SHORT:
    00200                                 case IL_UNSIGNED_SHORT:
    00201                                 #ifdef ALTIVEC_GCC
    00202                                         abcd2cbad_short(ShortPtr,iCurImage->SizeOfData,ShortPtr);
    00203                                 #else
    00204                                         SizeOfData = iCurImage->SizeOfData / 8;  // 4*2
    00205                                         #ifdef USE_WIN32_ASM
    00206                                                 __asm
    00207                                                 {
    00208                                                         mov ebx, ShortPtr
    00209                                                         mov ecx, SizeOfData
    00210                                                         L5:
    00211                                                                 mov ax,[ebx+0]
    00212                                                                 xchg ax,[ebx+4]
    00213                                                                 mov [ebx+0],ax
    00214                                                                 add ebx,8
    00215                                                                 loop L5
    00216                                                 }
    00217                                         #else
    00218                                                 for (i = 0; i < SizeOfData; i++) {
    00219                                                         TempShort = ShortPtr[0];
    00220                                                         ShortPtr[0] = ShortPtr[2];
    00221                                                         ShortPtr[2] = TempShort;
    00222                                                         ShortPtr += 4;
    00223                                                 }
    00224                                         #endif//USE_WIN32_ASM
    00225                                 #endif
    00226                                         return IL_TRUE;
    00227
    00228                                 case IL_INT:
    00229                                 case IL_UNSIGNED_INT:
    00230                                 #ifdef ALTIVEC_GCC
    00231                                         abcd2cbad_int(IntPtr,iCurImage->SizeOfData,IntPtr);
    00232                                 #else
    00233                                         SizeOfData = iCurImage->SizeOfData / 16;  // 4*4
    00234                                         #ifdef USE_WIN32_ASM
    00235                                                 __asm
    00236                                                 {
    00237                                                         mov ebx, IntPtr
    00238                                                         mov ecx, SizeOfData
    00239                                                         L6:
    00240                                                                 mov eax,[ebx+0]
    00241                                                                 xchg eax,[ebx+8]
    00242                                                                 mov [ebx+0],ax
    00243                                                                 add ebx,16
    00244                                                                 loop L6
    00245                                                 }
    00246                                         #else
    00247                                                 for (i = 0; i < SizeOfData; i++) {
    00248                                                         TempInt = IntPtr[0];
    00249                                                         IntPtr[0] = IntPtr[2];
    00250                                                         IntPtr[2] = TempInt;
    00251                                                         IntPtr += 4;
    00252                                                 }
    00253                                         #endif//USE_WIN32_ASM
    00254                                 #endif
    00255                                         return IL_TRUE;
    00256
    00257                                 case IL_FLOAT:
    00258                                 #ifdef ALTIVEC_GCC
    00259                                         abcd2cbad_float(FloatPtr,iCurImage->SizeOfData,FloatPtr);
    00260                                 #else
    00261                                         SizeOfData = iCurImage->SizeOfData / 16;  // 4*4
    00262                                         for (i = 0; i < SizeOfData; i++) {
    00263                                                 TempFloat = FloatPtr[0];
    00264                                                 FloatPtr[0] = FloatPtr[2];
    00265                                                 FloatPtr[2] = TempFloat;
    00266                                                 FloatPtr += 4;
    00267                                         }
    00268                                 #endif
    00269                                         return IL_TRUE;
    00270
    00271                                 case IL_DOUBLE:
    00272                                 #ifdef ALTIVEC_GCC
    00273                                         abcd2cbad_double(DblPtr,iCurImage->SizeOfData,DblPtr);
    00274                                 #else
    00275                                         SizeOfData = iCurImage->SizeOfData / 32;  // 4*8
    00276                                         for (i = 0; i < SizeOfData; i++) {
    00277                                                 TempDbl = DblPtr[0];
    00278                                                 DblPtr[0] = DblPtr[2];
    00279                                                 DblPtr[2] = TempDbl;
    00280                                                 DblPtr += 4;
    00281                                         }
    00282                                 #endif
    00283                                         return IL_TRUE;
    00284                         }
    00285         }
    00286
    00287
    00288         return IL_FALSE;
    00289 }
    00290