//! Generates a C-style header file for the current image. ILboolean ilSaveCHeader(ILimage* image, char *InternalName) { FILE *HeadFile = NULL; ILuint i = 0, j; ILimage *TempImage; const char *Name; if (image == NULL) { il2SetError(IL_ILLEGAL_OPERATION); return IL_FALSE; } Name = iGetString(IL_CHEAD_HEADER_STRING); if (Name == NULL) Name = InternalName; if (image->Bpc > 1) { TempImage = iConvertImage(image, image->Format, IL_UNSIGNED_BYTE); if (TempImage == NULL) return IL_FALSE; } else { TempImage = image; } FILE* file = (FILE*) image->io.handle; fprintf(HeadFile, "//#include <il/il.h>\n"); fprintf(HeadFile, "// C Image Header:\n\n\n"); fprintf(HeadFile, "// IMAGE_BPP is in bytes per pixel, *not* bits\n"); fprintf(HeadFile, "#define IMAGE_BPP %d\n",image->Bpp); fprintf(HeadFile, "#define IMAGE_WIDTH %d\n", image->Width); fprintf(HeadFile, "#define IMAGE_HEIGHT %d\n", image->Height); fprintf(HeadFile, "#define IMAGE_DEPTH %d\n\n\n", image->Depth); fprintf(HeadFile, "#define IMAGE_TYPE 0x%X\n", image->Type); fprintf(HeadFile, "#define IMAGE_FORMAT 0x%X\n\n\n", image->Format); fprintf(HeadFile, "ILubyte %s[] = {\n", Name); for (; i < TempImage->SizeOfData; i += MAX_LINE_WIDTH) { fprintf(HeadFile, "\t"); for (j = 0; j < MAX_LINE_WIDTH; j++) { if (i + j >= TempImage->SizeOfData - 1) { fprintf(HeadFile, "%4d", TempImage->Data[i+j]); break; } else fprintf(HeadFile, "%4d,", TempImage->Data[i+j]); } fprintf(HeadFile, "\n"); } if (TempImage != image) ilCloseImage(TempImage); fprintf(HeadFile, "};\n"); if (image->Pal.hasPalette()) { fprintf(HeadFile, "\n\n"); fprintf(HeadFile, "#define IMAGE_PALSIZE %u\n\n", image->Pal.getPalSize()); fprintf(HeadFile, "#define IMAGE_PALTYPE 0x%X\n\n", image->Pal.getPalType()); fprintf(HeadFile, "ILubyte %sPal[] = {\n", Name); for (i = 0; i < image->Pal.getPalSize(); i += MAX_LINE_WIDTH) { fprintf(HeadFile, "\t"); for (j = 0; j < MAX_LINE_WIDTH; j++) { if (i + j >= image->Pal.getPalSize() - 1) { fprintf(HeadFile, " %4d", image->Pal.getPalette()[i+j]); break; } else fprintf(HeadFile, " %4d,", image->Pal.getPalette()[i+j]); } fprintf(HeadFile, "\n"); } fprintf(HeadFile, "};\n"); } fclose(HeadFile); return IL_TRUE; }
//! Generates a C-style header file for the current image. static ILboolean iSaveCHEADInternal(ILimage* image) { const char *InternalName = "IL_IMAGE"; // FILE *HeadFile; ILuint i = 0, j; ILimage *TempImage; const char *Name; char tmp[512]; SIO * io; if (image == NULL) { iSetError(IL_ILLEGAL_OPERATION); return IL_FALSE; } io = &image->io; Name = iGetString(image, IL_META_DOCUMENT_NAME); if (Name == NULL) Name = InternalName; if (image->Bpc > 1) { TempImage = iConvertImage(image, image->Format, IL_UNSIGNED_BYTE); if (TempImage == NULL) return IL_FALSE; } else { TempImage = image; } SIOputs(io, "//#include <il/il.h>\n"); SIOputs(io, "// C Image Header:\n\n\n"); SIOputs(io, "// IMAGE_BPP is in bytes per pixel, *not* bits\n"); snprintf(tmp, sizeof(tmp), "#define IMAGE_BPP %d\n",image->Bpp); SIOputs(io, tmp); snprintf(tmp, sizeof(tmp), "#define IMAGE_WIDTH %d\n", image->Width); SIOputs(io, tmp); snprintf(tmp, sizeof(tmp), "#define IMAGE_HEIGHT %d\n", image->Height); SIOputs(io, tmp); snprintf(tmp, sizeof(tmp), "#define IMAGE_DEPTH %d\n\n\n", image->Depth); SIOputs(io, tmp); snprintf(tmp, sizeof(tmp), "#define IMAGE_TYPE 0x%X\n", image->Type); SIOputs(io, tmp); snprintf(tmp, sizeof(tmp), "#define IMAGE_FORMAT 0x%X\n\n\n", image->Format); SIOputs(io, tmp); snprintf(tmp, sizeof(tmp), "ILubyte %s[] = {\n", Name); SIOputs(io, tmp); for (; i < TempImage->SizeOfData; i += MAX_LINE_WIDTH) { SIOputs(io, "\t"); for (j = 0; j < MAX_LINE_WIDTH; j++) { if (i + j >= TempImage->SizeOfData - 1) { snprintf(tmp, sizeof(tmp), " %4d", TempImage->Data[i+j]); SIOputs(io, tmp); break; } else { snprintf(tmp, sizeof(tmp), " %4d,", TempImage->Data[i+j]); SIOputs(io, tmp); } } SIOputs(io, "\n"); } if (TempImage != image) iCloseImage(TempImage); SIOputs(io, "};\n"); if (image->Pal.Palette && image->Pal.PalSize && image->Pal.PalType != IL_PAL_NONE) { SIOputs(io, "\n\n"); snprintf(tmp, sizeof(tmp), "#define IMAGE_PALSIZE %u\n\n", image->Pal.PalSize); SIOputs(io, tmp); snprintf(tmp, sizeof(tmp), "#define IMAGE_PALTYPE 0x%X\n\n", image->Pal.PalType); SIOputs(io, tmp); snprintf(tmp, sizeof(tmp), "ILubyte %sPal[] = {\n", Name); SIOputs(io, tmp); for (i = 0; i < image->Pal.PalSize; i += MAX_LINE_WIDTH) { SIOputs(io, "\t"); for (j = 0; j < MAX_LINE_WIDTH; j++) { if (i + j >= image->Pal.PalSize - 1) { snprintf(tmp, sizeof(tmp), " %4d", image->Pal.Palette[i+j]); SIOputs(io, tmp); break; } else { snprintf(tmp, sizeof(tmp), " %4d,", image->Pal.Palette[i+j]); SIOputs(io, tmp); } } SIOputs(io, "\n"); } SIOputs(io, "};\n"); } return IL_TRUE; }
//! Generates a C-style header file for the current image. ILboolean ilSaveCHeader(ILconst_string FileName, char *InternalName) { FILE *HeadFile; ILuint i = 0, j; ILimage *TempImage; const char *Name; if (iCurImage == NULL) { ilSetError(IL_ILLEGAL_OPERATION); return IL_FALSE; } Name = iGetString(IL_CHEAD_HEADER_STRING); if (Name == NULL) Name = InternalName; if (FileName == NULL || Name == NULL || ilStrLen(FileName) < 1 || ilCharStrLen(Name) < 1) { ilSetError(IL_INVALID_VALUE); return IL_FALSE; } if (!iCheckExtension(FileName, IL_TEXT("h"))) { ilSetError(IL_INVALID_EXTENSION); return IL_FALSE; } if (ilGetBoolean(IL_FILE_MODE) == IL_FALSE) { if (iFileExists(FileName)) { ilSetError(IL_FILE_ALREADY_EXISTS); return IL_FALSE; } } if (iCurImage->Bpc > 1) { TempImage = iConvertImage(iCurImage, iCurImage->Format, IL_UNSIGNED_BYTE); if (TempImage == NULL) return IL_FALSE; } else { TempImage = iCurImage; } #ifndef _UNICODE HeadFile = fopen(FileName, "wb"); #else HeadFile = _wfopen(FileName, L"rb"); #endif//_UNICODE if (HeadFile == NULL) { ilSetError(IL_COULD_NOT_OPEN_FILE); return IL_FALSE; } fprintf(HeadFile, "//#include <il/il.h>\n"); fprintf(HeadFile, "// C Image Header:\n\n\n"); fprintf(HeadFile, "// IMAGE_BPP is in bytes per pixel, *not* bits\n"); fprintf(HeadFile, "#define IMAGE_BPP %d\n",iCurImage->Bpp); fprintf(HeadFile, "#define IMAGE_WIDTH %d\n", iCurImage->Width); fprintf(HeadFile, "#define IMAGE_HEIGHT %d\n", iCurImage->Height); fprintf(HeadFile, "#define IMAGE_DEPTH %d\n\n\n", iCurImage->Depth); fprintf(HeadFile, "#define IMAGE_TYPE 0x%X\n", iCurImage->Type); fprintf(HeadFile, "#define IMAGE_FORMAT 0x%X\n\n\n", iCurImage->Format); fprintf(HeadFile, "ILubyte %s[] = {\n", Name); for (; i < TempImage->SizeOfData; i += MAX_LINE_WIDTH) { fprintf(HeadFile, "\t"); for (j = 0; j < MAX_LINE_WIDTH; j++) { if (i + j >= TempImage->SizeOfData - 1) { fprintf(HeadFile, "%4d", TempImage->Data[i+j]); break; } else fprintf(HeadFile, "%4d,", TempImage->Data[i+j]); } fprintf(HeadFile, "\n"); } if (TempImage != iCurImage) ilCloseImage(TempImage); fprintf(HeadFile, "};\n"); if (iCurImage->Pal.Palette && iCurImage->Pal.PalSize && iCurImage->Pal.PalType != IL_PAL_NONE) { fprintf(HeadFile, "\n\n"); fprintf(HeadFile, "#define IMAGE_PALSIZE %u\n\n", iCurImage->Pal.PalSize); fprintf(HeadFile, "#define IMAGE_PALTYPE 0x%X\n\n", iCurImage->Pal.PalType); fprintf(HeadFile, "ILubyte %sPal[] = {\n", Name); for (i = 0; i < iCurImage->Pal.PalSize; i += MAX_LINE_WIDTH) { fprintf(HeadFile, "\t"); for (j = 0; j < MAX_LINE_WIDTH; j++) { if (i + j >= iCurImage->Pal.PalSize - 1) { fprintf(HeadFile, " %4d", iCurImage->Pal.Palette[i+j]); break; } else fprintf(HeadFile, " %4d,", iCurImage->Pal.Palette[i+j]); } fprintf(HeadFile, "\n"); } fprintf(HeadFile, "};\n"); } fclose(HeadFile); return IL_TRUE; }
// Internal function used to save the Tiff. ILboolean iSaveTiffInternal(char *Filename) { ILenum Format; ILenum Compression; ILuint ixLine; TIFF *File; char Description[512]; ILimage *TempImage; if(iCurImage == NULL) { ilSetError(IL_ILLEGAL_OPERATION); return IL_FALSE; } if (iGetHint(IL_COMPRESSION_HINT) == IL_USE_COMPRESSION) Compression = COMPRESSION_PACKBITS; else Compression = COMPRESSION_NONE; if (iCurImage->Format == IL_COLOUR_INDEX) { if (ilGetBppPal(iCurImage->Pal.PalType) == 4) // Preserve the alpha. TempImage = iConvertImage(iCurImage, IL_RGBA, IL_UNSIGNED_BYTE); else TempImage = iConvertImage(iCurImage, IL_RGB, IL_UNSIGNED_BYTE); if (TempImage == NULL) { return IL_FALSE; } } else { TempImage = iCurImage; } File = TIFFOpen(Filename, "w"); //File = iTIFFOpen("w"); if (File == NULL) { ilSetError(IL_COULD_NOT_OPEN_FILE); return IL_FALSE; } sprintf(Description, "Tiff generated by %s", ilGetString(IL_VERSION_NUM)); TIFFSetField(File, TIFFTAG_IMAGEWIDTH, TempImage->Width); TIFFSetField(File, TIFFTAG_IMAGELENGTH, TempImage->Height); TIFFSetField(File, TIFFTAG_COMPRESSION, Compression); TIFFSetField(File, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB); TIFFSetField(File, TIFFTAG_BITSPERSAMPLE, TempImage->Bpc << 3); TIFFSetField(File, TIFFTAG_SAMPLESPERPIXEL, TempImage->Bpp); TIFFSetField(File, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG); TIFFSetField(File, TIFFTAG_ROWSPERSTRIP, 1); TIFFSetField(File, TIFFTAG_SOFTWARE, ilGetString(IL_VERSION_NUM)); /*TIFFSetField(File, TIFFTAG_DOCUMENTNAME, iGetString(IL_TIF_DOCUMENTNAME_STRING) ? iGetString(IL_TIF_DOCUMENTNAME_STRING) : FileName);*/ if (iGetString(IL_TIF_DOCUMENTNAME_STRING)) TIFFSetField(File, TIFFTAG_DOCUMENTNAME, iGetString(IL_TIF_DOCUMENTNAME_STRING)); if (iGetString(IL_TIF_AUTHNAME_STRING)) TIFFSetField(File, TIFFTAG_ARTIST, iGetString(IL_TIF_AUTHNAME_STRING)); if (iGetString(IL_TIF_HOSTCOMPUTER_STRING)) TIFFSetField(File, TIFFTAG_HOSTCOMPUTER, iGetString(IL_TIF_HOSTCOMPUTER_STRING)); if (iGetString(IL_TIF_DESCRIPTION_STRING)) TIFFSetField(File, TIFFTAG_IMAGEDESCRIPTION, iGetString(IL_TIF_DESCRIPTION_STRING)); TIFFSetField(File, TIFFTAG_DATETIME, iMakeString()); // 24/4/2003 // Orientation flag is not always supported ( Photoshop, ...), orient the image data // and set it always to normal view TIFFSetField(File, TIFFTAG_ORIENTATION,ORIENTATION_TOPLEFT ); if( TempImage->Origin != IL_ORIGIN_UPPER_LEFT ) { ILubyte *Data = iGetFlipped(TempImage); ifree( (void*)TempImage->Data ); TempImage->Data = Data; } /* TIFFSetField(File, TIFFTAG_ORIENTATION, TempImage->Origin == IL_ORIGIN_UPPER_LEFT ? ORIENTATION_TOPLEFT : ORIENTATION_BOTLEFT); */ Format = TempImage->Format; if (Format == IL_BGR || Format == IL_BGRA) ilSwapColours(); for (ixLine = 0; ixLine < TempImage->Height; ++ixLine) { if (TIFFWriteScanline(File, TempImage->Data + ixLine * TempImage->Bps, ixLine, 0) < 0) { TIFFClose(File); ilSetError(IL_LIB_TIFF_ERROR); return IL_FALSE; } } if (Format == IL_BGR || Format == IL_BGRA) ilSwapColours(); if (TempImage != iCurImage) ilCloseImage(TempImage); TIFFClose(File); return IL_TRUE; }