示例#1
0
ILboolean ilImage::ActiveLayer(ILuint Number)
{
	if (this->Id) {
		this->Bind();
		return ilActiveLayer(Number);
	}
	return IL_FALSE;
}
示例#2
0
UInt32 GUCEF_PLUGIN_CALLSPEC_PREFIX
IMGCODECPLUGIN_EncodeImage( void* pluginData      ,
                            void* codecData       ,
                            const char* codecType ,
                            TImage* inputImage    ,
                            TIOAccess* output     )
{
    UInt32 i = 0;
    UInt32 n = 0;
    TImageInfo* imageInfo = NULL;
    char codecTypeExt[ 256 ];

    /* generate an image ID and make that ID the ID of the current image */
    ilBindImage( ilGenImage() );

    /* Only 1 layer is supported atm */
    ilActiveLayer( 0 );

    imageInfo = &inputImage->imageInfo;
    for ( i=0; i<imageInfo->nrOfFramesInImage; ++i )
    {
        TImageFrameInfo* imageFrameInfo = &inputImage->frames[ i ].frameInfo;
        
        /* activate the frame */
        ilActiveImage( i );        

        for ( n=0; n<imageFrameInfo->nrOfMipmapLevels; ++n )
        {
            /* create a shortcut */
            TImageMipMapLevelInfo* mipInfo = &inputImage->frames[ i ].mipmapLevel[ n ].mipLevelInfo;
            void* imageBuffer = inputImage->frames[ i ].mipmapLevel[ n ].pixelData;

            /* activate the mip-map */
            ilActiveMipmap( n );
            
            /* hand the data over to DevIL */
            if ( IL_TRUE != ilTexImage( (ILuint)mipInfo->frameWidth                                                   ,
                                        (ILuint)mipInfo->frameHeight                                                  ,
                                        (ILuint)1                                                                     ,
                                        (ILubyte) GetChannelCountForFormat( mipInfo->pixelStorageFormat )             ,
                                        (ILenum)ConvertGUCEFPixelFormatToILPixelFormat( mipInfo->pixelStorageFormat ) ,
                                        (ILenum)ConvertGUCEFTypeToILType( mipInfo->pixelComponentDataType )           ,
                                        (void*)imageBuffer                                                            ) )
            {
                /* Failed to transfer the data over to DevIL */
                return 0;
            }
                        
        }
    }
    
    /* Make sure we prefix a dot before the codecType */    
    strcpy_s( codecTypeExt+1, 255, codecType );
    codecTypeExt[ 0 ] = '.';

    /* now we can perform the actual save */
    currentResource = output;
    if ( IL_TRUE == ilSaveF( ilTypeFromExt( codecTypeExt ), output ) )
    {
        currentResource = NULL;
        return 1;
    }
    
    currentResource = NULL;
    return 0;
}
示例#3
0
UInt32 GUCEF_PLUGIN_CALLSPEC_PREFIX
IMGCODECPLUGIN_DecodeImage( void* pluginData      ,
                            void* codecData       ,
                            const char* codecType ,
                            TIOAccess* input      ,
                            TImage** imageOutput  ,
                            void** imageData      )
{
    UInt32 i=0, n=0, mipmapCount=0, frameCount=0;
    ILint imageID = 0, imageSize = 0;
    TImage* image = NULL;

    if ( ( NULL == codecType ) || ( NULL == input ) ) 
        return 0;
    
    /* generate an image ID and make that ID the ID of the current image */
    imageID = ilGenImage();
    ilBindImage( imageID );
    
    currentResource = input;
    
    if ( IL_TRUE == ilLoadF( ilTypeFromExt( codecType ), input ) )
    {        
        image = malloc( sizeof(TImage) );
        image->version = GUCEF_IMAGE_TIMAGE_VERSION;
        image->imageInfo.version = GUCEF_IMAGE_TIMAGEINFO_VERSION;
        frameCount = image->imageInfo.nrOfFramesInImage = (UInt32) ilGetInteger( IL_NUM_IMAGES );
        if ( frameCount == 0 )
        {
            /* DevIL returns a image count of 0 for single-image images */
            frameCount = image->imageInfo.nrOfFramesInImage = 1;
        }
        image->frames = (TImageFrame*) malloc( frameCount * sizeof( TImageFrame ) );

        /* Only 1 layer is supported atm */
        ilActiveLayer( 0 );
        
        for ( i=0; i<frameCount; ++i )
        {
            TImageFrame* imageFrame = &image->frames[ i ]; 
            imageFrame->version = GUCEF_IMAGE_TIMAGEFRAME_VERSION;

            /* activate the frame */
            ilActiveImage( i );
            
            /* init the TImageFrameInfo section */
            imageFrame->frameInfo.version = GUCEF_IMAGE_TIMAGEFRAMEINFO_VERSION;
            mipmapCount = imageFrame->frameInfo.nrOfMipmapLevels = (UInt32) ilGetInteger( IL_NUM_MIPMAPS );
            if ( mipmapCount == 0 )
            {
                /* DevIL returns a mipmap count of 0 images without mipmapping, we use 0 for the base image */
                mipmapCount = imageFrame->frameInfo.nrOfMipmapLevels = 1;
            }
            imageFrame->mipmapLevel = (TImageMipMapLevel*) malloc( mipmapCount * sizeof(TImageMipMapLevel) );
        
            for ( n=0; n<mipmapCount; ++n )
            {
                TImageMipMapLevel* mipmapLevel = &imageFrame->mipmapLevel[ n ]; 
                mipmapLevel->version = GUCEF_IMAGE_TIMAGEMIPMAPLEVEL_VERSION;
                
                /* activate the mip-map */
                ilActiveMipmap( n );
                
                // Converted paletted images
                if( ilGetInteger( IL_IMAGE_FORMAT ) == IL_COLOUR_INDEX )
                {
                    ilConvertImage( IL_BGRA, IL_UNSIGNED_BYTE );
                }
                
                /* init the TImageMipMapLevelInfo section */
                mipmapLevel->mipLevelInfo.version = GUCEF_IMAGE_TIMAGEMIPMAPLEVELINFO_VERSION;
                mipmapLevel->mipLevelInfo.pixelComponentDataType = DATATYPE_UINT8; /* DevIL only supports this type */
                mipmapLevel->mipLevelInfo.frameHeight = ilGetInteger( IL_IMAGE_HEIGHT );
                mipmapLevel->mipLevelInfo.frameWidth = ilGetInteger( IL_IMAGE_WIDTH );
                mipmapLevel->mipLevelInfo.pixelStorageFormat = ConvertILPixelFormatToGUCEFPixelFormat( ilGetInteger( IL_IMAGE_FORMAT ) );

                /* now we grab the pixel data */
                ilCompressFunc( IL_COMPRESS_NONE );
                mipmapLevel->pixelDataSizeInBytes = ilGetInteger( IL_IMAGE_SIZE_OF_DATA );
                mipmapLevel->pixelData = malloc( mipmapLevel->pixelDataSizeInBytes );
                memcpy( mipmapLevel->pixelData, ilGetData(), mipmapLevel->pixelDataSizeInBytes );
            }
        }
    }
    
    /*
     *  the image has been loaded into our GUCEF structures so we have no need for
     *  DevIL to store the data any more 
     */
    ilDeleteImage( imageID );
    
    *imageOutput = image;
    currentResource = NULL;
    
    return 1;
}