Powers of Two Converter


#1

I am look for a .bat, .met, or program that can take an TGA image file and convert it to a power of two. I was hoping someone had this already so I don’t have to code it myself. It just know to round up or down to the closest power of two.

-Hays


#2

Why not make a batch action in Photoshop and make it into a droplet? It shouldn’t be much more difficult than converting one of them in manually in photoshop and recording the action.


#3

Funny, I had a project that let users use non-power of two images. There is a lib for nVidia cards that deals with this. It basicly just resized the image on load, or added to it to make up the difference.


#4
#include <maya/MImage.h>
   #include <maya/MItDependencyNodes.h>
  #include <maya/MFnDependencyNode.h>
  
  unsigned GetBestP2(unsigned  dim) {
    if(dim>=512) return 512;
     if(dim>=256) return 256;
     if(dim>=128) return 128;
     if(dim>=64) return 64;
     if(dim>=32) return 32;
     if(dim>=16) return 16;
      if(dim>=8) return 8;
      if(dim>=4) return 4;
       if(dim>=2) return 2;
    return 1;
  }
  MString ExtFromFilename(MString filename)
  {
     unsigned len = filename.length();
     const char* str = filename.asChar();
     while(str[len] != '.') == len;
     return str+len+1;
  }
  void BlatMyTextureFiles()
  {
    MItDependencyNodes it(MFn::kFileTexture);
    while( !it.isDone() ) {
  	 MFnDependencyNode fn( it.item() );
  	 MPlug ftn = fn.findPlug("ftn");
  	 MString filename;
  	 ftn.getValue(filename);
  	 MImage img;
  	 if( img.readFromFile(filename) == MS::kSuccess)
  	 {
  	   unsigned w,h;
  	   img.getSize(w,h);
  	   img.resize( GetBestP2(w), GetBestP2(h), false );
  	   img.writeToFile(filename,ExtFromFilename(filename));
  	   img.release();
  	 }
  	 it.next();
    }
  }
  

or summit like that


#5

actually nvidia cards don’t care what sizes your textures are. consoles do though.


#6

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.