/[libvob]/libvob/org/nongnu/libvob/gl/MipzipFile.java
ViewVC logotype

Diff of /libvob/org/nongnu/libvob/gl/MipzipFile.java

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

revision 1.1 by tjl, Mon Oct 6 08:50:38 2003 UTC revision 1.2 by tjl, Fri Oct 10 13:52:23 2003 UTC
# Line 60  public class MipzipFile { Line 60  public class MipzipFile {
60       */       */
61      private final File file;      private final File file;
62    
63      /** The sizes of the mipmap levels.      /** The dimensions of the mipmap levels.
64       * The length of this array is the number of levels in the file.       * The length of this array is the number of levels in the file.
65       */       */
66      Dimension[] levelSizes;      Dimension[] levelDimensions;
67    
68        /** The physical sizes (in bytes) of the mipmap levels.
69         * This is the size needed after zip decompression.
70         */
71        int[] levelSizes;
72    
73      /** The texture format stored in the file.      /** The texture format stored in the file.
74         * Interned string, can be compared with "==".
75       */       */
76      private final String texFormat;      private final String texFormat;
77    
# Line 102  public class MipzipFile { Line 108  public class MipzipFile {
108              }              }
109              ZipEntry e = zipFile.getEntry("texformat");              ZipEntry e = zipFile.getEntry("texformat");
110              if(e == null) throw new IOException("Invalid format: no texformat in mipzip");              if(e == null) throw new IOException("Invalid format: no texformat in mipzip");
111              this.texFormat = e.getComment();              this.texFormat = e.getComment().intern();
112              this.compressedFormat = texFormat.indexOf("COMPRESS") != -1;              this.compressedFormat = texFormat.indexOf("COMPRESS") != -1;
113    
114              e = zipFile.getEntry("origsize");              e = zipFile.getEntry("origsize");
# Line 131  public class MipzipFile { Line 137  public class MipzipFile {
137                  l.add(new Dimension(w, h));                  l.add(new Dimension(w, h));
138    
139              }              }
140              levelSizes = (Dimension[])l.toArray(new Dimension[l.size()]);              levelDimensions = (Dimension[])l.toArray(new Dimension[l.size()]);
141              if( levelSizes[levelSizes.length-1].width != 1 ||              levelSizes = new int[levelDimensions.length];
142                  levelSizes[levelSizes.length-1].height != 1 ) {              for(int i=0; i<levelDimensions.length; i++) {
143                    e = zipFile.getEntry(""+i);
144                    levelSizes[i] = (int)e.getSize();
145                }
146    
147                if( levelDimensions[levelDimensions.length-1].width != 1 ||
148                    levelDimensions[levelDimensions.length-1].height != 1 ) {
149                  throw new IOException("Not all levels there!");                  throw new IOException("Not all levels there!");
150              }              }
151              closeZipFile();              closeZipFile();
# Line 148  public class MipzipFile { Line 160  public class MipzipFile {
160    
161      /** Get the texture format as a GL string, without the GL_ prefix.      /** Get the texture format as a GL string, without the GL_ prefix.
162       * For example, "COMPRESSED_RGB_S3TC_DXT1_EXT'       * For example, "COMPRESSED_RGB_S3TC_DXT1_EXT'
163         * Returns an interned string for fast comparisons.
164       */       */
165      public String getTexFormat() {      public String getTexFormat() {
166          return texFormat;          return texFormat;
# Line 156  public class MipzipFile { Line 169  public class MipzipFile {
169      /** Get the number of mipmap levels in the file.      /** Get the number of mipmap levels in the file.
170       */       */
171      public int getNLevels() {      public int getNLevels() {
172          return levelSizes.length;          return levelDimensions.length;
173      }      }
174    
175      /** Get the size of the given mipmap level.      /** Get the texel dimensions of the given mipmap level.
176       */       */
177      public Dimension getLevelSize(int level) {      public Dimension getLevelDimension(int level) {
178          return (Dimension)(levelSizes[level].clone());          return (Dimension)(levelDimensions[level].clone());
179        }
180    
181        /** Get the physical size (in bytes) of a given mipmap level.
182         */
183        public int getLevelSize(int level) {
184            return levelSizes[level];
185      }      }
186    
187      /** Get the width of the original image inside      /** Get the width of the original image inside
# Line 182  public class MipzipFile { Line 201  public class MipzipFile {
201       * This class does NOT cache any of the binary data.       * This class does NOT cache any of the binary data.
202       */       */
203      synchronized public byte[] getLevelData(int level) throws IOException {      synchronized public byte[] getLevelData(int level) throws IOException {
204            return getLevelData(level, null);
205        }
206        /** Get the binary data from the given level into the given array.
207         * This class does NOT cache any of the binary data.
208         * If the array is too small or null, return a new, larger array
209         * (analogous to java.util.Collection.toArray).
210         */
211        synchronized public byte[] getLevelData(int level, byte[] into)
212                                            throws IOException {
213          String name = ""+level;          String name = ""+level;
214          synchronized(zlibLock) {          synchronized(zlibLock) {
215              openZipFile();              openZipFile();
216              ZipEntry e = zipFile.getEntry(name);              ZipEntry e = zipFile.getEntry(name);
217              byte[] loadedData = new byte[(int)e.getSize()];              int size = getLevelSize(level);
218                byte[] loadedData;
219                if(into != null || into.length >= size)
220                    loadedData = into;
221                else
222                    loadedData = new byte[(int)e.getSize()];
223              InputStream i = zipFile.getInputStream(e);              InputStream i = zipFile.getInputStream(e);
224              int offs = 0;              int offs = 0;
225              while(offs < loadedData.length) {              while(offs < loadedData.length) {

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