INT_PTR APIENTRY AboutDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_INITDIALOG: { int i; ILenum ilError; TCHAR VersionNum[256]; wsprintf(VersionNum, L"Num: %d", ilGetInteger(IL_VERSION_NUM)); SetDlgItemText(hDlg, IDC_ABOUT_VENDOR, ilGetString(IL_VENDOR)); SetDlgItemText(hDlg, IDC_ABOUT_VER_STRING, ilGetString(IL_VERSION_NUM)); SetDlgItemText(hDlg, IDC_ABOUT_VER_NUM, VersionNum); for (i = 0; i < 6; i++) { ilError = ilGetError(); if (ilError == IL_NO_ERROR) break; SetDlgItemText(hDlg, IDC_ERROR1+i, iluErrorString(ilError)); } return (TRUE); } break; case WM_COMMAND: { if (LOWORD(wParam) == IDOK) EndDialog(hDlg, TRUE); if (LOWORD(wParam) == IDCANCEL) EndDialog(hDlg, FALSE); } break; case WM_CLOSE: EndDialog(hDlg, TRUE); break; } return FALSE; }
int InitCodecList( void ) { const char* ilSpaceDelimLoadOpts = NULL; int i=0, n=0, m=0, k=0, d=0; /* Currently our API does not differ between loading/saving when calling out supported types, use Load for now */ ilSpaceDelimLoadOpts = ilGetString( IL_LOAD_EXT ); if ( ilSpaceDelimLoadOpts == NULL ) return 0; k = strlen( ilSpaceDelimLoadOpts ); codecCount = 0; for ( i=0; i<k; ++i ) { if ( ilSpaceDelimLoadOpts[ i ] == ' ' ) { ++codecCount; } } supportedTypes = (char**) malloc( codecCount * sizeof( char* ) ); n=0; d=0; for ( i=0; i<k; ++i ) { if ( ilSpaceDelimLoadOpts[ i ] == ' ' ) { m = i-n; char* opt = (char*) malloc( m+1 ); memcpy( opt, ilSpaceDelimLoadOpts+n, m ); opt[ m ] = '\0'; supportedTypes[ d ] = opt; n=i+1; ++d; } } return 1; }
const char *ilState::GetString(ILenum StringName) { return ilGetString(StringName); }
void CGLView::ImportTextures(const QString& pScenePath) { ILboolean success; if(mScene == nullptr) { LogError("Trying to load textures for empty scene."); return; } // Before calling ilInit() version should be checked. if(ilGetInteger(IL_VERSION_NUM) < IL_VERSION) { LogError("Wrong DevIL version."); return; } ilInit();// Initialization of DevIL. // // Load embedded textures // if(mScene->HasTextures()) LogError("Support for meshes with embedded textures is not implemented."); // // Load textures from external files. // // Get textures file names and number of textures. for(size_t idx_material = 0; idx_material < mScene->mNumMaterials; idx_material++) { int idx_texture = 0; aiString path; do { if(mScene->mMaterials[idx_material]->GetTexture(aiTextureType_DIFFUSE, idx_texture, &path) != AI_SUCCESS) break; mTexture_IDMap[path.data] = 0;// Fill map with invalid ID's. idx_texture++; } while(true); }// for(size_t idx_mat = 0; idx_mat < scene->mNumMaterials; idx_mat++) // Textures list is empty, exit. if(mTexture_IDMap.size() == 0) { LogInfo("No textures for import."); return; } size_t num_textures = mTexture_IDMap.size(); ILuint* id_images = nullptr;// Array with DevIL image ID's. GLuint* id_textures = nullptr;// Array with OpenGL textures ID's. // Generate DevIL image IDs. id_images = new ILuint[num_textures]; ilGenImages(num_textures, id_images);// Generation of 'num_textures' image names. // Create and fill array with OpenGL texture ID's. id_textures = new GLuint[num_textures]; ///TODO: if can not load textures then will stay orphande texture ID's in OpenGL. Generate OpenGL ID's after successfull loading of image. glGenTextures(num_textures, id_textures);// Texture ID's generation. QMap<QString, GLuint>::iterator map_it = mTexture_IDMap.begin();// Get iterator QString basepath = pScenePath.left(pScenePath.lastIndexOf('/') + 1);// path with '/' at the end. for(size_t idx_texture = 0; idx_texture < num_textures; idx_texture++) { //save IL image ID QString filename = map_it.key();// get filename mTexture_IDMap[filename] = id_textures[idx_texture];// save texture ID for filename in map map_it++;// next texture ilBindImage(id_images[idx_texture]);// Binding of DevIL image name. QString fileloc = basepath + filename; /* Loading of image */ fileloc.replace('\\', "/"); success = ilLoadImage(fileloc.toLocal8Bit()); if(!success) { LogError(QString("Couldn't load Image: %1").arg(fileloc)); goto it_for_err; } // Convert every colour component into unsigned byte. If your image contains alpha channel you can replace IL_RGB with IL_RGBA. success = ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE); if(!success) { LogError("Couldn't convert image."); goto it_for_err; } glBindTexture(GL_TEXTURE_2D, id_textures[idx_texture]);// Binding of texture ID. // Redefine standard texture values glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);// We will use linear interpolation for magnification filter. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);// We will use linear interpolation for minifying filter. glTexImage2D(GL_TEXTURE_2D, 0, ilGetInteger(IL_IMAGE_BPP), ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT), 0, ilGetInteger(IL_IMAGE_FORMAT), GL_UNSIGNED_BYTE, ilGetData());// Texture specification. continue; it_for_err: LogError(QString("DevIL error: %1, [%2]").arg(ilGetError()).arg(ilGetString(ilGetError()))); mTexture_IDMap.remove(filename); }// for(size_t idx_texture = 0; idx_texture < num_textures; i++) // Because we have already copied image data into texture data we can release memory used by image. ilDeleteImages(num_textures, id_images); //Cleanup delete [] id_images; delete [] id_textures; }
void CDevILCodec::Initialize() { if(mInit) return; nstring line("Initializing DevIL codec..\n \ (Developer's Image Library (DevIL) is a programmer's \n \ library to develop applications with very powerful image \n \ loading capabilities, yet is easy for a developer to learn and use.\n\n"); line.append("Registered image extentions: \n"); const char *il_version = ilGetString ( IL_VERSION_NUM ); line += "DevIL version: "; line += il_version; line += "\n"; mExtentions.push_back(".bmp"); mExtentions.push_back(".cut"); mExtentions.push_back(".dds"); mExtentions.push_back(".exr"); mExtentions.push_back(".hdr"); mExtentions.push_back(".ico"); mExtentions.push_back(".jpg"); mExtentions.push_back(".lbm"); mExtentions.push_back(".mdl"); mExtentions.push_back(".mng"); mExtentions.push_back(".pcd"); mExtentions.push_back(".pcx"); mExtentions.push_back(".pic"); mExtentions.push_back(".png"); mExtentions.push_back(".psd"); mExtentions.push_back(".tif"); mExtentions.push_back(".tga"); mExtentions.push_back(".raw"); mCompressorList.push_back(SF_BMP); mCompressorList.push_back(SF_DDS); mCompressorList.push_back(SF_PCX); mCompressorList.push_back(SF_TGA); for(nova::nUInt32 i = 0; i < mExtentions.size(); ++i) line += "\t" + mExtentions[i] + "\n"; LOG_MESSAGE(line); ilSetMemory(DevILAlloc, DevILFree); ilInit(); iluInit(); ilEnable(IL_FILE_OVERWRITE); ilEnable(IL_ORIGIN_SET); ilOriginFunc(IL_ORIGIN_LOWER_LEFT); ILenum Error = 0; if((Error = ilGetError()) != NULL) { nstring str("CDevILCodec::Initialize(): Can not init DevIL - "); str.append(iluErrorString(Error)); throw NOVA_EXP(str.c_str(), BAD_OPERATION); } mInit = true; }
STDMETHODIMP my12doomImageSource::Load(LPCOLESTR pszFileName, __in_opt const AM_MEDIA_TYPE *pmt) { if (m_curfile[0]) return E_FAIL; wcscpy(m_curfile, pszFileName); // parse file MpoParser mpo; _3DPParser _3dp; void *data1 = NULL; void *data2 = NULL; int size1 = 0; int size2 = 0; ILenum type = IL_TYPE_UNKNOWN; bool need_delete = false; if (2 == mpo.parseFile(pszFileName)) { data1 = mpo.m_datas[0]; data2 = mpo.m_datas[1]; size1 = mpo.m_sizes[0]; size2 = mpo.m_sizes[1]; type = IL_JPG; m_layout = IStereoLayout_SideBySide; } else if (2 == _3dp.parseFile(pszFileName)) { data1 = _3dp.m_datas[0]; data2 = _3dp.m_datas[1]; size1 = _3dp.m_sizes[0]; size2 = _3dp.m_sizes[1]; type = IL_JPG; m_layout = IStereoLayout_SideBySide; } else { FILE *f = _wfopen(pszFileName, L"rb"); if (NULL != f) { fseek(f, 0, SEEK_END); size1 = ftell(f); fseek(f, 0, SEEK_SET); data1 = new char[size1]; need_delete = true; fread(data1, 1, size1, f); fclose(f); } } // decode file if (size1 == 0) return VFW_E_INVALID_FILE_FORMAT; CAutoLock lck(&g_ILLock); ilInit(); ilOriginFunc(IL_ORIGIN_UPPER_LEFT); ilEnable(IL_ORIGIN_SET); // first file / single file ILboolean result = ilLoadL(type, data1, size1 ); if (!result) { ILenum err = ilGetError() ; printf( "the error %d\n", err ); printf( "string is %s\n", ilGetString( err ) ); if (need_delete) delete [] data1; return VFW_E_INVALID_FILE_FORMAT; } ilConvertImage(IL_BGRA, IL_UNSIGNED_BYTE); int decoded_size = ilGetInteger(IL_IMAGE_SIZE_OF_DATA); int width = ilGetInteger(IL_IMAGE_WIDTH); m_height = ilGetInteger(IL_IMAGE_HEIGHT); m_width = width; m_decoded_data = new char[decoded_size]; assert(decoded_size >= width * m_height *4); char *data = (char*)ilGetData(); char *dst = m_decoded_data; for(int y=0; y<m_height; y++) { memcpy(dst, data, width*4); dst += m_width*4; data += width*4; } // second file if (size2 > 0) { result = ilLoadL(type, data2, size2 ); if (!result) { ILenum err = ilGetError() ; if (need_delete) delete [] data1; safe_delete(m_decoded_data); return VFW_E_INVALID_FILE_FORMAT; } ilConvertImage(IL_BGRA, IL_UNSIGNED_BYTE); decoded_size = ilGetInteger(IL_IMAGE_SIZE_OF_DATA); int width2 = ilGetInteger(IL_IMAGE_WIDTH); int height2 = ilGetInteger(IL_IMAGE_HEIGHT); m_decoded_data2 = new char[decoded_size]; assert(decoded_size >= width * m_height *4); data = (char*)ilGetData(); dst = m_decoded_data2; for(int y=0; y<min(height2,m_height); y++) { memcpy(dst, data, min(width, width2)*4); dst += m_width*4; data += width2*4; } } HRESULT hr = E_FAIL; m_paStreams[0] = new my12doomImageStream(&hr, this, L"Image Out", m_decoded_data, m_width, m_height); if(m_paStreams[0] == NULL) { if (need_delete) delete [] data1; return E_OUTOFMEMORY; } if (m_decoded_data2) { m_paStreams[1] = new my12doomImageStream(&hr, this, L"Image Out 2", m_decoded_data2, m_width, m_height); if(m_paStreams[1] == NULL) { if (need_delete) delete [] data1; return E_OUTOFMEMORY; } } if (need_delete) delete [] data1; return S_OK; }
// 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; }