Package com.sun.j3d.loaders.lw3d

Source Code of com.sun.j3d.loaders.lw3d.TargaReader

/*     */ package com.sun.j3d.loaders.lw3d;
/*     */
/*     */ import com.sun.j3d.loaders.IncorrectFormatException;
/*     */ import com.sun.j3d.loaders.ParsingErrorException;
/*     */ import java.awt.Image;
/*     */ import java.awt.image.BufferedImage;
/*     */ import java.awt.image.DataBufferInt;
/*     */ import java.awt.image.WritableRaster;
/*     */ import java.io.BufferedInputStream;
/*     */ import java.io.DataInputStream;
/*     */ import java.io.FileInputStream;
/*     */ import java.io.FileNotFoundException;
/*     */ import java.io.IOException;
/*     */
/*     */ class TargaReader extends ParserObject
/*     */ {
/*     */   BufferedInputStream bufferedReader;
/*  68 */   Image theImage = null;
/*     */
/*     */   TargaReader(String fileName, int debugVals)
/*     */     throws FileNotFoundException
/*     */   {
/*  75 */     super(debugVals);
/*  76 */     debugOutputLn(1, "constructor");
/*  77 */     this.bufferedReader = new BufferedInputStream(new DataInputStream(new FileInputStream(fileName)));
/*     */
/*  79 */     if (this.bufferedReader != null)
/*  80 */       parseFile();
/*     */   }
/*     */
/*     */   Image getImage()
/*     */   {
/*  88 */     return this.theImage;
/*     */   }
/*     */
/*     */   void parseFile()
/*     */     throws IncorrectFormatException, ParsingErrorException
/*     */   {
/*     */     try
/*     */     {
/* 129 */       int idLength = this.bufferedReader.read();
/* 130 */       int colormapPresent = this.bufferedReader.read();
/* 131 */       int imageType = this.bufferedReader.read();
/* 132 */       this.bufferedReader.skip(9L);
/* 133 */       int width = this.bufferedReader.read() | this.bufferedReader.read() << 8;
/* 134 */       int height = this.bufferedReader.read() | this.bufferedReader.read() << 8;
/* 135 */       int depth = this.bufferedReader.read();
/* 136 */       int flags = this.bufferedReader.read();
/* 137 */       boolean bottomToTop = (flags & 0x20) == 0;
/* 138 */       boolean leftToRight = (flags & 0x10) == 0;
/* 139 */       this.bufferedReader.skip(idLength);
/*     */
/* 142 */       if ((colormapPresent == 1) || (imageType != 2) || ((depth != 24) && (depth != 32)))
/*     */       {
/* 147 */         throw new IncorrectFormatException("This format is not readable by the Lightwave loader.  Only 24- or 32-bit true-color uncompressed Targa images will work");
/*     */       }
/*     */
/* 154 */       BufferedImage bImage = new BufferedImage(width, height, 2);
/*     */
/* 156 */       int[] imageBits = ((DataBufferInt)bImage.getRaster().getDataBuffer()).getData();
/*     */
/* 162 */       for (int i = 0; i < height; i++)
/*     */       {
/*     */         int row;
/*     */         int row;
/* 163 */         if (bottomToTop)
/* 164 */           row = height - i - 1;
/*     */         else
/* 166 */           row = i;
/* 167 */         for (int j = 0; j < width; j++)
/*     */         {
/*     */           int column;
/*     */           int column;
/* 169 */           if (leftToRight)
/* 170 */             column = j;
/*     */           else {
/* 172 */             column = width - j - 1;
/*     */           }
/* 174 */           int blue = this.bufferedReader.read();
/* 175 */           int green = this.bufferedReader.read();
/* 176 */           int red = this.bufferedReader.read();
/* 177 */           int alpha = 255;
/* 178 */           if (depth == 32)
/* 179 */             alpha = this.bufferedReader.read();
/* 180 */           imageBits[(row * width + column)] = (alpha << 24 | red << 16 | green << 8 | blue);
/*     */         }
/*     */
/*     */       }
/*     */
/* 186 */       this.theImage = bImage;
/*     */     }
/*     */     catch (IOException e) {
/* 189 */       throw new ParsingErrorException(e.getMessage());
/*     */     }
/*     */   }
/*     */ }

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

Related Classes of com.sun.j3d.loaders.lw3d.TargaReader

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.