- Main Page
- Data Structures
- Files

- File List

# E:/DevIL/src-ILUT/src/ilut_allegro.c

    00001 //-----------------------------------------------------------------------------
    00002 //
    00003 // ImageLib Sources
    00004 // Copyright (C) 2000 by Denton Woods
    00005 // Last modified: 11/23/2000 <--Y2K Compliant! =]
    00006 //
    00007 // Filename: openilut/allegro.c
    00008 //
    00009 // Description:  Allegro functions for images
    00010 //
    00011 //-----------------------------------------------------------------------------
    00012
    00013 #ifdef HAVE_CONFIG_H
    00014 #include "config.h"
    00015 #endif //HAVE_CONFIG_H
    00016
    00017 #ifdef ILUT_USE_ALLEGRO
    00018 #include "ilut_allegro.h"
    00019 #endif
    00020
    00021 #include "ilut_internal.h"
    00022
    00023 #ifdef ILUT_USE_ALLEGRO
    00024
    00025 ILboolean ilConvertPal(ILenum DestFormat);
    00026
    00027 // Does not account for converting luminance...
    00028 BITMAP* ILAPIENTRY ilutConvertToAlleg(PALETTE Pal)
    00029 {
    00030         BITMAP *Bitmap;
    00031         ILimage *TempImage;
    00032         ILuint i = 0, j = 0;
    00033
    00034         ilutCurImage = ilGetCurImage();
    00035
    00036         if (ilutCurImage == NULL) {
    00037                 ilSetError(ILUT_ILLEGAL_OPERATION);
    00038                 return NULL;
    00039         }
    00040
    00041         // Should be IL_BGR(A), but Djgpp screws up somewhere along the line.
    00042         if (ilutCurImage->Format == IL_RGB || ilutCurImage->Format == IL_RGBA) {
    00043                 iluSwapColours();
    00044         }
    00045
    00046         if (ilutCurImage->Origin == IL_ORIGIN_LOWER_LEFT)
    00047                 iluFlipImage();
    00048         if (ilutCurImage->Type > IL_UNSIGNED_BYTE) {}  // Can't do anything about this right now...
    00049         if (ilutCurImage->Type == IL_BYTE) {}  // Can't do anything about this right now...
    00050
    00051         Bitmap = create_bitmap_ex(ilutCurImage->Bpp * 8, ilutCurImage->Width, ilutCurImage->Height);
    00052         if (Bitmap == NULL) {
    00053                 return IL_FALSE;
    00054         }
    00055         memcpy(Bitmap->dat, ilutCurImage->Data, ilutCurImage->SizeOfData);
    00056
    00057         // Should we make this toggleable?
    00058         if (ilutCurImage->Bpp == 8 && ilutCurImage->Pal.PalType != IL_PAL_NONE) {
    00059                 // Use the image's palette if there is one
    00060
    00061                 // ilConvertPal is destructive to the original image
    00062                 // @TODO:  Use new ilCopyPal!!!
    00063                 TempImage = ilNewImage(ilutCurImage->Width, ilutCurImage->Height, ilutCurImage->Depth, ilutCurImage->Bpp, 1);
    00064                 ilCopyImageAttr(TempImage, ilutCurImage);
    00065                 ilSetCurImage(TempImage);
    00066
    00067                 if (!ilConvertPal(IL_PAL_RGB24)) {
    00068                         destroy_bitmap(Bitmap);
    00069                         ilSetError(ILUT_ILLEGAL_OPERATION);
    00070                         return NULL;
    00071                 }
    00072
    00073                 for (; i < ilutCurImage->Pal.PalSize && i < 768; i += 3, j++) {
    00074                         Pal[j].r = TempImage->Pal.Palette[i+0];
    00075                         Pal[j].g = TempImage->Pal.Palette[i+1];
    00076                         Pal[j].b = TempImage->Pal.Palette[i+2];
    00077                         Pal[j].filler = 255;
    00078                 }
    00079
    00080                 ilCloseImage(TempImage);
    00081                 ilSetCurImage(ilutCurImage);
    00082         }
    00083
    00084         return Bitmap;
    00085 }
    00086
    00087
    00088 #ifndef _WIN32_WCE
    00089 BITMAP* ILAPIENTRY ilutAllegLoadImage(ILstring FileName)
    00090 {
    00091         ILuint  ImgId;
    00092         PALETTE Pal;
    00093
    00094         ilGenImages(1, &ImgId);
    00095         ilBindImage(ImgId);
    00096         if (!ilLoadImage(FileName)) {
    00097                 ilDeleteImages(1, &ImgId);
    00098                 return 0;
    00099         }
    00100
    00101         ilDeleteImages(1, &ImgId);
    00102
    00103         return ilutConvertToAlleg(Pal);
    00104 }
    00105 #endif//_WIN32_WCE
    00106
    00107
    00108 // Unfinished
    00109 ILboolean ILAPIENTRY ilutAllegFromBitmap(BITMAP *Bitmap)
    00110 {
    00111         ilutCurImage = ilGetCurImage();
    00112         if (ilutCurImage == NULL) {
    00113                 ilSetError(ILUT_ILLEGAL_OPERATION);
    00114                 return IL_FALSE;
    00115         }
    00116
    00117         if (Bitmap == NULL || Bitmap->w == 0 || Bitmap->h == 0) {
    00118                 ilSetError(ILUT_INVALID_PARAM);
    00119                 return IL_FALSE;
    00120         }
    00121
    00122         if (!ilTexImage(Bitmap->w, Bitmap->h, 1, 3, IL_RGB, IL_UNSIGNED_BYTE, NULL))
    00123                 return IL_FALSE;
    00124
    00125         ilutCurImage->Origin = IL_ORIGIN_LOWER_LEFT;  // I have no idea.
    00126
    00127         return IL_TRUE;
    00128 }
    00129
    00130 #endif//ILUT_USE_ALLEGRO
    00131