Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

ilBlit or ilOverlay doesn't do what i expect

Help
GreyHound
2008-12-20
2013-05-02
  • GreyHound
    GreyHound
    2008-12-20

    Hi, i'm trying to create a picture that is twice as wide as the source and contains the source picture twice.

    ILuint target;
    ILuint src;

    ilGenImages(1, &target);
    ilGenImages(1, &src);

    ilBindImage(src);

    if(!ilLoadImage(file))
       return;

    int src_w = ilGetInteger(IL_IMAGE_WIDTH);
    int src_h = ilGetInteger(IL_IMAGE_HEIGHT);
    ILint bpp = ilGetInteger(IL_IMAGE_BPP);
    ILint pf = ilGetInteger(IL_IMAGE_FORMAT);
    ILint depth = ilGetInteger(IL_IMAGE_DEPTH);
    ILint type = ilGetInteger(IL_IMAGE_TYPE);

    ilBindImage(target);
    ilTexImage(src_w+src_w,src_h, depth, bpp,pf, type, NULL);
    ilOverlayImage(src, 0, 0, 0);
    ilOverlayImage(src, src_w, 0, 0);

    It just will not work correctly. If i just do the step once.
    ilBindImage(target);
    ilTexImage(src_w,src_h, depth, bpp,pf, type, NULL);
    ilOverlayImage(src, 0, 0, 0);

    it will work perfectly.

    I'm doing this with *.tga files. With1 alpha channel.

    Can anyone see where my problem is?

     
    • GreyHound
      GreyHound
      2008-12-20

      I should probably mention that it is actually creating a picture with 2 representations of my source. The alpha channel is just not anything i expect it to be. It's somehow flattened into the picture. It's also topdown.

       
    • GreyHound
      GreyHound
      2008-12-20

      I cleaned up my code a little for easier explaination and to give you the chance to test.

      void buildTextureAtlas(const char* fileA, const char* fileB){

          //the handles for target and 2 sources
          ILuint target;
          ILuint src1;
          ILuint src2;

          //keep track about errors
          ILboolean success;
         
          //gen 3 tex
          ilGenImages(1, &target);
          ilGenImages(1, &src1);
          ilGenImages(1, &src2);

          //bind source 1 and load
          ilBindImage(src1);
          success = ilLoadImage(fileA);

          if(!success)
              return;
         
          //save width and height
          int w1 = ilGetInteger(IL_IMAGE_WIDTH);
          int h1 = ilGetInteger(IL_IMAGE_HEIGHT);

          //bind 2nd source and load
          ilBindImage(src2);
          success = ilLoadImage(fileB);

          if(!success){
              ilDeleteImages(1, &src1);   
              return;
          }

          //save second width
          int w2 = ilGetInteger(IL_IMAGE_WIDTH);
          int h2 = ilGetInteger(IL_IMAGE_HEIGHT);   

          //use 2nd texture params for target (for now)
          ILint bpp = ilGetInteger(IL_IMAGE_BPP);
          ILint pf = ilGetInteger(IL_IMAGE_FORMAT);
          ILint depth = ilGetInteger(IL_IMAGE_DEPTH);
          ILint type = ilGetInteger(IL_IMAGE_TYPE);

          //extract filename only for test saving
          std::string identifier = fileA;
          identifier = identifier.substr(identifier.rfind("/")+1, identifier.rfind(".")-identifier.rfind("/")-1);
          std::string tar = identifier;
          tar.append("_Target.tga");

          //bind target
          ilBindImage(target); 
          //create with desired parameters
          ilTexImage(w1+w2,h1, depth, bpp, pf, type, (void*)NULL);
          ilOverlayImage(src1, 0, 0, 0);
          ilOverlayImage(src2, w1, 0, 0);

          if (!success)
             return;

         
          ilEnable(IL_FILE_OVERWRITE);
          ilSaveImage(tar.c_str());
      }

      This is exactly the code i use atm.

      For easy testing i currently try to call the function with the same parameters like:

      buildTextureAtlas("./file.tga","./file.tga");

       
    • GreyHound
      GreyHound
      2008-12-22

      Oki, so i looked into the src and found that the alpha layer is blended into the picture. ;((

      I'll probably write my own function to fix this then.

       
      • Denton Woods
        Denton Woods
        2008-12-22

        Hmm, I'm really not sure why the line that preserved alpha is commented out.  I may be uncommenting it.

         
    • GreyHound
      GreyHound
      2008-12-22

      Ah yeah, that commentet line in ilOverlay, i see. But the channel is also blended into the the color layers anyway. I don't think that's what someone expects.

      That's what i changed for now: in ilBlit(...)

      /*
                          Back = 1.0f - Front;
                          for (c = 0; c < bpp_without_alpha; c++)
                          {
                              Dest->Data[DestIndex + c] =
                                  (ILubyte)(Converted[SrcIndex + c] * Front
                                              + Dest->Data[DestIndex + c] * Back);
                          }
                          */
                          for (c = 0; c < Dest->Bpp; c++)
                          {
                              Dest->Data[DestIndex + c] = (ILubyte)(Converted[SrcIndex + c]);
                          }

      I'm not really into the lib so i don't really know how wrong this is. It just does the trick for me.

      Btw. Since ilBlit and ilOverlay are probably almost the same it should probably use more code in common. I think it should be written something like:

      ilOverlayImage(src,x,y,z){
         return ilBlit(src, x,y,z,xx,yy,zz,d);
      }

      to have the code only once.

       
      • Denton Woods
        Denton Woods
        2008-12-23

        I just added in the IL_BLIT_BLEND flag in CVS.  By default, the behavior is the same as it was, blending the source image into the destination image.  If you use this flag in ilDisable, it uses the code that you need.

         
        • GreyHound
          GreyHound
          2008-12-25

          Great, thanks a lot

           
  • GreyHound
    GreyHound
    2010-02-08

    It's been a while since this happened, but i thought i might report back anyway. I used my own workarround for a while but today i changed to 1.7.8 completly and therefore used the "correct" way to solve this.

    Thanks again,

    gl with ur phd