/[libvob]/libvob/vob/util/mipzipmaker.py
ViewVC logotype

Diff of /libvob/vob/util/mipzipmaker.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by tjl, Tue Apr 15 13:54:20 2003 UTC revision 1.2 by tjl, Tue Apr 22 19:49:12 2003 UTC
# Line 54  def chomp4(n): Line 54  def chomp4(n):
54      n /= 4      n /= 4
55      return 4 * n      return 4 * n
56    
57    def _init(w):
58        global format, suffix
59    
60        if GL.workaroundStupidBuggyAtiDrivers:
61            format = "RGB"
62            suffix = ".mipzipBLAH"
63        else:
64            format = "COMPRESSED_RGB_S3TC_DXT1_EXT"
65            suffix = ".mipzip"
66    
67    def makeMipzip(image, mipzip):
68        GL.freeQueue()
69    
70        im = GL.createImage(texfile)
71        d = im.getSize();
72        print d
73        w = roundup2(d.width)
74        h = roundup2(d.height)
75        tex = GL.createTexture()
76        tex.loadNull2D(0, format, w, h, 0, "RGB", "BYTE")
77        print "WH: ",w, h
78        tex.loadSubImage(0, im, 0, 0, 0, 0, chomp4(d.width), chomp4(d.height))
79    
80        print "Write ",of
81    
82        out = zip.ZipOutputStream(io.FileOutputStream(of))
83    
84        entry = zip.ZipEntry("texformat")
85        entry.setComment(format)
86        entry.setSize(0)
87        out.putNextEntry(entry)
88        out.closeEntry()
89    
90        l = 0
91        while 1:
92            w = int(tex.getLevelParameter(l, "TEXTURE_WIDTH")[0])
93            h = int(tex.getLevelParameter(l, "TEXTURE_HEIGHT")[0])
94            print "WH: ", w, h
95            if GL.workaroundStupidBuggyAtiDrivers:
96                bytes = jarray.zeros(4 * w * h, "b")
97                tex.getTexImage(l, "RGB", "BYTE", bytes)
98            else:
99                bytes = tex.getCompressedTexImage(l)
100            print "Bytes: ",l, len(bytes)
101            entry = zip.ZipEntry(str(l))
102            entry.setComment("%sx%s" % (int(w),int(h)))
103            entry.setSize(len(bytes))
104            out.putNextEntry(entry)
105            out.write(bytes)
106            out.closeEntry()
107            if w == 1 and h == 1 : break
108            l += 1
109        out.close()
110        del tex
111        java.lang.System.gc()
112        GL.freeQueue()
113        
114    
115  class Main(Runnable):  class Main(Runnable):
116      def __init__(self, texfiles):      def __init__(self, texfiles):
117          self.texfiles = texfiles          self.texfiles = texfiles
118      def run(self):      def run(self):
         global format, suffix  
   
         if GL.workaroundStupidBuggyAtiDrivers:  
             format = "RGB"  
             suffix = ".mipzipBLAH"  
         else:  
             format = "COMPRESSED_RGB_S3TC_DXT1_EXT"  
             suffix = ".mipzip"  
119          w = gfxapi.createWindow()          w = gfxapi.createWindow()
120          for texfile in self.texfiles:          for texfile in self.texfiles:
121              self.handle(texfile)              self.handle(texfile)
122          System.exit(0)          System.exit(0)
123    
124      def handle(self, texfile):      def handle(self, texfile):
         GL.freeQueue()  
         im = GL.createImage(texfile)  
         d = im.getSize();  
         print d  
         w = roundup2(d.width)  
         h = roundup2(d.height)  
         tex = GL.createTexture()  
         tex.loadNull2D(0, format, w, h, 0, "RGB", "BYTE")  
         print "WH: ",w, h  
         tex.loadSubImage(0, im, 0, 0, 0, 0, chomp4(d.width), chomp4(d.height))  
   
125          of = texfile + suffix          of = texfile + suffix
126            makeMipzip(texfile, of)
127    
128          print "Write ",of  if __name__ == '__main__':
   
         out = zip.ZipOutputStream(io.FileOutputStream(of))  
   
         entry = zip.ZipEntry("texformat")  
         entry.setComment(format)  
         entry.setSize(0)  
         out.putNextEntry(entry)  
         out.closeEntry()  
129    
130          l = 0      opts, args = getopt.getopt(sys.argv[1:],
131          while 1:              vob.util.dbg.short,
132              w = int(tex.getLevelParameter(l, "TEXTURE_WIDTH")[0])              vob.util.dbg.long)
133              h = int(tex.getLevelParameter(l, "TEXTURE_HEIGHT")[0])      for o,a in opts:
134              print "WH: ", w, h          print "Opt: ",o,a
135              if GL.workaroundStupidBuggyAtiDrivers:          if o in vob.util.dbg.all:
136                  bytes = jarray.zeros(4 * w * h, "b")              vob.util.dbg.option(o,a)
                 tex.getTexImage(l, "RGB", "BYTE", bytes)  
             else:  
                 bytes = tex.getCompressedTexImage(l)  
             print "Bytes: ",l, len(bytes)  
             entry = zip.ZipEntry(str(l))  
             entry.setComment("%sx%s" % (int(w),int(h)))  
             entry.setSize(len(bytes))  
             out.putNextEntry(entry)  
             out.write(bytes)  
             out.closeEntry()  
             if w == 1 and h == 1 : break  
             l += 1  
         out.close()  
           
   
 opts, args = getopt.getopt(sys.argv[1:],  
         vob.util.dbg.short,  
         vob.util.dbg.long)  
 for o,a in opts:  
     print "Opt: ",o,a  
     if o in vob.util.dbg.all:  
         vob.util.dbg.option(o,a)  
137    
138    
139  gfxapi = vob.GraphicsAPI.getInstance()      gfxapi = vob.GraphicsAPI.getInstance()
140  gfxapi.startUpdateManager(Main(args))      gfxapi.startUpdateManager(Main(args))
141    

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26