Package com.sun.j3d.loaders.objectfile

Source Code of com.sun.j3d.loaders.objectfile.RgbFile

/*     */ package com.sun.j3d.loaders.objectfile;
/*     */
/*     */ import java.awt.color.ColorSpace;
/*     */ import java.awt.image.BufferedImage;
/*     */ import java.awt.image.ComponentColorModel;
/*     */ import java.awt.image.DataBufferByte;
/*     */ import java.awt.image.WritableRaster;
/*     */ import java.io.BufferedInputStream;
/*     */ import java.io.IOException;
/*     */ import java.io.InputStream;
/*     */
/*     */ class RgbFile extends BufferedInputStream
/*     */ {
/*     */   short dimension;
/*     */   short xSize;
/*     */   short ySize;
/*     */   short zSize;
/*     */   String filename;
/*     */   private static final int DEBUG = 0;
/*     */
/*     */   short getShort()
/*     */     throws IOException
/*     */   {
/*  70 */     int t1 = (short)read();
/*  71 */     if (t1 == -1) throw new IOException("Unexpected EOF");
/*  72 */     int t2 = (short)read();
/*  73 */     if (t2 == -1) throw new IOException("Unexpected EOF");
/*  74 */     return (short)(t1 << 8 | t2);
/*     */   }
/*     */
/*     */   byte getByte()
/*     */     throws IOException
/*     */   {
/*  81 */     int t = read();
/*  82 */     if (t == -1) throw new IOException("Unexpected EOF");
/*  83 */     return (byte)t;
/*     */   }
/*     */
/*     */   int getInt()
/*     */     throws IOException
/*     */   {
/*  90 */     int ret = 0;
/*  91 */     for (int i = 0; i < 4; i++) {
/*  92 */       int t = read();
/*  93 */       if (t == -1) throw new IOException("Unexpected EOF");
/*  94 */       ret = ret << 8 | t;
/*     */     }
/*  96 */     return ret;
/*     */   }
/*     */
/*     */   public BufferedImage getImage()
/*     */     throws IOException
/*     */   {
/* 103 */     short magic = getShort();
/*     */
/* 105 */     if (magic != 474) throw new IOException("Unrecognized file format.");
/*     */
/* 107 */     byte storage = getByte();
/*     */
/* 109 */     if (storage != 0) {
/* 110 */       throw new IOException("RLE Compressed files not supported");
/*     */     }
/* 112 */     byte bpc = getByte();
/* 113 */     this.dimension = getShort();
/* 114 */     this.xSize = getShort();
/* 115 */     this.ySize = getShort();
/* 116 */     this.zSize = getShort();
/* 117 */     int pixMin = getInt();
/* 118 */     int pixMax = getInt();
/* 119 */     skip(84L);
/* 120 */     int colorMap = getInt();
/*     */
/* 134 */     if ((pixMin != 0) || (pixMax != 255) || (colorMap != 0) || (bpc != 1)) {
/* 135 */       throw new IOException("Unsupported options in file");
/*     */     }
/* 137 */     skip(404L);
/*     */
/* 139 */     ComponentColorModel cm = null;
/* 140 */     if (this.zSize == 1)
/*     */     {
/* 142 */       ColorSpace cs = ColorSpace.getInstance(1003);
/*     */
/* 144 */       int[] nBits = { 8 };
/* 145 */       cm = new ComponentColorModel(cs, nBits, false, false, 1, 0);
/*     */     }
/* 149 */     else if (this.zSize == 2)
/*     */     {
/* 151 */       ColorSpace cs = ColorSpace.getInstance(1003);
/*     */
/* 153 */       int[] nBits = { 8, 8 };
/* 154 */       cm = new ComponentColorModel(cs, nBits, true, false, 3, 0);
/*     */     }
/* 158 */     else if (this.zSize == 3)
/*     */     {
/* 160 */       ColorSpace cs = ColorSpace.getInstance(1000);
/*     */
/* 162 */       int[] nBits = { 8, 8, 8 };
/* 163 */       cm = new ComponentColorModel(cs, nBits, false, false, 1, 0);
/*     */     }
/* 167 */     else if (this.zSize == 4)
/*     */     {
/* 169 */       ColorSpace cs = ColorSpace.getInstance(1000);
/*     */
/* 171 */       int[] nBits = { 8, 8, 8, 8 };
/* 172 */       cm = new ComponentColorModel(cs, nBits, true, false, 3, 0);
/*     */     }
/*     */     else
/*     */     {
/* 176 */       throw new IOException("Unsupported options in file");
/*     */     }
/*     */
/* 179 */     WritableRaster r = cm.createCompatibleWritableRaster(this.xSize, this.ySize);
/* 180 */     BufferedImage bi = new BufferedImage(cm, r, false, null);
/*     */
/* 183 */     byte[] image = ((DataBufferByte)r.getDataBuffer()).getData();
/* 184 */     for (short z = 0; z < this.zSize; z = (short)(z + 1)) {
/* 185 */       for (int y = this.ySize - 1; y >= 0; y--) {
/* 186 */         for (short x = 0; x < this.xSize; x = (short)(x + 1)) {
/* 187 */           int t = read();
/* 188 */           if (t == -1) throw new IOException("Unexpected EOF");
/* 189 */           image[(y * (this.xSize * this.zSize) + x * this.zSize + z)] = ((byte)t);
/*     */         }
/*     */       }
/*     */     }
/*     */
/* 194 */     return bi;
/*     */   }
/*     */
/*     */   public RgbFile(InputStream s)
/*     */   {
/* 201 */     super(s);
/*     */   }
/*     */ }

/* Location:           Z:\System\Library\Java\Extensions\j3dutils.jar
* Qualified Name:     com.sun.j3d.loaders.objectfile.RgbFile
* JD-Core Version:    0.6.2
*/
TOP

Related Classes of com.sun.j3d.loaders.objectfile.RgbFile

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.