Generates a C-style header file for the current image.
| 19 | |
| 20 | //! Generates a C-style header file for the current image. |
| 21 | ILboolean ilSaveCHeader(ILconst_string FileName, char *InternalName) |
| 22 | { |
| 23 | FILE *HeadFile; |
| 24 | ILuint i = 0, j; |
| 25 | ILimage *TempImage; |
| 26 | const char *Name; |
| 27 | |
| 28 | if (iCurImage == NULL) { |
| 29 | ilSetError(IL_ILLEGAL_OPERATION); |
| 30 | return IL_FALSE; |
| 31 | } |
| 32 | |
| 33 | Name = iGetString(IL_CHEAD_HEADER_STRING); |
| 34 | if (Name == NULL) |
| 35 | Name = InternalName; |
| 36 | |
| 37 | if (FileName == NULL || Name == NULL || |
| 38 | ilStrLen(FileName) < 1 || ilCharStrLen(Name) < 1) { |
| 39 | ilSetError(IL_INVALID_VALUE); |
| 40 | return IL_FALSE; |
| 41 | } |
| 42 | |
| 43 | if (!iCheckExtension(FileName, IL_TEXT("h"))) { |
| 44 | ilSetError(IL_INVALID_EXTENSION); |
| 45 | return IL_FALSE; |
| 46 | } |
| 47 | |
| 48 | if (ilGetBoolean(IL_FILE_MODE) == IL_FALSE) { |
| 49 | if (iFileExists(FileName)) { |
| 50 | ilSetError(IL_FILE_ALREADY_EXISTS); |
| 51 | return IL_FALSE; |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | if (iCurImage->Bpc > 1) { |
| 56 | TempImage = iConvertImage(iCurImage, iCurImage->Format, IL_UNSIGNED_BYTE); |
| 57 | if (TempImage == NULL) |
| 58 | return IL_FALSE; |
| 59 | } else { |
| 60 | TempImage = iCurImage; |
| 61 | } |
| 62 | |
| 63 | #ifndef _UNICODE |
| 64 | HeadFile = fopen(FileName, "wb"); |
| 65 | #else |
| 66 | #ifdef _WIN32 |
| 67 | HeadFile = _wfopen(FileName, L"rb"); |
| 68 | #else |
| 69 | HeadFile = fopen((char*)FileName, "rb"); |
| 70 | #endif |
| 71 | |
| 72 | #endif//_UNICODE |
| 73 | |
| 74 | if (HeadFile == NULL) { |
| 75 | ilSetError(IL_COULD_NOT_OPEN_FILE); |
| 76 | return IL_FALSE; |
| 77 | } |
| 78 |