Updated to worldwind release 20070817
[worldwind-tracker.git] / gov / nasa / worldwind / formats / nitfs / NitfsImageBand.java
bloba4f65833c219e011094cb3ac82ba9280475dc202
1 package gov.nasa.worldwind.formats.nitfs;
3 /*
4 Copyright (C) 2001, 2007 United States Government
5 as represented by the Administrator of the
6 National Aeronautics and Space Administration.
7 All Rights Reserved.
8 */
10 /**
11 * @author Lado Garakanidze
12 * @version $Id: NitfsImageBand Apr 17, 2007 3:22:33 PM lado
14 class NitfsImageBand
16 private String representation;
17 private String significanceForImageCategory;
18 private String imageFilterCondition;
19 private String stdImageFilterCode;
20 private short numOfLookupTables;
21 private short numOfLookupTableEntries;
22 // public int[] lookupTablesOffset; // one byte per entry per band
23 private byte[][] lut;
25 private boolean isGrayImage;
26 private boolean hasTransparentEntry;
28 public boolean isGrayImage()
30 return this.isGrayImage;
33 public boolean isHasTransparentEntry()
35 return this.hasTransparentEntry;
38 public String getRepresentation()
40 return this.representation;
43 public short getNumOfLookupTables()
45 return this.numOfLookupTables;
48 public short getNumOfLookupTableEntries()
50 return this.numOfLookupTableEntries;
53 public NitfsImageBand(java.nio.ByteBuffer buffer)
55 this.representation = NitfsUtil.getString(buffer, 2);
56 this.significanceForImageCategory = NitfsUtil.getString(buffer, 6);
57 this.imageFilterCondition = NitfsUtil.getString(buffer, 1);
58 this.stdImageFilterCode = NitfsUtil.getString(buffer, 3);
59 this.numOfLookupTables = NitfsUtil.getShortNumeric(buffer, 1);
60 this.numOfLookupTableEntries = NitfsUtil.getShortNumeric(buffer, 5);
61 if (0 < this.numOfLookupTables && 0 < this.numOfLookupTableEntries)
63 this.lut = new byte[this.numOfLookupTables][this.numOfLookupTableEntries];
64 for (int j = 0; j < this.numOfLookupTables; j++)
66 buffer.get(this.lut[j], 0, this.numOfLookupTableEntries);
70 this.isGrayImage = (1 == this.numOfLookupTables);
71 this.hasTransparentEntry = (217 == this.numOfLookupTableEntries);
74 public final int lookupR5G6B5(int colorIndex)
76 int r, g, b;
77 if (3 == this.numOfLookupTables)
79 r = (0x00FF & this.lut[0][colorIndex]) >> 3;
80 g = (0x00FF & this.lut[1][colorIndex]) >> 2;
81 b = (0x00FF & this.lut[2][colorIndex]) >> 3;
83 else
85 int gray = 0x00FF & this.lut[0][ colorIndex ];
86 r = gray >> 3;
87 g = gray >> 2;
88 b = gray >> 3;
90 return 0x00FFFF & ((r << 11) | (g << 5) | b );
94 public final int lookupRGB(int colorIndex)
96 int r, g, b;
97 if (3 == this.numOfLookupTables)
99 r = (0x00FF & this.lut[0][colorIndex]);
100 g = (0x00FF & this.lut[1][colorIndex]);
101 b = (0x00FF & this.lut[2][colorIndex]);
103 else
105 r = g = b = 0x00FF & this.lut[0][ colorIndex ];
107 return (int) (0x00FFFFFFL & (long)((r << 16) | (g << 8) | b ));
110 public final int lookupGray(int colorIndex)
113 if (3 == this.numOfLookupTables)
115 int r = (0x00FF & this.lut[0][colorIndex]);
116 int g = (0x00FF & this.lut[1][colorIndex]);
117 int b = (0x00FF & this.lut[2][colorIndex]);
119 return (30 * r + 59 * g + 11 * b)/100;
121 else
123 return (0x00FF & this.lut[0][colorIndex]);