Results 1 to 9 of 9

Thread: [CoD] File Formats

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #8
    Assadministrator kung foo man's Avatar
    Join Date
    Jun 2012
    Location
    trailerpark
    Posts
    2,011
    Thanks
    2,102
    Thanked 1,084 Times in 753 Posts
    Unity3D needs at some point the raw RGBA data ^^

    I found a good DevIL C# wrapper and it works perfect so far

    PHP Code:
        public Texture2D LoadImageFromData(byte[] imageData)
        {
            const 
    int cNumImages 1;
            
    uint[] handles = new uint[cNumImages];
            
    Texture2D resTexture null;

            
    /* First we initialize the library. */
            /*Do not forget that... */
            
    DevILLoader.ilInit();

            
    /* We want all images to be loaded in a consistent manner */
            
    DevILLoader.ilEnable(DevILConstants.IL_ORIGIN_SET);

            
    /* In the next section, we load one image */
            
    DevILLoader.ilGenImages(cNumImageshandles);
            
    DevILLoader.ilBindImage(handles[0]);

            
    //
            //uint res = PluginLoader.ilLoadL(DevILConstants.IL_PNG, imageData, (uint)imageData.Length);
            
    bool res DevILLoader.ilLoadL(DevILConstants.IL_TYPE_UNKNOWNimageData, (uint)imageData.Length);
            if (!
    res)
            {
                
    Debug.LogWarning("Error! Cannot load image from data");
                return 
    resTexture;
            }

            
    /* Let's spy on it a little bit */
            
    int width DevILLoader.ilGetInteger(DevILConstants.IL_IMAGE_WIDTH); // getting image width
            
    int height DevILLoader.ilGetInteger(DevILConstants.IL_IMAGE_HEIGHT); // and height
            
    Debug.Log("Base image resolution: w = " width "; h = " height);

            
    // create result texture
            
    resTexture = new Texture2D(widthheightTextureFormat.RGBA32true);

            
    //
            
    Color32[] texColors GetColorDataFromCurrentImage();
            
            
    // set first mip map
            
    resTexture.SetPixels32(texColors0);

            
    // now, try to set another levels of bitmap
            
    {
                
    uint currMipMapLevel 1;
                const 
    uint cMaxMipMapLevel 15;
                while (
    currMipMapLevel cMaxMipMapLevel)
                {
                    
    res DevILLoader.ilActiveMipmap(currMipMapLevel);
                    
    Debug.Log("res = " res " currMipMapLevel = " currMipMapLevel);
                    if (!
    res)
                    {
                        break;
                    }

                    
    //
                    
    texColors GetColorDataFromCurrentImage();

                    
    Debug.Log("currMipMapLevel = " currMipMapLevel);

                    
    // set next mip map
                    
    resTexture.SetPixels32(texColors, (int)currMipMapLevel);

                    ++
    currMipMapLevel;

                    
    // restore base image
                    
    DevILLoader.ilBindImage(handles[0]);
                }
            }

            
    resTexture.Apply(true);
            
    //resTexture.Apply(false); // show this to ven!

            /* Finally, clean the mess! */
            
    DevILLoader.ilDeleteImages(cNumImageshandles);

            return 
    resTexture;
        }

        public 
    Color32[] GetColorDataFromCurrentImage()
        {
            
    int width DevILLoader.ilGetInteger(DevILConstants.IL_IMAGE_WIDTH); // getting image width
            
    int height DevILLoader.ilGetInteger(DevILConstants.IL_IMAGE_HEIGHT); // and height

            
    Debug.Log("Image resolution: w = " width "; h = " height);

            
    /* how much memory will we need? */
            
    int memoryNeeded width height 4;

            
    /* We multiply by 4 here because we want 4 components per pixel */
            
    byte[] imageColorData = new byte[memoryNeeded];

            
    /* finally get the image data */
            
    DevILLoader.ilCopyPixels(000, (uint)width, (uint)height1DevILConstants.IL_RGBADevILConstants.IL_UNSIGNED_BYTEimageColorData);

            if (
    imageColorData.Length <= 0)
            {
                return 
    null;
            }

            
    // create colors from color data
            
    Color32[] texColors = new Color32[imageColorData.Length 4];

            for (
    int i 00imageColorData.Length+= 4, ++j)
            {
                
    texColors[j].imageColorData[i];
                
    texColors[j].imageColorData[1];
                
    texColors[j].imageColorData[2];
                
    texColors[j].imageColorData[3];
            }

            return 
    texColors;
        } 
    IWI is supported by default.
    timescale 0.01

  2. The Following User Says Thank You to kung foo man For This Useful Post:

    smect@ (9th August 2014)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •