Your browser does not support JavaScript and this site utilizes JavaScript to build content and provide links to additional information. You should either enable JavaScript in your browser settings or use a browser that supports JavaScript in order to take full advantage of this site.
1 package com.imagero.uio.io; 2 import java.io.IOException ; 3 import java.io.InputStream ; 4 5 8 public class TargaRLEInputStream extends RLEInputStream { 9 10 int numSamples; 11 byte [] value; 12 boolean rawPacket; 13 int pixelSize; 14 int vindex; 15 16 public TargaRLEInputStream(InputStream in, int pixelSize) { 17 super(in); 18 this.pixelSize = pixelSize; 19 value = new byte[pixelSize]; 20 } 21 22 public int read() throws IOException { 23 if (numSamples == 0) { 24 int v = in.read(); 25 if(v == -1) { 26 return -1; 27 } 28 if ((v >> 7) == 1) { 29 for (int i = 0; i < value.length; i++) { 30 value[i] = (byte) in.read(); 31 } 32 numSamples = ((v & 0x7F) + 1) * pixelSize; 33 rawPacket = false; 34 } 35 else { 36 numSamples = (v + 1) * pixelSize; 37 rawPacket = true; 38 } 39 } 40 numSamples--; 41 if (rawPacket) { 42 return in.read(); 43 } 44 else { 45 int b = value[vindex++] & 0xFF; 46 if(vindex == pixelSize) { 47 vindex = 0; 48 } 49 return b; 50 } 51 } 52 } 53
| Popular Tags
|