ILboolean ilImage::TexImage(ILuint Width, ILuint Height, ILuint Depth, ILubyte Bpp, ILenum Format, ILenum Type, ILvoid *Data) { if (this->Id) { this->Bind(); return ilTexImage(Width, Height, Depth, Bpp, Format, Type, Data); } return IL_FALSE; }
//! Creates an ugly 64x64 black and yellow checkerboard image. ILboolean ILAPIENTRY il2DefaultImage(ILimage* image) { ILubyte *TempData; ILubyte Yellow[3] = { 18, 246, 243 }; ILubyte Black[3] = { 0, 0, 0 }; ILubyte *ColorPtr = Yellow; // The start color ILboolean Color = IL_TRUE; // Loop Variables ILint v, w, x, y; if (image == NULL) { il2SetError(IL_ILLEGAL_OPERATION); return IL_FALSE; } if (!ilTexImage(64, 64, 1, 3, IL_BGR, IL_UNSIGNED_BYTE, NULL)) { return IL_FALSE; } image->Origin = IL_ORIGIN_LOWER_LEFT; TempData = image->Data; for (v = 0; v < 8; v++) { // We do this because after a "block" line ends, the next row of blocks // above starts with the ending colour, but the very inner loop switches them. if (Color) { Color = IL_FALSE; ColorPtr = Black; } else { Color = IL_TRUE; ColorPtr = Yellow; } for (w = 0; w < 8; w++) { for (x = 0; x < 8; x++) { for (y = 0; y < 8; y++, TempData += image->Bpp) { TempData[0] = ColorPtr[0]; TempData[1] = ColorPtr[1]; TempData[2] = ColorPtr[2]; } // Switch to alternate between black and yellow if (Color) { Color = IL_FALSE; ColorPtr = Black; } else { Color = IL_TRUE; ColorPtr = Yellow; } } } } return IL_TRUE; }
ILboolean ReadGrey(PSDHEAD *Head) { ILuint ColorMode, ResourceSize, MiscInfo; ILushort Compressed; ILenum Type; ILubyte *Resources = NULL; ColorMode = GetBigUInt(); // Skip over the 'color mode data section' iseek(ColorMode, IL_SEEK_CUR); ResourceSize = GetBigUInt(); // Read the 'image resources section' Resources = (ILubyte*)ialloc(ResourceSize); if (Resources == NULL) { return IL_FALSE; } if (iread(Resources, 1, ResourceSize) != ResourceSize) goto cleanup_error; MiscInfo = GetBigUInt(); iseek(MiscInfo, IL_SEEK_CUR); Compressed = GetBigUShort(); ChannelNum = Head->Channels; Head->Channels = 1; // Temporary to read only one channel...some greyscale .psd files have 2. if (Head->Channels != 1) { ilSetError(IL_FORMAT_NOT_SUPPORTED); return IL_FALSE; } switch (Head->Depth) { case 8: Type = IL_UNSIGNED_BYTE; break; case 16: Type = IL_UNSIGNED_SHORT; break; default: ilSetError(IL_FORMAT_NOT_SUPPORTED); return IL_FALSE; } if (!ilTexImage(Head->Width, Head->Height, 1, 1, IL_LUMINANCE, Type, NULL)) goto cleanup_error; if (!PsdGetData(Head, iCurImage->Data, (ILboolean)Compressed)) goto cleanup_error; if (!ParseResources(ResourceSize, Resources)) goto cleanup_error; ifree(Resources); return IL_TRUE; cleanup_error: ifree(Resources); return IL_FALSE; }
void TileStorage::CompressTile(uint64_t uid) { uint8_t * m0; uint8_t * m1; uint8_t * m2; uint8_t * m3; uint8_t * dataptr = m_tiles[uid]; uint8_t * compressedmipmaps = new uint8_t[680]; if ( !dataptr ) { delete [] compressedmipmaps; throw InvalidTileDataPointerException(); } uint32_t s; uint32_t s2 = 0; ILuint mip1 = ilGenImage(); ilBindImage(mip1); ilTexImage(32,32,1,4,IL_RGBA,IL_UNSIGNED_BYTE,dataptr); /*std::stringstream ss; ss << "Tile" << uid << ".png"; ilSaveImage(ss.str().c_str());*/ m0 = ilCompressDXT(ilGetData(),32,32,1,IL_DXT1,&s); memcpy(&compressedmipmaps[s2],m0,s); s2 += s; iluScale(16,16,1); m1 = ilCompressDXT(ilGetData(),16,16,1,IL_DXT1,&s); memcpy(&compressedmipmaps[s2],m1,s); s2 += s; iluScale(8,8,1); m2 = ilCompressDXT(ilGetData(),8,8,1,IL_DXT1,&s); memcpy(&compressedmipmaps[s2],m2,s); s2 += s; iluScale(4,4,1); m3 = ilCompressDXT(ilGetData(),4,4,1,IL_DXT1,&s); memcpy(&compressedmipmaps[s2],m3,s); s2 += s; ilDeleteImage(mip1); /*squish::CompressImage(dataptr,32,32,m0,squish::kDxt1); squish::CompressImage(dataptr,16,16,m1,squish::kDxt1); squish::CompressImage(dataptr,8,8,m2,squish::kDxt1); squish::CompressImage(dataptr,4,4,m3,squish::kDxt1);*/ free(m0); free(m1); free(m2); free(m3); m_tiles_compressed[uid] = compressedmipmaps; //std::cout << "Tile " << uid << " compressed!" << std::endl; }
int main(const int argc, const char* const argv[]) { param_t parameters; if(!parse_args(argc, argv, ¶meters)) { return EXIT_FAILURE; } ilInit(); ilEnable(IL_ORIGIN_SET); ilOriginFunc(IL_ORIGIN_LOWER_LEFT); ILuint image; ilGenImages(1, &image); ilBindImage(image); const ILboolean load_success = ilLoadImage(parameters.in); if(load_success== IL_FALSE) { // handle error TODO ilDeleteImages(1, &image); return EXIT_FAILURE; } const ILboolean convert_success = ilConvertImage(IL_RGB, IL_UNSIGNED_BYTE); if(convert_success == IL_FALSE) { // handle error TODO ilDeleteImages(1, &image); return EXIT_FAILURE; } const ILint width = ilGetInteger(IL_IMAGE_WIDTH); const ILint height = ilGetInteger(IL_IMAGE_HEIGHT); const ILint out_width = width / parameters.scale; const ILint out_height = height / parameters.scale; ILubyte out_data[out_width * out_height]; const image_t in = { .width = width, .height = height, .data = ilGetData(), }; const image_t out = { .width = out_width, .height = out_height, .data = out_data, }; convert(in, out, parameters); ilDeleteImages(1, &image); ILuint out_image; ilGenImages(1, &out_image); ilBindImage(out_image); ilTexImage(out_width, out_height, 1, 1, IL_LUMINANCE, IL_UNSIGNED_BYTE, &out_data); ilEnable(IL_FILE_OVERWRITE); ilSaveImage(parameters.out); ilDeleteImages(1, &image); return EXIT_SUCCESS; }
// Access point for applications wishing to use the jpeg library directly in // conjunction with DevIL. // // The decompressor must be set up with an input source and all desired parameters // this function is called. The caller must call jpeg_finish_decompress because // the caller may still need decompressor after calling this for e.g. examining // saved markers. ILboolean ILAPIENTRY ilLoadFromJpegStruct(ILvoid *_JpegInfo) { #ifndef IL_NO_JPG #ifndef IL_USE_IJL // sam. void (*errorHandler)(j_common_ptr); ILubyte *TempPtr[1]; ILuint Returned; j_decompress_ptr JpegInfo = (j_decompress_ptr)_JpegInfo; //added on 2003-08-31 as explained in sf bug 596793 jpgErrorOccured = IL_FALSE; // sam. errorHandler = JpegInfo->err->error_exit; // sam. JpegInfo->err->error_exit = ExitErrorHandle; jpeg_start_decompress((j_decompress_ptr)JpegInfo); if (!ilTexImage(JpegInfo->output_width, JpegInfo->output_height, 1, (ILubyte)JpegInfo->output_components, 0, IL_UNSIGNED_BYTE, NULL)) { return IL_FALSE; } iCurImage->Origin = IL_ORIGIN_UPPER_LEFT; switch (iCurImage->Bpp) { case 1: iCurImage->Format = IL_LUMINANCE; break; case 3: iCurImage->Format = IL_RGB; break; case 4: iCurImage->Format = IL_RGBA; break; default: // Anyway to get here? Need to error out or something... break; } TempPtr[0] = iCurImage->Data; while (JpegInfo->output_scanline < JpegInfo->output_height) { Returned = jpeg_read_scanlines(JpegInfo, TempPtr, 1); // anyway to make it read all at once? TempPtr[0] += iCurImage->Bps; if (Returned == 0) break; } // sam. JpegInfo->err->error_exit = errorHandler; if (jpgErrorOccured) return IL_FALSE; ilFixImage(); return IL_TRUE; #endif #endif return IL_FALSE; }
// Note: .Cut support has not been tested yet! // A .cut can only have 1 bpp. // We need to add support for the .pal's PSP outputs with these... ILboolean iLoadCutInternal() { CUT_HEAD Header; ILuint Size, i = 0, j; ILubyte Count, Run; if (iCurImage == NULL) { ilSetError(IL_ILLEGAL_OPERATION); return IL_FALSE; } Header.Width = GetLittleShort(); Header.Height = GetLittleShort(); Header.Dummy = GetLittleInt(); if (Header.Width == 0 || Header.Height == 0) { ilSetError(IL_INVALID_FILE_HEADER); return IL_FALSE; } if (!ilTexImage(Header.Width, Header.Height, 1, 1, IL_COLOUR_INDEX, IL_UNSIGNED_BYTE, NULL)) { // always 1 bpp return IL_FALSE; } iCurImage->Origin = IL_ORIGIN_LOWER_LEFT; Size = Header.Width * Header.Height; while (i < Size) { Count = igetc(); if (Count == 0) { // end of row igetc(); // Not supposed to be here, but igetc(); // PSP is putting these two bytes here...WHY?! continue; } if (Count & BIT_7) { // rle-compressed ClearBits(Count, BIT_7); Run = igetc(); for (j = 0; j < Count; j++) { iCurImage->Data[i++] = Run; } } else { // run of pixels for (j = 0; j < Count; j++) { iCurImage->Data[i++] = igetc(); } } } iCurImage->Origin = IL_ORIGIN_UPPER_LEFT; // Not sure /*iCurImage->Pal.Palette = SharedPal.Palette; iCurImage->Pal.PalSize = SharedPal.PalSize; iCurImage->Pal.PalType = SharedPal.PalType;*/ return ilFixImage(); }
/* ---------------------------------- texture operation ---------------------------------- */ void ofxTexture::Allocate(unsigned int width, unsigned int height) { ilBindImage(m_ImageId); ilTexImage(width, height, 0, 4, IL_RGBA , IL_UNSIGNED_BYTE, NULL); ilClearColour(0.0f, 0.0f, 0.0f, 0.0f); ilClearImage(); m_Width = width; m_Height = height; m_Locked = false; }
void ImageData::create(int width, int height, void * data) { Lock lock(devilMutex); //automatically lock and unlock ILuint image; //create the image ilGenImages(1, &image); //bind it ilBindImage(image); while(ilGetError() != IL_NO_ERROR); //create and populate the image bool success = (ilTexImage(width, height, 1, bpp, IL_RGBA, IL_UNSIGNED_BYTE, data) == IL_TRUE); ILenum err = ilGetError(); while(ilGetError() != IL_NO_ERROR); if (!success) { ilDeleteImages(1, &image); if (err != IL_NO_ERROR) { switch (err) { case IL_ILLEGAL_OPERATION: throw love::Exception("Illegal operation"); case IL_INVALID_PARAM: throw love::Exception("Invalid parameters"); case IL_OUT_OF_MEMORY: throw love::Exception("Out of memory"); default: throw love::Exception("Unknown error (%d)", (int) err); } } throw love::Exception("Could not decode image data."); } try { this->data = new unsigned char[width*height*bpp]; } catch (std::bad_alloc) { ilDeleteImages(1, &image); throw love::Exception("Out of memory"); } memcpy(this->data, ilGetData(), width*height*bpp); ilDeleteImages(1, &image); }
// Internal function used to load the Gif. ILboolean iLoadGifInternal() { GIFHEAD Header; ILpal GlobalPal; if (iCurImage == NULL) { ilSetError(IL_ILLEGAL_OPERATION); return IL_FALSE; } GlobalPal.Palette = NULL; GlobalPal.PalSize = 0; //read header iread(&Header.Sig, 1, 6); Header.Width = GetLittleUShort(); Header.Height = GetLittleUShort(); Header.ColourInfo = igetc(); Header.Background = igetc(); Header.Aspect = igetc(); if (!strnicmp(Header.Sig, "GIF87A", 6)) { GifType = GIF87A; } else if (!strnicmp(Header.Sig, "GIF89A", 6)) { GifType = GIF89A; } else { ilSetError(IL_INVALID_FILE_HEADER); return IL_FALSE; } if (!ilTexImage(Header.Width, Header.Height, 1, 1, IL_COLOUR_INDEX, IL_UNSIGNED_BYTE, NULL)) return IL_FALSE; iCurImage->Origin = IL_ORIGIN_UPPER_LEFT; // Check for a global colour map. if (Header.ColourInfo & (1 << 7)) { if (!iGetPalette(Header.ColourInfo, &GlobalPal)) { return IL_FALSE; } } if (!GetImages(&GlobalPal, &Header)) return IL_FALSE; if (GlobalPal.Palette && GlobalPal.PalSize) ifree(GlobalPal.Palette); GlobalPal.Palette = NULL; GlobalPal.PalSize = 0; ilFixImage(); return IL_TRUE; }
void Texture::SaveAs(std::string pszFileName, size_t piWidth, size_t piHeight, size_t pType, size_t pFmt, void * pData) { ILuint _iImageId = 0; _iImageId = ilGenImage(); ilBindImage(_iImageId); ASSERT( ilTexImage(piWidth, piHeight, 0, 3, pType, pFmt, pData) == IL_TRUE , "Texture: Unable to set data!"); VERIFY( ilSaveImage(pszFileName.c_str()) == IL_TRUE , "Texture: Unable to save Image!"); ilDeleteImage(_iImageId); }
//--------------------------------------------------------------------------------------------- // the header's been read. set up the display stuff //--------------------------------------------------------------------------------------------- mng_bool MNG_DECL mymngprocessheader(mng_handle mng, mng_uint32 width, mng_uint32 height) { ILuint AlphaDepth; AlphaDepth = mng_get_alphadepth(mng); if (AlphaDepth == 0) { ilTexImage(width, height, 1, 3, IL_BGR, IL_UNSIGNED_BYTE, NULL); iCurImage->Origin = IL_ORIGIN_LOWER_LEFT; mng_set_canvasstyle(mng, MNG_CANVAS_BGR8); } else { // Use alpha channel ilTexImage(width, height, 1, 4, IL_BGRA, IL_UNSIGNED_BYTE, NULL); iCurImage->Origin = IL_ORIGIN_LOWER_LEFT; mng_set_canvasstyle(mng, MNG_CANVAS_BGRA8); } iCurImage->Origin = IL_ORIGIN_UPPER_LEFT; return MNG_TRUE; }
bool DrawAbstract::save(std::string path){ unsigned char *data = new unsigned char[4*screen_width*screen_height]; glReadBuffer(GL_BACK); glReadPixels(0,0,screen_width,screen_height,GL_RGBA, GL_UNSIGNED_BYTE,data); ilTexImage(screen_width,screen_height,1,4,IL_RGBA, IL_UNSIGNED_BYTE,data); ilEnable(IL_FILE_OVERWRITE); ilSaveImage(path.c_str()); delete data; return true; }
ILuint ImageManager::ClipImage(ILuint SourceID, ILuint X, ILuint Y, ILuint W, ILuint H) { ILuint ImageID; ilGenImages(1, &ImageID); ilBindImage(ImageID); ilTexImage(W, H, 1, 4, IL_BGRA, IL_UNSIGNED_BYTE, NULL); uint8_t* NewImageData = ilGetData(); ilBindImage(SourceID); ilCopyPixels(X, Y, 0, W, H, 1, IL_BGRA, IL_UNSIGNED_BYTE, NewImageData); return ImageID; }
ILboolean iLoadDcxInternal() { DCXHEAD Header; ILuint Signature, i, Entries[1024], Num = 0; ILimage *Image, *Base; if (iCurImage == NULL) { ilSetError(IL_ILLEGAL_OPERATION); return IL_FALSE; } if (!iIsValidDcx()) return IL_FALSE; iread(&Signature, 1, 4); do { if (iread(&Entries[Num], 1, 4) != 4) return IL_FALSE; Num++; } while (Entries[Num-1] != 0); iCurImage->NumNext = Num - 1; for (i = 0; i < Num; i++) { iseek(Entries[i], IL_SEEK_SET); iGetDcxHead(&Header); /*if (!iCheckDcx(&Header)) { ilSetError(IL_INVALID_FILE_HEADER); return IL_FALSE; }*/ Image = iUncompressDcx(&Header); if (Image == NULL) return IL_FALSE; if (i == 0) { ilTexImage(Image->Width, Image->Height, 1, Image->Bpp, Image->Format, Image->Type, Image->Data); Base = iCurImage; Base->Origin = IL_ORIGIN_UPPER_LEFT; ilCloseImage(Image); } else { iCurImage->Next = Image; iCurImage = iCurImage->Next; } } ilFixImage(); return IL_TRUE; }
void ofxTexture::Fill(ofFloatColor color, ofRectangle dest_rect) { if(m_Locked) return; ILuint dummy = ilGenImage(); ilBindImage(dummy); ilTexImage(dest_rect.width, dest_rect.height, 0, 4, IL_RGBA , IL_UNSIGNED_BYTE, NULL); ilClearColour(color.r, color.g, color.b, color.a); ilClearImage(); ilBindImage(m_ImageId); ilDisable(IL_BLIT_BLEND); ilBlit(dummy, dest_rect.x, dest_rect.y, 0, 0, 0, 0, dest_rect.width, dest_rect.height, 1); ilEnable(IL_BLIT_BLEND); ilDeleteImage(dummy); }
void Renderer::saveScreenshot(const std::string& filename, int width, int height) { ILuint tex; tex = IL_CHECK(ilGenImage()); IL_CHECK(ilBindImage(tex)); void* data = malloc(width * height * 3); glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, data); ilTexImage(width, height, 1, 3, IL_RGB, IL_UNSIGNED_BYTE, data); free(data); IL_CHECK(ilSaveImage(filename.c_str())); IL_CHECK(ilDeleteImage(tex)); }
// methods void Texture::Save(const char* filename) { uint handle = 0; ilGenImages(1, &handle); ilBindImage(handle); ilTexImage(width, height, 0, channels, format, IL_FLOAT, data); ilConvertImage(format, IL_UNSIGNED_BYTE); ilSaveImage(filename); ilDeleteImage(handle); ilBindImage(0); }
// Internal function used to load the Gif. ILboolean iLoadGifInternal(ILimage* image) { GIFHEAD Header; ILpal GlobalPal; if (image == NULL) { ilSetError(IL_ILLEGAL_OPERATION); return IL_FALSE; } GlobalPal.Palette = NULL; GlobalPal.PalSize = 0; // Read header iCurImage->io.read(iCurImage->io.handle, &Header, 1, sizeof(Header)); #ifdef __BIG_ENDIAN__ iSwapUShort(Header.Width); iSwapUShort(Header.Height); #endif if (strnicmp(Header.Sig, "GIF87A", 6) != 0 && strnicmp(Header.Sig, "GIF89A", 6) != 0) { ilSetError(IL_INVALID_FILE_HEADER); return IL_FALSE; } if (!ilTexImage(Header.Width, Header.Height, 1, 1, IL_COLOUR_INDEX, IL_UNSIGNED_BYTE, NULL)) //if (!ilTexImage(Header.Width, Header.Height, 1, 1, IL_RGB, IL_UNSIGNED_BYTE, NULL)) return IL_FALSE; image->Origin = IL_ORIGIN_UPPER_LEFT; // Check for a global colour map. if (Header.ColourInfo & (1 << 7)) { if (!iGetPalette(Header.ColourInfo, &GlobalPal, NULL)) { return IL_FALSE; } } if (!GetImages(image, &GlobalPal, &Header)) return IL_FALSE; if (GlobalPal.Palette && GlobalPal.PalSize) ifree(GlobalPal.Palette); GlobalPal.Palette = NULL; GlobalPal.PalSize = 0; return ilFixImage(); }
bool CBitmap::Save(std::string const& filename, bool opaque) const { if (type == BitmapTypeDDS) { #ifndef BITMAP_NO_OPENGL return ddsimage->save(filename); #else return false; #endif // !BITMAP_NO_OPENGL } unsigned char* buf = new unsigned char[xsize * ysize * 4]; const int ymax = (ysize - 1); /* HACK Flip the image so it saves the right way up. (Fiddling with ilOriginFunc didn't do anything?) Duplicated with ReverseYAxis. */ for (int y = 0; y < ysize; ++y) { for (int x = 0; x < xsize; ++x) { const int bi = 4 * (x + (xsize * (ymax - y))); const int mi = 4 * (x + (xsize * (y))); buf[bi + 0] = mem[mi + 0]; buf[bi + 1] = mem[mi + 1]; buf[bi + 2] = mem[mi + 2]; buf[bi + 3] = opaque ? 0xff : mem[mi + 3]; } } boost::mutex::scoped_lock lck(devilMutex); ilOriginFunc(IL_ORIGIN_UPPER_LEFT); ilEnable(IL_ORIGIN_SET); ilHint(IL_COMPRESSION_HINT, IL_USE_COMPRESSION); ilSetInteger(IL_JPG_QUALITY, 80); ILuint ImageName = 0; ilGenImages(1, &ImageName); ilBindImage(ImageName); ilTexImage(xsize, ysize, 1, 4, IL_RGBA, IL_UNSIGNED_BYTE, buf); const std::string fullpath = dataDirsAccess.LocateFile(filename, FileQueryFlags::WRITE); const bool success = ilSaveImage((char*)fullpath.c_str()); ilDeleteImages(1, &ImageName); ilDisable(IL_ORIGIN_SET); delete[] buf; return success; }
ILimage *ilReadBinaryPpm(PPMINFO *Info) { ILuint Size; Size = Info->Width * Info->Height * Info->Bpp; if (!ilTexImage(Info->Width, Info->Height, 1, (ILubyte)(Info->Bpp), 0, IL_UNSIGNED_BYTE, NULL)) { return IL_FALSE; } iCurImage->Origin = IL_ORIGIN_UPPER_LEFT; if (iread(iCurImage->Data, 1, Size) != Size) return NULL; return iCurImage; }
int main(int argc, char* argv[]) { if (argc != 3) { printf("Usage: %s <input data file> <output image file>", argv[0]); } byte* img = malloc(IMG_ARRAY_LENGTH); ilInit(); uint pos = 0; FILE* dataFile = fopen(argv[1], "r"); while (fscanf(dataFile, "%2hhx", &(img[pos++])) == 1) { } fclose(dataFile); ilTexImage(IMG_WIDTH, IMG_HEIGHT, 0, 3, IL_RGB, IL_UNSIGNED_BYTE, img); ilSaveImage(argv[2]); }
ILboolean iluCrop3D(ILuint XOff, ILuint YOff, ILuint ZOff, ILuint Width, ILuint Height, ILuint Depth) { ILuint x, y, z, c, OldBps, OldPlane; ILubyte *Data; ILenum Origin; iluCurImage = ilGetCurImage(); if (iluCurImage == NULL) { ilSetError(ILU_ILLEGAL_OPERATION); return IL_FALSE; } // Uh-oh, what about 0 dimensions?! if (Width > iluCurImage->Width || Height > iluCurImage->Height || Depth > iluCurImage->Depth) { ilSetError(ILU_ILLEGAL_OPERATION); return IL_FALSE; } Data = (ILubyte*)ialloc(iluCurImage->SizeOfData); if (Data == NULL) { return IL_FALSE; } OldBps = iluCurImage->Bps; OldPlane = iluCurImage->SizeOfPlane; Origin = iluCurImage->Origin; ilCopyPixels(0, 0, 0, iluCurImage->Width, iluCurImage->Height, iluCurImage->Depth, iluCurImage->Format, iluCurImage->Type, Data); if (!ilTexImage(Width - XOff, Height - YOff, Depth - ZOff, iluCurImage->Bpp, iluCurImage->Format, iluCurImage->Type, NULL)) { ifree(Data); } iluCurImage->Origin = Origin; for (z = 0; z < iluCurImage->Depth; z++) { for (y = 0; y < iluCurImage->Height; y++) { for (x = 0; x < iluCurImage->Bps; x += iluCurImage->Bpp) { for (c = 0; c < iluCurImage->Bpp; c++) { iluCurImage->Data[z * iluCurImage->SizeOfPlane + y * iluCurImage->Bps + x + c] = Data[(z + ZOff) * OldPlane + (y + YOff) * OldBps + (x + XOff) + c]; } } } } ifree(Data); return IL_TRUE; }
ILboolean iluCrop2D(ILuint XOff, ILuint YOff, ILuint Width, ILuint Height) { ILuint x, y, c, OldBps; ILubyte *Data; ILenum Origin; iluCurImage = ilGetCurImage(); if (iluCurImage == NULL) { ilSetError(ILU_ILLEGAL_OPERATION); return IL_FALSE; } // Uh-oh, what about 0 dimensions?! if (Width > iluCurImage->Width || Height > iluCurImage->Height) { ilSetError(ILU_ILLEGAL_OPERATION); return IL_FALSE; } Data = (ILubyte*)ialloc(iluCurImage->SizeOfData); if (Data == NULL) { return IL_FALSE; } OldBps = iluCurImage->Bps; Origin = iluCurImage->Origin; ilCopyPixels(0, 0, 0, iluCurImage->Width, iluCurImage->Height, 1, iluCurImage->Format, iluCurImage->Type, Data); if (!ilTexImage(Width, Height, iluCurImage->Depth, iluCurImage->Bpp, iluCurImage->Format, iluCurImage->Type, NULL)) { free(Data); return IL_FALSE; } iluCurImage->Origin = Origin; // @TODO: Optimize! (Especially XOff * iluCurImage->Bpp...get rid of it!) for (y = 0; y < iluCurImage->Height; y++) { for (x = 0; x < iluCurImage->Bps; x += iluCurImage->Bpp) { for (c = 0; c < iluCurImage->Bpp; c++) { iluCurImage->Data[y * iluCurImage->Bps + x + c] = Data[(y + YOff) * OldBps + x + XOff * iluCurImage->Bpp + c]; } } } ifree(Data); return IL_TRUE; }
ILboolean ILAPIENTRY iluRotate3D(ILfloat x, ILfloat y, ILfloat z, ILfloat Angle) { ILimage *Temp; // return IL_FALSE; iluCurImage = ilGetCurImage(); Temp = iluRotate3D_(iluCurImage, x, y, z, Angle); if (Temp != NULL) { ilTexImage(Temp->Width, Temp->Height, Temp->Depth, Temp->Bpp, Temp->Format, Temp->Type, Temp->Data); iluCurImage->Origin = Temp->Origin; ilSetPal(&Temp->Pal); ilCloseImage(Temp); return IL_TRUE; } return IL_FALSE; }
bool ImageLoader::saveImageRGBA(const char* image, u8* data, u32 width, u32 height) { ILuint handle; // In the next section, we load one image ilGenImages(1, &handle); ilBindImage(handle); ilTexImage(width, height, 1, 4, IL_RGBA, IL_UNSIGNED_BYTE, data); ilEnable(IL_FILE_OVERWRITE); const ILboolean saved = ilSaveImage(image); // Finally, clean the mess! ilDeleteImages(1, &handle); return saved ? true : false; }
ILboolean ILAPIENTRY iluRotate(ILfloat Angle) { ILimage *Temp, *Temp1, *CurImage = NULL; ILenum PalType = 0; iluCurImage = ilGetCurImage(); if (iluCurImage == NULL) { ilSetError(ILU_ILLEGAL_OPERATION); return IL_FALSE; } if (iluCurImage->Format == IL_COLOUR_INDEX) { PalType = iluCurImage->Pal.PalType; CurImage = iluCurImage; iluCurImage = iConvertImage(iluCurImage, ilGetPalBaseType(CurImage->Pal.PalType), IL_UNSIGNED_BYTE); } Temp = iluRotate_(iluCurImage, Angle); if (Temp != NULL) { if (PalType != 0) { ilCloseImage(iluCurImage); Temp1 = iConvertImage(Temp, IL_COLOUR_INDEX, IL_UNSIGNED_BYTE); ilCloseImage(Temp); Temp = Temp1; ilSetCurImage(CurImage); } ilTexImage(Temp->Width, Temp->Height, Temp->Depth, Temp->Bpp, Temp->Format, Temp->Type, Temp->Data); if (PalType != 0) { iluCurImage = ilGetCurImage(); iluCurImage->Pal.PalSize = Temp->Pal.PalSize; iluCurImage->Pal.PalType = Temp->Pal.PalType; iluCurImage->Pal.Palette = (ILubyte*)ialloc(Temp->Pal.PalSize); if (iluCurImage->Pal.Palette == NULL) { ilCloseImage(Temp); return IL_FALSE; } memcpy(iluCurImage->Pal.Palette, Temp->Pal.Palette, Temp->Pal.PalSize); } iluCurImage->Origin = Temp->Origin; ilCloseImage(Temp); return IL_TRUE; } return IL_FALSE; }
//------------------------------------------------------------------------------------ // Creates an Image and store it. //------------------------------------------------------------------------------------ bool Image::CreateImage( int Width, int Height, int Depth /*= 1*/, int BytesPerPixel /*= 4*/, ImageFormat imgFormat /*= EIF_BGRA*/, void* Data /*= NULL*/ ) { m_eFmt = imgFormat; ILenum fmt; switch (imgFormat) { case EIF_RGB: fmt = IL_RGB; m_ibpp = 24; m_iBpp = 3; break; case EIF_RGBA: fmt = IL_RGBA; m_ibpp = 32; m_iBpp = 4; break; case EIF_BGR: fmt = IL_BGR; m_ibpp = 24; m_iBpp = 3; break; case EIF_BGRA: fmt = IL_BGRA; m_ibpp = 32; m_iBpp = 4; break; case EIF_A: fmt = IL_ALPHA; m_ibpp = 8; m_iBpp = 1; break; } m_iWidth = Width; m_iHeight = Height; ilBindImage(m_iImgID); ILboolean b = ilTexImage(Width, Height, Depth, BytesPerPixel, fmt, IL_UNSIGNED_BYTE, Data); return b; } // CreateImage
void SaveImage(const char *fn, int components, GLenum type, int w,int h, void *data) { // We use the fact that DevIL has the same constants for component type as OpenGL /// ( GL_UNSIGNED_BYTE = IL_UNSIGNED_BYTE for example ) #ifdef TERRAIN_USE_IL // Save image ILuint out; ilGenImages(1,&out); ilBindImage(out); ILenum fmt=IL_RGB; if (components==4) fmt = IL_RGBA; if (components==1) fmt = IL_LUMINANCE; ilTexImage(w,h,1,components,fmt,type,data); filesystem.Remove(fn); ilSaveImage((ILstring)fn); ilDeleteImages(1,&out); #endif }
//! Copies everything from Src to the current bound image. ILboolean ILAPIENTRY ilCopyImage(ILuint Src) { ILuint DestName = ilGetCurName(); ILimage *DestImage = iCurImage, *SrcImage; if (iCurImage == NULL || DestName == 0) { ilSetError(IL_ILLEGAL_OPERATION); return IL_FALSE; } ilBindImage(Src); SrcImage = iCurImage; ilBindImage(DestName); ilTexImage(SrcImage->Width, SrcImage->Height, SrcImage->Depth, SrcImage->Bpp, SrcImage->Format, SrcImage->Type, SrcImage->Data); ilCopyImageAttr(DestImage, SrcImage); return IL_TRUE; }