9210的Micaps第15类调色板数据
来源:互联网 发布:淘宝紫米商学院怎么样 编辑:程序博客网 时间:2024/04/27 10:15
Diamond15.java
002 * *
003 * FUNCTION: 处理Micaps的第15类数据文件(调色板数据) *
004 * PACKAGE: cma.micaps.diamond *
005 * FILENAME: Diamond15.java *
006 * LANGUAGE: Java2 v1.4 *
007 * ORIGINAL: c++ *
008 * DESCRIPTION: Micaps diamond 15 data I/O *
009 * CREATE: 2001-07-18 2006-06-01 改写为 JAVA 版 *
010 * UPDATE: 2006-11-03 *
011 * AUTHOR: 刘泽军 (BJ0773@gmail.com) *
012 * *
013 *******************************************************************************/
014
015 package cma.micaps.diamond;
016
017 import java.io.*;
018 import java.util.*;
019 import java.lang.*;
020 import java.awt.Color;
021 import java.text.DecimalFormat;
022
023 import cma.common.atmos.*;
024 import cma.micaps.diamond.datatype.*;
025
026 public class Diamond15 {
027
028 public static String SYMBOL = "diamond"; //文件标志
029 public static int TYPE = 15; //文件类型
030 public static int COUNT = 512; //Micaps系统自定义的最大颜色数
031
032 public String title; //文件说明
033 public Color[] rgb; //颜色值
034
035 public String filename = "";
036
037 /**
038 * 功能:
039 * 根据云图像素点的byte值获得对应的颜色索引
040 * 参数:
041 * value - 像素点值
042 * 返回值:
043 * 颜色索引
044 * 说明:
045 *
046 */
047 public static int getIndex(byte value) {//云图像素点数据对应的颜色索引
048 int index = (new Byte(value)).intValue();
049 // -128 <= index <= 127
050 // 0 - 127 => 0 - 127
051 //-128 - -1 => 128 - 255
052 if( index < 0 ) index = index + 256;
053 if( index < 0 ) index = 0;
054 if( index > 255 ) index = 255;
055 return(index);
056 }
057
058 /**
059 * 功能:
060 * 获得指定索引号的颜色值
061 * 参数:
062 * index - 索引值
063 * 返回值:
064 * 对应RGB颜色值
065 */
066 public Color getColor(int index) {
067 return(rgb[index]);
068 }
069
070 /**
071 * 功能:
072 * 获得指定索引号的颜色值的红、绿、蓝色分量
073 * 参数:
074 * index - 索引值
075 * 返回值:
076 * 对应的红、绿、蓝色分量
077 */
078 public int getRed(int index) {
079 return(rgb[index].getRed());
080 }
081 public int getGreen(int index) {
082 return(rgb[index].getGreen());
083 }
084 public int getBlue(int index) {
085 return(rgb[index].getBlue());
086 }
087
088 /**
089 * 功能:
090 * 重新设置成员数据为缺省值
091 * 参数:
092 * 无
093 * 返回值:
094 * 无
095 */
096 public void reset() {
097 title = ""; //文件说明
098 filename = ""; //文件名
099 rgb = null; //颜色值
100 }
101
102 /**
103 * 功能:
104 * 类构造函数
105 * 参数:
106 * 无
107 * 返回值:
108 * 无
109 */
110 public Diamond15() {
111 reset();
112 }
113
114 /**
115 * 功能:
116 * 类构造函数
117 * 参数:
118 * fname - Micaps调色板文件名
119 * 返回值:
120 * 无
121 */
122 public Diamond15(String fname) {
123 reset();
124 loadFromFile(fname);
125 }
126
127 /**
128 * 功能:
129 * 读取Micaps调色板数据
130 * 参数:
131 * fname - Micaps调色板文件名
132 * 返回值:
133 * 是否读取成功
134 */
135 public boolean loadFromFile(String fname) {
136 if( !(new File(fname)).exists() ) {
137 System.out.println("Diamond15.java #137 : " + fname + " not found!");
138 return(false);
139 }
140 try {
141 Vector vectorData = new Vector();
142 InputStreamReader isReader = new InputStreamReader(new FileInputStream(fname), "gb2312");//支持汉字
143 BufferedReader bufReader = new BufferedReader(isReader);
144
145 String lineString;
146 StringTokenizer st;
147 while( null != ( lineString = bufReader.readLine() ) ) {
148 st = new StringTokenizer(lineString," /r/n");//按空格、回车、换行符号来分隔文件内容
149 while( st.hasMoreTokens() ) {
150 vectorData.add(st.nextToken());
151 }
152 }
153 isReader.close();
154
155 title = vectorData.size() >= 3 ? (String)vectorData.get(2) : "";//文件说明
156 int minLength = Math.min(vectorData.size(), 4 * COUNT + 3);//文件头长度为3项,文件内容为索引 红色分量 绿色分量 蓝色分量共4项
157 int maxIndex = 0;
158 int index = 0, rValue = 0, gValue = 0, bValue = 0;
159 for(int i=3;i<minLength;i=i+4) {
160 index = Integer.parseInt((String)vectorData.get(i+0));
161 maxIndex = Math.max(maxIndex, index);
162 }
163 if( maxIndex == 0 ) {
164 return(false);
165 }
166 rgb = new Color[maxIndex+1];
167 for(int i=0;i<=maxIndex;i++) {//赋缺省的灰度值
168 rgb[i] = new Color(i%256, i%256, i%256);
169 }
170 for(int i=3;i<minLength;i=i+4) {
171 index = Integer.parseInt((String)vectorData.get(i+0));
172 rValue = Integer.parseInt((String)vectorData.get(i+1)) % 256;
173 gValue = Integer.parseInt((String)vectorData.get(i+2)) % 256;
174 bValue = Integer.parseInt((String)vectorData.get(i+3)) % 256;
175 rgb[index] = new Color(rValue, gValue, bValue);
176 }
177 vectorData = null;
178 filename = fname;
179 return(true);
180 }
181 catch(Exception ex) {
182 System.out.println(ex.getMessage());
183 ex.printStackTrace();
184 reset();
185 return(false);
186 }
187 }
188
189 /**
190 * 功能:
191 * 获得Micaps调色板文件定义的颜色列表
192 * 参数:
193 * fname - 文件名
194 * 返回值:
195 * RGB数组
196 */
197 public static Color[] getColor(String fname) {
198 Diamond15 diamond15 = new Diamond15();
199 boolean enabled = diamond15.loadFromFile(fname);
200 return( enabled ? diamond15.rgb : null );
201 }
202
203 }
- 9210的Micaps第15类调色板数据
- 9210的Micaps第13类卫星云图数据
- 9210的Micaps第2类数据(高空填图)格式处理
- 处理9210的Micaps第一类数据格式(地面填图)
- 打算编写一gis的软件练练手,内容大致micaps的,项目暂定G-Micaps
- 第 16 章 调色板管理器
- 调色板的原理和调色板显示模式
- 神奇的的调色板
- 调色板的原理
- 调色板的原理
- 调色板的实现
- 调色板的原理
- 系统调色板的迷惑....
- 调色板的原理
- CPalette调色板的问题
- 调色板的原理
- 调色板的原理
- 简单的调色板
- VB ExeCuteLine
- 调用约定(calling convention)(转)
- WebLogic中SQL Server2000的JDBC Pool配置
- IIS 服务器的权限检查
- 一个比较不错的JS时间控件
- 9210的Micaps第15类调色板数据
- StreamWriter输出中文乱码
- 深入浅出VA函数的使用技巧
- 一个完整的DLL远程注入函数
- 今天注册了
- 禁止运行多个实例最简单的方法
- J2EE应用程序中的性能提升
- Oracle查询中rownum与Order by查询的关系
- C#面试题