- Main Page
- Data Structures
- Files

- File List

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

    00001 //-----------------------------------------------------------------------------
    00002 //
    00003 // ImageLib Sources
    00004 // Copyright (C) 2000-2008 by Denton Woods
    00005 // Last modified: 01/08/2007
    00006 //
    00007 // Filename: src-IL/src/il_convbuff.c
    00008 //
    00009 // Description: Converts between several image formats
    00010 //
    00011 //-----------------------------------------------------------------------------
    00012
    00013
    00014 #include "il_internal.h"
    00015 #include "il_manip.h"
    00016 #ifdef ALTIVEC_GCC
    00017 #include "altivec_typeconversion.h"
    00018 #endif
    00019 #include <limits.h>
    00020
    00021
    00022 void* ILAPIENTRY iSwitchTypes(ILuint SizeOfData, ILenum SrcType, ILenum DestType, void *Buffer);
    00023 ILushort ILAPIENTRY ilFloatToHalf(ILuint i);
    00024 ILuint   ILAPIENTRY ilHalfToFloat (ILushort y);
    00025 ILfloat  /*ILAPIENTRY*/ ilFloatToHalfOverflow();
    00026
    00027 #define CHECK_ALLOC()   if (NewData == NULL) { \
    00028                                                         if (Data != Buffer) \
    00029                                                                 ifree(Data); \
    00030                                                         return IL_FALSE; \
    00031                                                 }
    00032
    00033 ILAPI void* ILAPIENTRY ilConvertBuffer(ILuint SizeOfData, ILenum SrcFormat, ILenum DestFormat, ILenum SrcType, ILenum DestType, void *Buffer)
    00034 {
    00035         //static const  ILfloat LumFactor[3] = { 0.299f, 0.587f, 0.114f };  // Used for conversion to luminance
    00036         //static const  ILfloat LumFactor[3] = { 0.3086f, 0.6094f, 0.0820f };  // http://www.sgi.com/grafica/matrix/index.html
    00037         static const    ILfloat LumFactor[3] = { 0.212671f, 0.715160f, 0.072169f };  // http://www.inforamp.net/~poynton/ and libpng's libpng.txt
    00038
    00039         ILubyte         *NewData = NULL;
    00040         ILuint          i, j, c, Size;
    00041         ILfloat         Resultf;
    00042         ILdouble        Resultd;
    00043         ILuint          NumPix;  // Really number of pixels * bpp.
    00044         ILuint          BpcDest;
    00045         void            *Data = NULL;
    00046
    00047         if (SizeOfData == 0 || Buffer == NULL) {
    00048                 ilSetError(IL_INVALID_PARAM);
    00049                 return NULL;
    00050         }
    00051
    00052         Data = iSwitchTypes(SizeOfData, SrcType, DestType, Buffer);
    00053         if (Data == NULL)
    00054                 return NULL;
    00055
    00056         BpcDest = ilGetBpcType(DestType);
    00057         NumPix = SizeOfData / ilGetBpcType(SrcType);
    00058
    00059         if (DestFormat == SrcFormat) {
    00060                 NewData = (ILubyte*)ialloc(NumPix * BpcDest);
    00061                 if (NewData == NULL) {
    00062                         return IL_FALSE;
    00063                 }
    00064                 memcpy(NewData, Data, NumPix * BpcDest);
    00065                 if (Data != Buffer)
    00066                         ifree(Data);
    00067
    00068                 return NewData;
    00069         }
    00070
    00071         switch (SrcFormat)
    00072         {
    00073                 case IL_RGB:
    00074                         switch (DestFormat)
    00075                         {
    00076                                 case IL_BGR:
    00077                                         NewData = (ILubyte*)ialloc(NumPix * BpcDest);
    00078                                         CHECK_ALLOC();
    00079                                         switch (DestType)
    00080                                         {
    00081                                                 case IL_UNSIGNED_BYTE:
    00082                                                 case IL_BYTE:
    00083                                                 #ifdef ALTIVEC_GCC
    00084                                                         abc2cba_byte((ILubyte*)Data,NumPix * BpcDest,NewData);
    00085                                                 #else
    00086                                                         for (i = 0; i < NumPix; i += 3) {
    00087                                                                 NewData[i] = ((ILubyte*)(Data))[i+2];
    00088                                                                 NewData[i+1] = ((ILubyte*)(Data))[i+1];
    00089                                                                 NewData[i+2] = ((ILubyte*)(Data))[i];
    00090                                                         }
    00091                                                 #endif
    00092                                                         break;
    00093                                                 case IL_UNSIGNED_SHORT:
    00094                                                 case IL_SHORT:
    00095                                                 case IL_HALF:
    00096                                                 #ifdef ALTIVEC_GCC
    00097                                                         abc2cba_short((ILushort*)Data,NumPix * BpcDest,(ILushort*)NewData);
    00098                                                 #else
    00099                                                         for (i = 0; i < NumPix; i += 3) {
    00100                                                                 ((ILushort*)(NewData))[i] = ((ILushort*)(Data))[i+2];
    00101                                                                 ((ILushort*)(NewData))[i+1] = ((ILushort*)(Data))[i+1];
    00102                                                                 ((ILushort*)(NewData))[i+2] = ((ILushort*)(Data))[i];
    00103                                                         }
    00104                                                 #endif
    00105                                                         break;
    00106                                                 case IL_UNSIGNED_INT:
    00107                                                 case IL_INT:
    00108                                                 #ifdef ALTIVEC_GCC
    00109                                                         abc2cba_int((ILuint*)Data,NumPix * BpcDest,(ILuint*)NewData);
    00110                                                 #else
    00111                                                         for (i = 0; i < NumPix; i += 3) {
    00112                                                                 ((ILuint*)(NewData))[i] = ((ILuint*)(Data))[i+2];
    00113                                                                 ((ILuint*)(NewData))[i+1] = ((ILuint*)(Data))[i+1];
    00114                                                                 ((ILuint*)(NewData))[i+2] = ((ILuint*)(Data))[i];
    00115                                                         }
    00116                                                 #endif
    00117                                                         break;
    00118                                                 case IL_FLOAT:
    00119                                                 #ifdef ALTIVEC_GCC
    00120                                                         abc2cba_float(Data,NumPix * BpcDest,NewData);
    00121                                                 #else
    00122                                                         for (i = 0; i < NumPix; i += 3) {
    00123                                                                 ((ILfloat*)(NewData))[i] = ((ILfloat*)(Data))[i+2];
    00124                                                                 ((ILfloat*)(NewData))[i+1] = ((ILfloat*)(Data))[i+1];
    00125                                                                 ((ILfloat*)(NewData))[i+2] = ((ILfloat*)(Data))[i];
    00126                                                         }
    00127                                                 #endif
    00128                                                         break;
    00129                                                 case IL_DOUBLE:
    00130                                                 #ifdef ALTIVEC_GCC
    00131                                                         abc2cba_double((ILdouble*)Data,NumPix * BpcDest,(ILdouble*)NewData);
    00132                                                 #else
    00133                                                         for (i = 0; i < NumPix; i += 3) {
    00134                                                                 ((ILdouble*)(NewData))[i] = ((ILdouble*)(Data))[i+2];
    00135                                                                 ((ILdouble*)(NewData))[i+1] = ((ILdouble*)(Data))[i+1];
    00136                                                                 ((ILdouble*)(NewData))[i+2] = ((ILdouble*)(Data))[i];
    00137                                                         }
    00138                                                         break;
    00139                                                 #endif
    00140                                         }
    00141                                         break;
    00142
    00143                                 case IL_RGBA:
    00144                                         NewData = (ILubyte*)ialloc(NumPix * BpcDest * 4 / 3);
    00145                                         CHECK_ALLOC();
    00146                                         switch (DestType)
    00147                                         {
    00148                                                 case IL_UNSIGNED_BYTE:
    00149                                                 case IL_BYTE:
    00150                                                         for (i = 0, j = 0; i < NumPix; i += 3, j += 4) {
    00151                                                                 NewData[j] = ((ILubyte*)(Data))[i];
    00152                                                                 NewData[j+1] = ((ILubyte*)(Data))[i+1];
    00153                                                                 NewData[j+2] = ((ILubyte*)(Data))[i+2];
    00154                                                                 NewData[j+3] = UCHAR_MAX;
    00155                                                         }
    00156                                                         break;
    00157                                                 case IL_UNSIGNED_SHORT:
    00158                                                 case IL_SHORT:
    00159                                                 case IL_HALF:
    00160                                                         for (i = 0, j = 0; i < NumPix; i += 3, j += 4) {
    00161                                                                 ((ILushort*)(NewData))[j] = ((ILushort*)(Data))[i];
    00162                                                                 ((ILushort*)(NewData))[j+1] = ((ILushort*)(Data))[i+1];
    00163                                                                 ((ILushort*)(NewData))[j+2] = ((ILushort*)(Data))[i+2];
    00164                                                                 ((ILushort*)(NewData))[j+3] = USHRT_MAX;
    00165                                                         }
    00166                                                         break;
    00167                                                 case IL_UNSIGNED_INT:
    00168                                                 case IL_INT:
    00169                                                         for (i = 0, j = 0; i < NumPix; i += 3, j += 4) {
    00170                                                                 ((ILuint*)(NewData))[j] = ((ILuint*)(Data))[i];
    00171                                                                 ((ILuint*)(NewData))[j+1] = ((ILuint*)(Data))[i+1];
    00172                                                                 ((ILuint*)(NewData))[j+2] = ((ILuint*)(Data))[i+2];
    00173                                                                 ((ILuint*)(NewData))[j+3] = UINT_MAX;
    00174                                                         }
    00175                                                         break;
    00176                                                 case IL_FLOAT:
    00177                                                         for (i = 0, j = 0; i < NumPix; i += 3, j += 4) {
    00178                                                                 ((ILfloat*)(NewData))[j] = ((ILfloat*)(Data))[i];
    00179                                                                 ((ILfloat*)(NewData))[j+1] = ((ILfloat*)(Data))[i+1];
    00180                                                                 ((ILfloat*)(NewData))[j+2] = ((ILfloat*)(Data))[i+2];
    00181                                                                 ((ILfloat*)(NewData))[j+3] = 1.0f;
    00182                                                         }
    00183                                                         break;
    00184                                                 case IL_DOUBLE:
    00185                                                         for (i = 0, j = 0; i < NumPix; i += 3, j += 4) {
    00186                                                                 ((ILdouble*)(NewData))[j] = ((ILdouble*)(Data))[i];
    00187                                                                 ((ILdouble*)(NewData))[j+1] = ((ILdouble*)(Data))[i+1];
    00188                                                                 ((ILdouble*)(NewData))[j+2] = ((ILdouble*)(Data))[i+2];
    00189                                                                 ((ILdouble*)(NewData))[j+3] = 1.0;
    00190                                                         }
    00191                                                         break;
    00192                                         }
    00193                                         break;
    00194
    00195                                 case IL_BGRA:
    00196                                         NewData = (ILubyte*)ialloc(NumPix * BpcDest * 4 / 3);
    00197                                         CHECK_ALLOC();
    00198                                         switch (DestType)
    00199                                         {
    00200                                                 case IL_UNSIGNED_BYTE:
    00201                                                 case IL_BYTE:
    00202                                                         for (i = 0, j = 0; i < NumPix; i += 3, j += 4) {
    00203                                                                 NewData[j] = ((ILubyte*)(Data))[i+2];
    00204                                                                 NewData[j+1] = ((ILubyte*)(Data))[i+1];
    00205                                                                 NewData[j+2] = ((ILubyte*)(Data))[i];
    00206                                                                 NewData[j+3] = UCHAR_MAX;
    00207                                                         }
    00208                                                         break;
    00209                                                 case IL_UNSIGNED_SHORT:
    00210                                                 case IL_SHORT:
    00211                                                 case IL_HALF:
    00212                                                         for (i = 0, j = 0; i < NumPix; i += 3, j += 4) {
    00213                                                                 ((ILushort*)(NewData))[j] = ((ILushort*)(Data))[i+2];
    00214                                                                 ((ILushort*)(NewData))[j+1] = ((ILushort*)(Data))[i+1];
    00215                                                                 ((ILushort*)(NewData))[j+2] = ((ILushort*)(Data))[i];
    00216                                                                 ((ILushort*)(NewData))[j+3] = USHRT_MAX;
    00217                                                         }
    00218                                                         break;
    00219                                                 case IL_UNSIGNED_INT:
    00220                                                 case IL_INT:
    00221                                                         for (i = 0, j = 0; i < NumPix; i += 3, j += 4) {
    00222                                                                 ((ILuint*)(NewData))[j] = ((ILuint*)(Data))[i+2];
    00223                                                                 ((ILuint*)(NewData))[j+1] = ((ILuint*)(Data))[i+1];
    00224                                                                 ((ILuint*)(NewData))[j+2] = ((ILuint*)(Data))[i];
    00225                                                                 ((ILuint*)(NewData))[j+3] = UINT_MAX;
    00226                                                         }
    00227                                                         break;
    00228                                                 case IL_FLOAT:
    00229                                                         for (i = 0, j = 0; i < NumPix; i += 3, j += 4) {
    00230                                                                 ((ILfloat*)(NewData))[j] = ((ILfloat*)(Data))[i+2];
    00231                                                                 ((ILfloat*)(NewData))[j+1] = ((ILfloat*)(Data))[i+1];
    00232                                                                 ((ILfloat*)(NewData))[j+2] = ((ILfloat*)(Data))[i];
    00233                                                                 ((ILfloat*)(NewData))[j+3] = 1.0f;
    00234                                                         }
    00235                                                         break;
    00236                                                 case IL_DOUBLE:
    00237                                                         for (i = 0, j = 0; i < NumPix; i += 3, j += 4) {
    00238                                                                 ((ILdouble*)(NewData))[j] = ((ILdouble*)(Data))[i+2];
    00239                                                                 ((ILdouble*)(NewData))[j+1] = ((ILdouble*)(Data))[i+1];
    00240                                                                 ((ILdouble*)(NewData))[j+2] = ((ILdouble*)(Data))[i];
    00241                                                                 ((ILdouble*)(NewData))[j+3] = 1.0f;
    00242                                                         }
    00243                                                         break;
    00244                                         }
    00245                                         break;
    00246
    00247                                 case IL_LUMINANCE:
    00248                                         NewData = (ILubyte*)ialloc(NumPix * BpcDest / 3);
    00249                                         CHECK_ALLOC();
    00250                                         Size = NumPix / 3;
    00251                                         switch (DestType)
    00252                                         {
    00253                                                 case IL_UNSIGNED_BYTE:
    00254                                                 case IL_BYTE:
    00255                                                         for (i = 0; i < Size; i++) {
    00256                                                                 Resultf = 0;
    00257                                                                 for (c = 0; c < 3; c++) {
    00258                                                                         Resultf += ((ILubyte*)(Data))[i * 3 + c] * LumFactor[c];
    00259                                                                 }
    00260                                                                 NewData[i] = (ILubyte)Resultf;
    00261                                                         }
    00262                                                         break;
    00263                                                 case IL_UNSIGNED_SHORT:
    00264                                                 case IL_SHORT:
    00265                                                 case IL_HALF:
    00266                                                         for (i = 0; i < Size; i++) {
    00267                                                                 Resultf = 0;
    00268                                                                 for (c = 0; c < 3; c++) {
    00269                                                                         Resultf += ((ILushort*)(Data))[i * 3 + c] * LumFactor[c];
    00270                                                                 }
    00271                                                                 ((ILushort*)(NewData))[i] = (ILushort)Resultf;
    00272                                                         }
    00273                                                         break;
    00274                                                 case IL_UNSIGNED_INT:
    00275                                                 case IL_INT:
    00276                                                         for (i = 0; i < Size; i++) {
    00277                                                                 Resultf = 0;
    00278                                                                 for (c = 0; c < 3; c++) {
    00279                                                                         Resultf += ((ILuint*)(Data))[i * 3 + c] * LumFactor[c];
    00280                                                                 }
    00281                                                                 ((ILuint*)(NewData))[i] = (ILuint)Resultf;
    00282                                                         }
    00283                                                         break;
    00284                                                 case IL_FLOAT:
    00285                                                         for (i = 0; i < Size; i++) {
    00286                                                                 Resultf = 0;
    00287                                                                 for (c = 0; c < 3; c++) {
    00288                                                                         Resultf += ((ILfloat*)(Data))[i * 3 + c] * LumFactor[c];
    00289                                                                 }
    00290                                                                 ((ILfloat*)(NewData))[i] = Resultf;
    00291                                                         }
    00292                                                         break;
    00293                                                 case IL_DOUBLE:
    00294                                                         for (i = 0; i < Size; i++) {
    00295                                                                 Resultd = 0;
    00296                                                                 for (c = 0; c < 3; c++) {
    00297                                                                         Resultd += ((ILdouble*)(Data))[i * 3 + c] * LumFactor[c];
    00298                                                                 }
    00299                                                                 ((ILdouble*)(NewData))[i] = Resultd;
    00300                                                         }
    00301                                                         break;
    00302                                         }
    00303                                         break;
    00304
    00305                                 case IL_LUMINANCE_ALPHA:
    00306                                         NewData = (ILubyte*)ialloc(NumPix * BpcDest / 3 * 2);
    00307                                         CHECK_ALLOC();
    00308                                         Size = NumPix / 3;
    00309                                         switch (DestType)
    00310                                         {
    00311                                                 case IL_UNSIGNED_BYTE:
    00312                                                 case IL_BYTE:
    00313                                                         for (i = 0; i < Size; i++) {
    00314                                                                 Resultf = 0;
    00315                                                                 for (c = 0; c < 3; c++) {
    00316                                                                         Resultf += ((ILubyte*)(Data))[i * 3 + c] * LumFactor[c];
    00317                                                                 }
    00318                                                                 NewData[i*2] = (ILubyte)Resultf;
    00319                                                                 NewData[i*2+1] = UCHAR_MAX;
    00320                                                         }
    00321                                                         break;
    00322                                                 case IL_UNSIGNED_SHORT:
    00323                                                 case IL_SHORT:
    00324                                                 case IL_HALF:
    00325                                                         for (i = 0; i < Size; i++) {
    00326                                                                 Resultf = 0;
    00327                                                                 for (c = 0; c < 3; c++) {
    00328                                                                         Resultf += ((ILushort*)(Data))[i * 3 + c] * LumFactor[c];
    00329                                                                 }
    00330                                                                 ((ILushort*)(NewData))[i*2] = (ILushort)Resultf;
    00331                                                                 ((ILushort*)(NewData))[i*2+1] = USHRT_MAX;
    00332                                                         }
    00333                                                         break;
    00334                                                 case IL_UNSIGNED_INT:
    00335                                                 case IL_INT:
    00336                                                         for (i = 0; i < Size; i++) {
    00337                                                                 Resultf = 0;
    00338                                                                 for (c = 0; c < 3; c++) {
    00339                                                                         Resultf += ((ILuint*)(Data))[i * 3 + c] * LumFactor[c];
    00340                                                                 }
    00341                                                                 ((ILuint*)(NewData))[i*2] = (ILuint)Resultf;
    00342                                                                 ((ILuint*)(NewData))[i*2+1] = UINT_MAX;
    00343                                                         }
    00344                                                         break;
    00345                                                 case IL_FLOAT:
    00346                                                         for (i = 0; i < Size; i++) {
    00347                                                                 Resultf = 0;
    00348                                                                 for (c = 0; c < 3; c++) {
    00349                                                                         Resultf += ((ILfloat*)(Data))[i * 3 + c] * LumFactor[c];
    00350                                                                 }
    00351                                                                 ((ILfloat*)(NewData))[i*2] = Resultf;
    00352                                                                 ((ILfloat*)(NewData))[i*2+1] = 1.0f;
    00353                                                         }
    00354                                                         break;
    00355                                                 case IL_DOUBLE:
    00356                                                         for (i = 0; i < Size; i++) {
    00357                                                                 Resultd = 0;
    00358                                                                 for (c = 0; c < 3; c++) {
    00359                                                                         Resultd += ((ILdouble*)(Data))[i * 3 + c] * LumFactor[c];
    00360                                                                 }
    00361                                                                 ((ILdouble*)(NewData))[i*2] = Resultd;
    00362                                                                 ((ILdouble*)(NewData))[i*2+1] = 1.0;
    00363                                                         }
    00364                                                         break;
    00365                                         }
    00366                                         break;
    00367
    00368                                 case IL_ALPHA:
    00369                                         NewData = (ILubyte*)ialloc(NumPix * BpcDest / 3);
    00370                                         CHECK_ALLOC();
    00371                                         memset(NewData, 0, NumPix * BpcDest);
    00372                                         break;
    00373
    00374                                 default:
    00375                                         ilSetError(IL_INVALID_CONVERSION);
    00376                                         if (Data != Buffer)
    00377                                                 ifree(Data);
    00378                                         return NULL;
    00379                         }
    00380                         break;
    00381
    00382                 case IL_RGBA:
    00383                         switch (DestFormat)
    00384                         {
    00385                                 case IL_BGRA:
    00386                                         NewData = (ILubyte*)ialloc(NumPix * BpcDest);
    00387                                         CHECK_ALLOC();
    00388                                         switch (DestType)
    00389                                         {
    00390                                                 case IL_UNSIGNED_BYTE:
    00391                                                 case IL_BYTE:
    00392                                                 #ifdef ALTIVEC_GCC
    00393                                                         abcd2cbad_byte(NewData,iCurImage->SizeOfData,NewData);
    00394                                                 #else
    00395                                                         for (i = 0; i < NumPix; i += 4) {
    00396                                                                 NewData[i] = ((ILubyte*)(Data))[i+2];
    00397                                                                 NewData[i+1] = ((ILubyte*)(Data))[i+1];
    00398                                                                 NewData[i+2] = ((ILubyte*)(Data))[i];
    00399                                                                 NewData[i+3] = ((ILubyte*)(Data))[i+3];
    00400                                                         }
    00401                                                 #endif
    00402                                                         break;
    00403                                                 case IL_UNSIGNED_SHORT:
    00404                                                 case IL_SHORT:
    00405                                                 case IL_HALF:
    00406                                                 #ifdef ALTIVEC_GCC
    00407                                                         abcd2cbad_short((ILushort*)Data,iCurImage->SizeOfData,(ILushort*)NewData);
    00408                                                 #else
    00409                                                         for (i = 0; i < NumPix; i += 4) {
    00410                                                                 ((ILushort*)(NewData))[i] = ((ILushort*)(Data))[i+2];
    00411                                                                 ((ILushort*)(NewData))[i+1] = ((ILushort*)(Data))[i+1];
    00412                                                                 ((ILushort*)(NewData))[i+2] = ((ILushort*)(Data))[i];
    00413                                                                 ((ILushort*)(NewData))[i+3] = ((ILushort*)(Data))[i+3];
    00414                                                         }
    00415                                                 #endif
    00416                                                         break;
    00417                                                 case IL_UNSIGNED_INT:
    00418                                                 case IL_INT:
    00419                                                 #ifdef ALTIVEC_GCC
    00420                                                         abcd2cbad_int((ILuint*)Data,iCurImage->SizeOfData,(ILuint*)NewData);
    00421                                                 #else
    00422                                                         for (i = 0; i < NumPix; i += 4) {
    00423                                                                 ((ILuint*)(NewData))[i] = ((ILuint*)(Data))[i+2];
    00424                                                                 ((ILuint*)(NewData))[i+1] = ((ILuint*)(Data))[i+1];
    00425                                                                 ((ILuint*)(NewData))[i+2] = ((ILuint*)(Data))[i];
    00426                                                                 ((ILuint*)(NewData))[i+3] = ((ILuint*)(Data))[i+3];
    00427                                                         }
    00428                                                 #endif
    00429                                                         break;
    00430                                                 case IL_FLOAT:
    00431                                                 #ifdef ALTIVEC_GCC
    00432                                                         abcd2cbad_float(Data,iCurImage->SizeOfData,NewData);
    00433                                                 #else
    00434                                                         for (i = 0; i < NumPix; i += 4) {
    00435                                                                 ((ILfloat*)(NewData))[i] = ((ILfloat*)(Data))[i+2];
    00436                                                                 ((ILfloat*)(NewData))[i+1] = ((ILfloat*)(Data))[i+1];
    00437                                                                 ((ILfloat*)(NewData))[i+2] = ((ILfloat*)(Data))[i];
    00438                                                                 ((ILfloat*)(NewData))[i+3] = ((ILfloat*)(Data))[i+3];
    00439                                                         }
    00440                                                 #endif
    00441                                                         break;
    00442                                                 case IL_DOUBLE:
    00443                                                 #ifdef ALTIVEC_GCC
    00444                                                         abcd2cbad_double((ILdouble*)Data,iCurImage->SizeOfData,(ILdouble*)NewData);
    00445                                                 #else
    00446                                                         for (i = 0; i < NumPix; i += 4) {
    00447                                                                 ((ILdouble*)(NewData))[i] = ((ILdouble*)(Data))[i+2];
    00448                                                                 ((ILdouble*)(NewData))[i+1] = ((ILdouble*)(Data))[i+1];
    00449                                                                 ((ILdouble*)(NewData))[i+2] = ((ILdouble*)(Data))[i];
    00450                                                                 ((ILdouble*)(NewData))[i+3] = ((ILdouble*)(Data))[i+3];
    00451                                                         }
    00452                                                 #endif
    00453                                                         break;
    00454                                         }
    00455                                         break;
    00456
    00457                                 case IL_RGB:
    00458                                         NewData = (ILubyte*)ialloc(NumPix * BpcDest * 3 / 4);
    00459                                         CHECK_ALLOC();
    00460                                         switch (DestType)
    00461                                         {
    00462                                                 case IL_UNSIGNED_BYTE:
    00463                                                 case IL_BYTE:
    00464                                                         for (i = 0, j = 0; i < NumPix; i += 4, j += 3) {
    00465                                                                 NewData[j] = ((ILubyte*)(Data))[i];
    00466                                                                 NewData[j+1] = ((ILubyte*)(Data))[i+1];
    00467                                                                 NewData[j+2] = ((ILubyte*)(Data))[i+2];
    00468                                                         }
    00469                                                         break;
    00470                                                 case IL_UNSIGNED_SHORT:
    00471                                                 case IL_SHORT:
    00472                                                 case IL_HALF:
    00473                                                         for (i = 0, j = 0; i < NumPix; i += 4, j += 3) {
    00474                                                                 ((ILushort*)(NewData))[j] = ((ILushort*)(Data))[i];
    00475                                                                 ((ILushort*)(NewData))[j+1] = ((ILushort*)(Data))[i+1];
    00476                                                                 ((ILushort*)(NewData))[j+2] = ((ILushort*)(Data))[i+2];
    00477                                                         }
    00478                                                         break;
    00479                                                 case IL_UNSIGNED_INT:
    00480                                                 case IL_INT:
    00481                                                         for (i = 0, j = 0; i < NumPix; i += 4, j += 3) {
    00482                                                                 ((ILuint*)(NewData))[j] = ((ILuint*)(Data))[i];
    00483                                                                 ((ILuint*)(NewData))[j+1] = ((ILuint*)(Data))[i+1];
    00484                                                                 ((ILuint*)(NewData))[j+2] = ((ILuint*)(Data))[i+2];
    00485                                                         }
    00486                                                         break;
    00487                                                 case IL_FLOAT:
    00488                                                         for (i = 0, j = 0; i < NumPix; i += 4, j += 3) {
    00489                                                                 ((ILfloat*)(NewData))[j] = ((ILfloat*)(Data))[i];
    00490                                                                 ((ILfloat*)(NewData))[j+1] = ((ILfloat*)(Data))[i+1];
    00491                                                                 ((ILfloat*)(NewData))[j+2] = ((ILfloat*)(Data))[i+2];
    00492                                                         }
    00493                                                         break;
    00494                                                 case IL_DOUBLE:
    00495                                                         for (i = 0, j = 0; i < NumPix; i += 4, j += 3) {
    00496                                                                 ((ILdouble*)(NewData))[j] = ((ILdouble*)(Data))[i];
    00497                                                                 ((ILdouble*)(NewData))[j+1] = ((ILdouble*)(Data))[i+1];
    00498                                                                 ((ILdouble*)(NewData))[j+2] = ((ILdouble*)(Data))[i+2];
    00499                                                         }
    00500                                                         break;
    00501                                         }
    00502                                         break;
    00503
    00504                                 case IL_BGR:
    00505                                         NewData = (ILubyte*)ialloc(NumPix * BpcDest * 3 / 4);
    00506                                         CHECK_ALLOC();
    00507                                         switch (DestType)
    00508                                         {
    00509                                                 case IL_UNSIGNED_BYTE:
    00510                                                 case IL_BYTE:
    00511                                                         for (i = 0, j = 0; i < NumPix; i += 4, j += 3) {
    00512                                                                 NewData[j] = ((ILubyte*)(Data))[i+2];
    00513                                                                 NewData[j+1] = ((ILubyte*)(Data))[i+1];
    00514                                                                 NewData[j+2] = ((ILubyte*)(Data))[i];
    00515                                                         }
    00516                                                         break;
    00517                                                 case IL_UNSIGNED_SHORT:
    00518                                                 case IL_SHORT:
    00519                                                 case IL_HALF:
    00520                                                         for (i = 0, j = 0; i < NumPix; i += 4, j += 3) {
    00521                                                                 ((ILushort*)(NewData))[j] = ((ILushort*)(Data))[i+2];
    00522                                                                 ((ILushort*)(NewData))[j+1] = ((ILushort*)(Data))[i+1];
    00523                                                                 ((ILushort*)(NewData))[j+2] = ((ILushort*)(Data))[i];
    00524                                                         }
    00525                                                         break;
    00526                                                 case IL_UNSIGNED_INT:
    00527                                                 case IL_INT:
    00528                                                         for (i = 0, j = 0; i < NumPix; i += 4, j += 3) {
    00529                                                                 ((ILuint*)(NewData))[j] = ((ILuint*)(Data))[i+2];
    00530                                                                 ((ILuint*)(NewData))[j+1] = ((ILuint*)(Data))[i+1];
    00531                                                                 ((ILuint*)(NewData))[j+2] = ((ILuint*)(Data))[i];
    00532                                                         }
    00533                                                         break;
    00534                                                 case IL_FLOAT:
    00535                                                         for (i = 0, j = 0; i < NumPix; i += 4, j += 3) {
    00536                                                                 ((ILfloat*)(NewData))[j] = ((ILfloat*)(Data))[i+2];
    00537                                                                 ((ILfloat*)(NewData))[j+1] = ((ILfloat*)(Data))[i+1];
    00538                                                                 ((ILfloat*)(NewData))[j+2] = ((ILfloat*)(Data))[i];
    00539                                                         }
    00540                                                         break;
    00541                                                 case IL_DOUBLE:
    00542                                                         for (i = 0, j = 0; i < NumPix; i += 4, j += 3) {
    00543                                                                 ((ILdouble*)(NewData))[j] = ((ILdouble*)(Data))[i+2];
    00544                                                                 ((ILdouble*)(NewData))[j+1] = ((ILdouble*)(Data))[i+1];
    00545                                                                 ((ILdouble*)(NewData))[j+2] = ((ILdouble*)(Data))[i];
    00546                                                         }
    00547                                                         break;
    00548                                         }
    00549                                         break;
    00550
    00551                                 case IL_LUMINANCE:
    00552                                         NewData = (ILubyte*)ialloc(NumPix * BpcDest / 4);
    00553                                         CHECK_ALLOC();
    00554                                         Size = NumPix / 4;
    00555                                         switch (DestType)
    00556                                         {
    00557                                                 case IL_UNSIGNED_BYTE:
    00558                                                 case IL_BYTE:
    00559                                                         for (i = 0; i < Size; i++) {
    00560                                                                 Resultf = 0.0f;
    00561                                                                 for (c = 0; c < 3; c++) {
    00562                                                                         Resultf += ((ILubyte*)(Data))[i * 4 + c] * LumFactor[c];
    00563                                                                 }
    00564                                                                 NewData[i] = (ILubyte)Resultf;
    00565                                                         }
    00566                                                         break;
    00567                                                 case IL_UNSIGNED_SHORT:
    00568                                                 case IL_SHORT:
    00569                                                 case IL_HALF:
    00570                                                         for (i = 0; i < Size; i++) {
    00571                                                                 Resultf = 0.0f;
    00572                                                                 for (c = 0; c < 3; c++) {
    00573                                                                         Resultf += ((ILushort*)(Data))[i * 4 + c] * LumFactor[c];
    00574                                                                 }
    00575                                                                 ((ILushort*)(NewData))[i] = (ILushort)Resultf;
    00576                                                         }
    00577                                                         break;
    00578                                                 case IL_UNSIGNED_INT:
    00579                                                 case IL_INT:
    00580                                                         for (i = 0; i < Size; i++) {
    00581                                                                 Resultd = 0.0;
    00582                                                                 for (c = 0; c < 3; c++) {
    00583                                                                         Resultd += ((ILuint*)(Data))[i * 4 + c] * LumFactor[c];
    00584                                                                 }
    00585                                                                 ((ILuint*)(NewData))[i] = (ILuint)Resultd;
    00586                                                         }
    00587                                                         break;
    00588                                                 case IL_FLOAT:
    00589                                                         for (i = 0; i < Size; i++) {
    00590                                                                 Resultd = 0.0;
    00591                                                                 for (c = 0; c < 3; c++) {
    00592                                                                         Resultd += ((ILfloat*)(Data))[i * 4 + c] * LumFactor[c];
    00593                                                                 }
    00594                                                                 ((ILfloat*)(NewData))[i] = (ILfloat)Resultd;
    00595                                                         }
    00596                                                         break;
    00597                                                 case IL_DOUBLE:
    00598                                                         for (i = 0; i < Size; i++) {
    00599                                                                 Resultd = 0.0;
    00600                                                                 for (c = 0; c < 3; c++) {
    00601                                                                         Resultd += ((ILdouble*)(Data))[i * 4 + c] * LumFactor[c];
    00602                                                                 }
    00603                                                                 ((ILdouble*)(NewData))[i] = Resultd;
    00604                                                         }
    00605                                                         break;
    00606                                         }
    00607                                         break;
    00608
    00609                                 case IL_LUMINANCE_ALPHA:
    00610                                         NewData = (ILubyte*)ialloc(NumPix * BpcDest / 4 * 2);
    00611                                         CHECK_ALLOC();
    00612                                         Size = NumPix / 4 * 2;
    00613                                         switch (DestType)
    00614                                         {
    00615                                                 case IL_UNSIGNED_BYTE:
    00616                                                 case IL_BYTE:
    00617                                                         for (i = 0; i < Size; i += 2) {
    00618                                                                 Resultf = 0.0f;
    00619                                                                 for (c = 0; c < 3; c++) {
    00620                                                                         Resultf += ((ILubyte*)(Data))[i * 2 + c] * LumFactor[c];
    00621                                                                 }
    00622                                                                 NewData[i] = (ILubyte)Resultf;
    00623                                                                 NewData[i+1] = ((ILubyte*)(Data))[i * 2 + 3];
    00624                                                         }
    00625                                                         break;
    00626                                                 case IL_UNSIGNED_SHORT:
    00627                                                 case IL_SHORT:
    00628                                                 case IL_HALF:
    00629                                                         for (i = 0; i < Size; i += 2) {
    00630                                                                 Resultf = 0.0f;
    00631                                                                 for (c = 0; c < 3; c++) {
    00632                                                                         Resultf += ((ILushort*)(Data))[i * 2 + c] * LumFactor[c];
    00633                                                                 }
    00634                                                                 ((ILushort*)(NewData))[i] = (ILushort)Resultf;
    00635                                                                 ((ILushort*)(NewData))[i+1] = ((ILushort*)(Data))[i * 2 + 3];
    00636                                                         }
    00637                                                         break;
    00638                                                 case IL_UNSIGNED_INT:
    00639                                                 case IL_INT:
    00640                                                         for (i = 0; i < Size; i += 2) {
    00641                                                                 Resultd = 0.0;
    00642                                                                 for (c = 0; c < 3; c++) {
    00643                                                                         Resultd += ((ILuint*)(Data))[i * 2 + c] * LumFactor[c];
    00644                                                                 }
    00645                                                                 ((ILuint*)(NewData))[i] = (ILuint)Resultd;
    00646                                                                 ((ILuint*)(NewData))[i+1] = ((ILuint*)(Data))[i * 2 + 3];
    00647                                                         }
    00648                                                         break;
    00649                                                 case IL_FLOAT:
    00650                                                         for (i = 0; i < Size; i += 2) {
    00651                                                                 Resultd = 0.0;
    00652                                                                 for (c = 0; c < 3; c++) {
    00653                                                                         Resultd += ((ILfloat*)(Data))[i * 2 + c] * LumFactor[c];
    00654                                                                 }
    00655                                                                 ((ILfloat*)(NewData))[i] = (ILfloat)Resultd;
    00656                                                                 ((ILfloat*)(NewData))[i+1] = ((ILfloat*)(Data))[i * 2 + 3];
    00657                                                         }
    00658                                                         break;
    00659                                                 case IL_DOUBLE:
    00660                                                         for (i = 0; i < Size; i += 2) {
    00661                                                                 Resultd = 0.0;
    00662                                                                 for (c = 0; c < 3; c++) {
    00663                                                                         Resultd += ((ILdouble*)(Data))[i * 2 + c] * LumFactor[c];
    00664                                                                 }
    00665                                                                 ((ILdouble*)(NewData))[i] = Resultd;
    00666                                                                 ((ILdouble*)(NewData))[i+1] = ((ILdouble*)(Data))[i * 2 + 3];
    00667                                                         }
    00668                                                         break;
    00669                                         }
    00670                                         break;
    00671
    00672                                 case IL_ALPHA:
    00673                                         NewData = (ILubyte*)ialloc(NumPix * BpcDest / 4);
    00674                                         CHECK_ALLOC();
    00675                                         Size = NumPix / 4;
    00676                                         switch (DestType)
    00677                                         {
    00678                                                 case IL_UNSIGNED_BYTE:
    00679                                                 case IL_BYTE:
    00680                                                         for (i = 0; i < Size; i++) {
    00681                                                                 NewData[i] = ((ILubyte*)(Data))[i * 4 + 3];
    00682                                                         }
    00683                                                         break;
    00684                                                 case IL_UNSIGNED_SHORT:
    00685                                                 case IL_SHORT:
    00686                                                 case IL_HALF:
    00687                                                         for (i = 0; i < Size; i++) {
    00688                                                                 ((ILushort*)(NewData))[i] = ((ILushort*)(Data))[i * 4 + 3];
    00689                                                         }
    00690                                                         break;
    00691                                                 case IL_UNSIGNED_INT:
    00692                                                 case IL_INT:
    00693                                                         for (i = 0; i < Size; i++) {
    00694                                                                 ((ILuint*)(NewData))[i] = ((ILuint*)(Data))[i * 4 + 3];
    00695                                                         }
    00696                                                         break;
    00697                                                 case IL_FLOAT:
    00698                                                         for (i = 0; i < Size; i++) {
    00699                                                                 ((ILfloat*)(NewData))[i] = ((ILfloat*)(Data))[i * 4 + 3];
    00700                                                         }
    00701                                                         break;
    00702                                                 case IL_DOUBLE:
    00703                                                         for (i = 0; i < Size; i++) {
    00704                                                                 ((ILdouble*)(NewData))[i] = ((ILdouble*)(Data))[i * 4 + 3];
    00705                                                         }
    00706                                                         break;
    00707                                         }
    00708                                         break;
    00709
    00710                                 default:
    00711                                         ilSetError(IL_INVALID_CONVERSION);
    00712                                         if (Data != Buffer)
    00713                                                 ifree(Data);
    00714                                         return NULL;
    00715                         }
    00716                         break;
    00717
    00718                 case IL_BGR:
    00719                         switch (DestFormat)
    00720                         {
    00721                                 case IL_RGB:
    00722                                         NewData = (ILubyte*)ialloc(NumPix * BpcDest);
    00723                                         CHECK_ALLOC();
    00724                                         switch (DestType)
    00725                                         {
    00726                                                 case IL_UNSIGNED_BYTE:
    00727                                                 case IL_BYTE:
    00728                                                 #ifdef ALTIVEC_GCC
    00729                                                         abc2cba_byte(((ILubyte*)Data),NumPix * BpcDest,NewData);
    00730                                                 #else
    00731                                                         for (i = 0; i < NumPix; i += 3) {
    00732                                                                 NewData[i] = ((ILubyte*)(Data))[i+2];
    00733                                                                 NewData[i+1] = ((ILubyte*)(Data))[i+1];
    00734                                                                 NewData[i+2] = ((ILubyte*)(Data))[i];
    00735                                                         }
    00736                                                 #endif
    00737                                                         break;
    00738                                                 case IL_UNSIGNED_SHORT:
    00739                                                 case IL_SHORT:
    00740                                                 case IL_HALF:
    00741                                                 #ifdef ALTIVEC_GCC
    00742                                                         abc2cba_short((ILushort*)Data,NumPix * BpcDest,(ILushort*)NewData);
    00743                                                 #else
    00744                                                         for (i = 0; i < NumPix; i += 3) {
    00745                                                                 ((ILushort*)(NewData))[i] = ((ILushort*)(Data))[i+2];
    00746                                                                 ((ILushort*)(NewData))[i+1] = ((ILushort*)(Data))[i+1];
    00747                                                                 ((ILushort*)(NewData))[i+2] = ((ILushort*)(Data))[i];
    00748                                                         }
    00749                                                 #endif
    00750                                                         break;
    00751                                                 case IL_UNSIGNED_INT:
    00752                                                 case IL_INT:
    00753                                                 #ifdef ALTIVEC_GCC
    00754                                                         abc2cba_int((ILuint*)Data,NumPix * BpcDest,(ILuint*)NewData);
    00755                                                 #else
    00756                                                         for (i = 0; i < NumPix; i += 3) {
    00757                                                                 ((ILuint*)(NewData))[i] = ((ILuint*)(Data))[i+2];
    00758                                                                 ((ILuint*)(NewData))[i+1] = ((ILuint*)(Data))[i+1];
    00759                                                                 ((ILuint*)(NewData))[i+2] = ((ILuint*)(Data))[i];
    00760                                                         }
    00761                                                 #endif
    00762                                                         break;
    00763                                                 case IL_FLOAT:
    00764                                                 #ifdef ALTIVEC_GCC
    00765                                                         abc2cba_float(Data,NumPix * BpcDest,NewData);
    00766                                                 #else
    00767                                                         for (i = 0; i < NumPix; i += 3) {
    00768                                                                 ((ILfloat*)(NewData))[i] = ((ILfloat*)(Data))[i+2];
    00769                                                                 ((ILfloat*)(NewData))[i+1] = ((ILfloat*)(Data))[i+1];
    00770                                                                 ((ILfloat*)(NewData))[i+2] = ((ILfloat*)(Data))[i];
    00771                                                         }
    00772                                                 #endif
    00773                                                         break;
    00774                                                 case IL_DOUBLE:
    00775                                                 #ifdef ALTIVEC_GCC
    00776                                                         abc2cba_double((ILdouble*)Data,iCurImage->SizeOfData,(ILdouble*)NewData);
    00777                                                 #else
    00778                                                         for (i = 0; i < NumPix; i += 3) {
    00779                                                                 ((ILdouble*)(NewData))[i] = ((ILdouble*)(Data))[i+2];
    00780                                                                 ((ILdouble*)(NewData))[i+1] = ((ILdouble*)(Data))[i+1];
    00781                                                                 ((ILdouble*)(NewData))[i+2] = ((ILdouble*)(Data))[i];
    00782                                                         }
    00783                                                 #endif
    00784                                                         break;
    00785                                         }
    00786                                         break;
    00787
    00788                                 case IL_BGRA:
    00789                                         NewData = (ILubyte*)ialloc(NumPix * BpcDest * 4 / 3);
    00790                                         CHECK_ALLOC();
    00791                                         switch (DestType)
    00792                                         {
    00793                                                 case IL_UNSIGNED_BYTE:
    00794                                                 case IL_BYTE:
    00795                                                         for (i = 0, j = 0; i < NumPix; i += 3, j += 4) {
    00796                                                                 NewData[j] = ((ILubyte*)(Data))[i];
    00797                                                                 NewData[j+1] = ((ILubyte*)(Data))[i+1];
    00798                                                                 NewData[j+2] = ((ILubyte*)(Data))[i+2];
    00799                                                                 NewData[j+3] = UCHAR_MAX;
    00800                                                         }
    00801                                                         break;
    00802                                                 case IL_UNSIGNED_SHORT:
    00803                                                 case IL_SHORT:
    00804                                                 case IL_HALF:
    00805                                                         for (i = 0, j = 0; i < NumPix; i += 3, j += 4) {
    00806                                                                 ((ILushort*)(NewData))[j] = ((ILushort*)(Data))[i];
    00807                                                                 ((ILushort*)(NewData))[j+1] = ((ILushort*)(Data))[i+1];
    00808                                                                 ((ILushort*)(NewData))[j+2] = ((ILushort*)(Data))[i+2];
    00809                                                                 ((ILushort*)(NewData))[j+3] = USHRT_MAX;
    00810                                                         }
    00811                                                         break;
    00812                                                 case IL_UNSIGNED_INT:
    00813                                                 case IL_INT:
    00814                                                         for (i = 0, j = 0; i < NumPix; i += 3, j += 4) {
    00815                                                                 ((ILuint*)(NewData))[j] = ((ILuint*)(Data))[i];
    00816                                                                 ((ILuint*)(NewData))[j+1] = ((ILuint*)(Data))[i+1];
    00817                                                                 ((ILuint*)(NewData))[j+2] = ((ILuint*)(Data))[i+2];
    00818                                                                 ((ILuint*)(NewData))[j+3] = UINT_MAX;
    00819                                                         }
    00820                                                         break;
    00821                                                 case IL_FLOAT:
    00822                                                         for (i = 0, j = 0; i < NumPix; i += 3, j += 4) {
    00823                                                                 ((ILfloat*)(NewData))[j] = ((ILfloat*)(Data))[i];
    00824                                                                 ((ILfloat*)(NewData))[j+1] = ((ILfloat*)(Data))[i+1];
    00825                                                                 ((ILfloat*)(NewData))[j+2] = ((ILfloat*)(Data))[i+2];
    00826                                                                 ((ILfloat*)(NewData))[j+3] = 1.0f;
    00827                                                         }
    00828                                                         break;
    00829                                                 case IL_DOUBLE:
    00830                                                         for (i = 0, j = 0; i < NumPix; i += 3, j += 4) {
    00831                                                                 ((ILdouble*)(NewData))[j] = ((ILdouble*)(Data))[i];
    00832                                                                 ((ILdouble*)(NewData))[j+1] = ((ILdouble*)(Data))[i+1];
    00833                                                                 ((ILdouble*)(NewData))[j+2] = ((ILdouble*)(Data))[i+2];
    00834                                                                 ((ILdouble*)(NewData))[j+3] = 1.0;
    00835                                                         }
    00836                                                         break;
    00837                                         }
    00838                                         break;
    00839
    00840                                 case IL_RGBA:
    00841                                         NewData = (ILubyte*)ialloc(NumPix * BpcDest * 4 / 3);
    00842                                         CHECK_ALLOC();
    00843                                         switch (DestType)
    00844                                         {
    00845                                                 case IL_UNSIGNED_BYTE:
    00846                                                 case IL_BYTE:
    00847                                                         for (i = 0, j = 0; i < NumPix; i += 3, j += 4) {
    00848                                                                 NewData[j] = ((ILubyte*)(Data))[i+2];
    00849                                                                 NewData[j+1] = ((ILubyte*)(Data))[i+1];
    00850                                                                 NewData[j+2] = ((ILubyte*)(Data))[i];
    00851                                                                 NewData[j+3] = UCHAR_MAX;
    00852                                                         }
    00853                                                         break;
    00854                                                 case IL_UNSIGNED_SHORT:
    00855                                                 case IL_SHORT:
    00856                                                 case IL_HALF:
    00857                                                         for (i = 0, j = 0; i < NumPix; i += 3, j += 4) {
    00858                                                                 ((ILushort*)(NewData))[j] = ((ILushort*)(Data))[i+2];
    00859                                                                 ((ILushort*)(NewData))[j+1] = ((ILushort*)(Data))[i+1];
    00860                                                                 ((ILushort*)(NewData))[j+2] = ((ILushort*)(Data))[i];
    00861                                                                 ((ILushort*)(NewData))[j+3] = USHRT_MAX;
    00862                                                         }
    00863                                                         break;
    00864                                                 case IL_UNSIGNED_INT:
    00865                                                 case IL_INT:
    00866                                                         for (i = 0, j = 0; i < NumPix; i += 3, j += 4) {
    00867                                                                 ((ILuint*)(NewData))[j] = ((ILuint*)(Data))[i+2];
    00868                                                                 ((ILuint*)(NewData))[j+1] = ((ILuint*)(Data))[i+1];
    00869                                                                 ((ILuint*)(NewData))[j+2] = ((ILuint*)(Data))[i];
    00870                                                                 ((ILuint*)(NewData))[j+3] = UINT_MAX;
    00871                                                         }
    00872                                                         break;
    00873                                                 case IL_FLOAT:
    00874                                                         for (i = 0, j = 0; i < NumPix; i += 3, j += 4) {
    00875                                                                 ((ILfloat*)(NewData))[j] = ((ILfloat*)(Data))[i+2];
    00876                                                                 ((ILfloat*)(NewData))[j+1] = ((ILfloat*)(Data))[i+1];
    00877                                                                 ((ILfloat*)(NewData))[j+2] = ((ILfloat*)(Data))[i];
    00878                                                                 ((ILfloat*)(NewData))[j+3] = 1.0f;
    00879                                                         }
    00880                                                         break;
    00881                                                 case IL_DOUBLE:
    00882                                                         for (i = 0, j = 0; i < NumPix; i += 3, j += 4) {
    00883                                                                 ((ILdouble*)(NewData))[j] = ((ILdouble*)(Data))[i+2];
    00884                                                                 ((ILdouble*)(NewData))[j+1] = ((ILdouble*)(Data))[i+1];
    00885                                                                 ((ILdouble*)(NewData))[j+2] = ((ILdouble*)(Data))[i];
    00886                                                                 ((ILdouble*)(NewData))[j+3] = 1.0;
    00887                                                         }
    00888                                                         break;
    00889                                         }
    00890                                         break;
    00891
    00892                                 case IL_LUMINANCE:
    00893                                         NewData = (ILubyte*)ialloc(NumPix * BpcDest / 3);
    00894                                         CHECK_ALLOC();
    00895                                         Size = NumPix / 3;
    00896                                         switch (DestType)
    00897                                         {
    00898                                                 case IL_UNSIGNED_BYTE:
    00899                                                 case IL_BYTE:
    00900                                                         for (i = 0; i < Size; i++) {
    00901                                                                 Resultf = 0.0f;  j = 2;
    00902                                                                 for (c = 0; c < 3; c++, j--) {
    00903                                                                         Resultf += ((ILubyte*)(Data))[i * 3 + c] * LumFactor[j];
    00904                                                                 }
    00905                                                                 NewData[i] = (ILubyte)Resultf;
    00906                                                         }
    00907                                                         break;
    00908                                                 case IL_UNSIGNED_SHORT:
    00909                                                 case IL_SHORT:
    00910                                                 case IL_HALF:
    00911                                                         for (i = 0; i < Size; i++) {
    00912                                                                 Resultf = 0.0f;  j = 2;
    00913                                                                 for (c = 0; c < 3; c++, j--) {
    00914                                                                         Resultf += ((ILushort*)(Data))[i * 3 + c] * LumFactor[j];
    00915                                                                 }
    00916                                                                 ((ILushort*)(NewData))[i] = (ILushort)Resultf;
    00917                                                         }
    00918                                                         break;
    00919                                                 case IL_UNSIGNED_INT:
    00920                                                 case IL_INT:
    00921                                                         for (i = 0; i < Size; i++) {
    00922                                                                 Resultd = 0.0f;  j = 2;
    00923                                                                 for (c = 0; c < 3; c++, j--) {
    00924                                                                         Resultd += ((ILuint*)(Data))[i * 3 + c] * LumFactor[j];
    00925                                                                 }
    00926                                                                 ((ILuint*)(NewData))[i] = (ILuint)Resultd;
    00927                                                         }
    00928                                                         break;
    00929                                                 case IL_FLOAT:
    00930                                                         for (i = 0; i < Size; i++) {
    00931                                                                 Resultd = 0.0f;  j = 2;
    00932                                                                 for (c = 0; c < 3; c++, j--) {
    00933                                                                         Resultd += ((ILfloat*)(Data))[i * 3 + c] * LumFactor[j];
    00934                                                                 }
    00935                                                                 ((ILfloat*)(NewData))[i] = (ILfloat)Resultd;
    00936                                                         }
    00937                                                         break;
    00938                                                 case IL_DOUBLE:
    00939                                                         for (i = 0; i < Size; i++) {
    00940                                                                 Resultd = 0.0f;  j = 2;
    00941                                                                 for (c = 0; c < 3; c++, j--) {
    00942                                                                         Resultd += ((ILdouble*)(Data))[i * 3 + c] * LumFactor[j];
    00943                                                                 }
    00944                                                                 ((ILdouble*)(NewData))[i] = Resultd;
    00945                                                         }
    00946                                                         break;
    00947                                         }
    00948                                         break;
    00949
    00950                                 case IL_LUMINANCE_ALPHA:
    00951                                         NewData = (ILubyte*)ialloc(NumPix * BpcDest / 3 * 2);
    00952                                         CHECK_ALLOC();
    00953                                         Size = NumPix / 3;
    00954                                         switch (DestType)
    00955                                         {
    00956                                                 case IL_UNSIGNED_BYTE:
    00957                                                 case IL_BYTE:
    00958                                                         for (i = 0; i < Size; i++) {
    00959                                                                 Resultf = 0;
    00960                                                                 for (c = 0; c < 3; c++) {
    00961                                                                         Resultf += ((ILubyte*)(Data))[i * 3 + c] * LumFactor[c];
    00962                                                                 }
    00963                                                                 NewData[i*2] = (ILubyte)Resultf;
    00964                                                                 NewData[i*2+1] = UCHAR_MAX;
    00965                                                         }
    00966                                                         break;
    00967                                                 case IL_UNSIGNED_SHORT:
    00968                                                 case IL_SHORT:
    00969                                                 case IL_HALF:
    00970                                                         for (i = 0; i < Size; i++) {
    00971                                                                 Resultf = 0;
    00972                                                                 for (c = 0; c < 3; c++) {
    00973                                                                         Resultf += ((ILushort*)(Data))[i * 3 + c] * LumFactor[c];
    00974                                                                 }
    00975                                                                 ((ILushort*)(NewData))[i*2] = (ILushort)Resultf;
    00976                                                                 ((ILushort*)(NewData))[i*2+1] = USHRT_MAX;
    00977                                                         }
    00978                                                         break;
    00979                                                 case IL_UNSIGNED_INT:
    00980                                                 case IL_INT:
    00981                                                         for (i = 0; i < Size; i++) {
    00982                                                                 Resultf = 0;
    00983                                                                 for (c = 0; c < 3; c++) {
    00984                                                                         Resultf += ((ILuint*)(Data))[i * 3 + c] * LumFactor[c];
    00985                                                                 }
    00986                                                                 ((ILuint*)(NewData))[i*2] = (ILuint)Resultf;
    00987                                                                 ((ILuint*)(NewData))[i*2+1] = UINT_MAX;
    00988                                                         }
    00989                                                         break;
    00990                                                 case IL_FLOAT:
    00991                                                         for (i = 0; i < Size; i++) {
    00992                                                                 Resultf = 0;
    00993                                                                 for (c = 0; c < 3; c++) {
    00994                                                                         Resultf += ((ILfloat*)(Data))[i * 3 + c] * LumFactor[c];
    00995                                                                 }
    00996                                                                 ((ILfloat*)(NewData))[i*2] = Resultf;
    00997                                                                 ((ILfloat*)(NewData))[i*2+1] = 1.0f;
    00998                                                         }
    00999                                                         break;
    01000                                                 case IL_DOUBLE:
    01001                                                         for (i = 0; i < Size; i++) {
    01002                                                                 Resultd = 0;
    01003                                                                 for (c = 0; c < 3; c++) {
    01004                                                                         Resultd += ((ILdouble*)(Data))[i * 3 + c] * LumFactor[c];
    01005                                                                 }
    01006                                                                 ((ILdouble*)(NewData))[i*2] = Resultd;
    01007                                                                 ((ILdouble*)(NewData))[i*2+1] = 1.0;
    01008                                                         }
    01009                                                         break;
    01010                                         }
    01011                                         break;
    01012
    01013                                 case IL_ALPHA:
    01014                                         NewData = (ILubyte*)ialloc(NumPix * BpcDest / 3);
    01015                                         CHECK_ALLOC();
    01016                                         memset(NewData, 0, NumPix * BpcDest / 3);
    01017                                         break;
    01018
    01019                                 default:
    01020                                         ilSetError(IL_INVALID_CONVERSION);
    01021                                         if (Data != Buffer)
    01022                                                 ifree(Data);
    01023                                         return NULL;
    01024                         }
    01025                         break;
    01026
    01027                 case IL_BGRA:
    01028                         switch (DestFormat)
    01029                         {
    01030                                 case IL_RGBA:
    01031                                         NewData = (ILubyte*)ialloc(NumPix * BpcDest);
    01032                                         CHECK_ALLOC();
    01033                                         switch (DestType)
    01034                                         {
    01035                                                 case IL_UNSIGNED_BYTE:
    01036                                                 case IL_BYTE:
    01037                                                 #ifdef ALTIVEC_GCC
    01038                                                         abcd2cbad_byte(NewData,iCurImage->SizeOfData,NewData);
    01039                                                 #else
    01040                                                         for (i = 0; i < NumPix; i += 4) {
    01041                                                                 NewData[i] = ((ILubyte*)(Data))[i+2];
    01042                                                                 NewData[i+1] = ((ILubyte*)(Data))[i+1];
    01043                                                                 NewData[i+2] = ((ILubyte*)(Data))[i];
    01044                                                                 NewData[i+3] = ((ILubyte*)(Data))[i+3];
    01045                                                         }
    01046                                                 #endif
    01047                                                         break;
    01048                                                 case IL_UNSIGNED_SHORT:
    01049                                                 case IL_SHORT:
    01050                                                 case IL_HALF:
    01051                                                 #ifdef ALTIVEC_GCC
    01052                                                         abcd2cbad_short((ILushort*)Data,iCurImage->SizeOfData,(ILushort*)NewData);
    01053                                                 #else
    01054                                                         for (i = 0; i < NumPix; i += 4) {
    01055                                                                 ((ILushort*)(NewData))[i] = ((ILushort*)(Data))[i+2];
    01056                                                                 ((ILushort*)(NewData))[i+1] = ((ILushort*)(Data))[i+1];
    01057                                                                 ((ILushort*)(NewData))[i+2] = ((ILushort*)(Data))[i];
    01058                                                                 ((ILushort*)(NewData))[i+3] = ((ILushort*)(Data))[i+3];
    01059                                                         }
    01060                                                 #endif
    01061                                                         break;
    01062                                                 case IL_UNSIGNED_INT:
    01063                                                 case IL_INT:
    01064                                                 #ifdef ALTIVEC_GCC
    01065                                                         abcd2cbad_int((ILuint*)NewData,iCurImage->SizeOfData,(ILuint*)NewData);
    01066                                                 #else
    01067                                                         for (i = 0; i < NumPix; i += 4) {
    01068                                                                 ((ILuint*)(NewData))[i] = ((ILuint*)(Data))[i+2];
    01069                                                                 ((ILuint*)(NewData))[i+1] = ((ILuint*)(Data))[i+1];
    01070                                                                 ((ILuint*)(NewData))[i+2] = ((ILuint*)(Data))[i];
    01071                                                                 ((ILuint*)(NewData))[i+3] = ((ILuint*)(Data))[i+3];
    01072                                                         }
    01073                                                 #endif
    01074                                                         break;
    01075                                                 case IL_FLOAT:
    01076                                                 #ifdef ALTIVEC_GCC
    01077                                                         abcd2cbad_float(NewData,iCurImage->SizeOfData,NewData);
    01078                                                 #else
    01079                                                         for (i = 0; i < NumPix; i += 4) {
    01080                                                                 ((ILfloat*)(NewData))[i] = ((ILfloat*)(Data))[i+2];
    01081                                                                 ((ILfloat*)(NewData))[i+1] = ((ILfloat*)(Data))[i+1];
    01082                                                                 ((ILfloat*)(NewData))[i+2] = ((ILfloat*)(Data))[i];
    01083                                                                 ((ILfloat*)(NewData))[i+3] = ((ILfloat*)(Data))[i+3];
    01084                                                         }
    01085                                                 #endif
    01086                                                         break;
    01087                                                 case IL_DOUBLE:
    01088                                                 #ifdef ALTIVEC_GCC
    01089                                                         abcd2cbad_double((ILdouble*)Data,iCurImage->SizeOfData,(ILdouble*)NewData);
    01090                                                 #else
    01091                                                         for (i = 0; i < NumPix; i += 4) {
    01092                                                                 ((ILdouble*)(NewData))[i] = ((ILdouble*)(Data))[i+2];
    01093                                                                 ((ILdouble*)(NewData))[i+1] = ((ILdouble*)(Data))[i+1];
    01094                                                                 ((ILdouble*)(NewData))[i+2] = ((ILdouble*)(Data))[i];
    01095                                                                 ((ILdouble*)(NewData))[i+3] = ((ILdouble*)(Data))[i+3];
    01096                                                         }
    01097                                                 #endif
    01098                                                         break;
    01099                                         }
    01100                                         break;
    01101
    01102                                 case IL_BGR:
    01103                                         NewData = (ILubyte*)ialloc(NumPix * BpcDest * 3 / 4);
    01104                                         CHECK_ALLOC();
    01105                                         switch (DestType)
    01106                                         {
    01107                                                 case IL_UNSIGNED_BYTE:
    01108                                                 case IL_BYTE:
    01109                                                         for (i = 0, j = 0; i < NumPix; i += 4, j += 3) {
    01110                                                                 NewData[j] = ((ILubyte*)(Data))[i];
    01111                                                                 NewData[j+1] = ((ILubyte*)(Data))[i+1];
    01112                                                                 NewData[j+2] = ((ILubyte*)(Data))[i+2];
    01113                                                         }
    01114                                                         break;
    01115                                                 case IL_UNSIGNED_SHORT:
    01116                                                 case IL_SHORT:
    01117                                                 case IL_HALF:
    01118                                                         for (i = 0, j = 0; i < NumPix; i += 4, j += 3) {
    01119                                                                 ((ILushort*)(NewData))[j] = ((ILushort*)(Data))[i];
    01120                                                                 ((ILushort*)(NewData))[j+1] = ((ILushort*)(Data))[i+1];
    01121                                                                 ((ILushort*)(NewData))[j+2] = ((ILushort*)(Data))[i+2];
    01122                                                         }
    01123                                                         break;
    01124                                                 case IL_UNSIGNED_INT:
    01125                                                 case IL_INT:
    01126                                                         for (i = 0, j = 0; i < NumPix; i += 4, j += 3) {
    01127                                                                 ((ILuint*)(NewData))[j] = ((ILuint*)(Data))[i];
    01128                                                                 ((ILuint*)(NewData))[j+1] = ((ILuint*)(Data))[i+1];
    01129                                                                 ((ILuint*)(NewData))[j+2] = ((ILuint*)(Data))[i+2];
    01130                                                         }
    01131                                                         break;
    01132                                                 case IL_FLOAT:
    01133                                                         for (i = 0, j = 0; i < NumPix; i += 4, j += 3) {
    01134                                                                 ((ILfloat*)(NewData))[j] = ((ILfloat*)(Data))[i];
    01135                                                                 ((ILfloat*)(NewData))[j+1] = ((ILfloat*)(Data))[i+1];
    01136                                                                 ((ILfloat*)(NewData))[j+2] = ((ILfloat*)(Data))[i+2];
    01137                                                         }
    01138                                                         break;
    01139                                                 case IL_DOUBLE:
    01140                                                         for (i = 0, j = 0; i < NumPix; i += 4, j += 3) {
    01141                                                                 ((ILdouble*)(NewData))[j] = ((ILdouble*)(Data))[i];
    01142                                                                 ((ILdouble*)(NewData))[j+1] = ((ILdouble*)(Data))[i+1];
    01143                                                                 ((ILdouble*)(NewData))[j+2] = ((ILdouble*)(Data))[i+2];
    01144                                                         }
    01145                                                         break;
    01146                                         }
    01147                                         break;
    01148
    01149                                 case IL_RGB:
    01150                                         NewData = (ILubyte*)ialloc(NumPix * BpcDest * 3 / 4);
    01151                                         CHECK_ALLOC();
    01152                                         switch (DestType)
    01153                                         {
    01154                                                 case IL_UNSIGNED_BYTE:
    01155                                                 case IL_BYTE:
    01156                                                         for (i = 0, j = 0; i < NumPix; i += 4, j += 3) {
    01157                                                                 NewData[j] = ((ILubyte*)(Data))[i+2];
    01158                                                                 NewData[j+1] = ((ILubyte*)(Data))[i+1];
    01159                                                                 NewData[j+2] = ((ILubyte*)(Data))[i];
    01160                                                         }
    01161                                                         break;
    01162                                                 case IL_UNSIGNED_SHORT:
    01163                                                 case IL_SHORT:
    01164                                                 case IL_HALF:
    01165                                                         for (i = 0, j = 0; i < NumPix; i += 4, j += 3) {
    01166                                                                 ((ILushort*)(NewData))[j] = ((ILushort*)(Data))[i+2];
    01167                                                                 ((ILushort*)(NewData))[j+1] = ((ILushort*)(Data))[i+1];
    01168                                                                 ((ILushort*)(NewData))[j+2] = ((ILushort*)(Data))[i];
    01169                                                         }
    01170                                                         break;
    01171                                                 case IL_UNSIGNED_INT:
    01172                                                 case IL_INT:
    01173                                                         for (i = 0, j = 0; i < NumPix; i += 4, j += 3) {
    01174                                                                 ((ILuint*)(NewData))[j] = ((ILuint*)(Data))[i+2];
    01175                                                                 ((ILuint*)(NewData))[j+1] = ((ILuint*)(Data))[i+1];
    01176                                                                 ((ILuint*)(NewData))[j+2] = ((ILuint*)(Data))[i];
    01177                                                         }
    01178                                                         break;
    01179                                                 case IL_FLOAT:
    01180                                                         for (i = 0, j = 0; i < NumPix; i += 4, j += 3) {
    01181                                                                 ((ILfloat*)(NewData))[j] = ((ILfloat*)(Data))[i+2];
    01182                                                                 ((ILfloat*)(NewData))[j+1] = ((ILfloat*)(Data))[i+1];
    01183                                                                 ((ILfloat*)(NewData))[j+2] = ((ILfloat*)(Data))[i];
    01184                                                         }
    01185                                                         break;
    01186                                                 case IL_DOUBLE:
    01187                                                         for (i = 0, j = 0; i < NumPix; i += 4, j += 3) {
    01188                                                                 ((ILdouble*)(NewData))[j] = ((ILdouble*)(Data))[i+2];
    01189                                                                 ((ILdouble*)(NewData))[j+1] = ((ILdouble*)(Data))[i+1];
    01190                                                                 ((ILdouble*)(NewData))[j+2] = ((ILdouble*)(Data))[i];
    01191                                                         }
    01192                                                         break;
    01193                                         }
    01194                                         break;
    01195
    01196                                 case IL_LUMINANCE:
    01197                                         NewData = (ILubyte*)ialloc(NumPix * BpcDest / 4);
    01198                                         CHECK_ALLOC();
    01199                                         Size = NumPix / 4;
    01200                                         switch (DestType)
    01201                                         {
    01202                                                 case IL_UNSIGNED_BYTE:
    01203                                                 case IL_BYTE:
    01204                                                         for (i = 0; i < Size; i++) {
    01205                                                                 Resultf = 0.0f;  j = 2;
    01206                                                                 for (c = 0; c < 3; c++, j--) {
    01207                                                                         Resultf += ((ILubyte*)(Data))[i * 4 + c] * LumFactor[j];
    01208                                                                 }
    01209                                                                 NewData[i] = (ILubyte)Resultf;
    01210                                                         }
    01211                                                         break;
    01212                                                 case IL_UNSIGNED_SHORT:
    01213                                                 case IL_SHORT:
    01214                                                 case IL_HALF:
    01215                                                         for (i = 0; i < Size; i++) {
    01216                                                                 Resultf = 0.0f;  j = 2;
    01217                                                                 for (c = 0; c < 3; c++, j--) {
    01218                                                                         Resultf += ((ILushort*)(Data))[i * 4 + c] * LumFactor[j];
    01219                                                                 }
    01220                                                                 ((ILushort*)(NewData))[i] = (ILushort)Resultf;
    01221                                                         }
    01222                                                         break;
    01223                                                 case IL_UNSIGNED_INT:
    01224                                                 case IL_INT:
    01225                                                         for (i = 0; i < Size; i++) {
    01226                                                                 Resultd = 0.0f;  j = 2;
    01227                                                                 for (c = 0; c < 3; c++, j--) {
    01228                                                                         Resultd += ((ILuint*)(Data))[i * 4 + c] * LumFactor[j];
    01229                                                                 }
    01230                                                                 ((ILuint*)(NewData))[i] = (ILuint)Resultd;
    01231                                                         }
    01232                                                         break;
    01233                                                 case IL_FLOAT:
    01234                                                         for (i = 0; i < Size; i++) {
    01235                                                                 Resultd = 0.0f;  j = 2;
    01236                                                                 for (c = 0; c < 3; c++, j--) {
    01237                                                                         Resultd += ((ILfloat*)(Data))[i * 4 + c] * LumFactor[j];
    01238                                                                 }
    01239                                                                 ((ILfloat*)(NewData))[i] = (ILfloat)Resultd;
    01240                                                         }
    01241                                                         break;
    01242                                                 case IL_DOUBLE:
    01243                                                         for (i = 0; i < Size; i++) {
    01244                                                                 Resultd = 0.0f;  j = 2;
    01245                                                                 for (c = 0; c < 3; c++, j--) {
    01246                                                                         Resultd += ((ILdouble*)(Data))[i * 4 + c] * LumFactor[j];
    01247                                                                 }
    01248                                                                 ((ILdouble*)(NewData))[i] = Resultd;
    01249                                                         }
    01250                                                         break;
    01251                                         }
    01252                                         break;
    01253
    01254                                 case IL_LUMINANCE_ALPHA:
    01255                                         NewData = (ILubyte*)ialloc(NumPix * BpcDest / 4 * 2);
    01256                                         CHECK_ALLOC();
    01257                                         Size = NumPix / 4 * 2;
    01258                                         switch (DestType)
    01259                                         {
    01260                                                 case IL_UNSIGNED_BYTE:
    01261                                                 case IL_BYTE:
    01262                                                         for (i = 0; i < Size; i += 2) {
    01263                                                                 Resultf = 0.0f;
    01264                                                                 for (c = 0; c < 3; c++) {
    01265                                                                         Resultf += ((ILubyte*)(Data))[i * 2 + c] * LumFactor[c];
    01266                                                                 }
    01267                                                                 NewData[i] = (ILubyte)Resultf;
    01268                                                                 NewData[i+1] = ((ILubyte*)(Data))[i * 2 + 3];
    01269                                                         }
    01270                                                         break;
    01271                                                 case IL_UNSIGNED_SHORT:
    01272                                                 case IL_SHORT:
    01273                                                 case IL_HALF:
    01274                                                         for (i = 0; i < Size; i += 2) {
    01275                                                                 Resultf = 0.0f;
    01276                                                                 for (c = 0; c < 3; c++) {
    01277                                                                         Resultf += ((ILushort*)(Data))[i * 2 + c] * LumFactor[c];
    01278                                                                 }
    01279                                                                 ((ILushort*)(NewData))[i] = (ILushort)Resultf;
    01280                                                                 ((ILushort*)(NewData))[i+1] = ((ILushort*)(Data))[i * 2 + 3];
    01281                                                         }
    01282                                                         break;
    01283                                                 case IL_UNSIGNED_INT:
    01284                                                 case IL_INT:
    01285                                                         for (i = 0; i < Size; i += 2) {
    01286                                                                 Resultd = 0.0;
    01287                                                                 for (c = 0; c < 3; c++) {
    01288                                                                         Resultd += ((ILuint*)(Data))[i * 2 + c] * LumFactor[c];
    01289                                                                 }
    01290                                                                 ((ILuint*)(NewData))[i] = (ILuint)Resultd;
    01291                                                                 ((ILuint*)(NewData))[i+1] = ((ILuint*)(Data))[i * 2 + 3];
    01292                                                         }
    01293                                                         break;
    01294                                                 case IL_FLOAT:
    01295                                                         for (i = 0; i < Size; i += 2) {
    01296                                                                 Resultd = 0.0;
    01297                                                                 for (c = 0; c < 3; c++) {
    01298                                                                         Resultd += ((ILfloat*)(Data))[i * 2 + c] * LumFactor[c];
    01299                                                                 }
    01300                                                                 ((ILfloat*)(NewData))[i] = (ILfloat)Resultd;
    01301                                                                 ((ILfloat*)(NewData))[i+1] = ((ILfloat*)(Data))[i * 2 + 3];
    01302                                                         }
    01303                                                         break;
    01304                                                 case IL_DOUBLE:
    01305                                                         for (i = 0; i < Size; i += 2) {
    01306                                                                 Resultd = 0.0;
    01307                                                                 for (c = 0; c < 3; c++) {
    01308                                                                         Resultd += ((ILdouble*)(Data))[i * 2 + c] * LumFactor[c];
    01309                                                                 }
    01310                                                                 ((ILdouble*)(NewData))[i] = Resultd;
    01311                                                                 ((ILdouble*)(NewData))[i+1] = ((ILdouble*)(Data))[i * 2 + 3];
    01312                                                         }
    01313                                                         break;
    01314                                         }
    01315                                         break;
    01316
    01317                                 case IL_ALPHA:
    01318                                         NewData = (ILubyte*)ialloc(NumPix * BpcDest / 4);
    01319                                         CHECK_ALLOC();
    01320                                         Size = NumPix / 4;
    01321                                         switch (DestType)
    01322                                         {
    01323                                                 case IL_UNSIGNED_BYTE:
    01324                                                 case IL_BYTE:
    01325                                                         for (i = 0; i < Size; i++) {
    01326                                                                 NewData[i] = ((ILubyte*)(Data))[i * 4 + 3];
    01327                                                         }
    01328                                                         break;
    01329                                                 case IL_UNSIGNED_SHORT:
    01330                                                 case IL_SHORT:
    01331                                                 case IL_HALF:
    01332                                                         for (i = 0; i < Size; i++) {
    01333                                                                 ((ILushort*)(NewData))[i] = ((ILushort*)(Data))[i * 4 + 3];
    01334                                                         }
    01335                                                         break;
    01336                                                 case IL_UNSIGNED_INT:
    01337                                                 case IL_INT:
    01338                                                         for (i = 0; i < Size; i++) {
    01339                                                                 ((ILuint*)(NewData))[i] = ((ILuint*)(Data))[i * 4 + 3];
    01340                                                         }
    01341                                                         break;
    01342                                                 case IL_FLOAT:
    01343                                                         for (i = 0; i < Size; i++) {
    01344                                                                 ((ILfloat*)(NewData))[i] = ((ILfloat*)(Data))[i * 4 + 3];
    01345                                                         }
    01346                                                         break;
    01347                                                 case IL_DOUBLE:
    01348                                                         for (i = 0; i < Size; i++) {
    01349                                                                 ((ILdouble*)(NewData))[i] = ((ILdouble*)(Data))[i * 4 + 3];
    01350                                                         }
    01351                                                         break;
    01352                                         }
    01353                                         break;
    01354
    01355                                 default:
    01356                                         ilSetError(IL_INVALID_CONVERSION);
    01357                                         if (Data != Buffer)
    01358                                                 ifree(Data);
    01359                                         return NULL;
    01360                         }
    01361                         break;
    01362
    01363
    01364                 case IL_LUMINANCE:
    01365                         switch (DestFormat)
    01366                         {
    01367                                 case IL_RGB:
    01368                                 case IL_BGR:
    01369                                         NewData = (ILubyte*)ialloc(NumPix * BpcDest * 3);
    01370                                         CHECK_ALLOC();
    01371
    01372                                         switch (DestType)
    01373                                         {
    01374                                                 case IL_UNSIGNED_BYTE:
    01375                                                 case IL_BYTE:
    01376                                                         for (i = 0, j = 0; i < NumPix; i++, j += 3) {
    01377                                                                 for (c = 0; c < 3; c++) {
    01378                                                                         NewData[j + c] = ((ILubyte*)(Data))[i];
    01379                                                                 }
    01380                                                         }
    01381                                                         break;
    01382                                                 case IL_UNSIGNED_SHORT:
    01383                                                 case IL_SHORT:
    01384                                                 case IL_HALF:
    01385                                                         for (i = 0, j = 0; i < NumPix; i++, j += 3) {
    01386                                                                 for (c = 0; c < 3; c++) {
    01387                                                                         ((ILushort*)(NewData))[j + c] = ((ILushort*)(Data))[i];
    01388                                                                 }
    01389                                                         }
    01390                                                         break;
    01391                                                 case IL_UNSIGNED_INT:
    01392                                                 case IL_INT:
    01393                                                         for (i = 0, j = 0; i < NumPix; i++, j += 3) {
    01394                                                                 for (c = 0; c < 3; c++) {
    01395                                                                         ((ILuint*)(NewData))[j + c] = ((ILuint*)(Data))[i];
    01396                                                                 }
    01397                                                         }
    01398                                                         break;
    01399                                                 case IL_FLOAT:
    01400                                                         for (i = 0, j = 0; i < NumPix; i++, j += 3) {
    01401                                                                 for (c = 0; c < 3; c++) {
    01402                                                                         ((ILfloat*)(NewData))[j + c] = ((ILfloat*)(Data))[i];
    01403                                                                 }
    01404                                                         }
    01405                                                         break;
    01406                                                 case IL_DOUBLE:
    01407                                                         for (i = 0, j = 0; i < NumPix; i++, j += 3) {
    01408                                                                 for (c = 0; c < 3; c++) {
    01409                                                                         ((ILdouble*)(NewData))[j + c] = ((ILdouble*)(Data))[i];
    01410                                                                 }
    01411                                                         }
    01412                                                         break;
    01413                                         }
    01414                                         break;
    01415
    01416                                 case IL_RGBA:
    01417                                 case IL_BGRA:
    01418                                         NewData = (ILubyte*)ialloc(NumPix * BpcDest * 4);
    01419                                         CHECK_ALLOC();
    01420
    01421                                         switch (DestType)
    01422                                         {
    01423                                                 case IL_UNSIGNED_BYTE:
    01424                                                 case IL_BYTE:
    01425                                                         for (i = 0, j = 0; i < NumPix; i++, j += 4) {
    01426                                                                 for (c = 0; c < 3; c++) {
    01427                                                                         NewData[j + c] = ((ILubyte*)(Data))[i];
    01428                                                                 }
    01429                                                                 NewData[j + 3] = UCHAR_MAX;  // Full opacity
    01430                                                         }
    01431                                                         break;
    01432                                                 case IL_UNSIGNED_SHORT:
    01433                                                 case IL_SHORT:
    01434                                                 case IL_HALF:
    01435                                                         for (i = 0, j = 0; i < NumPix; i++, j += 4) {
    01436                                                                 for (c = 0; c < 3; c++) {
    01437                                                                         ((ILushort*)(NewData))[j + c] = ((ILushort*)(Data))[i];
    01438                                                                 }
    01439                                                                 ((ILushort*)(NewData))[j + 3] = USHRT_MAX;  // Full opacity
    01440                                                         }
    01441                                                         break;
    01442                                                 case IL_UNSIGNED_INT:
    01443                                                 case IL_INT:
    01444                                                         for (i = 0, j = 0; i < NumPix; i++, j += 4) {
    01445                                                                 for (c = 0; c < 3; c++) {
    01446                                                                         ((ILuint*)(NewData))[j + c] = ((ILuint*)(Data))[i];
    01447                                                                 }
    01448                                                                 ((ILuint*)(NewData))[j + 3] = UINT_MAX;  // Full opacity
    01449                                                         }
    01450                                                         break;
    01451                                                 case IL_FLOAT:
    01452                                                         for (i = 0, j = 0; i < NumPix; i++, j += 4) {
    01453                                                                 for (c = 0; c < 3; c++) {
    01454                                                                         ((ILfloat*)(NewData))[j + c] = ((ILfloat*)(Data))[i];
    01455                                                                 }
    01456                                                                 ((ILfloat*)(NewData))[j + 3] = 1.0f;  // Full opacity
    01457                                                         }
    01458                                                         break;
    01459                                                 case IL_DOUBLE:
    01460                                                         for (i = 0, j = 0; i < NumPix; i++, j += 4) {
    01461                                                                 for (c = 0; c < 3; c++) {
    01462                                                                         ((ILdouble*)(NewData))[j + c] = ((ILdouble*)(Data))[i];
    01463                                                                 }
    01464                                                                 ((ILdouble*)(NewData))[j + 3] = 1.0;  // Full opacity
    01465                                                         }
    01466                                                         break;
    01467                                         }
    01468                                         break;
    01469
    01470                                 case IL_LUMINANCE_ALPHA:
    01471                                         NewData = (ILubyte*)ialloc(NumPix * BpcDest * 2);
    01472                                         CHECK_ALLOC();
    01473
    01474                                         switch (DestType)
    01475                                         {
    01476                                                 case IL_UNSIGNED_BYTE:
    01477                                                 case IL_BYTE:
    01478                                                         for (i = 0; i < NumPix; i++) {
    01479                                                                 NewData[i * 2] = ((ILubyte*)(Data))[i];
    01480                                                                 NewData[i * 2 + 1] = UCHAR_MAX;  // Full opacity
    01481                                                         }
    01482                                                         break;
    01483                                                 case IL_UNSIGNED_SHORT:
    01484                                                 case IL_SHORT:
    01485                                                 case IL_HALF:
    01486                                                         for (i = 0; i < NumPix; i++) {
    01487                                                                 ((ILushort*)(NewData))[i * 2] = ((ILushort*)(Data))[i];
    01488                                                                 ((ILushort*)(NewData))[i * 2 + 1] = USHRT_MAX;  // Full opacity
    01489                                                         }
    01490                                                         break;
    01491                                                 case IL_UNSIGNED_INT:
    01492                                                 case IL_INT:
    01493                                                         for (i = 0; i < NumPix; i++) {
    01494                                                                 ((ILuint*)(NewData))[i * 2] = ((ILuint*)(Data))[i];
    01495                                                                 ((ILuint*)(NewData))[i * 2 + 1] = UINT_MAX;  // Full opacity
    01496                                                         }
    01497                                                         break;
    01498                                                 case IL_FLOAT:
    01499                                                         for (i = 0; i < NumPix; i++) {
    01500                                                                 ((ILfloat*)(NewData))[i * 2] = ((ILfloat*)(Data))[i];
    01501                                                                 ((ILfloat*)(NewData))[i * 2 + 1] = 1.0f;  // Full opacity
    01502                                                         }
    01503                                                         break;
    01504                                                 case IL_DOUBLE:
    01505                                                         for (i = 0; i < NumPix; i++) {
    01506                                                                 ((ILdouble*)(NewData))[i * 2] = ((ILdouble*)(Data))[i];
    01507                                                                 ((ILdouble*)(NewData))[i * 2 + 1] = 1.0;  // Full opacity
    01508                                                         }
    01509                                                         break;
    01510                                         }
    01511                                         break;
    01512
    01513                                 case IL_ALPHA:
    01514                                         NewData = (ILubyte*)ialloc(NumPix * BpcDest);
    01515                                         CHECK_ALLOC();
    01516                                         memset(NewData, 0, NumPix * BpcDest);
    01517                                         break;
    01518
    01519                                 /*case IL_COLOUR_INDEX:
    01520                                         NewData = (ILubyte*)ialloc(iCurImage->SizeOfData);
    01521                                         NewImage->Pal.Palette = (ILubyte*)ialloc(768);
    01522                                         if (NewData == NULL || NewImage->Pal.Palette) {
    01523                                                 ifree(NewImage);
    01524                                                 return IL_FALSE;
    01525                                         }
    01526
    01527                                         // Fill the palette
    01528                                         for (i = 0; i < 256; i++) {
    01529                                                 for (c = 0; c < 3; c++) {
    01530                                                         NewImage->Pal.Palette[i * 3 + c] = (ILubyte)i;
    01531                                                 }
    01532                                         }
    01533                                         // Copy the data
    01534                                         for (i = 0; i < iCurImage->SizeOfData; i++) {
    01535                                                 NewData[i] = iCurImage->Data[i];
    01536                                         }
    01537                                         break;*/
    01538
    01539                                 default:
    01540                                         ilSetError(IL_INVALID_CONVERSION);
    01541                                         if (Data != Buffer)
    01542                                                 ifree(Data);
    01543                                         return NULL;
    01544                         }
    01545                         break;
    01546
    01547
    01548                 case IL_LUMINANCE_ALPHA:
    01549                         switch (DestFormat)
    01550                         {
    01551                                 case IL_RGB:
    01552                                 case IL_BGR:
    01553                                         NewData = (ILubyte*)ialloc(NumPix * BpcDest / 2 * 3);
    01554                                         CHECK_ALLOC();
    01555
    01556                                         switch (DestType)
    01557                                         {
    01558                                                 case IL_UNSIGNED_BYTE:
    01559                                                 case IL_BYTE:
    01560                                                         for (i = 0, j = 0; i < NumPix; i += 2, j += 3) {
    01561                                                                 for (c = 0; c < 3; c++) {
    01562                                                                         NewData[j + c] = ((ILubyte*)(Data))[i];
    01563                                                                 }
    01564                                                         }
    01565                                                         break;
    01566                                                 case IL_UNSIGNED_SHORT:
    01567                                                 case IL_SHORT:
    01568                                                 case IL_HALF:
    01569                                                         for (i = 0, j = 0; i < NumPix; i += 2, j += 3) {
    01570                                                                 for (c = 0; c < 3; c++) {
    01571                                                                         ((ILushort*)(NewData))[j + c] = ((ILushort*)(Data))[i];
    01572                                                                 }
    01573                                                         }
    01574                                                         break;
    01575                                                 case IL_UNSIGNED_INT:
    01576                                                 case IL_INT:
    01577                                                         for (i = 0, j = 0; i < NumPix; i += 2, j += 3) {
    01578                                                                 for (c = 0; c < 3; c++) {
    01579                                                                         ((ILuint*)(NewData))[j + c] = ((ILuint*)(Data))[i];
    01580                                                                 }
    01581                                                         }
    01582                                                         break;
    01583                                                 case IL_FLOAT:
    01584                                                         for (i = 0, j = 0; i < NumPix; i += 2, j += 3) {
    01585                                                                 for (c = 0; c < 3; c++) {
    01586                                                                         ((ILfloat*)(NewData))[j + c] = ((ILfloat*)(Data))[i];
    01587                                                                 }
    01588                                                         }
    01589                                                         break;
    01590                                                 case IL_DOUBLE:
    01591                                                         for (i = 0, j = 0; i < NumPix; i += 2, j += 3) {
    01592                                                                 for (c = 0; c < 3; c++) {
    01593                                                                         ((ILdouble*)(NewData))[j + c] = ((ILdouble*)(Data))[i];
    01594                                                                 }
    01595                                                         }
    01596                                                         break;
    01597                                         }
    01598                                         break;
    01599
    01600                                 case IL_RGBA:
    01601                                 case IL_BGRA:
    01602                                         NewData = (ILubyte*)ialloc(NumPix * BpcDest / 2 * 4);
    01603                                         CHECK_ALLOC();
    01604
    01605                                         switch (DestType)
    01606                                         {
    01607                                                 case IL_UNSIGNED_BYTE:
    01608                                                 case IL_BYTE:
    01609                                                         for (i = 0, j = 0; i < NumPix; i += 2, j += 4) {
    01610                                                                 for (c = 0; c < 3; c++) {
    01611                                                                         NewData[j + c] = ((ILubyte*)(Data))[i];
    01612                                                                 }
    01613                                                                 NewData[j + 3] = ((ILubyte*)(Data))[i+1];
    01614                                                         }
    01615                                                         break;
    01616                                                 case IL_UNSIGNED_SHORT:
    01617                                                 case IL_SHORT:
    01618                                                 case IL_HALF:
    01619                                                         for (i = 0, j = 0; i < NumPix; i += 2, j += 4) {
    01620                                                                 for (c = 0; c < 3; c++) {
    01621                                                                         ((ILushort*)(NewData))[j + c] = ((ILushort*)(Data))[i];
    01622                                                                 }
    01623                                                                 ((ILushort*)(NewData))[j + 3] = ((ILushort*)(Data))[i+1];
    01624                                                         }
    01625                                                         break;
    01626                                                 case IL_UNSIGNED_INT:
    01627                                                 case IL_INT:
    01628                                                         for (i = 0, j = 0; i < NumPix; i += 2, j += 4) {
    01629                                                                 for (c = 0; c < 3; c++) {
    01630                                                                         ((ILuint*)(NewData))[j + c] = ((ILuint*)(Data))[i];
    01631                                                                 }
    01632                                                                 ((ILuint*)(NewData))[j + 3] = ((ILuint*)(Data))[i+1];
    01633                                                         }
    01634                                                         break;
    01635                                                 case IL_FLOAT:
    01636                                                         for (i = 0, j = 0; i < NumPix; i += 2, j += 4) {
    01637                                                                 for (c = 0; c < 3; c++) {
    01638                                                                         ((ILfloat*)(NewData))[j + c] = ((ILfloat*)(Data))[i];
    01639                                                                 }
    01640                                                                 ((ILfloat*)(NewData))[j + 3] = ((ILfloat*)(Data))[i+1];
    01641                                                         }
    01642                                                         break;
    01643                                                 case IL_DOUBLE:
    01644                                                         for (i = 0, j = 0; i < NumPix; i += 2, j += 4) {
    01645                                                                 for (c = 0; c < 3; c++) {
    01646                                                                         ((ILdouble*)(NewData))[j + c] = ((ILdouble*)(Data))[i];
    01647                                                                 }
    01648                                                                 ((ILdouble*)(NewData))[j + 3] = ((ILdouble*)(Data))[i+1];
    01649                                                         }
    01650                                                         break;
    01651                                         }
    01652                                         break;
    01653
    01654                                 case IL_LUMINANCE:
    01655                                         NewData = (ILubyte*)ialloc(NumPix * BpcDest / 2);
    01656                                         CHECK_ALLOC();
    01657
    01658                                         switch (DestType)
    01659                                         {
    01660                                                 case IL_UNSIGNED_BYTE:
    01661                                                 case IL_BYTE:
    01662                                                         for (i = 0, j = 0; i < NumPix; i += 2, j++) {
    01663                                                                 NewData[j] = ((ILubyte*)(Data))[i];
    01664                                                         }
    01665                                                         break;
    01666                                                 case IL_UNSIGNED_SHORT:
    01667                                                 case IL_SHORT:
    01668                                                 case IL_HALF:
    01669                                                         for (i = 0, j = 0; i < NumPix; i += 2, j++) {
    01670                                                                 ((ILushort*)(NewData))[j] = ((ILushort*)(Data))[i];
    01671                                                         }
    01672                                                         break;
    01673                                                 case IL_UNSIGNED_INT:
    01674                                                 case IL_INT:
    01675                                                         for (i = 0, j = 0; i < NumPix; i += 2, j++) {
    01676                                                                 ((ILuint*)(NewData))[j] = ((ILuint*)(Data))[i];
    01677                                                         }
    01678                                                         break;
    01679                                                 case IL_FLOAT:
    01680                                                         for (i = 0, j = 0; i < NumPix; i += 2, j++) {
    01681                                                                 ((ILfloat*)(NewData))[j] = ((ILfloat*)(Data))[i];
    01682                                                         }
    01683                                                         break;
    01684                                                 case IL_DOUBLE:
    01685                                                         for (i = 0, j = 0; i < NumPix; i += 2, j++) {
    01686                                                                 ((ILdouble*)(NewData))[j] = ((ILdouble*)(Data))[i];
    01687                                                         }
    01688                                                         break;
    01689                                         }
    01690                                         break;
    01691
    01692                                 case IL_ALPHA:
    01693                                         NewData = (ILubyte*)ialloc(NumPix * BpcDest / 2);
    01694                                         CHECK_ALLOC();
    01695                                         Size = NumPix / 2;
    01696                                         switch (DestType)
    01697                                         {
    01698                                                 case IL_UNSIGNED_BYTE:
    01699                                                 case IL_BYTE:
    01700                                                         for (i = 0; i < Size; i++) {
    01701                                                                 NewData[i] = ((ILubyte*)(Data))[i * 2 + 3];
    01702                                                         }
    01703                                                         break;
    01704                                                 case IL_UNSIGNED_SHORT:
    01705                                                 case IL_SHORT:
    01706                                                 case IL_HALF:
    01707                                                         for (i = 0; i < Size; i++) {
    01708                                                                 ((ILushort*)(NewData))[i] = ((ILushort*)(Data))[i * 2 + 3];
    01709                                                         }
    01710                                                         break;
    01711                                                 case IL_UNSIGNED_INT:
    01712                                                 case IL_INT:
    01713                                                         for (i = 0; i < Size; i++) {
    01714                                                                 ((ILuint*)(NewData))[i] = ((ILuint*)(Data))[i * 2 + 3];
    01715                                                         }
    01716                                                         break;
    01717                                                 case IL_FLOAT:
    01718                                                         for (i = 0; i < Size; i++) {
    01719                                                                 ((ILfloat*)(NewData))[i] = ((ILfloat*)(Data))[i * 2 + 3];
    01720                                                         }
    01721                                                         break;
    01722                                                 case IL_DOUBLE:
    01723                                                         for (i = 0; i < Size; i++) {
    01724                                                                 ((ILdouble*)(NewData))[i] = ((ILdouble*)(Data))[i * 2 + 3];
    01725                                                         }
    01726                                                         break;
    01727                                         }
    01728                                         break;
    01729
    01730                                 /*case IL_COLOUR_INDEX:
    01731                                         NewData = (ILubyte*)ialloc(iCurImage->SizeOfData);
    01732                                         NewImage->Pal.Palette = (ILubyte*)ialloc(768);
    01733                                         if (NewData == NULL || NewImage->Pal.Palette) {
    01734                                                 ifree(NewImage);
    01735                                                 return IL_FALSE;
    01736                                         }
    01737
    01738                                         // Fill the palette
    01739                                         for (i = 0; i < 256; i++) {
    01740                                                 for (c = 0; c < 3; c++) {
    01741                                                         NewImage->Pal.Palette[i * 3 + c] = (ILubyte)i;
    01742                                                 }
    01743                                         }
    01744                                         // Copy the data
    01745                                         for (i = 0; i < iCurImage->SizeOfData; i++) {
    01746                                                 NewData[i] = iCurImage->Data[i];
    01747                                         }
    01748                                         break;*/
    01749
    01750                                 default:
    01751                                         ilSetError(IL_INVALID_CONVERSION);
    01752                                         if (Data != Buffer)
    01753                                                 ifree(Data);
    01754                                         return NULL;
    01755                         }
    01756                         break;
    01757
    01758
    01759                 case IL_ALPHA:
    01760                         switch (DestFormat)
    01761                         {
    01762                                 case IL_RGB:
    01763                                 case IL_BGR:
    01764                                         NewData = (ILubyte*)ialloc(NumPix * BpcDest * 3);
    01765                                         CHECK_ALLOC();
    01766
    01767                                         switch (DestType)
    01768                                         {
    01769                                                 case IL_UNSIGNED_BYTE:
    01770                                                 case IL_BYTE:
    01771                                                 case IL_UNSIGNED_SHORT:
    01772                                                 case IL_SHORT:
    01773                                                 case IL_HALF:
    01774                                                 case IL_UNSIGNED_INT:
    01775                                                 case IL_INT:
    01776                                                 case IL_FLOAT:
    01777                                                 case IL_DOUBLE:
    01778                                                         memset(NewData, 0, NumPix * BpcDest * 3);  // Easy enough
    01779                                                         break;
    01780                                                 //@TODO: Do we need to a check for default: (error)?
    01781                                         }
    01782                                         break;
    01783
    01784                                 case IL_RGBA:
    01785                                 case IL_BGRA:
    01786                                         NewData = (ILubyte*)ialloc(NumPix * BpcDest * 4);
    01787                                         CHECK_ALLOC();
    01788
    01789                                         switch (DestType)
    01790                                         {
    01791                                                 case IL_UNSIGNED_BYTE:
    01792                                                 case IL_BYTE:
    01793                                                         for (i = 0, j = 0; i < NumPix; i++, j += 4) {
    01794                                                                 for (c = 0; c < 3; c++) {
    01795                                                                         NewData[j + c] = 0;
    01796                                                                 }
    01797                                                                 NewData[j + 3] = ((ILubyte*)(Data))[i];  // Only value that matters
    01798                                                         }
    01799                                                         break;
    01800                                                 case IL_UNSIGNED_SHORT:
    01801                                                 case IL_SHORT:
    01802                                                 case IL_HALF:
    01803                                                         for (i = 0, j = 0; i < NumPix; i++, j += 4) {
    01804                                                                 for (c = 0; c < 3; c++) {
    01805                                                                         ((ILushort*)(NewData))[j + c] = 0;
    01806                                                                 }
    01807                                                                 ((ILushort*)(NewData))[j + 3] = ((ILushort*)(Data))[i];
    01808                                                         }
    01809                                                         break;
    01810                                                 case IL_UNSIGNED_INT:
    01811                                                 case IL_INT:
    01812                                                         for (i = 0, j = 0; i < NumPix; i++, j += 4) {
    01813                                                                 for (c = 0; c < 3; c++) {
    01814                                                                         ((ILuint*)(NewData))[j + c] = 0;
    01815                                                                 }
    01816                                                                 ((ILuint*)(NewData))[j + 3] = ((ILuint*)(Data))[i];
    01817                                                         }
    01818                                                         break;
    01819                                                 case IL_FLOAT:
    01820                                                         for (i = 0, j = 0; i < NumPix; i++, j += 4) {
    01821                                                                 for (c = 0; c < 3; c++) {
    01822                                                                         ((ILfloat*)(NewData))[j + c] = 0;
    01823                                                                 }
    01824                                                                 ((ILfloat*)(NewData))[j + 3] = ((ILfloat*)(Data))[i];
    01825                                                         }
    01826                                                         break;
    01827                                                 case IL_DOUBLE:
    01828                                                         for (i = 0, j = 0; i < NumPix; i++, j += 4) {
    01829                                                                 for (c = 0; c < 3; c++) {
    01830                                                                         ((ILdouble*)(NewData))[j + c] = 0;
    01831                                                                 }
    01832                                                                 ((ILdouble*)(NewData))[j + 3] = ((ILdouble*)(Data))[i];
    01833                                                         }
    01834                                                         break;
    01835                                         }
    01836                                         break;
    01837
    01838                                 case IL_LUMINANCE_ALPHA:
    01839                                         NewData = (ILubyte*)ialloc(NumPix * BpcDest * 2);
    01840                                         CHECK_ALLOC();
    01841
    01842                                         switch (DestType)
    01843                                         {
    01844                                                 case IL_UNSIGNED_BYTE:
    01845                                                 case IL_BYTE:
    01846                                                         for (i = 0; i < NumPix; i++) {
    01847                                                                 NewData[i * 2] = 0;
    01848                                                                 NewData[i * 2 + 1] = ((ILubyte*)(Data))[i];
    01849                                                         }
    01850                                                         break;
    01851                                                 case IL_UNSIGNED_SHORT:
    01852                                                 case IL_SHORT:
    01853                                                 case IL_HALF:
    01854                                                         for (i = 0; i < NumPix; i++) {
    01855                                                                 ((ILushort*)(NewData))[i * 2] = 0;
    01856                                                                 ((ILushort*)(NewData))[i * 2 + 1] = ((ILushort*)(Data))[i];
    01857                                                         }
    01858                                                         break;
    01859                                                 case IL_UNSIGNED_INT:
    01860                                                 case IL_INT:
    01861                                                         for (i = 0; i < NumPix; i++) {
    01862                                                                 ((ILuint*)(NewData))[i * 2] = 0;
    01863                                                                 ((ILuint*)(NewData))[i * 2 + 1] = ((ILuint*)(Data))[i];
    01864                                                         }
    01865                                                         break;
    01866                                                 case IL_FLOAT:
    01867                                                         for (i = 0; i < NumPix; i++) {
    01868                                                                 ((ILfloat*)(NewData))[i * 2] = 0;
    01869                                                                 ((ILfloat*)(NewData))[i * 2 + 1] = ((ILfloat*)(Data))[i];
    01870                                                         }
    01871                                                         break;
    01872                                                 case IL_DOUBLE:
    01873                                                         for (i = 0; i < NumPix; i++) {
    01874                                                                 ((ILdouble*)(NewData))[i * 2] = 0;
    01875                                                                 ((ILdouble*)(NewData))[i * 2 + 1] = ((ILdouble*)(Data))[i];
    01876                                                         }
    01877                                                         break;
    01878                                         }
    01879                                         break;
    01880
    01881
    01882                                 /*case IL_COLOUR_INDEX:
    01883                                         NewData = (ILubyte*)ialloc(iCurImage->SizeOfData);
    01884                                         NewImage->Pal.Palette = (ILubyte*)ialloc(768);
    01885                                         if (NewData == NULL || NewImage->Pal.Palette) {
    01886                                                 ifree(NewImage);
    01887                                                 return IL_FALSE;
    01888                                         }
    01889
    01890                                         // Fill the palette
    01891                                         for (i = 0; i < 256; i++) {
    01892                                                 for (c = 0; c < 3; c++) {
    01893                                                         NewImage->Pal.Palette[i * 3 + c] = (ILubyte)i;
    01894                                                 }
    01895                                         }
    01896                                         // Copy the data
    01897                                         for (i = 0; i < iCurImage->SizeOfData; i++) {
    01898                                                 NewData[i] = iCurImage->Data[i];
    01899                                         }
    01900                                         break;*/
    01901
    01902                                 default:
    01903                                         ilSetError(IL_INVALID_CONVERSION);
    01904                                         if (Data != Buffer)
    01905                                                 ifree(Data);
    01906                                         return NULL;
    01907                         }
    01908                         break;
    01909         }
    01910
    01911         if (Data != Buffer)
    01912                 ifree(Data);
    01913
    01914         return NewData;
    01915 }
    01916
    01917
    01918 // Really shouldn't have to check for default, as in above ilConvertBuffer().
    01919 //  This now converts better from lower bpp to higher bpp.  For example, when
    01920 //  converting from 8 bpp to 16 bpp, if the value is 0xEC, the new value is 0xECEC.
    01921 void* ILAPIENTRY iSwitchTypes(ILuint SizeOfData, ILenum SrcType, ILenum DestType, void *Buffer)
    01922 {
    01923         ILuint          BpcSrc, BpcDest, Size, i;
    01924         ILubyte         *NewData, *BytePtr;
    01925         ILushort        *ShortPtr;
    01926         ILuint          *IntPtr;
    01927         ILfloat         *FloatPtr, tempFloat;
    01928         ILdouble        *DblPtr, tempDouble;
    01929         ILushort        *HalfPtr;
    01930
    01931         BpcSrc = ilGetBpcType(SrcType);
    01932         BpcDest = ilGetBpcType(DestType);
    01933
    01934         if (BpcSrc == 0 || BpcDest == 0) {
    01935                 ilSetError(IL_INTERNAL_ERROR);
    01936                 return IL_FALSE;
    01937         }
    01938
    01939         Size = SizeOfData / BpcSrc;
    01940
    01941         if (BpcSrc == BpcDest) {
    01942                 return Buffer;
    01943         }
    01944
    01945         NewData = (ILubyte*)ialloc(Size * BpcDest);
    01946         if (NewData == NULL) {
    01947                 return IL_FALSE;
    01948         }
    01949
    01950         switch (DestType)
    01951         {
    01952                 case IL_UNSIGNED_BYTE:
    01953                 case IL_BYTE:
    01954                         BytePtr = (ILubyte*)NewData;
    01955                         switch (SrcType)
    01956                         {
    01957                                 case IL_UNSIGNED_SHORT:
    01958                                 case IL_SHORT:
    01959                                         for (i = 0; i < Size; i++) {
    01960                                                 BytePtr[i] = ((ILushort*)Buffer)[i] >> 8;
    01961                                         }
    01962                                         break;
    01963                                 case IL_UNSIGNED_INT:
    01964                                 case IL_INT:
    01965                                         for (i = 0; i < Size; i++) {
    01966                                                 BytePtr[i] = ((ILuint*)Buffer)[i] >> 24;
    01967                                         }
    01968                                         break;
    01969                                 case IL_FLOAT:
    01970                                         for (i = 0; i < Size; i++) {
    01971                                                 #if CLAMP_FLOATS
    01972                                                         tempFloat = IL_CLAMP(((ILfloat*)Buffer)[i]);
    01973                                                         BytePtr[i] = (ILubyte)(tempFloat * UCHAR_MAX);
    01974                                                 #else
    01975                                                         BytePtr[i] = (ILubyte)(((ILfloat*)Buffer)[i] * UCHAR_MAX);
    01976                                                 #endif
    01977                                         }
    01978                                         break;
    01979                                 case IL_HALF:
    01980                                         for (i = 0; i < Size; i++) {
    01981                                                 #if CLAMP_HALF
    01982                                                         *((ILuint*)&tempFloat) = ilHalfToFloat(((ILushort*)Buffer)[i]);
    01983                                                         tempFloat = IL_CLAMP(tempFloat);
    01984                                                         BytePtr[i] = (ILubyte)(tempFloat * UCHAR_MAX);
    01985                                                 #else
    01986                                                         *((ILuint*)&tempFloat) = ilHalfToFloat(((ILushort*)Buffer)[i]);
    01987                                                         BytePtr[i] = (ILubyte)(tempFloat * UCHAR_MAX);
    01988                                                 #endif
    01989                                         }
    01990                                         break;
    01991                                 case IL_DOUBLE:
    01992                                         for (i = 0; i < Size; i++) {
    01993                                                 #if CLAMP_DOUBLES
    01994                                                         tempDouble = IL_CLAMP(((ILdouble*)Buffer)[i]);
    01995                                                         BytePtr[i] = (ILubyte)(tempDouble * UCHAR_MAX);
    01996                                                 #else
    01997                                                         BytePtr[i] = (ILubyte)( ((ILdouble*)Buffer)[i] * UCHAR_MAX);
    01998                                                 #endif
    01999                                         }
    02000                                         break;
    02001                         }
    02002                         break;
    02003
    02004                 case IL_UNSIGNED_SHORT:
    02005                 case IL_SHORT:
    02006                         ShortPtr = (ILushort*)NewData;
    02007                         switch (SrcType)
    02008                         {
    02009                                 case IL_UNSIGNED_BYTE:
    02010                                 case IL_BYTE:
    02011                                         for (i = 0; i < Size; i++) {
    02012                                                 ShortPtr[i] = (((ILubyte*)Buffer)[i] << 8) | ((ILubyte*)Buffer)[i];
    02013                                         }
    02014                                         break;
    02015                                 case IL_UNSIGNED_INT:
    02016                                 case IL_INT:
    02017                                         for (i = 0; i < Size; i++) {
    02018                                                 ShortPtr[i] = ((ILuint*)Buffer)[i] >> 16;
    02019                                         }
    02020                                         break;
    02021                                 case IL_FLOAT:
    02022                                         for (i = 0; i < Size; i++) {
    02023                                                 #if CLAMP_FLOATS
    02024                                                         tempFloat = IL_CLAMP(((ILfloat*)Buffer)[i]);
    02025                                                         ShortPtr[i] = (ILushort)(tempFloat * USHRT_MAX);
    02026                                                 #else
    02027                                                         ShortPtr[i] = (ILushort)( ((ILfloat*)Buffer)[i] * USHRT_MAX);
    02028                                                 #endif
    02029                                         }
    02030                                         break;
    02031                                 case IL_HALF:
    02032                                         for (i = 0; i < Size; i++) {
    02033                                                 #if CLAMP_FLOATS
    02034                                                         *((ILuint*)&tempFloat) = ilHalfToFloat(((ILushort*)Buffer)[i]);
    02035                                                         tempFloat = IL_CLAMP(tempFloat);
    02036                                                         ShortPtr[i] = (ILushort)(tempFloat * USHRT_MAX);
    02037                                                 #else
    02038                                                         *((ILuint*)&tempFloat) = ilHalfToFloat(((ILushort*)Buffer)[i]);
    02039                                                         ShortPtr[i] = (ILushort)(tempFloat * USHRT_MAX);
    02040                                                 #endif
    02041                                         }
    02042                                         break;
    02043                                 case IL_DOUBLE:
    02044                                         for (i = 0; i < Size; i++) {
    02045                                                 #if CLAMP_DOUBLES
    02046                                                         tempDouble = IL_CLAMP(((ILdouble*)Buffer)[i]);
    02047                                                         ShortPtr[i] = (ILushort)(tempDouble * USHRT_MAX);
    02048                                                 #else
    02049                                                         ShortPtr[i] = (ILushort)( ((ILdouble*)Buffer)[i] * USHRT_MAX);
    02050                                                 #endif
    02051                                         }
    02052                                         break;
    02053                         }
    02054                         break;
    02055
    02056                 case IL_UNSIGNED_INT:
    02057                 case IL_INT:
    02058                         IntPtr = (ILuint*)NewData;
    02059                         switch (SrcType)
    02060                         {
    02061                                 case IL_UNSIGNED_BYTE:
    02062                                 case IL_BYTE:
    02063                                         for (i = 0; i < Size; i++) {
    02064                                                 IntPtr[i] = (((ILubyte*)Buffer)[i] << 24) | (((ILubyte*)Buffer)[i] << 16) |
    02065                                                         (((ILubyte*)Buffer)[i] << 8) | ((ILubyte*)Buffer)[i];
    02066                                         }
    02067                                         break;
    02068                                 case IL_UNSIGNED_SHORT:
    02069                                 case IL_SHORT:
    02070                                         for (i = 0; i < Size; i++) {
    02071                                                 IntPtr[i] = (((ILushort*)Buffer)[i] << 16) | ((ILushort*)Buffer)[i];
    02072                                         }
    02073                                         break;
    02074                                 case IL_FLOAT:
    02075                                         for (i = 0; i < Size; i++) {
    02076                                                 #if CLAMP_FLOATS
    02077                                                         tempFloat = IL_CLAMP(((ILfloat*)Buffer)[i]);
    02078                                                         IntPtr[i] = (ILuint)(tempFloat * UINT_MAX);
    02079                                                 #else
    02080                                                         IntPtr[i] = (ILuint)( ((ILfloat*)Buffer)[i] * UINT_MAX);
    02081                                                 #endif
    02082                                         }
    02083                                         break;
    02084                                 case IL_HALF:
    02085                                         for (i = 0; i < Size; i++) {
    02086                                                 #if CLAMP_FLOATS
    02087                                                         *((ILuint*)&tempFloat) = ilHalfToFloat(((ILushort*)Buffer)[i]);
    02088                                                         tempFloat = IL_CLAMP(tempFloat);
    02089                                                         IntPtr[i] = (ILuint)(tempFloat * UINT_MAX);
    02090                                                 #else
    02091                                                 *((ILuint*)&tempFloat) = ilHalfToFloat(((ILushort*)Buffer)[i]);
    02092                                                 IntPtr[i] = (ILuint)(tempFloat * UINT_MAX);
    02093                                                 #endif
    02094                                         }
    02095                                         break;
    02096                                 case IL_DOUBLE:
    02097                                         for (i = 0; i < Size; i++) {
    02098                                                 #if CLAMP_DOUBLES
    02099                                                         tempDouble = IL_CLAMP(((ILdouble*)Buffer)[i]);
    02100                                                         IntPtr[i] = (ILuint)(tempDouble * UINT_MAX);
    02101                                                 #else
    02102                                                         IntPtr[i] = (ILuint)( ((ILdouble*)Buffer)[i] * UINT_MAX);
    02103                                                 #endif
    02104                                         }
    02105                                         break;
    02106                         }
    02107                         break;
    02108
    02109                 // @TODO:  Handle signed better.
    02110                 case IL_FLOAT:
    02111                         FloatPtr = (ILfloat*)NewData;
    02112                         switch (SrcType)
    02113                         {
    02114                                 case IL_UNSIGNED_BYTE:
    02115                                         for (i = 0; i < Size; i++) {
    02116                                                 FloatPtr[i] = ((ILubyte*)Buffer)[i] / (ILfloat)UCHAR_MAX;
    02117                                         }
    02118                                         break;
    02119                                 case IL_BYTE:
    02120                                         for (i = 0; i < Size; i++) {
    02121                                                 FloatPtr[i] = ((ILbyte*)Buffer)[i] / (ILfloat)UCHAR_MAX;
    02122                                         }
    02123                                         break;
    02124                                 case IL_UNSIGNED_SHORT:
    02125                                         for (i = 0; i < Size; i++) {
    02126                                                 FloatPtr[i] = ((ILushort*)Buffer)[i] / (ILfloat)USHRT_MAX;
    02127                                         }
    02128                                         break;
    02129                                 case IL_SHORT:
    02130                                         for (i = 0; i < Size; i++) {
    02131                                                 FloatPtr[i] = ((ILshort*)Buffer)[i] / (ILfloat)USHRT_MAX;
    02132                                         }
    02133                                         break;
    02134                                 case IL_UNSIGNED_INT:
    02135                                         for (i = 0; i < Size; i++) {
    02136                                                 FloatPtr[i] = (ILfloat)((ILuint*)Buffer)[i] / (ILfloat)UINT_MAX;
    02137                                         }
    02138                                         break;
    02139                                 case IL_INT:
    02140                                         for (i = 0; i < Size; i++) {
    02141                                                 FloatPtr[i] = (ILfloat)((ILint*)Buffer)[i] / (ILfloat)UINT_MAX;
    02142                                         }
    02143                                         break;
    02144                                 case IL_HALF:
    02145                                         for (i = 0; i < Size; i++) {
    02146                                                 *((ILuint*)&FloatPtr[i]) = ilHalfToFloat(((ILushort*)Buffer)[i]);
    02147                                         }
    02148                                 case IL_DOUBLE:
    02149                                         for (i = 0; i < Size; i++) {
    02150                                                 FloatPtr[i] = (ILfloat)((ILdouble*)Buffer)[i];
    02151                                         }
    02152                                         break;
    02153                         }
    02154                         break;
    02155
    02156                 case IL_DOUBLE:
    02157                         DblPtr = (ILdouble*)NewData;
    02158                         switch (SrcType)
    02159                         {
    02160                                 case IL_UNSIGNED_BYTE:
    02161                                         for (i = 0; i < Size; i++) {
    02162                                                 DblPtr[i] = ((ILubyte*)Buffer)[i] / (ILdouble)UCHAR_MAX;
    02163                                         }
    02164                                         break;
    02165                                 case IL_BYTE:
    02166                                         for (i = 0; i < Size; i++) {
    02167                                                 DblPtr[i] = ((ILbyte*)Buffer)[i] / (ILdouble)UCHAR_MAX;
    02168                                         }
    02169                                         break;
    02170                                 case IL_UNSIGNED_SHORT:
    02171                                         for (i = 0; i < Size; i++) {
    02172                                                 DblPtr[i] = ((ILushort*)Buffer)[i] / (ILdouble)USHRT_MAX;
    02173                                         }
    02174                                         break;
    02175                                 case IL_SHORT:
    02176                                         for (i = 0; i < Size; i++) {
    02177                                                 DblPtr[i] = ((ILshort*)Buffer)[i] / (ILdouble)USHRT_MAX;
    02178                                         }
    02179                                         break;
    02180                                 case IL_UNSIGNED_INT:
    02181                                         for (i = 0; i < Size; i++) {
    02182                                                 DblPtr[i] = ((ILuint*)Buffer)[i] / (ILdouble)UINT_MAX;
    02183                                         }
    02184                                         break;
    02185                                 case IL_INT:
    02186                                         for (i = 0; i < Size; i++) {
    02187                                                 DblPtr[i] = ((ILint*)Buffer)[i] / (ILdouble)UINT_MAX;
    02188                                         }
    02189                                         break;
    02190                                 case IL_HALF:
    02191                                         for (i = 0; i < Size; i++) {
    02192                                                 *(ILushort*)&tempFloat = ilHalfToFloat(((ILushort*)Buffer)[i]);
    02193                                                 DblPtr[i] = tempFloat;
    02194                                         }
    02195                                 case IL_FLOAT:
    02196                                         for (i = 0; i < Size; i++) {
    02197                                                 DblPtr[i] = ((ILfloat*)Buffer)[i];
    02198                                         }
    02199                                         break;
    02200                         }
    02201                         break;
    02202
    02203                 case IL_HALF:
    02204                         HalfPtr = (ILushort*)NewData;
    02205                         switch (SrcType)
    02206                         {
    02207                         case IL_UNSIGNED_BYTE:
    02208                                 for (i = 0; i < Size; i++) {
    02209                                         tempFloat = ((ILubyte*)Buffer)[i] / (ILfloat)UCHAR_MAX;
    02210                                         *((ILushort*)&HalfPtr[i]) = ilFloatToHalf(*(ILuint*)&tempFloat);
    02211                                 }
    02212                                 break;
    02213                         case IL_BYTE:
    02214                                 for (i = 0; i < Size; i++) {
    02215                                         tempFloat = ((ILbyte*)Buffer)[i] / (ILfloat)UCHAR_MAX;
    02216                                         *((ILushort*)&HalfPtr[i]) = ilFloatToHalf(*(ILuint*)&tempFloat);
    02217                                 }
    02218                                 break;
    02219                         case IL_UNSIGNED_SHORT:
    02220                                 for (i = 0; i < Size; i++) {
    02221                                         tempFloat = ((ILushort*)Buffer)[i] / (ILfloat)USHRT_MAX;
    02222                                         *((ILushort*)&HalfPtr[i]) = ilFloatToHalf(*(ILuint*)&tempFloat);
    02223                                 }
    02224                                 break;
    02225                         case IL_SHORT:
    02226                                 for (i = 0; i < Size; i++) {
    02227                                         tempFloat = ((ILshort*)Buffer)[i] / (ILfloat)USHRT_MAX;
    02228                                         *((ILushort*)&HalfPtr[i]) = ilFloatToHalf(*(ILuint*)&tempFloat);
    02229                                 }
    02230                                 break;
    02231                         case IL_UNSIGNED_INT:
    02232                                 for (i = 0; i < Size; i++) {
    02233                                         tempFloat = ((ILuint*)Buffer)[i] / (ILfloat)UINT_MAX;
    02234                                         *((ILushort*)&HalfPtr[i]) = ilFloatToHalf(*(ILuint*)&tempFloat);
    02235                                 }
    02236                                 break;
    02237                         case IL_INT:
    02238                                 for (i = 0; i < Size; i++) {
    02239                                         tempFloat = ((ILint*)Buffer)[i] / (ILfloat)UINT_MAX;
    02240                                         *((ILushort*)&HalfPtr[i]) = ilFloatToHalf(*(ILuint*)&tempFloat);
    02241                                 }
    02242                                 break;
    02243                         case IL_DOUBLE:
    02244                                 for (i = 0; i < Size; i++) {
    02245                                         tempFloat = (ILfloat)((ILdouble*)Buffer)[i];
    02246                                         *((ILushort*)&HalfPtr[i]) = ilFloatToHalf(*(ILuint*)&tempFloat);
    02247                                 }
    02248                         case IL_FLOAT:
    02249                                 for (i = 0; i < Size; i++) {
    02250                                         tempFloat = ((ILfloat*)Buffer)[i];
    02251                                         *((ILushort*)&HalfPtr[i]) = ilFloatToHalf(*(ILuint*)&tempFloat);
    02252                                 }
    02253                                 break;
    02254                         }
    02255                         break;
    02256         }
    02257
    02258
    02259         return NewData;
    02260 }
    02261
    02262
    02263
    02264